OpenMS
Loading...
Searching...
No Matches
ArrowIOHelpers.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Timo Sachsenberg $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/config.h>
14#include <OpenMS/FORMAT/MSExperimentArrowExport.h> // for ParquetWriteConfig
15
16#include <cstdint>
17#include <map>
18#include <memory>
19#include <string>
20#include <utility>
21#include <unordered_set>
22#include <vector>
23
24// Forward declarations
25namespace arrow
26{
27 class Array;
28 class KeyValueMetadata;
29 class Table;
30}
31
32namespace OpenMS
33{
34class ConsensusMap;
35class MetaInfoInterface;
36namespace MS1LabelState { struct Keys; }
37
47namespace ArrowIOHelpers
48{
56 OPENMS_DLLAPI std::string generateUuidV4();
57
70 OPENMS_DLLAPI Size tableRowCount(const std::shared_ptr<arrow::Table>& table);
71
80 OPENMS_DLLAPI bool writeTableToParquet(
81 const std::shared_ptr<arrow::Table>& table,
82 const std::string& filename,
83 const ParquetWriteConfig& config = ParquetWriteConfig{});
84
101 const std::vector<std::shared_ptr<arrow::Table>>& tables,
102 const std::string& filename,
103 const ParquetWriteConfig& config = ParquetWriteConfig{},
104 const std::shared_ptr<const arrow::KeyValueMetadata>& metadata = nullptr);
105
106 // ---------------------------------------------------------------------------
107 // QPX file metadata
108 // ---------------------------------------------------------------------------
109
132 OPENMS_DLLAPI std::shared_ptr<const arrow::KeyValueMetadata> qpxFileMetadata(
133 const std::string& file_type,
134 const ParquetWriteConfig& config = ParquetWriteConfig{},
135 const std::map<std::string, std::string>& extra = {});
136
146 OPENMS_DLLAPI std::string qpxScanFormat(const std::string& native_id);
147
155 OPENMS_DLLAPI std::string qpxScanFormat(const std::vector<std::string>& native_ids);
156
167 OPENMS_DLLAPI std::string qpxRunFileName(const std::string& ms_run_path);
168
185 OPENMS_DLLAPI std::vector<Int32> qpxScanComponents(const std::string& spectrum_reference);
186
203
224 OPENMS_DLLAPI std::string qpxPsmRunFileName(const MetaInfoInterface& hit,
225 const MetaInfoInterface& identification,
226 const std::string& resolved_run_file,
227 const QPXRunFileNameKeys& keys);
228
242 OPENMS_DLLAPI bool qpxWarnOnRunNameCollisions(
243 const std::string& context,
244 const std::vector<std::string>& ms_run_paths);
245
246
269 OPENMS_DLLAPI std::string qpxIntensityLabel(
270 const std::string& column_label,
271 const std::string& channel_name);
272
287 OPENMS_DLLAPI std::map<std::uint64_t, std::string> qpxIntensityLabels(
288 const ConsensusMap& cmap);
289
300 OPENMS_DLLAPI bool qpxIsCanonicalIntensityLabel(const std::string& label);
301
316 OPENMS_DLLAPI std::vector<std::pair<std::string, std::string>> qpxCvParams(const MetaInfoInterface& hit);
317
319 OPENMS_DLLAPI std::vector<std::pair<std::string, std::string>> qpxCvParams(const MetaInfoInterface& hit,
320 const MS1LabelState::Keys& keys);
321
322 // ---------------------------------------------------------------------------
323 // Read helpers
324 // ---------------------------------------------------------------------------
325
332 OPENMS_DLLAPI std::shared_ptr<arrow::Array> getColumn(
333 const std::shared_ptr<arrow::Table>& table,
334 const std::string& name,
335 bool required = true);
336
338 OPENMS_DLLAPI std::string getStringValue(
339 const std::shared_ptr<arrow::Array>& array,
340 int64_t row);
341
343 OPENMS_DLLAPI double getDoubleValue(
344 const std::shared_ptr<arrow::Array>& array,
345 int64_t row,
346 double default_val = 0.0);
347
349 OPENMS_DLLAPI float getFloatValue(
350 const std::shared_ptr<arrow::Array>& array,
351 int64_t row,
352 float default_val = 0.0f);
353
355 OPENMS_DLLAPI int32_t getInt32Value(
356 const std::shared_ptr<arrow::Array>& array,
357 int64_t row,
358 int32_t default_val = 0);
359
361 OPENMS_DLLAPI int64_t getInt64Value(
362 const std::shared_ptr<arrow::Array>& array,
363 int64_t row,
364 int64_t default_val = 0);
365
367 OPENMS_DLLAPI bool getBoolValue(
368 const std::shared_ptr<arrow::Array>& array,
369 int64_t row,
370 bool default_val = false);
371
373 OPENMS_DLLAPI bool isNull(
374 const std::shared_ptr<arrow::Array>& array,
375 int64_t row);
376
383 OPENMS_DLLAPI void readMetaValues(
384 const std::shared_ptr<arrow::Array>& array,
385 int64_t row,
386 MetaInfoInterface& target,
387 const std::unordered_set<std::string>& excluded_keys = {});
388}
389
390} // namespace OpenMS
A container for consensus elements.
Definition ConsensusMap.h:67
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:35
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
std::string qpxPsmRunFileName(const MetaInfoInterface &hit, const MetaInfoInterface &identification, const std::string &resolved_run_file, const QPXRunFileNameKeys &keys)
The QPX run_file_name the psm view writes for one identification and hit.
int32_t getInt32Value(const std::shared_ptr< arrow::Array > &array, int64_t row, int32_t default_val=0)
Read an int32 at row, or default_val if null.
bool writeTableToParquet(const std::shared_ptr< arrow::Table > &table, const std::string &filename, const ParquetWriteConfig &config=ParquetWriteConfig{})
Write an Arrow table to a Parquet file.
int64_t getInt64Value(const std::shared_ptr< arrow::Array > &array, int64_t row, int64_t default_val=0)
Read an int64 at row, or default_val if null.
bool getBoolValue(const std::shared_ptr< arrow::Array > &array, int64_t row, bool default_val=false)
Read a bool at row, or default_val if null.
std::vector< Int32 > qpxScanComponents(const std::string &spectrum_reference)
The QPX scan column value for one spectrum reference.
float getFloatValue(const std::shared_ptr< arrow::Array > &array, int64_t row, float default_val=0.0f)
Read a float at row, or default_val if null.
std::vector< std::pair< std::string, std::string > > qpxCvParams(const MetaInfoInterface &hit)
The meta values of an identification that QPX carries as cv_params.
double getDoubleValue(const std::shared_ptr< arrow::Array > &array, int64_t row, double default_val=0.0)
Read a double at row, or default_val if null.
std::string generateUuidV4()
Generate a lowercase hyphenated RFC 4122 version-4 UUID string.
void readMetaValues(const std::shared_ptr< arrow::Array > &array, int64_t row, MetaInfoInterface &target, const std::unordered_set< std::string > &excluded_keys={})
Read metavalues from a list<struct{name,value,value_type}> column.
std::shared_ptr< arrow::Array > getColumn(const std::shared_ptr< arrow::Table > &table, const std::string &name, bool required=true)
Fetch a named column from a table, combining chunks if needed.
std::string qpxIntensityLabel(const std::string &column_label, const std::string &channel_name)
QPX intensities[].label for a ConsensusMap column header.
std::string qpxRunFileName(const std::string &ms_run_path)
Reduce an MS run path to the QPX run_file_name form.
std::string getStringValue(const std::shared_ptr< arrow::Array > &array, int64_t row)
Read a string at row, or "" if null/out-of-bounds.
bool qpxIsCanonicalIntensityLabel(const std::string &label)
Test whether a string is in the canonical SDRF/QPX intensity-label vocabulary.
std::string qpxScanFormat(const std::string &native_id)
Classify a spectrum native ID into a QPX scan_format token.
bool concatenateAndWriteToParquet(const std::vector< std::shared_ptr< arrow::Table > > &tables, const std::string &filename, const ParquetWriteConfig &config=ParquetWriteConfig{}, const std::shared_ptr< const arrow::KeyValueMetadata > &metadata=nullptr)
Concatenate a vector of Arrow tables and write the result to a Parquet file.
std::shared_ptr< const arrow::KeyValueMetadata > qpxFileMetadata(const std::string &file_type, const ParquetWriteConfig &config=ParquetWriteConfig{}, const std::map< std::string, std::string > &extra={})
Build the canonical QPX file-level key-value metadata.
bool qpxWarnOnRunNameCollisions(const std::string &context, const std::vector< std::string > &ms_run_paths)
Warn once per export about source files that collapse onto one run_file_name.
bool isNull(const std::shared_ptr< arrow::Array > &array, int64_t row)
Whether array is null at row (or unset)
Size tableRowCount(const std::shared_ptr< arrow::Table > &table)
Number of rows in an Arrow table, or 0 when it is null.
std::map< std::uint64_t, std::string > qpxIntensityLabels(const ConsensusMap &cmap)
Derive canonical QPX intensity labels for every ConsensusMap column.
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition ArrowIOHelpers.h:26
MetaInfo indices qpxPsmRunFileName() consults, resolved once.
Definition ArrowIOHelpers.h:195
QPXRunFileNameKeys()
Resolve the keys against the current registry.
UInt run_file_name
Index of run_file_name, or UInt(-1) when it is not registered.
Definition ArrowIOHelpers.h:201
UInt reference_file_name
Index of reference_file_name, or UInt(-1) when it is not registered.
Definition ArrowIOHelpers.h:199
The registry indices of the three keys, resolved once for a loop over many hits.
Definition MS1LabelState.h:65
Configuration for Parquet file writing.
Definition MSExperimentArrowExport.h:136