OpenMS
Loading...
Searching...
No Matches
OpenMS::ArrowIOHelpers Namespace Reference

Public helpers for writing and concatenating Arrow tables to Parquet files. More...

Functions

std::string generateUuidV4 ()
 Generate a lowercase hyphenated RFC 4122 version-4 UUID string.
 
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.
 
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.
 
std::string qpxScanFormat (const std::string &native_id)
 Classify a spectrum native ID into a QPX scan_format token.
 
std::string qpxScanFormat (const std::vector< std::string > &native_ids)
 Derive a single QPX scan_format token for a set of native IDs.
 
std::string qpxRunFileName (const std::string &ms_run_path)
 Reduce an MS run path to the QPX run_file_name form.
 
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.
 
std::string qpxIntensityLabel (const std::string &column_label, const std::string &channel_name)
 QPX intensities[].label for a ConsensusMap column header.
 
std::map< std::uint64_t, std::string > qpxIntensityLabels (const ConsensusMap &cmap)
 Derive canonical QPX intensity labels for every ConsensusMap column.
 
bool qpxIsCanonicalIntensityLabel (const std::string &label)
 Test whether a string is in the canonical SDRF/QPX intensity-label vocabulary.
 
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 getStringValue (const std::shared_ptr< arrow::Array > &array, int64_t row)
 Read a string at row, or "" if null/out-of-bounds.
 
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.
 
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.
 
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.
 
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.
 
bool isNull (const std::shared_ptr< arrow::Array > &array, int64_t row)
 Whether array is null at row (or unset)
 
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.
 

Detailed Description

Public helpers for writing and concatenating Arrow tables to Parquet files.

TOPP tools link against libOpenMS (which exports these helpers) but not directly against Arrow/Parquet. These wrappers keep all Arrow/Parquet API calls inside libOpenMS so downstream binaries don't need to import Arrow symbols.

Function Documentation

◆ concatenateAndWriteToParquet()

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.

All tables must share the same schema. An empty input vector is a no-op (returns true without writing).

Parameters
[in]tablesVector of Arrow tables to concatenate (must share schema)
[in]filenameOutput file path
[in]configParquet writer configuration
[in]metadataSchema key-value metadata for the merged file. Concatenation otherwise inherits the first input's metadata, i.e. that table's identity; pass a fresh one (see qpxFileMetadata()) so the merged file is its own. nullptr keeps whatever the concatenation produced.
Returns
true on success (or if tables is empty), false on error

◆ generateUuidV4()

std::string generateUuidV4 ( )

Generate a lowercase hyphenated RFC 4122 version-4 UUID string.

Used by QPX Parquet exporters when attaching file metadata.

Returns
UUID string, e.g. "550e8400-e29b-41d4-a716-446655440000"

◆ getBoolValue()

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.

◆ getColumn()

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.

Returns nullptr if the column is missing or contains no chunks. When required is true, missing columns are logged as errors.

◆ getDoubleValue()

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.

◆ getFloatValue()

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.

◆ getInt32Value()

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.

◆ getInt64Value()

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.

◆ getStringValue()

std::string getStringValue ( const std::shared_ptr< arrow::Array > &  array,
int64_t  row 
)

Read a string at row, or "" if null/out-of-bounds.

◆ isNull()

bool isNull ( const std::shared_ptr< arrow::Array > &  array,
int64_t  row 
)

Whether array is null at row (or unset)

◆ qpxFileMetadata()

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.

Writes the keys defined by the QPX serialization spec: qpx_version, file_type, creator, software_provider, creation_date (ISO 8601), compression_format and uuid, plus any extra keys.

Build this once per output file and reuse the returned object for both the writer schema and every batch — each call mints a fresh uuid and creation_date, so calling it per batch would produce mismatched schemas.

Parameters
[in]file_typeQPX view token: "psm_file", "feature_file" or "pg_file"
[in]configWrite configuration; supplies compression_format
[in]extraAdditional keys, e.g. {{"scan_format", "scan"}}
Returns
The metadata, or nullptr if config selects a compression QPX does not define (LZ4). Callers must treat nullptr as a write failure.

◆ qpxIntensityLabel()

std::string qpxIntensityLabel ( const std::string &  column_label,
const std::string &  channel_name 
)

QPX intensities[].label for a ConsensusMap column header.

The label is a join key: QPX matches intensities[].label against the unnested run.samples[].label of run.parquet (docs/spec/views.md), so it must be a canonical channel token, not a channel index or a file name.

Isobaric channels resolve to the reporter name prefixed by the method family, using OpenMS' own channel names — "TMT126", "TMT131" (TMT10-plex channel 10), "ITRAQ114". Label-free maps resolve to "LFQ". Recognizable SILAC modification labels resolve by mass class; callers that have a whole ConsensusMap should prefer qpxIntensityLabels(), which can distinguish a two-plex second channel (heavy by role) from a three-plex medium channel.

Parameters
[in]column_labelConsensusMap::ColumnHeader::label. IsobaricChannelExtractor writes "&lt;methodname&gt;_&lt;channelname&gt;" (e.g. "tmt10plex_126"); ProteomicsLFQ writes "label-free".
[in]channel_nameThe header's channel_name meta value (e.g. "126"); when it is absent from an isobaric header, the validated column_label suffix is used.
Returns
The label, or "" when the isobaric method, non-isobaric vocabulary token, or SILAC role cannot be identified — writing a guessed token into a join key is worse than writing none, so callers must handle the empty result.

◆ qpxIntensityLabels()

std::map< std::uint64_t, std::string > qpxIntensityLabels ( const ConsensusMap &  cmap)

Derive canonical QPX intensity labels for every ConsensusMap column.

Unlike the scalar overload, this sees all columns of one source run. It recognizes the FeatureFinderMultiplex SILAC shapes and maps them to the active SDRF/QPX vocabulary: "SILAC light" / "SILAC heavy" for two-plex and "SILAC light" / "SILAC medium" / "SILAC heavy" for three-plex. The mapping is by channel role, so a two-plex Arg6 channel is correctly called heavy even though the same modification is the medium channel in the standard three-plex.

Parameters
[in]cmapConsensusMap whose column headers are labelled
Returns
Map index to canonical label. An unrepresentable header maps to "" and is logged; exporters must refuse it.

◆ qpxIsCanonicalIntensityLabel()

bool qpxIsCanonicalIntensityLabel ( const std::string &  label)

Test whether a string is in the canonical SDRF/QPX intensity-label vocabulary.

Covers every isobaric method supported by OpenMS plus the QPX LFQ, SILAC, mTRAQ, and dimethyl plex labels. Intended for write-time value validation, after producer-specific labels have been normalized.

Parameters
[in]labelCandidate label
Returns
true if label is a canonical QPX channel token

◆ qpxRunFileName()

std::string qpxRunFileName ( const std::string &  ms_run_path)

Reduce an MS run path to the QPX run_file_name form.

QPX defines run_file_name as the raw data file name without extension, and uses it as a primary-key component in the psm, feature and pg views (and to join them against run.parquet). The full name with extension belongs in run.file_name.

Parameters
[in]ms_run_pathSource path, e.g. /data/proj/S1_Frontal_1.mzML
Returns
The stem, e.g. S1_Frontal_1; empty input yields an empty result.

Referenced by QuantificationUnits::QuantificationUnits().

◆ qpxScanFormat() [1/2]

std::string qpxScanFormat ( const std::string &  native_id)

Classify a spectrum native ID into a QPX scan_format token.

Parameters
[in]native_idA spectrum native ID (e.g. controllerType=0 ... scan=1234)
Returns
"index" for index= IDs, "scan" for other recognized native IDs, or "" when the convention cannot be determined.
See also
qpxScanFormat(const std::vector<std::string>&)

◆ qpxScanFormat() [2/2]

std::string qpxScanFormat ( const std::vector< std::string > &  native_ids)

Derive a single QPX scan_format token for a set of native IDs.

Unrecognized IDs are ignored. Returns "" when no ID is recognized, or when the inputs disagree — mixed conventions are reported once via the log rather than guessed at, so an ambiguous export omits scan_format instead of mislabeling it.

◆ qpxWarnOnRunNameCollisions()

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.

QPX defines the column as the file name without path or extension, so two distinct paths sharing a stem (/a/run1.mzML and /b/run1.mzML) become indistinguishable as a join and partition key. Same-named files in different directories are a legitimate layout and the origin is known – only the spec's representation cannot express it – so this warns rather than failing, matching the policy the PSM exporter already applies.

Parameters
[in]contextCaller name for the log line
[in]ms_run_pathsSource paths participating in one QPX collection
Returns
true if every distinct path yields a distinct run name

◆ readMetaValues()

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.

Decodes typed entries (int, double/float, *_list, string) and assigns them to target. Keys in excluded_keys are skipped.

◆ writeTableToParquet()

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.

Parameters
[in]tableThe Arrow table to write (must not be null)
[in]filenameOutput file path
[in]configParquet writer configuration (compression, row group size, ...)
Returns
true on success, false on error (errors are logged)