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>
13#include <OpenMS/FORMAT/MSExperimentArrowExport.h> // for ParquetWriteConfig
14
15#include <cstdint>
16#include <map>
17#include <memory>
18#include <string>
19#include <unordered_set>
20#include <vector>
21
22// Forward declarations
23namespace arrow
24{
25 class Array;
26 class KeyValueMetadata;
27 class Table;
28}
29
30namespace OpenMS
31{
32class ConsensusMap;
33class MetaInfoInterface;
34
44namespace ArrowIOHelpers
45{
53 OPENMS_DLLAPI std::string generateUuidV4();
54
67 OPENMS_DLLAPI Size tableRowCount(const std::shared_ptr<arrow::Table>& table);
68
77 OPENMS_DLLAPI bool writeTableToParquet(
78 const std::shared_ptr<arrow::Table>& table,
79 const std::string& filename,
80 const ParquetWriteConfig& config = ParquetWriteConfig{});
81
97 OPENMS_DLLAPI bool concatenateAndWriteToParquet(
98 const std::vector<std::shared_ptr<arrow::Table>>& tables,
99 const std::string& filename,
100 const ParquetWriteConfig& config = ParquetWriteConfig{},
101 const std::shared_ptr<const arrow::KeyValueMetadata>& metadata = nullptr);
102
103 // ---------------------------------------------------------------------------
104 // QPX file metadata
105 // ---------------------------------------------------------------------------
106
124 OPENMS_DLLAPI std::shared_ptr<const arrow::KeyValueMetadata> qpxFileMetadata(
125 const std::string& file_type,
126 const ParquetWriteConfig& config = ParquetWriteConfig{},
127 const std::map<std::string, std::string>& extra = {});
128
138 OPENMS_DLLAPI std::string qpxScanFormat(const std::string& native_id);
139
147 OPENMS_DLLAPI std::string qpxScanFormat(const std::vector<std::string>& native_ids);
148
159 OPENMS_DLLAPI std::string qpxRunFileName(const std::string& ms_run_path);
160
174 OPENMS_DLLAPI bool qpxWarnOnRunNameCollisions(
175 const std::string& context,
176 const std::vector<std::string>& ms_run_paths);
177
178
201 OPENMS_DLLAPI std::string qpxIntensityLabel(
202 const std::string& column_label,
203 const std::string& channel_name);
204
219 OPENMS_DLLAPI std::map<std::uint64_t, std::string> qpxIntensityLabels(
220 const ConsensusMap& cmap);
221
232 OPENMS_DLLAPI bool qpxIsCanonicalIntensityLabel(const std::string& label);
233
234 // ---------------------------------------------------------------------------
235 // Read helpers
236 // ---------------------------------------------------------------------------
237
244 OPENMS_DLLAPI std::shared_ptr<arrow::Array> getColumn(
245 const std::shared_ptr<arrow::Table>& table,
246 const std::string& name,
247 bool required = true);
248
250 OPENMS_DLLAPI std::string getStringValue(
251 const std::shared_ptr<arrow::Array>& array,
252 int64_t row);
253
255 OPENMS_DLLAPI double getDoubleValue(
256 const std::shared_ptr<arrow::Array>& array,
257 int64_t row,
258 double default_val = 0.0);
259
261 OPENMS_DLLAPI float getFloatValue(
262 const std::shared_ptr<arrow::Array>& array,
263 int64_t row,
264 float default_val = 0.0f);
265
267 OPENMS_DLLAPI int32_t getInt32Value(
268 const std::shared_ptr<arrow::Array>& array,
269 int64_t row,
270 int32_t default_val = 0);
271
273 OPENMS_DLLAPI int64_t getInt64Value(
274 const std::shared_ptr<arrow::Array>& array,
275 int64_t row,
276 int64_t default_val = 0);
277
279 OPENMS_DLLAPI bool getBoolValue(
280 const std::shared_ptr<arrow::Array>& array,
281 int64_t row,
282 bool default_val = false);
283
285 OPENMS_DLLAPI bool isNull(
286 const std::shared_ptr<arrow::Array>& array,
287 int64_t row);
288
295 OPENMS_DLLAPI void readMetaValues(
296 const std::shared_ptr<arrow::Array>& array,
297 int64_t row,
298 MetaInfoInterface& target,
299 const std::unordered_set<std::string>& excluded_keys = {});
300}
301
302} // 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
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
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.
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:24
Configuration for Parquet file writing.
Definition MSExperimentArrowExport.h:136