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

Opaque QPX row identities (feature_id, psm_id, pg_id) More...

Classes

struct  Float32
 A float32 composite component. More...
 
struct  Null
 A composite component that is JSON null (a null column value) More...
 

Typedefs

using FeatureLinks = std::unordered_map< Int64, Int64 >
 The feature↔PSM edge of one QPX collection, as psm_id → feature_id.
 
using Value = std::variant< Null, std::string, Int64, Float32, std::vector< Int32 >, std::vector< std::string > >
 JSON array of strings (grouped_runs)
 

Functions

std::string formatFloat (float value)
 Render one float32 the way Python's repr writes it inside JSON.
 
std::string canonical (const std::vector< Value > &values, const std::vector< size_t > &unordered_list_indices={})
 Canonical JSON encoding of an identity composite.
 
Int64 deriveId (const std::vector< Value > &values, const std::vector< size_t > &unordered_list_indices={})
 Derive an opaque signed 64-bit identity from a composite.
 
Int64 featureId (const std::string &run_file_name, const std::string &peptidoform, Int64 charge, std::optional< float > rt, const std::vector< Int32 > &scan, float observed_mz)
 feature_id from a feature row's persisted column values
 
Int64 psmId (const std::string &run_file_name, const std::vector< Int32 > &scan, const std::string &peptidoform, Int64 charge)
 psm_id from a psm row's persisted column values
 
Int64 pgId (const std::vector< std::string > &pg_accessions, const std::vector< std::string > &grouped_runs, const std::optional< std::string > &label)
 pg_id from a protein-group row's persisted column values
 

Variables

const char *const FEATURE_COMPOSITE
 Footer identity_composite for the feature view.
 
const char *const PSM_COMPOSITE
 Footer identity_composite for the psm view.
 
const char *const PG_COMPOSITE
 Footer identity_composite for the pg view.
 

Detailed Description

Opaque QPX row identities (feature_id, psm_id, pg_id)

Every QPX view carries a mandatory int64 identity column that is its primary key. The value is opaque – it is not meant to be parsed or reversed, only compared – and is derived deterministically from a footer-declared identity_composite of ordinary columns.

These functions reproduce qpx.core.data.identity byte for byte. That is a hard requirement, not a nicety. qpxc re-derives feature_id for identified rows from the declared composite, but never rewrites the psm.feature_id that points at it. An OpenMS collection whose ids were invented rather than derived would therefore turn into one with dangling cross-references the moment it was converted – which qpx's own dataset validation reports as dangling_feature_id.

The derivation is BLAKE2b truncated to 8 bytes over the canonical JSON encoding of the composite, read as a big-endian signed 64-bit integer. Negative values are normal and carry no meaning.

Note
Identity is meaningful within a file only. Two QPX files must not be joined on feature_id alone, and a test reference must not pin id values across files: the feature composite contains rt and observed_mz, so one ULP of platform drift changes the whole id rather than one digit of it.
Experimental classes:
This API is experimental and may change in future versions.

Class Documentation

◆ OpenMS::QPXIdentity::Float32

struct OpenMS::QPXIdentity::Float32

A float32 composite component.

Distinct from double so a caller cannot pass an unrounded value by accident: QPX hashes the value as persisted, so a column stored as float32 must be narrowed to float before it is encoded, whatever precision it was computed at.

Class Members
float value

◆ OpenMS::QPXIdentity::Null

struct OpenMS::QPXIdentity::Null

A composite component that is JSON null (a null column value)

Typedef Documentation

◆ FeatureLinks

using FeatureLinks = std::unordered_map<Int64, Int64>

The feature↔PSM edge of one QPX collection, as psm_id → feature_id.

Collected by ConsensusMapArrowExport::exportToArrow() / exportToParquet() / exportToParquetStreaming() through their out_links parameter, then handed to the psm exporter, which fills psm.feature_id from it. Keying on the id rather than on a pointer or a row index is what keeps the two directions consistent: both views derive the key from the same four persisted columns, so they agree by construction rather than by both happening to walk the identifications in the same order.

◆ Value

using Value = std::variant<Null, std::string, Int64, Float32, std::vector<Int32>, std::vector<std::string> >

JSON array of strings (grouped_runs)

Function Documentation

◆ canonical()

std::string canonical ( const std::vector< Value > &  values,
const std::vector< size_t > &  unordered_list_indices = {} 
)

Canonical JSON encoding of an identity composite.

Compact separators, ASCII-escaped strings – the exact bytes qpx hashes.

Parameters
[in]valuesThe composite components, in the order the composite declares
[in]unordered_list_indicesPositions whose list value is a set and is sorted before encoding. QPX uses this for grouped_runs; ordered lists such as scan keep their order.
Returns
The encoded composite, e.g. ["BSA1_F1",[2311],"PEPTIDER",2]

◆ deriveId()

Int64 deriveId ( const std::vector< Value > &  values,
const std::vector< size_t > &  unordered_list_indices = {} 
)

Derive an opaque signed 64-bit identity from a composite.

Parameters
[in]valuesThe composite components, in the order the composite declares
[in]unordered_list_indicesSet-valued positions, see canonical()
Returns
The identity; uniqueness is not guaranteed by construction but by the primary-key uniqueness check, which reports a collision rather than losing a row to it

◆ featureId()

Int64 featureId ( const std::string &  run_file_name,
const std::string &  peptidoform,
Int64  charge,
std::optional< float >  rt,
const std::vector< Int32 > &  scan,
float  observed_mz 
)

feature_id from a feature row's persisted column values

Composite: (run_file_name, peptidoform, charge, rt, scan, observed_mz). The floats are what make an unidentified feature row identifiable at all – such a row has an empty peptidoform and an empty scan, and its run and charge are shared with dozens of others.

Parameters
[in]run_file_nameBare run name (no directory, no extension)
[in]peptidoformProForma notation; empty for an unidentified feature
[in]chargeCharge state as persisted (int16)
[in]rtRetention time in seconds, or nullopt when the column is null
[in]scanScan components; empty for an unidentified feature
[in]observed_mzExperimental m/z

◆ formatFloat()

std::string formatFloat ( float  value)

Render one float32 the way Python's repr writes it inside JSON.

QPX encodes composites with json.dumps, which formats floats with float.__repr__: the shortest decimal that round-trips, switching to exponential notation when the decimal point would fall at position <= -4 or > 16, and appending ".0" to a value that would otherwise look like an integer. C++'s own general format picks between fixed and scientific by a different rule, so it cannot be used directly.

Parameters
[in]valueThe value as persisted; it is widened to double first, exactly as Arrow's cast + to_pylist does on the reading side
Returns
e.g. "0.1", "1000000000000000.0", "1e+16", "9.999e-05", "-0.0"

◆ pgId()

Int64 pgId ( const std::vector< std::string > &  pg_accessions,
const std::vector< std::string > &  grouped_runs,
const std::optional< std::string > &  label 
)

pg_id from a protein-group row's persisted column values

Composite: (pg_accessions, grouped_runs, label). Both lists are treated as sets – deduplicated and sorted by their JSON encoding – because neither the order in which a group lists its members nor the order of the runs aggregated into one quantity is part of the group's identity.

The FULL membership keys the id, not the leading protein alone. Two distinct groups that happen to share a leader (P1;P2 and P1;P3) would otherwise derive the same pg_id, and since the id is this view's primary key, that collision is a refused export rather than a merely inaccurate value.

Parameters
[in]pg_accessionsEvery accession in the group, in any order
[in]grouped_runsRaw files of this quantification unit, in any order
[in]labelChannel label, or nullopt for an identification-only group

◆ psmId()

Int64 psmId ( const std::string &  run_file_name,
const std::vector< Int32 > &  scan,
const std::string &  peptidoform,
Int64  charge 
)

psm_id from a psm row's persisted column values

Composite: (run_file_name, scan, peptidoform, charge) – no floats, so a psm identity is stable across platforms.

Parameters
[in]run_file_nameBare run name (no directory, no extension)
[in]scanScan components, in order
[in]peptidoformProForma notation
[in]chargePrecursor charge as persisted (int16)

Variable Documentation

◆ FEATURE_COMPOSITE

const char* const FEATURE_COMPOSITE
extern

Footer identity_composite for the feature view.

◆ PG_COMPOSITE

const char* const PG_COMPOSITE
extern

Footer identity_composite for the pg view.

◆ PSM_COMPOSITE

const char* const PSM_COMPOSITE
extern

Footer identity_composite for the psm view.