Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MzTabFile.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-2017.
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: Timo Sachsenberg $
32 // $Authors: Timo Sachsenberg $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_FORMAT_MZTABFILE_H
36 #define OPENMS_FORMAT_MZTABFILE_H
37 
38 #include <OpenMS/FORMAT/MzTab.h>
39 
44 
45 #include <boost/math/special_functions/fpclassify.hpp>
46 
47 #include <vector>
48 #include <algorithm>
49 
50 namespace OpenMS
51 {
52  class String;
53  class SVOutStream;
59  class OPENMS_DLLAPI MzTabFile
60  {
61 public:
63  MzTabFile();
65  ~MzTabFile();
66 
67  typedef std::map<std::pair<String, String>, std::vector<PeptideHit> > MapAccPepType;
68 
69  // store MzTab file
70  void store(const String& filename, const MzTab& mz_tab) const;
71 
72  // Set store behaviour of optional "reliability" and "uri" columns (default=no)
73  void storeProteinReliabilityColumn(bool store);
74  void storePeptideReliabilityColumn(bool store);
75  void storePSMReliabilityColumn(bool store);
76  void storeSmallMoleculeReliabilityColumn(bool store);
77  void storeProteinUriColumn(bool store);
78  void storePeptideUriColumn(bool store);
79  void storePSMUriColumn(bool store);
80  void storeSmallMoleculeUriColumn(bool store);
81  void storeProteinGoTerms(bool store);
82 
83  // load MzTab file
84  void load(const String& filename, MzTab& mz_tab);
85 
86 protected:
96 
97  void generateMzTabMetaDataSection_(const MzTabMetaData& map, StringList& sl) const;
98 
99  void generateMzTabProteinSection_(const MzTabProteinSectionRows& rows, StringList& sl, const std::vector<String>& optional_columns) const;
100 
101  String generateMzTabProteinHeader_(const MzTabProteinSectionRow& reference_row, const Size n_best_search_engine_scores, const std::vector<String>& optional_columns) const;
102 
103  String generateMzTabProteinSectionRow_(const MzTabProteinSectionRow& row, const std::vector<String>& optional_columns) const;
104 
105  void generateMzTabPeptideSection_(const MzTabPeptideSectionRows& rows, StringList& sl, const std::vector<String>& optional_columns) const;
106 
107  String generateMzTabPeptideHeader_(Size search_ms_runs, Size n_best_search_engine_scores, Size n_search_engine_score, Size assays, Size study_variables, const std::vector<String>& optional_columns) const;
108 
109  String generateMzTabPeptideSectionRow_(const MzTabPeptideSectionRow& row, const std::vector<String>& optional_columns) const;
110 
111  void generateMzTabPSMSection_(const MzTabPSMSectionRows& rows, StringList& sl, const std::vector<String>& optional_columns) const;
112 
113  String generateMzTabPSMHeader_(Size n_search_engine_scores, const std::vector<String>& optional_columns) const;
114 
115  String generateMzTabPSMSectionRow_(const MzTabPSMSectionRow& row, const std::vector<String>& optional_columns) const;
116 
117  void generateMzTabSmallMoleculeSection_(const MzTabSmallMoleculeSectionRows& map, StringList& sl, const std::vector<String>& optional_columns) const;
118 
119  String generateMzTabSmallMoleculeHeader_(Size search_ms_runs, Size n_best_search_engine_scores, Size n_search_engine_score, Size assays, Size study_variables, const std::vector<String>& optional_columns) const;
120 
121  String generateMzTabSmallMoleculeSectionRow_(const MzTabSmallMoleculeSectionRow& row, const std::vector<String>& optional_columns) const;
122 
123  // auxiliary functions
124  // extract two integers from string (e.g. search_engine_score[1]_ms_run[2] -> 1,2)
125  static std::pair<int, int> extractIndexPairsFromBrackets_(const String& s);
126 
127  static void sortPSM_(std::vector<PeptideIdentification>::iterator begin, std::vector<PeptideIdentification>::iterator end);
128 
129  static void keepFirstPSM_(std::vector<PeptideIdentification>::iterator begin, std::vector<PeptideIdentification>::iterator end);
130 
132  static void partitionIntoRuns_(const std::vector<PeptideIdentification>& pep_ids,
133  const std::vector<ProteinIdentification>& pro_ids,
134  std::map<String, std::vector<PeptideIdentification> >& map_run_to_pepids,
135  std::map<String, std::vector<ProteinIdentification> >& map_run_to_proids
136  );
137 
138 
140  static void createProteinToPeptideLinks_(const std::map<String, std::vector<PeptideIdentification> >& map_run_to_pepids, MapAccPepType& map_run_accession_to_pephits);
141 
143  static String extractProteinAccession_(const PeptideHit& peptide_hit);
144 
146  static String extractPeptideModifications_(const PeptideHit& peptide_hit);
147 
149  static String mapSearchEngineToCvParam_(const String& openms_search_engine_name);
150 
151  static String mapSearchEngineScoreToCvParam_(const String& openms_search_engine_name, double score, String score_type);
152 
153  static String extractNumPeptides_(const String& common_identifier, const String& protein_accession,
154  const MapAccPepType& map_run_accession_to_peptides);
155 
156  // mzTab definition of distinct
157  static String extractNumPeptidesDistinct_(String common_identifier, String protein_accession,
158  const MapAccPepType& map_run_accession_to_peptides);
159 
160  // same as distinct but additional constraint of uniqueness (=maps to exactly one Protein)
161  static String extractNumPeptidesUnambiguous_(String common_identifier, String protein_accession,
162  const MapAccPepType& map_run_accession_to_peptides);
163 
164  static std::map<String, Size> extractNumberOfSubSamples_(const std::map<String, std::vector<ProteinIdentification> >& map_run_to_proids);
165 
166  static void writePeptideHeader_(SVOutStream& output, std::map<String, Size> n_sub_samples);
167 
168  static void writeProteinHeader_(SVOutStream& output, std::map<String, Size> n_sub_samples);
169 
170  static void writeProteinData_(SVOutStream& output,
171  const ProteinIdentification& prot_id,
172  Size run_count,
173  String input_filename,
174  bool has_coverage,
175  const MapAccPepType& map_run_accession_to_peptides,
176  const std::map<String, Size>& map_run_to_num_sub
177  );
178 
179  };
180 
181 } // namespace OpenMS
182 
183 #endif // OPENMS_FORMAT_MZTABFILE_H
Representation of a protein identification run.
Definition: ProteinIdentification.h:62
bool store_protein_reliability_
Definition: MzTabFile.h:87
A more convenient string class.
Definition: String.h:57
Definition: MzTab.h:579
bool store_smallmolecule_uri_
Definition: MzTabFile.h:94
std::vector< MzTabSmallMoleculeSectionRow > MzTabSmallMoleculeSectionRows
Definition: MzTab.h:692
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool store_protein_goterms_
Definition: MzTabFile.h:95
bool store_protein_uri_
Definition: MzTabFile.h:91
std::vector< MzTabProteinSectionRow > MzTabProteinSectionRows
Definition: MzTab.h:689
bool store_peptide_reliability_
Definition: MzTabFile.h:88
bool store_peptide_uri_
Definition: MzTabFile.h:92
Definition: MzTab.h:517
bool store_psm_reliability_
Definition: MzTabFile.h:89
Definition: MzTab.h:634
Representation of a peptide hit.
Definition: PeptideHit.h:55
File adapter for MzTab files.
Definition: MzTabFile.h:59
std::vector< MzTabPeptideSectionRow > MzTabPeptideSectionRows
Definition: MzTab.h:690
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
bool store_psm_uri_
Definition: MzTabFile.h:93
Definition: MzTab.h:608
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
Stream class for writing to comma/tab/...-separated values files.
Definition: SVOutStream.h:55
std::vector< MzTabPSMSectionRow > MzTabPSMSectionRows
Definition: MzTab.h:691
bool store_smallmolecule_reliability_
Definition: MzTabFile.h:90
std::map< std::pair< String, String >, std::vector< PeptideHit > > MapAccPepType
Definition: MzTabFile.h:67
Data model of MzTab files. Please see the official MzTab specification at https://code.google.com/p/mztab/.
Definition: MzTab.h:700

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:02 using doxygen 1.8.13