Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions include/mzpeak/metadata/scans.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*

This file is part of the mzpeak project. It is subject to the license
specified in the LICENSE file which can be found in the top-level
directory of this repository.

*/

#pragma once

#include <memory>
#include <vector>

namespace MzPeak::Util {
class Parquet;
}

namespace MzPeak::Metadata {

/**
* The method of precursor-ion selection and activation.
*/
class Scans final {
public:
/// Data for all scans.
struct Raw {
std::vector<float> scan_start_time;
};

/// Default constructor;
Scans();

/// Constructor.
Scans(std::unique_ptr<Util::Parquet>, uint64_t);

/**
* Return the raw table data for all scans.
*/
const Raw& raw() const { return raw_; }

private:
Raw raw_;
};

} // namespace MzPeak::Metadata
6 changes: 6 additions & 0 deletions include/mzpeak/metadata/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ class Spectrum final {
*/
const std::vector<double>& delta_model() const { return delta_model_; }

/**
* The scan time in minutes.
*/
std::optional<double> scan_time() const { return scan_time_; };

private:
std::optional<uint8_t> ms_level_;
std::optional<double> scan_time_;
std::vector<double> delta_model_;
};

Expand Down
95 changes: 65 additions & 30 deletions include/mzpeak/schema/data_kind.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,79 @@ directory of this repository.

#pragma once

#include <optional>
#include <string>
#include <variant>

namespace MzPeak::Schema {

/**
* Indicates how data is encoded in a parquet file.
*/
enum class DataKind {
/// Files that contain signal data.
DataArray,

/// Processed data (e.g. centroided). It is expected that the
/// unprocessed version of the data is present in the same MzPeak
/// file as a DataArray.
Peaks,

/// Metadata relating to one of the other files.
Metadata,

/// Non-standard file that can't be decoded by this library.
/// However, users of this library can access the raw bytes of
/// this file.
Proprietary,

/// Non-standard file that can't be decoded by this library.
/// However, users of this library can access the raw bytes of
/// this file.
Other
};
class DataKind final {
public:
enum Type {
/// Files that contain signal data.
DataArray,

/**
* Convert a DataKind to a string.
*/
std::string data_kind_to_string(DataKind);
/// Processed data (e.g. centroided). It is expected that the
/// unprocessed version of the data is present in the same MzPeak
/// file as a DataArray.
Peaks,

/**
* Parse a DataKind from a string view.
*/
DataKind data_kind_from_string(std::string_view);
/// Metadata relating to one of the other files.
Metadata,

/// A scan or acquisition from the original raw file used to
/// create a spectrum.
Scans,

/// The method of precursor-ion selection and activation.
Precursors,

/// An ion isolated for dissociation.
SelectedIons,

/// When describing single reaction monitoring (SRM) or multiple
/// reaction monitoring (MRM) experiments, each product ion is
/// isolated separately with a different isolation window. This
/// table is usually empty or absent
Products,

/// Non-standard file that can't be decoded by this library.
/// However, users of this library can access the raw bytes of
/// this file.
Proprietary,
};

// Internal storage type.
using value_type = std::variant<Type, std::string>;

/// Constructor.
DataKind(std::string_view);

/// Constructor.
DataKind(Type);

/**
* Return the string representation of the data kind.
*/
std::string to_string() const;

/**
* Return the enumerated type of the data kind if it is known.
*/
std::optional<Type> type() const;

/**
* Return `true` if this data kind is a known holder of metadata.
* For example, the `Scans` and `Precursors` type are both
* considered to be metadata.
*/
bool is_metadata() const;

private:
value_type val_;
};

} // namespace MzPeak::Schema
7 changes: 1 addition & 6 deletions include/mzpeak/schema/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ class File final {
/// Conversion from JSON.
explicit File(const json::object&);

/// Return `true` if this file is associated with the given file.
/// For example, if this file is a DataArray and the other file is a
/// Metadata file with a similar name.
bool is_associated_with(const File&) const;

/// Equality operator.
bool operator==(const File&) const;

Expand All @@ -57,7 +52,7 @@ class File final {

private:
std::string file_name_;
DataKind data_kind_ = DataKind::Other;
DataKind data_kind_ = DataKind("other");
EntityType entity_type_ = EntityType::Other;
std::vector<Column> columns_;
};
Expand Down
19 changes: 19 additions & 0 deletions include/mzpeak/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ top-level directory of this repository.
#include <vector>

#include "mzpeak/data/array_index.h"
#include "mzpeak/metadata/scans.h"

namespace MzPeak {

Expand Down Expand Up @@ -50,6 +51,22 @@ class Spectrum final {
*/
uint8_t ms_level() const;

/**
* Scan time in minutes.
*
* If the scan time was not stored in the spectra metadata then it
* will be fetched from the scans array.
*
* If the scan metadata is also empty then this method will return
* 0.0.
*/
double scan_time();

/**
* Return scan details.
*/
const Metadata::Scans& scans();

protected:
friend class Spectra;

Expand All @@ -66,6 +83,8 @@ class Spectrum final {
std::vector<double> mz_;
std::vector<float> intensity_;
uint8_t ms_level_;
std::optional<double> scan_time_;
std::optional<Metadata::Scans> scans_;
};

} // namespace MzPeak
8 changes: 7 additions & 1 deletion include/mzpeak/util/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ class Manager final {
/**
* Find a file given its name.
*/
std::vector<Schema::File>::const_iterator find_file(std::string_view name) const;
std::vector<Schema::File>::const_iterator find_file(std::string_view) const;

/**
* Find a file given its `EntityType` and `DataKind`.
*/
std::vector<Schema::File>::const_iterator find_file(Schema::EntityType,
Schema::DataKind::Type) const;

/**
* Open a Parquet file from the mzPeak archive.
Expand Down
Loading