OpenMS  2.6.0
IdentificationDataConverter.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2020.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Hendrik Weisser $
32 // $Authors: Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 #include <OpenMS/FORMAT/MzTab.h>
42 
43 namespace OpenMS
44 {
45  class OPENMS_DLLAPI IdentificationDataConverter
46  {
47  public:
48 
50  static void importIDs(IdentificationData& id_data,
51  const std::vector<ProteinIdentification>& proteins,
52  const std::vector<PeptideIdentification>& peptides);
53 
55  static void exportIDs(const IdentificationData& id_data,
56  std::vector<ProteinIdentification>& proteins,
57  std::vector<PeptideIdentification>& peptides,
58  bool export_oligonucleotides = false);
59 
61  static MzTab exportMzTab(const IdentificationData& id_data);
62 
64  static void importSequences(IdentificationData& id_data,
65  const std::vector<FASTAFile::FASTAEntry>& fasta,
68  const String& decoy_pattern = "");
69 
70  protected:
71 
73  template <typename MzTabSectionRow>
76  std::vector<MzTabSectionRow>& output,
77  std::map<IdentificationData::ScoreTypeRef, Size>& score_map)
78  {
79  MzTabSectionRow row;
80  row.accession.set(parent.accession);
81  exportStepsAndScoresToMzTab_(parent.steps_and_scores, row.search_engine,
82  row.best_search_engine_score, score_map);
83  row.description.set(parent.description);
84  row.coverage.set(parent.coverage);
85  if (!parent.sequence.empty())
86  {
88  opt_seq.first = "opt_sequence";
89  opt_seq.second.set(parent.sequence);
90  row.opt_.push_back(opt_seq);
91  }
92  output.push_back(row);
93  }
94 
96  template <typename MzTabSectionRow, typename IdentSeq>
98  const IdentSeq& identified, std::vector<MzTabSectionRow>& output,
99  std::map<IdentificationData::ScoreTypeRef, Size>& score_map)
100  {
101  MzTabSectionRow row;
102  // @TODO: handle modifications properly
103  row.sequence.set(identified.sequence.toString());
104  exportStepsAndScoresToMzTab_(identified.steps_and_scores,
105  row.search_engine,
106  row.best_search_engine_score, score_map);
107  if (identified.parent_matches.empty()) // no parent information given
108  {
109  // row.unique.set(false); // leave this unset?
110  output.push_back(row);
111  }
112  else // generate entries (with duplicated data) for every accession
113  {
114  // in mzTab, "unique" means "peptide is unique for this protein"
115  row.unique.set(identified.parent_matches.size() == 1);
116  for (const auto& match_pair : identified.parent_matches)
117  {
118  row.accession.set(match_pair.first->accession);
119  for (const IdentificationData::MoleculeParentMatch& match :
120  match_pair.second)
121  {
122  MzTabSectionRow copy = row;
123  addMzTabMoleculeParentContext_(match, copy);
124  output.push_back(copy);
125  }
126  }
127  }
128  }
129 
131  template <typename MzTabSectionRow>
133  const String& sequence,
134  const IdentificationData::MoleculeQueryMatch& match, double calc_mass,
135  std::vector<MzTabSectionRow>& output,
136  std::map<IdentificationData::ScoreTypeRef, Size>& score_map,
137  std::map<IdentificationData::InputFileRef, Size>& file_map)
138  {
139  MzTabSectionRow xsm; // PSM or OSM
140  // @TODO: handle modifications properly
141  xsm.sequence.set(sequence);
142  exportStepsAndScoresToMzTab_(match.steps_and_scores, xsm.search_engine,
143  xsm.search_engine_score, score_map);
144  const IdentificationData::DataQuery& query = *match.data_query_ref;
145  std::vector<MzTabDouble> rts(1);
146  rts[0].set(query.rt);
147  xsm.retention_time.set(rts);
148  xsm.charge.set(match.charge);
149  xsm.exp_mass_to_charge.set(query.mz);
150  xsm.calc_mass_to_charge.set(calc_mass / abs(match.charge));
151  if (query.input_file_opt)
152  {
153  xsm.spectra_ref.setMSFile(file_map[*query.input_file_opt]);
154  }
155  xsm.spectra_ref.setSpecRef(query.data_id);
156  // @TODO: find a way of passing in the names of relevant meta values
157  // (e.g. from NucleicAcidSearchEngine), instead of hard-coding them here
158  static const std::vector<String> meta_out({"adduct", "isotope_offset"});
159  for (const String& meta : meta_out)
160  {
161  if (match.metaValueExists(meta))
162  {
163  MzTabOptionalColumnEntry opt_meta;
164  opt_meta.first = "opt_" + meta;
165  opt_meta.second.set(match.getMetaValue(meta));
166  xsm.opt_.push_back(opt_meta);
167  }
168  }
169  // don't repeat data from the peptide section (e.g. accessions)
170  // why are "pre"/"post"/"start"/"end" not in the peptide section?!
171  output.push_back(xsm);
172  }
173 
175  static void exportStepsAndScoresToMzTab_(
176  const IdentificationData::AppliedProcessingSteps& steps_and_scores,
177  MzTabParameterList& steps_out, std::map<Size, MzTabDouble>& scores_out,
178  std::map<IdentificationData::ScoreTypeRef, Size>& score_map);
179 
181  static void addMzTabSEScores_(
182  const std::map<IdentificationData::ScoreTypeRef, Size>& scores,
183  std::map<Size, MzTabParameter>& output);
184 
186  static void addMzTabMoleculeParentContext_(
189 
191  static void addMzTabMoleculeParentContext_(
194 
196  static IdentificationData::SearchParamRef importDBSearchParameters_(
198  IdentificationData& id_data);
199 
201  static ProteinIdentification::SearchParameters exportDBSearchParameters_(
203 
205  static void exportMSRunInformation_(
207  ProteinIdentification& protein);
208  };
209 }
OpenMS::IdentificationDataInternal::DataQuery::mz
double mz
Definition: DataQuery.h:55
OpenMS::IdentificationDataInternal::MoleculeType
MoleculeType
Definition: MetaData.h:63
OpenMS::IdentificationData::AppliedProcessingSteps
IdentificationDataInternal::AppliedProcessingSteps AppliedProcessingSteps
Definition: IdentificationData.h:123
OpenMS::MetaInfoInterface::getMetaValue
const DataValue & getMetaValue(const String &name, const DataValue &default_value=DataValue::EMPTY) const
Returns the value corresponding to a string, or a default value (default: DataValue::EMPTY) if not fo...
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::MzTabPeptideSectionRow
PEP - Peptide section (Table based)
Definition: MzTab.h:573
OpenMS::IdentificationDataInternal::PROTEIN
Definition: MetaData.h:65
OpenMS::IdentificationDataInternal::ScoredProcessingResult::steps_and_scores
AppliedProcessingSteps steps_and_scores
Definition: ScoredProcessingResult.h:46
OpenMS::MzTab
Data model of MzTab files. Please see the official MzTab specification at https://code....
Definition: MzTab.h:800
OpenMS::ProteinIdentification
Representation of a protein identification run.
Definition: ProteinIdentification.h:70
OpenMS::IdentificationDataConverter::exportPeptideOrOligoToMzTab_
static void exportPeptideOrOligoToMzTab_(const IdentSeq &identified, std::vector< MzTabSectionRow > &output, std::map< IdentificationData::ScoreTypeRef, Size > &score_map)
Export an identified sequence (peptide or oligonucleotide, but not small molecule/compound) to mzTab.
Definition: IdentificationDataConverter.h:97
OpenMS::IdentificationDataInternal::DataQuery::input_file_opt
boost::optional< InputFileRef > input_file_opt
Definition: DataQuery.h:53
OpenMS::IdentificationDataConverter::exportParentMoleculeToMzTab_
static void exportParentMoleculeToMzTab_(const IdentificationData::ParentMolecule &parent, std::vector< MzTabSectionRow > &output, std::map< IdentificationData::ScoreTypeRef, Size > &score_map)
Export a parent molecule (protein or nucleic acid) to mzTab.
Definition: IdentificationDataConverter.h:74
OpenMS::IdentificationDataInternal::ParentMolecule::accession
String accession
Definition: ParentMolecule.h:51
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::IdentificationDataInternal::DataQuery::data_id
String data_id
spectrum or feature ID (from the file referenced by "input_file_ref"):
Definition: DataQuery.h:50
FASTAFile.h
OpenMS::MzTabParameterList
Definition: MzTab.h:270
OpenMS::IdentificationDataInternal::IteratorWrapper
Wrapper that adds operator< to iterators, so they can be used as (part of) keys in maps/sets or multi...
Definition: MetaData.h:43
ProteinIdentification.h
OpenMS::IdentificationDataInternal::DataQuery
Search query, e.g. spectrum or feature.
Definition: DataQuery.h:47
OpenMS::IdentificationDataInternal::MoleculeQueryMatch
Meta data for a search hit (e.g. peptide-spectrum match).
Definition: MoleculeQueryMatch.h:61
MzTab.h
OpenMS::IdentificationDataInternal::ParentMolecule::coverage
double coverage
sequence coverage as a fraction between 0 and 1
Definition: ParentMolecule.h:61
OpenMS::IdentificationDataInternal::ParentMolecule
Representation of a parent molecule that is identified only indirectly (e.g. a protein).
Definition: ParentMolecule.h:49
OpenMS::IdentificationDataInternal::DataQuery::rt
double rt
Definition: DataQuery.h:55
OpenMS::IdentificationData
Representation of spectrum identification results and associated data.
Definition: IdentificationData.h:89
OpenMS::MetaInfoInterface::metaValueExists
bool metaValueExists(const String &name) const
Returns whether an entry with the given name exists.
OpenMS::MzTabOligonucleotideSectionRow
OLI - Oligonucleotide section (table-based)
Definition: MzTab.h:719
OpenMS::IdentificationDataInternal::MoleculeQueryMatch::data_query_ref
DataQueryRef data_query_ref
Definition: MoleculeQueryMatch.h:65
IdentificationData.h
OpenMS::IdentificationDataInternal::MoleculeParentMatch
Meta data for the association between an identified molecule (e.g. peptide) and a parent molecule (e....
Definition: MoleculeParentMatch.h:45
OpenMS::IdentificationDataConverter
Definition: IdentificationDataConverter.h:45
OpenMS::IdentificationDataInternal::ParentMolecule::description
String description
Definition: ParentMolecule.h:59
OpenMS::IdentificationDataInternal::MoleculeQueryMatch::charge
Int charge
Definition: MoleculeQueryMatch.h:67
PeptideIdentification.h
OpenMS::ProteinIdentification::SearchParameters
Search parameters of the DB search.
Definition: ProteinIdentification.h:258
OpenMS::MzTabOptionalColumnEntry
std::pair< String, MzTabString > MzTabOptionalColumnEntry
Definition: MzTab.h:531
OpenMS::IdentificationDataConverter::exportQueryMatchToMzTab_
static void exportQueryMatchToMzTab_(const String &sequence, const IdentificationData::MoleculeQueryMatch &match, double calc_mass, std::vector< MzTabSectionRow > &output, std::map< IdentificationData::ScoreTypeRef, Size > &score_map, std::map< IdentificationData::InputFileRef, Size > &file_map)
Export a molecule-query match (peptide- or oligonucleotide-spectrum match) to mzTab.
Definition: IdentificationDataConverter.h:132
OpenMS::IdentificationDataInternal::ParentMolecule::sequence
String sequence
Definition: ParentMolecule.h:57