OpenMS  3.0.0
MSstatsFile.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-2022.
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, Lukas Heumos $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 #include <OpenMS/FORMAT/TextFile.h>
40 
41 #include <map>
42 #include <utility>
43 #include <unordered_map>
44 #include <set>
45 #include <vector>
46 
47 namespace OpenMS
48 {
50  using IndProtGrps = std::vector<IndProtGrp>;
51 
57  class OPENMS_DLLAPI MSstatsFile
58  {
59  public:
61  MSstatsFile() = default;
63  ~MSstatsFile() = default;
64 
66  void storeLFQ(const String& filename,
67  const ConsensusMap &consensus_map, // we might add singleton protein groups
68  const ExperimentalDesign& design,
69  const StringList& reannotate_filenames,
70  const bool is_isotope_label_type,
71  const String& bioreplicate,
72  const String& condition,
73  const String& retention_time_summarization_method);
74 
76  void storeISO(const String& filename,
77  const ConsensusMap &consensus_map,
78  const ExperimentalDesign& design,
79  const StringList& reannotate_filenames,
80  const String& bioreplicate,
81  const String& condition,
82  const String& mixture,
83  const String& retention_time_summarization_method);
84 
85  private:
88 
89  static const String na_string_;
90  static const char delim_ = ',';
91  static const char accdelim_ = ';';
92  static const char quote_ = '"';
93 
94  /*
95  * @brief: Struct to aggregate intermediate information from ConsensusFeature and ConsensusMap,
96  * such as filenames, intensities, retention times, labels and features (for further processing)
97  */
99  {
100  std::vector< std::vector< String > > consensus_feature_filenames; //< Filenames of ConsensusFeature
101  std::vector< std::vector< Intensity > > consensus_feature_intensities; //< Intensities of ConsensusFeature
102  std::vector< std::vector< Coordinate > > consensus_feature_retention_times; //< Retention times of ConsensusFeature
103  std::vector< std::vector< unsigned > > consensus_feature_labels; //< Labels of ConsensusFeature
104  std::vector<BaseFeature> features; //<s Features of ConsensusMap
105  };
106 
107  /*
108  * @brief: Aggregates information from ConsensusFeature and ConsensusMap,
109  * such as filenames, intensities, retention times, labels and features.
110  * Stores them in AggregatedConsensusInfo for later processing
111  */
112  MSstatsFile::AggregatedConsensusInfo aggregateInfo_(const ConsensusMap& consensus_map,
113  const std::vector<String>& spectra_paths);
114 
115  /*
116  * @brief: Internal function to check if MSstats_BioReplicate and MSstats_Condition exists in Experimental Design
117  */
118  static void checkConditionLFQ_(const ExperimentalDesign::SampleSection& sampleSection, const String& bioreplicate, const String& condition);
119 
120  /*
121  * @brief: Internal function to check if MSstats_BioReplicate, MSstats_Condition and MSstats_Mixture in Experimental Design
122  */
123  static void checkConditionISO_(const ExperimentalDesign::SampleSection& sampleSection, const String& bioreplicate, const String& condition, const String& mixture);
124 
125  /*
126  * @brief MSstats treats runs differently than OpenMS. In MSstats, runs are an enumeration of (SpectraFilePath, Fraction)
127  * In OpenMS, a run is split into multiple fractions.
128  */
129  static void assembleRunMap_(
130  std::map< std::pair< String, unsigned>, unsigned> &run_map,
131  const ExperimentalDesign &design);
132 
133  /*
134  * @brief checks two vectors for same content
135  */
136  static bool checkUnorderedContent_(const std::vector< String> &first, const std::vector< String > &second);
137 
138  OpenMS::Peak2D::IntensityType sumIntensity_(const std::set< OpenMS::Peak2D::IntensityType > &intensities) const
139  {
141  for (const OpenMS::Peak2D::IntensityType &intensity : intensities)
142  {
143  result += intensity;
144  }
145  return result;
146  }
147 
148  OpenMS::Peak2D::IntensityType meanIntensity_(const std::set< OpenMS::Peak2D::IntensityType > &intensities) const
149  {
150  return sumIntensity_(intensities) / intensities.size();
151  }
152 
154  {
155  public :
157  bool _has_fraction,
158  const String& _accession,
159  const String& _sequence,
160  const String& _precursor_charge,
161  const String& _fragment_ion,
162  const String& _frag_charge,
163  const String& _isotope_label_type,
164  const String& _condition,
165  const String& _bioreplicate,
166  const String& _run,
167  const String& _fraction
168  ): has_fraction_(_has_fraction),
169  accession_(_accession),
170  sequence_(_sequence),
171  precursor_charge_(_precursor_charge),
172  fragment_ion_(_fragment_ion),
173  frag_charge_(_frag_charge),
174  isotope_label_type_(_isotope_label_type),
175  condition_(_condition),
176  bioreplicate_(_bioreplicate),
177  run_(_run),
178  fraction_(_fraction) {}
179 
180  const String& accession() const {return this->accession_;}
181  const String& sequence() const {return this->sequence_;}
182  const String& precursor_charge() const {return this->precursor_charge_;}
183  const String& run() const {return this->run_;}
184 
185  String toString() const
186  {
187  const String delim(",");
188  return accession_
189  + delim + sequence_
190  + delim + precursor_charge_
191  + delim + fragment_ion_
192  + delim + frag_charge_
193  + delim + isotope_label_type_
194  + delim + condition_
195  + delim + bioreplicate_
196  + delim + run_
197  + (this->has_fraction_ ? delim + String(fraction_) : "");
198  }
199 
200  friend bool operator<(const MSstatsLine_ &l,
201  const MSstatsLine_ &r) {
202 
203  return std::tie(l.accession_, l.run_, l.condition_, l.bioreplicate_, l.precursor_charge_, l.sequence_) <
205  }
206 
207 
208  private:
220  };
221 
223  {
224  public :
226  const String& _accession,
227  const String& _sequence,
228  const String& _precursor_charge,
229  const String& _channel,
230  const String& _condition,
231  const String& _bioreplicate,
232  const String& _run,
233  const String& _mixture,
234  const String& _techrepmixture,
235  const String& _fraction
236  ): accession_(_accession),
237  sequence_(_sequence),
238  precursor_charge_(_precursor_charge),
239  channel_(_channel),
240  condition_(_condition),
241  bioreplicate_(_bioreplicate),
242  run_(_run),
243  mixture_(_mixture),
244  techrepmixture_(_techrepmixture),
245  fraction_(_fraction) {}
246 
247  const String& accession() const {return this->accession_;}
248  const String& sequence() const {return this->sequence_;}
249  const String& precursor_charge() const {return this->precursor_charge_;}
250  const String& run() const {return this->run_;}
251 
252  String toString() const
253  {
254  const String delim(",");
255  return accession_
256  + delim + sequence_
257  + delim + precursor_charge_
258  + delim + channel_
259  + delim + condition_
260  + delim + bioreplicate_
261  + delim + run_
262  + delim + mixture_
263  + delim + techrepmixture_
264  + delim + String(fraction_);
265  }
266 
267  friend bool operator<(const MSstatsTMTLine_ &l,
268  const MSstatsTMTLine_ &r) {
269 
270  return std::tie(l.accession_, l.run_, l.condition_, l.bioreplicate_, l.mixture_, l.precursor_charge_, l.sequence_, l.channel_) <
272  }
273 
274 
275  private:
286  };
287 
288  /*
289  * @brief Constructs the lines and adds them to the TextFile
290  * @param peptideseq_quantifyable Has to be a set (only) for deterministic ordered output
291  */
292  template <class LineType>
293  void constructFile_(const String& retention_time_summarization_method,
294  const bool rt_summarization_manual,
295  TextFile& csv_out,
296  const std::set<String>& peptideseq_quantifyable,
297  LineType & peptideseq_to_prefix_to_intensities) const;
298 
299  /*
300  * @brief Constructs the accession to indist. group mapping
301  */
302  static std::unordered_map<OpenMS::String, const IndProtGrp* > getAccessionToGroupMap_(const IndProtGrps& ind_prots);
303 
304 
305  /*
306  * @brief Based on the evidence accession set in a PeptideHit, checks if is unique and therefore quantifyable
307  * in a group context.
308  *
309  */
310  bool isQuantifyable_(
311  const std::set<String>& accs,
312  const std::unordered_map<String, const IndProtGrp*>& accession_to_group) const;
313 
314  };
315 } // namespace OpenMS
OpenMS::MSstatsFile::MSstatsTMTLine_::precursor_charge_
String precursor_charge_
Definition: MSstatsFile.h:278
ConsensusXMLFile.h
MzTabFile.h
OpenMS::MSstatsFile::AggregatedConsensusInfo::features
std::vector< BaseFeature > features
Definition: MSstatsFile.h:104
OpenMS::MSstatsFile::MSstatsLine_::isotope_label_type_
String isotope_label_type_
Definition: MSstatsFile.h:215
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:147
OpenMS::ExperimentalDesign
Representation of an experimental design in OpenMS. Instances can be loaded with the ExperimentalDesi...
Definition: ExperimentalDesign.h:242
OpenMS::ExperimentalDesignFile::load
static ExperimentalDesign load(const String &tsv_file, bool require_spectra_files)
Loads an experimental design from a tabular separated file.
FileHandler.h
TextFile.h
OpenMS::MSstatsFile::AggregatedConsensusInfo::consensus_feature_filenames
std::vector< std::vector< String > > consensus_feature_filenames
Definition: MSstatsFile.h:100
OpenMS::IndProtGrps
std::vector< IndProtGrp > IndProtGrps
Definition: MSstatsFile.h:50
double
ExperimentalDesignFile.h
OpenMS::MSstatsFile::MSstatsLine_::accession
const String & accession() const
Definition: MSstatsFile.h:180
OpenMS::MSstatsFile::MSstatsLine_::has_fraction_
bool has_fraction_
Definition: MSstatsFile.h:209
OpenMS::String
A more convenient string class.
Definition: String.h:58
ConsensusMap.h
OpenMS::FileTypes::CONSENSUSXML
OpenMS consensus map format (.consensusXML)
Definition: FileTypes.h:65
OpenMS::TextFile
This class provides some basic file handling methods for text files.
Definition: TextFile.h:46
FeatureXMLFile.h
OpenMS::MSstatsFile::MSstatsTMTLine_::run
const String & run() const
Definition: MSstatsFile.h:250
OpenMS::MSstatsFile::MSstatsTMTLine_::mixture_
String mixture_
Definition: MSstatsFile.h:283
OpenMS::MSstatsFile::MSstatsTMTLine_::condition_
String condition_
Definition: MSstatsFile.h:280
OpenMS::MSstatsFile::MSstatsLine_::accession_
String accession_
Definition: MSstatsFile.h:210
OpenMS::MSstatsFile::Coordinate
OpenMS::Peak2D::CoordinateType Coordinate
Definition: MSstatsFile.h:87
OpenMS::MSstatsFile::MSstatsLine_
Definition: MSstatsFile.h:153
OpenMS::MSstatsFile::MSstatsTMTLine_::sequence_
String sequence_
Definition: MSstatsFile.h:277
OpenMS::MSstatsFile::MSstatsLine_::frag_charge_
String frag_charge_
Definition: MSstatsFile.h:214
OpenMS::MSstatsFile::AggregatedConsensusInfo::consensus_feature_intensities
std::vector< std::vector< Intensity > > consensus_feature_intensities
Definition: MSstatsFile.h:101
OpenMS::MSstatsFile::MSstatsTMTLine_::precursor_charge
const String & precursor_charge() const
Definition: MSstatsFile.h:249
OPENMS_LOG_FATAL_ERROR
#define OPENMS_LOG_FATAL_ERROR
Macro to be used if fatal error are reported (processing stops)
Definition: LogStream.h:450
OpenMS::MSstatsFile::sumIntensity_
OpenMS::Peak2D::IntensityType sumIntensity_(const std::set< OpenMS::Peak2D::IntensityType > &intensities) const
Definition: MSstatsFile.h:138
OpenMS::MSstatsFile::MSstatsTMTLine_::bioreplicate_
String bioreplicate_
Definition: MSstatsFile.h:281
MSstatsFile.h
OpenMS::MSstatsFile::MSstatsLine_::sequence
const String & sequence() const
Definition: MSstatsFile.h:181
OpenMS::MSstatsFile::MSstatsTMTLine_::accession
const String & accession() const
Definition: MSstatsFile.h:247
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::MSstatsFile::MSstatsTMTLine_::sequence
const String & sequence() const
Definition: MSstatsFile.h:248
OpenMS::MSstatsFile::MSstatsTMTLine_::run_
String run_
Definition: MSstatsFile.h:282
OpenMS::MSstatsFile::MSstatsLine_::operator<
friend bool operator<(const MSstatsLine_ &l, const MSstatsLine_ &r)
Definition: MSstatsFile.h:200
OpenMS::MSstatsFile::MSstatsLine_::bioreplicate_
String bioreplicate_
Definition: MSstatsFile.h:217
OpenMS::MSstatsFile::AggregatedConsensusInfo::consensus_feature_labels
std::vector< std::vector< unsigned > > consensus_feature_labels
Definition: MSstatsFile.h:103
OpenMS::ExperimentalDesign::SampleSection
Definition: ExperimentalDesign.h:263
OpenMS::FileTypes::Type
Type
Actual file types enum.
Definition: FileTypes.h:56
OpenMS::MSstatsFile::MSstatsTMTLine_
Definition: MSstatsFile.h:222
OpenMS::MSstatsFile::na_string_
static const String na_string_
Definition: MSstatsFile.h:89
OpenMS::FileHandler::getType
static FileTypes::Type getType(const String &filename)
Tries to determine the file type (by name or content)
OpenMS::MSstatsFile::MSstatsTMTLine_::accession_
String accession_
Definition: MSstatsFile.h:276
MzTab.h
OpenMS::MSstatsFile::MSstatsTMTLine_::operator<
friend bool operator<(const MSstatsTMTLine_ &l, const MSstatsTMTLine_ &r)
Definition: MSstatsFile.h:267
OpenMS::MSstatsFile::MSstatsTMTLine_::channel_
String channel_
Definition: MSstatsFile.h:279
OpenMS::ConsensusMap
A container for consensus elements.
Definition: ConsensusMap.h:82
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::ConsensusXMLFile::load
void load(const String &filename, ConsensusMap &map)
Loads a consensus map from file and calls updateRanges.
OpenMS::MSstatsFile::Intensity
OpenMS::Peak2D::IntensityType Intensity
Definition: MSstatsFile.h:86
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
ExperimentalDesign.h
OpenMS::ExperimentalDesign::getSampleSection
const ExperimentalDesign::SampleSection & getSampleSection() const
OpenMS::MSstatsFile::MSstatsTMTLine_::MSstatsTMTLine_
MSstatsTMTLine_(const String &_accession, const String &_sequence, const String &_precursor_charge, const String &_channel, const String &_condition, const String &_bioreplicate, const String &_run, const String &_mixture, const String &_techrepmixture, const String &_fraction)
Definition: MSstatsFile.h:225
OpenMS::MSstatsFile::MSstatsLine_::fragment_ion_
String fragment_ion_
Definition: MSstatsFile.h:213
OpenMS::MSstatsFile::MSstatsLine_::precursor_charge_
String precursor_charge_
Definition: MSstatsFile.h:212
OpenMS::MSstatsFile::MSstatsLine_::MSstatsLine_
MSstatsLine_(bool _has_fraction, const String &_accession, const String &_sequence, const String &_precursor_charge, const String &_fragment_ion, const String &_frag_charge, const String &_isotope_label_type, const String &_condition, const String &_bioreplicate, const String &_run, const String &_fraction)
Definition: MSstatsFile.h:156
float
OpenMS::MSstatsFile::MSstatsLine_::condition_
String condition_
Definition: MSstatsFile.h:216
OpenMS::MSstatsFile::storeISO
void storeISO(const String &filename, const ConsensusMap &consensus_map, const ExperimentalDesign &design, const StringList &reannotate_filenames, const String &bioreplicate, const String &condition, const String &mixture, const String &retention_time_summarization_method)
store isobaric experiment (MSstatsTMT)
OpenMS::MSstatsFile::MSstatsLine_::sequence_
String sequence_
Definition: MSstatsFile.h:211
OpenMS::MSstatsFile::MSstatsLine_::run
const String & run() const
Definition: MSstatsFile.h:183
OpenMS::MSstatsFile::storeLFQ
void storeLFQ(const String &filename, const ConsensusMap &consensus_map, const ExperimentalDesign &design, const StringList &reannotate_filenames, const bool is_isotope_label_type, const String &bioreplicate, const String &condition, const String &retention_time_summarization_method)
store label free experiment (MSstats)
OpenMS::MSstatsFile
File adapter for MSstats files.
Definition: MSstatsFile.h:57
OpenMS::MSstatsFile::MSstatsTMTLine_::fraction_
String fraction_
Definition: MSstatsFile.h:285
OpenMS::MSstatsFile::MSstatsLine_::precursor_charge
const String & precursor_charge() const
Definition: MSstatsFile.h:182
OpenMS::MSstatsFile::AggregatedConsensusInfo
Definition: MSstatsFile.h:98
OpenMS::MSstatsFile::MSstatsLine_::fraction_
String fraction_
Definition: MSstatsFile.h:219
OpenMS::MSstatsFile::MSstatsTMTLine_::toString
String toString() const
Definition: MSstatsFile.h:252
OpenMS::MSstatsFile::MSstatsLine_::toString
String toString() const
Definition: MSstatsFile.h:185
OpenMS::MSstatsFile::AggregatedConsensusInfo::consensus_feature_retention_times
std::vector< std::vector< Coordinate > > consensus_feature_retention_times
Definition: MSstatsFile.h:102
File.h
TOPPBase.h
OpenMS::MSstatsFile::MSstatsTMTLine_::techrepmixture_
String techrepmixture_
Definition: MSstatsFile.h:284
OpenMS::ConsensusXMLFile
This class provides Input functionality for ConsensusMaps and Output functionality for alignments and...
Definition: ConsensusXMLFile.h:58
OpenMS::ProteinIdentification::ProteinGroup
Bundles multiple (e.g. indistinguishable) proteins in a group.
Definition: ProteinIdentification.h:117
OpenMS::MSstatsFile::MSstatsLine_::run_
String run_
Definition: MSstatsFile.h:218
OpenMS::MSstatsFile::meanIntensity_
OpenMS::Peak2D::IntensityType meanIntensity_(const std::set< OpenMS::Peak2D::IntensityType > &intensities) const
Definition: MSstatsFile.h:148