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
7 changes: 4 additions & 3 deletions bin/mzp-inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ top-level directory of this repository.

#include "mzpeak.h"
#include "mzpeak/schema/group.h"
#include "mzpeak/util/manager.h" // IWYU pragma: keep

/******************************************************************************/
namespace po = boost::program_options;
Expand All @@ -22,14 +23,14 @@ namespace po = boost::program_options;
std::unique_ptr<MzPeak::Util::Parquet> open_parquet_file(MzPeak::Index& index,
const std::string& file)
{
auto it = std::ranges::find(index.files(), file, &MzPeak::Schema::File::file_name);
auto it = index.find(file);

if (it == index.files().end()) {
std::println(stderr, "file \"{}\" is not in the mzPeak file index", file);
return nullptr;
}

return index.parquet(*it);
return index.manager()->parquet(*it);
}

/******************************************************************************/
Expand All @@ -39,7 +40,7 @@ int print_array_index(MzPeak::Index& index, const std::string& file)
if (parquet == nullptr) return 1;

auto fmd = parquet->file_metadata();
auto et = parquet->index_file().entity_type;
auto et = parquet->index_file().entity_type();
auto key = MzPeak::Schema::entity_type_to_string(et) + "_array_index";
auto json = parquet->kv_string(fmd, key);

Expand Down
35 changes: 23 additions & 12 deletions include/mzpeak/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ directory of this repository.

#pragma once

#include "mzpeak/io/archive.h"
#include "mzpeak/schema/file.h"
#include "mzpeak/spectra.h"
#include "mzpeak/util/parquet.h"
#include <memory>
#include <vector>

namespace MzPeak {

// Internal implementation.
namespace IO {
class Archive;
}

namespace Schema {
class File;
}

namespace Util {
class Manager;
}

class Spectra;

/**
* Read-only access to the index inside a MzPeak archive.
Expand All @@ -25,27 +35,28 @@ class Index {
/// Constructor.
Index(std::unique_ptr<MzPeak::IO::Archive>);

/// Destructor.
~Index();

/**
* Return a list of files found in the index.
*/
const std::vector<Schema::File>& files() const;

/**
* Find a file in the mzPeak archive with the given name.
*/
std::vector<Schema::File>::const_iterator find(const std::string_view&) const;

/**
* Access the spectra in the file.
*/
Spectra spectra() const;

/**
* Open a Parquet file directly.
* Access the low-level MzPeak Manager object.
*/
std::unique_ptr<Util::Parquet> parquet(const Schema::File&) const;
std::shared_ptr<Util::Manager> manager() const;

protected:
struct Impl;
std::unique_ptr<Impl> impl_;
std::shared_ptr<Util::Manager> manager_;
};

} // namespace MzPeak
17 changes: 2 additions & 15 deletions include/mzpeak/metadata/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,18 @@ top-level directory of this repository.
#include <vector>

namespace MzPeak::Util {
class Slice;
}

namespace MzPeak::Schema {
class Group;
class Parquet;
}

namespace MzPeak::Metadata {

class Table;

/**
* Metadata from the spectrum table.
*/
class Spectrum final {
public:
/// Constructor.
Spectrum(std::shared_ptr<Table>, uint64_t);

/// Destructor.
~Spectrum() = default;
Spectrum(std::unique_ptr<Util::Parquet>, uint64_t);

/**
* Return the spectrum level (MS:1000511).
Expand All @@ -50,10 +41,6 @@ class Spectrum final {
const std::vector<double>& delta_model() const { return delta_model_; }

private:
std::shared_ptr<Table> table_;
std::shared_ptr<Schema::Group> group_;
uint64_t index_;

std::optional<uint8_t> ms_level_;
std::vector<double> delta_model_;
};
Expand Down
34 changes: 25 additions & 9 deletions include/mzpeak/schema/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ directory of this repository.
namespace MzPeak::Schema {
namespace json = boost::json;

struct File {
/**
* A description of a file in the mzPeak archive.
*/
class File final {
public:
struct Column {
std::string name;
std::string path;
std::optional<std::string> accession;
std::optional<std::string> unit;
};

/// Constructor from a file name.
explicit File(const std::string& name)
: file_name(name)
{
}
explicit File(const std::string& name);

/// Conversion from JSON.
explicit File(const json::object&);
Expand All @@ -34,16 +41,25 @@ struct File {
bool is_associated_with(const File&) const;

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

/// The name of this file.
std::string file_name;
const std::string& file_name() const { return file_name_; }

/// This file's data kind.
DataKind data_kind = DataKind::Other;
DataKind data_kind() const { return data_kind_; }

/// This file's entity type.
EntityType entity_type = EntityType::Other;
EntityType entity_type() const { return entity_type_; }

/// Column definitions for this file.
const std::vector<Column>& columns() const { return columns_; }

private:
std::string file_name_;
DataKind data_kind_ = DataKind::Other;
EntityType entity_type_ = EntityType::Other;
std::vector<Column> columns_;
};

} // namespace MzPeak::Schema
35 changes: 27 additions & 8 deletions include/mzpeak/schema/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ top-level directory of this repository.
#include <string>

#include "mzpeak/schema/cv.h"
#include "mzpeak/schema/file.h"
#include "mzpeak/util/types.h"

// Forward declarations.
namespace parquet::schema {
class Node;
class GroupNode;
} // namespace parquet::schema

Expand Down Expand Up @@ -87,16 +89,10 @@ class Group final {
*/
index_type absolute_index() const;

/**
* The name of this field using underscores to replace spaces and
* other special characters.
*/
const std::string& name() const;

/**
* The name of this field as recognized by parquet.
*/
const std::string& schema_name() const;
const std::string& name() const;

/**
* The structural type this field represents.
Expand Down Expand Up @@ -129,7 +125,6 @@ class Group final {
index_type rel_index_;
index_type abs_index_;
std::string schema_name_;
std::string clean_name_;
std::optional<CVType> cv_type_;
std::optional<CVUnit> cv_unit_;
std::optional<Util::Type> type_;
Expand All @@ -140,8 +135,13 @@ class Group final {
/// Fields are stored in a map for quick look-up using their name.
using field_map_t = std::map<std::string, std::shared_ptr<Field>>;

/// Constructor for the root group to hold all of the top-level
/// columns that are not in a separate struct/group.
explicit Group(const parquet::schema::GroupNode&, const Schema::File&);

/// Constructor from a parquet schema descriptor.
explicit Group(const parquet::schema::GroupNode&,
const Schema::File&,
index_type index,
index_type offset);

Expand Down Expand Up @@ -176,8 +176,27 @@ class Group final {
*/
const field_map_t& fields() const;

/**
* Return true if this is the root group.
*
* There is only one root group and its fields represent the
* top-level columns that are not themselves members of a group or
* struct.
*/
bool is_root() const;

/**
* Return a schema path to the given field. Mostly useful for error
* messages.
*/
std::string path(const Field&) const;

private:
void
make_fields(const parquet::schema::GroupNode&, const Schema::File&, index_type);

std::string name_;
bool is_root_;
index_type index_;
field_map_t fields_;
};
Expand Down
8 changes: 4 additions & 4 deletions include/mzpeak/spectra.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace MzPeak::Data {
class Signals;
} // namespace MzPeak::Data

namespace MzPeak::Metadata {
class Table;
namespace MzPeak::Util {
class Manager;
}

namespace MzPeak {
Expand All @@ -28,12 +28,12 @@ namespace MzPeak {
class Spectra final : public Util::EnumerableProxy<Spectrum> {
public:
/// Low-level constructor from a Parquet file.
explicit Spectra(std::unique_ptr<Data::Signals>, std::unique_ptr<Metadata::Table>);
explicit Spectra(std::unique_ptr<Data::Signals>, std::shared_ptr<Util::Manager>);

private:
// Internal data access.
std::shared_ptr<Data::Signals> data_;
std::shared_ptr<Metadata::Table> meta_;
std::shared_ptr<Util::Manager> manager_;

// Function to fetch a specific spectrum.
Spectrum fetch(uint64_t);
Expand Down
28 changes: 14 additions & 14 deletions include/mzpeak/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ top-level directory of this repository.
#pragma once

#include <memory>
#include <vector>

#include "mzpeak/data/array_index.h"
#include "mzpeak/data/encoding.h"
#include "mzpeak/data/signals.h"
#include "mzpeak/metadata/spectrum.h"
#include "mzpeak/metadata/table.h"
#include "mzpeak/util/slice.h"

namespace MzPeak {

// Forward declaration.
namespace Data {
class Signals;
} // namespace Data

namespace Util {
class Slice;
class Manager;
} // namespace Util

class Spectra;

/**
* Access to a single spectrum in an MzPeak file.
*/
class Spectrum final {
public:
/// The type of decoder used.
using decoder_type = Data::Encoding::Decoder<double>;

/// Destructor.
~Spectrum() = default;

Expand All @@ -54,18 +55,17 @@ class Spectrum final {

/// Internal constructor.
Spectrum(uint64_t index,
std::shared_ptr<Util::Manager>,
std::shared_ptr<Data::Signals>,
const std::vector<Data::ArrayIndex::Dimension>&,
std::unique_ptr<Util::Slice>,
std::shared_ptr<Metadata::Table>);
std::unique_ptr<Util::Slice>);

private:
uint64_t index_;
std::shared_ptr<Metadata::Table> md_table_;
Metadata::Spectrum md_spec_;
decoder_type decoder_;
std::shared_ptr<Util::Manager> manager_;
std::vector<double> mz_;
std::vector<float> intensity_;
uint8_t ms_level_;
};

} // namespace MzPeak
Loading