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 <unordered_set>
21#include <vector>
22
23// Forward declarations
24namespace arrow
25{
26 class Array;
27 class KeyValueMetadata;
28 class Table;
29}
30
31namespace OpenMS
32{
33class ConsensusMap;
34class MetaInfoInterface;
35
45namespace ArrowIOHelpers
46{
54 OPENMS_DLLAPI std::string generateUuidV4();
55
68 OPENMS_DLLAPI Size tableRowCount(const std::shared_ptr<arrow::Table>& table);
69
78 OPENMS_DLLAPI bool writeTableToParquet(
79 const std::shared_ptr<arrow::Table>& table,
80 const std::string& filename,
81 const ParquetWriteConfig& config = ParquetWriteConfig{});
82
98 OPENMS_DLLAPI bool concatenateAndWriteToParquet(
99 const std::vector<std::shared_ptr<arrow::Table>>& tables,
100 const std::string& filename,
101 const ParquetWriteConfig& config = ParquetWriteConfig{},
102 const std::shared_ptr<const arrow::KeyValueMetadata>& metadata = nullptr);
103
104 // ---------------------------------------------------------------------------
105 // QPX file metadata
106 // ---------------------------------------------------------------------------
107
130 OPENMS_DLLAPI std::shared_ptr<const arrow::KeyValueMetadata> qpxFileMetadata(
131 const std::string& file_type,
132 const ParquetWriteConfig& config = ParquetWriteConfig{},
133 const std::map<std::string, std::string>& extra = {});
134
144 OPENMS_DLLAPI std::string qpxScanFormat(const std::string& native_id);
145
153 OPENMS_DLLAPI std::string qpxScanFormat(const std::vector<std::string>& native_ids);
154
165 OPENMS_DLLAPI std::string qpxRunFileName(const std::string& ms_run_path);
166
183 OPENMS_DLLAPI std::vector<Int32> qpxScanComponents(const std::string& spectrum_reference);
184
201
222 OPENMS_DLLAPI std::string qpxPsmRunFileName(const MetaInfoInterface& hit,
223 const MetaInfoInterface& identification,
224 const std::string& resolved_run_file,
225 const QPXRunFileNameKeys& keys);
226
240 OPENMS_DLLAPI bool qpxWarnOnRunNameCollisions(
241 const std::string& context,
242 const std::vector<std::string>& ms_run_paths);
243
244
267 OPENMS_DLLAPI std::string qpxIntensityLabel(
268 const std::string& column_label,
269 const std::string& channel_name);
270
285 OPENMS_DLLAPI std::map<std::uint64_t, std::string> qpxIntensityLabels(
286 const ConsensusMap& cmap);
287
298 OPENMS_DLLAPI bool qpxIsCanonicalIntensityLabel(const std::string& label);
299
300 // ---------------------------------------------------------------------------
301 // Read helpers
302 // ---------------------------------------------------------------------------
303
310 OPENMS_DLLAPI std::shared_ptr<arrow::Array> getColumn(
311 const std::shared_ptr<arrow::Table>& table,
312 const std::string& name,
313 bool required = true);
314
316 OPENMS_DLLAPI std::string getStringValue(
317 const std::shared_ptr<arrow::Array>& array,
318 int64_t row);
319
321 OPENMS_DLLAPI double getDoubleValue(
322 const std::shared_ptr<arrow::Array>& array,
323 int64_t row,
324 double default_val = 0.0);
325
327 OPENMS_DLLAPI float getFloatValue(
328 const std::shared_ptr<arrow::Array>& array,
329 int64_t row,
330 float default_val = 0.0f);
331
333 OPENMS_DLLAPI int32_t getInt32Value(
334 const std::shared_ptr<arrow::Array>& array,
335 int64_t row,
336 int32_t default_val = 0);
337
339 OPENMS_DLLAPI int64_t getInt64Value(
340 const std::shared_ptr<arrow::Array>& array,
341 int64_t row,
342 int64_t default_val = 0);
343
345 OPENMS_DLLAPI bool getBoolValue(
346 const std::shared_ptr<arrow::Array>& array,
347 int64_t row,
348 bool default_val = false);
349
351 OPENMS_DLLAPI bool isNull(
352 const std::shared_ptr<arrow::Array>& array,
353 int64_t row);
354
361 OPENMS_DLLAPI void readMetaValues(
362 const std::shared_ptr<arrow::Array>& array,
363 int64_t row,
364 MetaInfoInterface& target,
365 const std::unordered_set<std::string>& excluded_keys = {});
366}
367
368} // 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.
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:25
MetaInfo indices qpxPsmRunFileName() consults, resolved once.
Definition ArrowIOHelpers.h:193
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:199
UInt reference_file_name
Index of reference_file_name, or UInt(-1) when it is not registered.
Definition ArrowIOHelpers.h:197
Configuration for Parquet file writing.
Definition MSExperimentArrowExport.h:136