OpenMS
Loading...
Searching...
No Matches
MSstatsFile.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: Timo Sachsenberg $
6// $Authors: Timo Sachsenberg, Lukas Heumos $
7// --------------------------------------------------------------------------
8
9#pragma once
10
14
15#include <map>
16#include <utility>
17#include <unordered_map>
18#include <set>
19#include <vector>
20
21namespace OpenMS
22{
24 using IndProtGrps = std::vector<IndProtGrp>;
25
31 class OPENMS_DLLAPI MSstatsFile
32 {
33 public:
35 MSstatsFile() = default;
37 ~MSstatsFile() = default;
38
51 void storeLFQ(const std::string& filename,
52 const ConsensusMap &consensus_map, // we might add singleton protein groups
53 const ExperimentalDesign& design,
54 const StringList& reannotate_filenames,
55 const bool is_isotope_label_type,
56 const std::string& bioreplicate,
57 const std::string& condition,
58 const std::string& retention_time_summarization_method,
59 const bool remove_shared_peptides = true);
60
73 void storeISO(const std::string& filename,
74 const ConsensusMap &consensus_map,
75 const ExperimentalDesign& design,
76 const StringList& reannotate_filenames,
77 const std::string& bioreplicate,
78 const std::string& condition,
79 const std::string& mixture,
80 const std::string& retention_time_summarization_method,
81 const bool remove_shared_peptides = true);
82
83 private:
86
87 static const std::string na_string_;
88 static const char delim_ = ',';
89 static const char accdelim_ = ';';
90 static const char quote_ = '"';
91
92 /*
93 * @brief Quote a free-text CSV field if it contains the delimiter, a quote character, or a
94 * newline, doubling any embedded quote characters (RFC 4180). Fields that don't need it are
95 * returned unchanged, so most lines keep their current, unquoted form.
96 */
97 static std::string csvQuoteIfNeeded_(const std::string& field);
98
99 /*
100 * @brief: Struct to aggregate intermediate information from ConsensusFeature and ConsensusMap,
101 * such as filenames, intensities, retention times, labels and features (for further processing)
102 */
104 {
105 std::vector< std::vector< std::string > > consensus_feature_filenames; //< Filenames of ConsensusFeature
106 std::vector< std::vector< Intensity > > consensus_feature_intensities; //< Intensities of ConsensusFeature
107 std::vector< std::vector< Coordinate > > consensus_feature_retention_times; //< Retention times of ConsensusFeature
108 std::vector< std::vector< unsigned > > consensus_feature_labels; //< Labels of ConsensusFeature
109 std::vector<BaseFeature> features; //<s Features of ConsensusMap
110 };
111
112 /*
113 * @brief: Aggregates information from ConsensusFeature and ConsensusMap,
114 * such as filenames, intensities, retention times, labels and features.
115 * Stores them in AggregatedConsensusInfo for later processing
116 */
118 const std::vector<std::string>& spectra_paths);
119
120 /*
121 * @brief: Internal function to check if MSstats_BioReplicate and MSstats_Condition exists in Experimental Design
122 */
123 static void checkConditionLFQ_(const ExperimentalDesign::SampleSection& sampleSection, const std::string& bioreplicate, const std::string& condition);
124
125 /*
126 * @brief: Internal function to check if MSstats_BioReplicate, MSstats_Condition and MSstats_Mixture in Experimental Design
127 */
128 static void checkConditionISO_(const ExperimentalDesign::SampleSection& sampleSection, const std::string& bioreplicate, const std::string& condition, const std::string& mixture);
129
130 /*
131 * @brief MSstats treats runs differently than OpenMS. In MSstats, runs are an enumeration of (SpectraFilePath, Fraction)
132 * In OpenMS, a run is split into multiple fractions.
133 */
134 static void assembleRunMap_(
135 std::map< std::pair< std::string, unsigned>, unsigned> &run_map,
136 const ExperimentalDesign &design);
137
138 /*
139 * @brief checks if the first vector is a subset of the second
140 */
141 static bool isSubsetOf_(const std::vector< std::string> &first, const std::vector< std::string > &second);
142 static void warnOnSubsetFiles_(const std::vector<std::string>& spectra_paths, const std::vector<std::string>& design_filenames);
143
144 OpenMS::Peak2D::IntensityType sumIntensity_(const std::set< OpenMS::Peak2D::IntensityType > &intensities) const
145 {
147 for (const OpenMS::Peak2D::IntensityType &intensity : intensities)
148 {
149 result += intensity;
150 }
151 return result;
152 }
153
154 OpenMS::Peak2D::IntensityType meanIntensity_(const std::set< OpenMS::Peak2D::IntensityType > &intensities) const
155 {
156 return sumIntensity_(intensities) / intensities.size();
157 }
158
160 {
161 public :
163 bool _has_fraction,
164 const std::string& _accession,
165 const std::string& _sequence,
166 const std::string& _precursor_charge,
167 const std::string& _fragment_ion,
168 const std::string& _frag_charge,
169 const std::string& _isotope_label_type,
170 const std::string& _condition,
171 const std::string& _bioreplicate,
172 const std::string& _run,
173 const std::string& _fraction
174 ): has_fraction_(_has_fraction),
175 accession_(_accession),
176 sequence_(_sequence),
177 precursor_charge_(_precursor_charge),
178 fragment_ion_(_fragment_ion),
179 frag_charge_(_frag_charge),
180 isotope_label_type_(_isotope_label_type),
181 condition_(_condition),
182 bioreplicate_(_bioreplicate),
183 run_(_run),
184 fraction_(_fraction) {}
185
186 const std::string& accession() const {return this->accession_;}
187 const std::string& sequence() const {return this->sequence_;}
188 const std::string& precursor_charge() const {return this->precursor_charge_;}
189 const std::string& run() const {return this->run_;}
190
191 std::string toString() const
192 {
193 const std::string delim(",");
194 return MSstatsFile::csvQuoteIfNeeded_(accession_)
195 + delim + sequence_
196 + delim + precursor_charge_
197 + delim + fragment_ion_
198 + delim + frag_charge_
199 + delim + isotope_label_type_
200 + delim + MSstatsFile::csvQuoteIfNeeded_(condition_)
201 + delim + MSstatsFile::csvQuoteIfNeeded_(bioreplicate_)
202 + delim + MSstatsFile::csvQuoteIfNeeded_(run_)
203 + (this->has_fraction_ ? delim + std::string(fraction_) : "");
204 }
205
206 friend bool operator<(const MSstatsLine_ &l,
207 const MSstatsLine_ &r) {
208
209 return std::tie(l.accession_, l.run_, l.condition_, l.bioreplicate_, l.precursor_charge_, l.sequence_) <
211 }
212
213
214 private:
216 std::string accession_;
217 std::string sequence_;
218 std::string precursor_charge_;
219 std::string fragment_ion_;
220 std::string frag_charge_;
222 std::string condition_;
223 std::string bioreplicate_;
224 std::string run_;
225 std::string fraction_;
226 };
227
229 {
230 public :
232 const std::string& _accession,
233 const std::string& _sequence,
234 const std::string& _precursor_charge,
235 const std::string& _channel,
236 const std::string& _condition,
237 const std::string& _bioreplicate,
238 const std::string& _run,
239 const std::string& _mixture,
240 const std::string& _techrepmixture,
241 const std::string& _fraction
242 ): accession_(_accession),
243 sequence_(_sequence),
244 precursor_charge_(_precursor_charge),
245 channel_(_channel),
246 condition_(_condition),
247 bioreplicate_(_bioreplicate),
248 run_(_run),
249 mixture_(_mixture),
250 techrepmixture_(_techrepmixture),
251 fraction_(_fraction) {}
252
253 const std::string& accession() const {return this->accession_;}
254 const std::string& sequence() const {return this->sequence_;}
255 const std::string& precursor_charge() const {return this->precursor_charge_;}
256 const std::string& run() const {return this->run_;}
257
258 std::string toString() const
259 {
260 const std::string delim(",");
261 return MSstatsFile::csvQuoteIfNeeded_(accession_)
262 + delim + MSstatsFile::csvQuoteIfNeeded_(sequence_)
263 + delim + precursor_charge_
264 + delim + channel_
265 + delim + MSstatsFile::csvQuoteIfNeeded_(condition_)
266 + delim + MSstatsFile::csvQuoteIfNeeded_(bioreplicate_)
267 + delim + MSstatsFile::csvQuoteIfNeeded_(run_)
268 + delim + MSstatsFile::csvQuoteIfNeeded_(mixture_)
269 + delim + MSstatsFile::csvQuoteIfNeeded_(techrepmixture_)
270 + delim + std::string(fraction_);
271 }
272
273 friend bool operator<(const MSstatsTMTLine_ &l,
274 const MSstatsTMTLine_ &r) {
275
276 return std::tie(l.accession_, l.run_, l.condition_, l.bioreplicate_, l.mixture_, l.precursor_charge_, l.sequence_, l.channel_) <
278 }
279
280
281 private:
282 std::string accession_;
283 std::string sequence_;
284 std::string precursor_charge_;
285 std::string channel_;
286 std::string condition_;
287 std::string bioreplicate_;
288 std::string run_;
289 std::string mixture_;
290 std::string techrepmixture_;
291 std::string fraction_;
292 };
293
294 /*
295 * @brief Constructs the lines and adds them to the TextFile
296 * @param[out] peptideseq_quantifyable Has to be a set (only) for deterministic ordered output
297 */
298 template <class LineType>
299 void constructFile_(const std::string& retention_time_summarization_method,
300 const bool rt_summarization_manual,
301 TextFile& csv_out,
302 const std::set<std::string>& peptideseq_quantifyable,
303 LineType & peptideseq_to_prefix_to_intensities) const;
304
305 /*
306 * @brief Constructs the accession to indist. group mapping
307 */
308 static std::unordered_map<std::string, const IndProtGrp* > getAccessionToGroupMap_(const IndProtGrps& ind_prots);
309
310
311 /*
312 * @brief Based on the evidence accession set in a PeptideHit, checks if is unique and therefore quantifyable
313 * in a group context.
314 *
315 */
317 const std::set<std::string>& accs,
318 const std::unordered_map<std::string, const IndProtGrp*>& accession_to_group) const;
319
320 };
321} // namespace OpenMS
A container for consensus elements.
Definition ConsensusMap.h:67
The sample section: one named row per sample, one column per factor.
Definition ExperimentalDesign.h:507
Representation of an experimental design in OpenMS. Instances can be loaded with the ExperimentalDesi...
Definition ExperimentalDesign.h:449
Definition MSstatsFile.h:160
std::string toString() const
Definition MSstatsFile.h:191
std::string precursor_charge_
Definition MSstatsFile.h:218
std::string fragment_ion_
Definition MSstatsFile.h:219
const std::string & sequence() const
Definition MSstatsFile.h:187
const std::string & precursor_charge() const
Definition MSstatsFile.h:188
std::string run_
Definition MSstatsFile.h:224
std::string frag_charge_
Definition MSstatsFile.h:220
bool has_fraction_
Definition MSstatsFile.h:215
const std::string & accession() const
Definition MSstatsFile.h:186
std::string sequence_
Definition MSstatsFile.h:217
friend bool operator<(const MSstatsLine_ &l, const MSstatsLine_ &r)
Definition MSstatsFile.h:206
std::string accession_
Definition MSstatsFile.h:216
std::string fraction_
Definition MSstatsFile.h:225
const std::string & run() const
Definition MSstatsFile.h:189
MSstatsLine_(bool _has_fraction, const std::string &_accession, const std::string &_sequence, const std::string &_precursor_charge, const std::string &_fragment_ion, const std::string &_frag_charge, const std::string &_isotope_label_type, const std::string &_condition, const std::string &_bioreplicate, const std::string &_run, const std::string &_fraction)
Definition MSstatsFile.h:162
std::string bioreplicate_
Definition MSstatsFile.h:223
std::string isotope_label_type_
Definition MSstatsFile.h:221
std::string condition_
Definition MSstatsFile.h:222
Definition MSstatsFile.h:229
std::string channel_
Definition MSstatsFile.h:285
MSstatsTMTLine_(const std::string &_accession, const std::string &_sequence, const std::string &_precursor_charge, const std::string &_channel, const std::string &_condition, const std::string &_bioreplicate, const std::string &_run, const std::string &_mixture, const std::string &_techrepmixture, const std::string &_fraction)
Definition MSstatsFile.h:231
std::string toString() const
Definition MSstatsFile.h:258
std::string precursor_charge_
Definition MSstatsFile.h:284
const std::string & sequence() const
Definition MSstatsFile.h:254
const std::string & precursor_charge() const
Definition MSstatsFile.h:255
std::string run_
Definition MSstatsFile.h:288
const std::string & accession() const
Definition MSstatsFile.h:253
std::string techrepmixture_
Definition MSstatsFile.h:290
std::string sequence_
Definition MSstatsFile.h:283
std::string accession_
Definition MSstatsFile.h:282
friend bool operator<(const MSstatsTMTLine_ &l, const MSstatsTMTLine_ &r)
Definition MSstatsFile.h:273
std::string fraction_
Definition MSstatsFile.h:291
const std::string & run() const
Definition MSstatsFile.h:256
std::string bioreplicate_
Definition MSstatsFile.h:287
std::string mixture_
Definition MSstatsFile.h:289
std::string condition_
Definition MSstatsFile.h:286
File adapter for MSstats files.
Definition MSstatsFile.h:32
static void checkConditionLFQ_(const ExperimentalDesign::SampleSection &sampleSection, const std::string &bioreplicate, const std::string &condition)
static std::unordered_map< std::string, const IndProtGrp * > getAccessionToGroupMap_(const IndProtGrps &ind_prots)
OpenMS::Peak2D::IntensityType sumIntensity_(const std::set< OpenMS::Peak2D::IntensityType > &intensities) const
Definition MSstatsFile.h:144
std::vector< std::vector< unsigned > > consensus_feature_labels
Definition MSstatsFile.h:108
OpenMS::Peak2D::CoordinateType Coordinate
Definition MSstatsFile.h:85
static void checkConditionISO_(const ExperimentalDesign::SampleSection &sampleSection, const std::string &bioreplicate, const std::string &condition, const std::string &mixture)
static void assembleRunMap_(std::map< std::pair< std::string, unsigned >, unsigned > &run_map, const ExperimentalDesign &design)
static const std::string na_string_
Definition MSstatsFile.h:87
std::vector< std::vector< std::string > > consensus_feature_filenames
Definition MSstatsFile.h:105
MSstatsFile::AggregatedConsensusInfo aggregateInfo_(const ConsensusMap &consensus_map, const std::vector< std::string > &spectra_paths)
void storeISO(const std::string &filename, const ConsensusMap &consensus_map, const ExperimentalDesign &design, const StringList &reannotate_filenames, const std::string &bioreplicate, const std::string &condition, const std::string &mixture, const std::string &retention_time_summarization_method, const bool remove_shared_peptides=true)
Store isobaric experiment (MSstatsTMT)
static std::string csvQuoteIfNeeded_(const std::string &field)
void constructFile_(const std::string &retention_time_summarization_method, const bool rt_summarization_manual, TextFile &csv_out, const std::set< std::string > &peptideseq_quantifyable, LineType &peptideseq_to_prefix_to_intensities) const
std::vector< std::vector< Intensity > > consensus_feature_intensities
Definition MSstatsFile.h:106
std::vector< BaseFeature > features
Definition MSstatsFile.h:109
static bool isSubsetOf_(const std::vector< std::string > &first, const std::vector< std::string > &second)
bool isQuantifyable_(const std::set< std::string > &accs, const std::unordered_map< std::string, const IndProtGrp * > &accession_to_group) const
std::vector< std::vector< Coordinate > > consensus_feature_retention_times
Definition MSstatsFile.h:107
OpenMS::Peak2D::IntensityType meanIntensity_(const std::set< OpenMS::Peak2D::IntensityType > &intensities) const
Definition MSstatsFile.h:154
MSstatsFile()=default
Default constructor.
~MSstatsFile()=default
Destructor.
static void warnOnSubsetFiles_(const std::vector< std::string > &spectra_paths, const std::vector< std::string > &design_filenames)
OpenMS::Peak2D::IntensityType Intensity
Definition MSstatsFile.h:84
void storeLFQ(const std::string &filename, const ConsensusMap &consensus_map, const ExperimentalDesign &design, const StringList &reannotate_filenames, const bool is_isotope_label_type, const std::string &bioreplicate, const std::string &condition, const std::string &retention_time_summarization_method, const bool remove_shared_peptides=true)
Store label free experiment (MSstats)
double CoordinateType
Coordinate type (of the position)
Definition Peak2D.h:39
float IntensityType
Intensity type.
Definition Peak2D.h:37
Bundles multiple (e.g. indistinguishable) proteins in a group.
Definition ProteinIdentification.h:73
Definition TextFile.h:21
OpenMS looks in the< code > OPENMS_THERMO_MANAGED_DIR</code > environment variable first
Definition common-cmake-parameters.doxygen:199
std::vector< std::string > StringList
Vector of String.
Definition TypeAliases.h:39
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::vector< IndProtGrp > IndProtGrps
Definition MSstatsFile.h:24