OpenMS
Loading...
Searching...
No Matches
IdentificationData.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: Hendrik Weisser $
6// $Authors: Hendrik Weisser $
7// --------------------------------------------------------------------------
8
9#pragma once
10
24
25#include <unordered_set>
26
27namespace OpenMS
28{
70 template <typename ContainerType, typename PredicateType>
71 static void removeFromSetIf_(ContainerType& container, PredicateType predicate)
72 {
73 for (auto it = container.begin(); it != container.end(); )
74 {
75 if (predicate(it))
76 {
77 it = container.erase(it);
78 }
79 else
80 {
81 ++it;
82 }
83 }
84 }
85
86 class OPENMS_DLLAPI IdentificationData: public MetaInfoInterface
87 {
88 public:
89
90 // to be able to add overloads and still find the inherited ones
91 using MetaInfoInterface::setMetaValue;
92
93 // type definitions:
96
100
107
111
116
120
123
128
132
136
139
144
149
153
155
157
161
165
166 // @todo: allow multiple sets of groups, like with parent sequences
167 // ("ParentGroupSets")?
171
180
181 using AddressLookup = std::unordered_set<uintptr_t>;
182
185 std::map<InputFileRef, InputFileRef> input_file_refs;
186 std::map<ScoreTypeRef, ScoreTypeRef> score_type_refs;
187 std::map<ProcessingSoftwareRef, ProcessingSoftwareRef> processing_software_refs;
188 std::map<SearchParamRef, SearchParamRef> search_param_refs;
189 std::map<ProcessingStepRef, ProcessingStepRef> processing_step_refs;
190 std::map<ObservationRef, ObservationRef> observation_refs;
191 std::map<ParentSequenceRef, ParentSequenceRef> parent_sequence_refs;
192 std::map<IdentifiedPeptideRef, IdentifiedPeptideRef> identified_peptide_refs;
193 std::map<IdentifiedOligoRef, IdentifiedOligoRef> identified_oligo_refs;
194 std::map<IdentifiedCompoundRef, IdentifiedCompoundRef> identified_compound_refs;
195 std::map<AdductRef, AdductRef> adduct_refs;
196 std::map<ObservationMatchRef, ObservationMatchRef> observation_match_refs;
197
198 bool allow_missing = false;
199
201
203
204 };
205
208 current_step_ref_(processing_steps_.end()), no_checks_(false)
209 {
210 }
211
219
224
229
234
241
248 const ProcessingSoftware& software);
249
256
263 step);
264
272 const ProcessingStep& step, SearchParamRef search_ref);
273
280
287
294
297
304 peptide);
305
312 compound);
313
320
327
334
341
344 {
345 return input_files_;
346 }
347
350 {
351 return processing_softwares_;
352 }
353
356 {
357 return processing_steps_;
358 }
359
362 {
363 return db_search_params_;
364 }
365
368 {
369 return db_search_steps_;
370 }
371
374 {
375 return score_types_;
376 }
377
380 {
381 return observations_;
382 }
383
386 {
387 return parents_;
388 }
389
392 {
393 return parent_groups_;
394 }
395
398 {
399 return identified_peptides_;
400 }
401
404 {
405 return identified_compounds_;
406 }
407
410 {
411 return identified_oligos_;
412 }
413
415 const Adducts& getAdducts() const
416 {
417 return adducts_;
418 }
419
422 {
423 return observation_matches_;
424 }
425
428 {
429 return observation_match_groups_;
430 }
431
433 void addScore(ObservationMatchRef match_ref, ScoreTypeRef score_ref,
434 double value);
435
444
451
454
464 static bool observationMatchLess(const ObservationMatch& left, const ObservationMatch& right);
465
477 std::vector<ObservationMatchRef> getBestMatchPerObservation(ScoreTypeRef score_ref,
478 bool require_score = false) const;
479 // @todo: this currently doesn't take molecule type into account - should it?
480
482 std::pair<ObservationMatchRef, ObservationMatchRef> getMatchesForObservation(ObservationRef obs_ref) const;
483
491 template <typename PredicateType>
492 void removeObservationMatchesIf(PredicateType&& func)
493 {
494 auto count = observation_matches_.size();
495 removeFromSetIf_(observation_matches_, func);
496 if (count != observation_matches_.size()) cleanup();
497 }
498
506 template <typename PredicateType>
507 void removeParentSequencesIf(PredicateType&& func)
508 {
509 auto count = parents_.size();
510 removeFromSetIf_(parents_, func);
511 if (count != parents_.size()) cleanup();
512 }
513
514 template <typename PredicateType>
515 void applyToObservations(PredicateType&& func)
516 {
517 for (auto it = observations_.begin(); it != observations_.end(); ++it)
518 observations_.modify(it, func);
519 }
520
526 ScoreTypeRef findScoreType(const std::string& score_name) const;
527
529 void calculateCoverages(bool check_molecule_length = false);
530
542 void cleanup(bool require_observation_match = true,
543 bool require_identified_sequence = true,
544 bool require_parent_match = true,
545 bool require_parent_group = false,
546 bool require_match_group = false);
547
549 bool empty() const;
550
562
565
567 void clear();
568
584 template <class ScoredProcessingResults>
585 ScoreTypeRef pickScoreType(const ScoredProcessingResults& container,
586 bool all_elements = false, bool any_score = false) const
587 {
588 std::map<ScoreTypeRef, Size> score_counts;
589
590 if (any_score)
591 {
592 for (const auto& element : container)
593 {
594 for (const auto& step : element.steps_and_scores)
595 {
596 for (const auto& pair : step.scores)
597 {
598 score_counts[pair.first]++;
599 }
600 }
601 }
602 }
603 else
604 {
605 for (const auto& element : container)
606 {
607 auto score_info = element.getMostRecentScore();
608 if (std::get<2>(score_info)) // check success indicator
609 {
610 ScoreTypeRef score_ref = *std::get<1>(score_info); // unpack the option
611 if (!all_elements) return score_ref;
612 score_counts[score_ref]++; // elements are zero-initialized
613 }
614 }
615 }
616 if (score_counts.empty()) return score_types_.end();
617 auto pos = max_element(score_counts.begin(), score_counts.end());
618 // @TODO: break ties according to some criterion
619 return pos->first;
620 }
621
623 void setMetaValue(const ObservationMatchRef ref, const std::string& key, const DataValue& value);
624
626 void setMetaValue(const ObservationRef ref, const std::string& key, const DataValue& value);
627
629 void setMetaValue(const IdentifiedMolecule& var, const std::string& key, const DataValue& value);
630
631 // @TODO: add overloads for other data types derived from MetaInfoInterface
632
635 void removeMetaValue(const ObservationMatchRef ref, const std::string& key);
636
637 protected:
638
639 // containers:
644 // @TODO: store SearchParamRef inside ProcessingStep? (may not be required
645 // for many processing steps)
657
660
667
668 // look-up tables for fast checking of reference validity:
671 // @TODO: just use one "identified_molecule_lookup_" for all molecule types?
676
678 void checkScoreTypes_(const std::map<ScoreTypeRef, double>& scores) const;
679
682 steps_and_scores) const;
683
686 MoleculeType expected_type) const;
687
696 const ScoredProcessingResult& other,
697 const RefTranslator& trans);
698
704 template <typename ElementType>
706
712 template <typename ElementType>
714
720 template <typename ElementType>
722
724 template <typename ContainerType, typename ElementType>
725 typename ContainerType::iterator insertIntoMultiIndex_(ContainerType& container, const ElementType& element);
726
728 template <typename ContainerType, typename ElementType>
729 typename ContainerType::iterator insertIntoMultiIndex_(
730 ContainerType& container, const ElementType& element,
731 AddressLookup& lookup);
732
733 };
734
735}
Mass-arithmetic helper for ionizing adducts (e.g. [M+H]+, [2M-H]-, [M+2K-H]+).
Definition AdductInfo.h:91
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition DataValue.h:33
A collection of identification records, unique and ordered by the key formed from the members KeyMemb...
Definition IDDataContainer.h:62
Definition IdentificationData.h:87
ObservationRef registerObservation(const Observation &obs)
Register an observation (e.g. MS2 spectrum or feature)
IdentificationDataInternal::PeakAnnotations PeakAnnotations
Definition IdentificationData.h:156
DBSearchParams db_search_params_
Definition IdentificationData.h:643
void setMetaValue(const ObservationRef ref, const std::string &key, const DataValue &value)
Set a meta value on a stored observation.
ParentGroupSets parent_groups_
Definition IdentificationData.h:650
IdentificationDataInternal::ParentMatches ParentMatches
Definition IdentificationData.h:138
void calculateCoverages(bool check_molecule_length=false)
Calculate sequence coverages of parent sequences.
ProcessingSoftwares processing_softwares_
Definition IdentificationData.h:641
IdentificationData(const IdentificationData &other)
Copy constructor.
const ScoreTypes & getScoreTypes() const
Return the registered score types (immutable)
Definition IdentificationData.h:373
std::unordered_set< uintptr_t > AddressLookup
Definition IdentificationData.h:181
ProcessingSteps processing_steps_
Definition IdentificationData.h:642
IdentificationData(IdentificationData &&other) noexcept
Move constructor.
ObservationMatchGroups observation_match_groups_
Definition IdentificationData.h:656
const DBSearchParams & getDBSearchParams() const
Return the registered database search parameters (immutable)
Definition IdentificationData.h:361
ObservationMatches observation_matches_
Definition IdentificationData.h:655
void removeObservationMatchesIf(PredicateType &&func)
Helper function for filtering observation matches (e.g. PSMs) in IdentificationData.
Definition IdentificationData.h:492
const IdentifiedPeptides & getIdentifiedPeptides() const
Return the registered identified peptides (immutable)
Definition IdentificationData.h:397
IdentificationDataInternal::ScoreTypes ScoreTypes
Definition IdentificationData.h:118
const ParentGroupSets & getParentGroupSets() const
Return the registered parent sequence groupings (immutable)
Definition IdentificationData.h:391
AdductRef registerAdduct(const AdductInfo &adduct)
Register an adduct.
AddressLookup observation_match_lookup_
Definition IdentificationData.h:675
MatchGroupRef registerObservationMatchGroup(const ObservationMatchGroup &group)
Register a group of observation matches that belong together.
AddressLookup observation_lookup_
Definition IdentificationData.h:669
const IdentifiedCompounds & getIdentifiedCompounds() const
Return the registered compounds (immutable)
Definition IdentificationData.h:403
ProcessingStepRef registerProcessingStep(const ProcessingStep &step, SearchParamRef search_ref)
Register a database search step with associated parameters.
AddressLookup identified_oligo_lookup_
Definition IdentificationData.h:674
IdentifiedOligos identified_oligos_
Definition IdentificationData.h:653
bool no_checks_
Suppress validity checks in register... calls?
Definition IdentificationData.h:666
IdentificationData & operator=(IdentificationData &&other) noexcept
Move assignment operator.
void addScore(ObservationMatchRef match_ref, ScoreTypeRef score_ref, double value)
Add a score to an input match (e.g. PSM)
IdentifiedCompoundRef registerIdentifiedCompound(const IdentifiedCompound &compound)
Register an identified compound (small molecule)
ObservationMatchRef registerObservationMatch(const ObservationMatch &match)
Register an observation match (e.g. peptide-spectrum match)
IdentificationDataInternal::Adducts Adducts
Definition IdentificationData.h:158
IdentifiedOligoRef registerIdentifiedOligo(const IdentifiedOligo &oligo)
Register an identified RNA oligonucleotide.
bool empty() const
Return whether the data structure is empty (no data)
const ObservationMatchGroups & getObservationMatchGroups() const
Return the registered groups of observation matches (immutable)
Definition IdentificationData.h:427
Adducts adducts_
Definition IdentificationData.h:654
void setCurrentProcessingStep(ProcessingStepRef step_ref)
Set a data processing step that will apply to all subsequent "register..." calls.
const IdentifiedOligos & getIdentifiedOligos() const
Return the registered identified oligonucleotides (immutable)
Definition IdentificationData.h:409
void swap(IdentificationData &other)
Swap contents with a second instance.
ScoreTypeRef registerScoreType(const ScoreType &score)
Register a score type.
void applyToObservations(PredicateType &&func)
Definition IdentificationData.h:515
const ProcessingSoftwares & getProcessingSoftwares() const
Return the registered data processing software (immutable)
Definition IdentificationData.h:349
void setMetaValue(const IdentifiedMolecule &var, const std::string &key, const DataValue &value)
Set a meta value on a stored identified molecule (variant)
ScoreTypeRef findScoreType(const std::string &score_name) const
Look up a score type by name.
ProcessingStepRef registerProcessingStep(const ProcessingStep &step)
Register a data processing step.
IdentificationDataInternal::DBSearchParams DBSearchParams
Definition IdentificationData.h:113
IdentificationData()
Default constructor.
Definition IdentificationData.h:207
std::pair< ObservationMatchRef, ObservationMatchRef > getMatchesForObservation(ObservationRef obs_ref) const
Get range of matches (cf. equal_range) for a given observation.
IdentifiedCompounds identified_compounds_
Definition IdentificationData.h:652
DBSearchSteps db_search_steps_
Definition IdentificationData.h:646
ProcessingStepRef getCurrentProcessingStep()
Return the current processing step (set via setCurrentProcessingStep()).
ProcessingSoftwareRef registerProcessingSoftware(const ProcessingSoftware &software)
Register data processing software.
void checkParentMatches_(const ParentMatches &matches, MoleculeType expected_type) const
Helper function to check if all parent matches are valid.
Observations observations_
Definition IdentificationData.h:648
IdentificationDataInternal::ProcessingSteps ProcessingSteps
Definition IdentificationData.h:109
IdentificationDataInternal::DBSearchSteps DBSearchSteps
Definition IdentificationData.h:115
ParentSequenceRef registerParentSequence(const ParentSequence &parent)
Register a parent sequence (e.g. protein or intact RNA)
ScoreTypes score_types_
Definition IdentificationData.h:647
InputFiles input_files_
Definition IdentificationData.h:640
IdentificationDataInternal::AdductOpt AdductOpt
Definition IdentificationData.h:160
IdentificationDataInternal::ParentGroupSets ParentGroupSets
Definition IdentificationData.h:179
void mergeScoredProcessingResults_(ScoredProcessingResult &result, const ScoredProcessingResult &other, const RefTranslator &trans)
Helper function to merge scored processing results while updating references (to processing steps and...
ContainerType::iterator insertIntoMultiIndex_(ContainerType &container, const ElementType &element)
Helper function for adding entries (derived from ScoredProcessingResult) to a boost::multi_index_cont...
InputFileRef registerInputFile(const InputFile &file)
Register an input file.
IdentifiedPeptideRef registerIdentifiedPeptide(const IdentifiedPeptide &peptide)
Register an identified peptide.
const Observations & getObservations() const
Return the registered observations (immutable)
Definition IdentificationData.h:379
AddressLookup identified_peptide_lookup_
Definition IdentificationData.h:672
ContainerType::iterator insertIntoMultiIndex_(ContainerType &container, const ElementType &element, AddressLookup &lookup)
Variant of insertIntoMultiIndex_() that also updates a look-up table of valid references (addresses)
const ParentSequences & getParentSequences() const
Return the registered parent sequences (immutable)
Definition IdentificationData.h:385
ProcessingStepRef current_step_ref_
Reference to the current data processing step (see setCurrentProcessingStep())
Definition IdentificationData.h:659
const ObservationMatches & getObservationMatches() const
Return the registered observation matches (immutable)
Definition IdentificationData.h:421
void clear()
Clear all contents.
void clearCurrentProcessingStep()
Cancel the effect of setCurrentProcessingStep().
void cleanup(bool require_observation_match=true, bool require_identified_sequence=true, bool require_parent_match=true, bool require_parent_group=false, bool require_match_group=false)
Clean up the data structure after filtering parts of it.
IdentificationDataInternal::ProcessingSoftwares ProcessingSoftwares
Definition IdentificationData.h:104
void removeParentSequencesIf(PredicateType &&func)
Helper function for filtering parent sequences (e.g. protein sequences) in IdentificationData.
Definition IdentificationData.h:507
const Adducts & getAdducts() const
Return the registered adducts (immutable)
Definition IdentificationData.h:415
SearchParamRef registerDBSearchParam(const DBSearchParam &param)
Register database search parameters.
const InputFiles & getInputFiles() const
Return the registered input files (immutable)
Definition IdentificationData.h:343
void checkScoreTypes_(const std::map< ScoreTypeRef, double > &scores) const
Helper function to check if all score types are valid.
AddressLookup parent_lookup_
Definition IdentificationData.h:670
void checkAppliedProcessingSteps_(const AppliedProcessingSteps &steps_and_scores) const
Helper function to check if all applied processing steps are valid.
IdentificationData & operator=(const IdentificationData &other)
Copy assignment operator.
AddressLookup identified_compound_lookup_
Definition IdentificationData.h:673
const DBSearchSteps & getDBSearchSteps() const
Return the registered database search steps (immutable)
Definition IdentificationData.h:367
RefTranslator merge(const IdentificationData &other)
Merge in data from another instance.
std::vector< ObservationMatchRef > getBestMatchPerObservation(ScoreTypeRef score_ref, bool require_score=false) const
Return the best match for each observation, according to a given score type.
IdentifiedPeptides identified_peptides_
Definition IdentificationData.h:651
void registerParentGroupSet(const ParentGroupSet &groups)
Register a grouping of parent sequences (e.g. protein inference result)
void setMetaValue(const ObservationMatchRef ref, const std::string &key, const DataValue &value)
Set a meta value on a stored observation match (e.g. PSM)
ParentSequences parents_
Definition IdentificationData.h:649
static bool observationMatchLess(const ObservationMatch &left, const ObservationMatch &right)
Compare molecule, charge and adduct values for reproducible exact-score ties.
const ProcessingSteps & getProcessingSteps() const
Return the registered data processing steps (immutable)
Definition IdentificationData.h:355
ScoreTypeRef pickScoreType(const ScoredProcessingResults &container, bool all_elements=false, bool any_score=false) const
Definition IdentificationData.h:585
void removeMetaValue(const ObservationMatchRef ref, const std::string &key)
Helper functor for adding processing steps to elements in a boost::multi_index_container structure.
Definition IdentificationData.h:705
Helper functor for adding scores to elements in a boost::multi_index_container structure.
Definition IdentificationData.h:713
Helper functor for removing invalid parent matches from elements in a boost::multi_index_container st...
Definition IdentificationData.h:721
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:35
static void removeFromSetIf_(ContainerType &container, PredicateType predicate)
Representation of spectrum identification results and associated data.
Definition IdentificationData.h:71
std::map< ProcessingStepRef, SearchParamRef > DBSearchSteps
Definition DBSearchParam.h:75
std::optional< AdductRef > AdductOpt
Definition ObservationMatch.h:43
std::set< ScoreType > ScoreTypes
Definition ScoreType.h:71
std::set< DBSearchParam > DBSearchParams
Definition DBSearchParam.h:73
std::vector< PeptideHit::PeakAnnotation > PeakAnnotations
Definition ObservationMatch.h:25
MoleculeType
Definition MetaData.h:40
std::vector< ParentGroupSet > ParentGroupSets
Definition ParentGroup.h:48
std::map< ParentSequenceRef, std::set< ParentMatch > > ParentMatches
mapping: parent sequence -> match information
Definition ParentMatch.h:75
std::set< ProcessingStep > ProcessingSteps
Definition ProcessingStep.h:52
std::set< ProcessingSoftware > ProcessingSoftwares
Definition ProcessingSoftware.h:41
MassType
Definition MetaData.h:48
std::set< AdductInfo, AdductCompare > Adducts
Definition ObservationMatch.h:41
: Group of ambiguously identified parent sequences (e.g. protein group)
Definition ParentGroup.h:24
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Parameters specific to a database search step.
Definition DBSearchParam.h:29
Variant type holding Peptide/Compound/Oligo references and convenience functions.
Definition IdentifiedMolecule.h:29
Representation of an identified sequence (peptide or oligonucleotide)
Definition IdentifiedSequence.h:26
Information about input files that were processed.
Definition InputFile.h:25
: Group of related (co-identified) input matches
Definition ObservationMatchGroup.h:25
Representation of a search hit (e.g. peptide-spectrum match).
Definition ObservationMatch.h:47
Representation of an observation, e.g. a spectrum or feature, in an input data file.
Definition Observation.h:26
Set of groups of ambiguously identified parent sequences (e.g. results of running a protein inference...
Definition ParentGroup.h:36
Meta data for the association between an identified molecule (e.g. peptide) and a parent sequence (e....
Definition ParentMatch.h:20
Representation of a parent sequence that is identified only indirectly (e.g. a protein).
Definition ParentSequence.h:23
Information about software used for data processing.
Definition ProcessingSoftware.h:23
Data processing step that is applied to the data (e.g. database search, PEP calculation,...
Definition ProcessingStep.h:22
Information about a score type.
Definition ScoreType.h:26
Base class for ID data with scores and processing steps (and meta info)
Definition ScoredProcessingResult.h:23
structure that maps references of corresponding objects after copying
Definition IdentificationData.h:184
std::map< ObservationMatchRef, ObservationMatchRef > observation_match_refs
Definition IdentificationData.h:196
std::map< ProcessingSoftwareRef, ProcessingSoftwareRef > processing_software_refs
Definition IdentificationData.h:187
std::map< IdentifiedPeptideRef, IdentifiedPeptideRef > identified_peptide_refs
Definition IdentificationData.h:192
IdentifiedMolecule translate(IdentifiedMolecule old) const
std::map< ParentSequenceRef, ParentSequenceRef > parent_sequence_refs
Definition IdentificationData.h:191
ObservationMatchRef translate(ObservationMatchRef old) const
std::map< SearchParamRef, SearchParamRef > search_param_refs
Definition IdentificationData.h:188
std::map< ScoreTypeRef, ScoreTypeRef > score_type_refs
Definition IdentificationData.h:186
std::map< IdentifiedCompoundRef, IdentifiedCompoundRef > identified_compound_refs
Definition IdentificationData.h:194
std::map< ProcessingStepRef, ProcessingStepRef > processing_step_refs
Definition IdentificationData.h:189
std::map< AdductRef, AdductRef > adduct_refs
Definition IdentificationData.h:195
std::map< ObservationRef, ObservationRef > observation_refs
Definition IdentificationData.h:190
std::map< IdentifiedOligoRef, IdentifiedOligoRef > identified_oligo_refs
Definition IdentificationData.h:193
std::map< InputFileRef, InputFileRef > input_file_refs
Definition IdentificationData.h:185