OpenMS
Loading...
Searching...
No Matches
ExperimentalDesign.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 $
7// --------------------------------------------------------------------------
8
9#pragma once
10
14
15#include <vector>
16#include <map>
17#include <set>
18
19namespace OpenMS
20{
21 class ConsensusMap;
22 class FeatureMap;
23
108 class OPENMS_DLLAPI ExperimentalDesign
109 {
110
111 public:
118 class OPENMS_DLLAPI MSFileSectionEntry
119 {
120 public:
122 unsigned fraction_group = 1;
123 unsigned fraction = 1;
124 std::string path = "UNKNOWN_FILE";
125 unsigned label = 1;
126 unsigned sample = 0;
127 std::string sample_name = "0";
128 };
129
130 class OPENMS_DLLAPI SampleSection
131 {
132 public:
133
134 SampleSection() = default;
135
137 const std::vector< std::vector < std::string > >& content,
138 const std::map< std::string, Size >& sample_to_rowindex,
139 const std::map< std::string, Size >& columnname_to_columnindex
140 );
141
142 // Get set of all samples that are present in the sample section
143 std::set< std::string > getSamples() const;
144
145 // Add a sample as the last row
146 void addSample(const std::string& sample, const std::vector<std::string>& content = {});
147
148 // TODO should it include the Sample ID column or not??
149 // Get set of all factors (column names) that were defined for the sample section
150 std::set< std::string > getFactors() const;
151
152 // Checks whether sample section has row for a sample number
153 bool hasSample(const std::string& sample) const;
154
155 // Checks whether Sample Section has a specific factor (i.e. column name)
156 bool hasFactor(const std::string &factor) const;
157
158 // Returns value of factor for given sample and factor name
159 std::string getFactorValue(const std::string& sample_name, const std::string &factor) const;
160
161 // Returns value of factor for given sample index and factor name
162 std::string getFactorValue(unsigned sample_idx, const std::string &factor) const;
163
164 // Returns column index of factor
165 Size getFactorColIdx(const std::string &factor) const;
166
167 // Returns the name/ID of the sample. Not necessarily the row index
168 std::string getSampleName(unsigned sample_row) const;
169
170 // Returns the row index in the sample section for a sample name/ID
171 unsigned getSampleRow(const std::string& sample) const;
172
175
176 private:
177
178 // The entries of the Sample Section, filled while parsing
179 // the Experimental Design File
180 std::vector< std::vector < std::string > > content_;
181
182 // Maps the Sample Entry name to the row where the sample
183 // appears in the Sample section, its sample index
184 std::map< std::string, Size > sample_to_rowindex_;
185
186 // Maps the column name of the SampleSection to the
187 // Index of the column
188 std::map< std::string, Size > columnname_to_columnindex_;
189 };
190
191 using MSFileSection = std::vector<MSFileSectionEntry>;
192
193 // Experimental Design c'tors
195
196 ExperimentalDesign(const MSFileSection& msfile_section, const SampleSection& sample_section);
197
199
200 void setMSFileSection(const MSFileSection& msfile_section);
201
202 // Returns the Sample Section of the experimental design file
204
205 void setSampleSection(const SampleSection& sample_section);
206
209 std::map<std::vector<std::string>, std::set<std::string>> getUniqueSampleRowToSampleMapping() const;
210
214 std::map<std::string, unsigned> getSampleToPrefractionationMapping() const;
215
217 //TODO this probably needs a basename parameter to be fully compatible with the other mappings!! Implicit full path.
218 std::map<unsigned int, std::vector<std::string> > getFractionToMSFilesMapping() const;
219
222 //TODO this probably needs a basename parameter to be fully compatible with the other mappings!! Implicit full path.
223 std::vector<std::vector<std::pair<std::string, unsigned>>> getConditionToPathLabelVector() const;
224
226 std::map<std::vector<std::string>, std::set<unsigned>> getConditionToSampleMapping() const;
227
228 /*
229 * The (Path, Label) tuples in the experimental design have to be unique, so we can map them
230 * uniquely to the sample number, fraction number, and fraction_group number
231 */
232
235 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToPrefractionationMapping(bool use_basename_only) const;
236
239 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToConditionMapping(bool use_basename_only) const;
240
245 std::map<std::string, unsigned> getSampleToConditionMapping() const;
246
248 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToSampleMapping(bool use_basename_only) const;
249
251 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToFractionMapping(bool use_basename_only) const;
252
254 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToFractionGroupMapping(bool use_basename_only) const;
255
256 // @return the number of samples measured (= number of rows in the sample section).
257 // NOT the highest sample index: MSFileSectionEntry::sample is zero-based, so the highest
258 // index is one less than this.
259 unsigned getNumberOfSamples() const;
260
261 // @return the number of fractions (= highest fraction index)
262 unsigned getNumberOfFractions() const;
263
264 // @return the number of labels per file
265 unsigned getNumberOfLabels() const;
266
267 // @return the number of MS files (= fractions * fraction groups)
268 unsigned getNumberOfMSFiles() const;
269
270 // @return the number of fraction_groups
271 // Allows to group fraction ids and source files
273
274 // @return sample index (depends on fraction_group and label)
275 unsigned getSample(unsigned fraction_group, unsigned label = 1);
276
278 // This is the case if we have at least one fraction group with >= 2 fractions
279 bool isFractionated() const;
280
284 Size filterByBasenames(const std::set<std::string>& bns);
285
288
291
310
313
315 static ExperimentalDesign fromIdentifications(const std::vector<ProteinIdentification>& proteins);
316 //TODO create another overload here, that takes two enums outerVec and innerVec with entries Replicate, Fraction, Sample
317
318 private:
319 // sample row index -> sample name; the reverse of SampleSection's name->row store
320 std::map<Size, std::string> sampleRowToName_() const;
321
322 // MS filename column, optionally trims to basename
323 std::vector< std::string > getFileNames_(bool basename) const;
324
325 // returns label column
326 std::vector<unsigned> getLabels_() const;
327
328 // returns fraction column
329 std::vector<unsigned> getFractions_() const;
330
332 std::map< std::pair< std::string, unsigned >, unsigned> pathLabelMapper_(
333 bool,
334 unsigned (*f)(const ExperimentalDesign::MSFileSectionEntry&)) const;
335
336 // sort to obtain the default order
337 void sort_();
338
339 template<typename T>
340 static void errorIfAlreadyExists(std::set<T> &container, T &item, const std::string &message);
341
342 // basic consistency checks
343 void isValid_();
344
347 };
348}
349
A container for consensus elements.
Definition ConsensusMap.h:67
Definition ExperimentalDesign.h:119
Definition ExperimentalDesign.h:131
std::map< std::string, Size > sample_to_rowindex_
Definition ExperimentalDesign.h:184
void addSample(const std::string &sample, const std::vector< std::string > &content={})
std::set< std::string > getFactors() const
std::string getSampleName(unsigned sample_row) const
bool hasFactor(const std::string &factor) const
std::map< std::string, Size > columnname_to_columnindex_
Definition ExperimentalDesign.h:188
std::set< std::string > getSamples() const
Size getContentSize() const
returns the number of entries in content_ member
std::vector< std::vector< std::string > > content_
Definition ExperimentalDesign.h:180
std::string getFactorValue(const std::string &sample_name, const std::string &factor) const
std::string getFactorValue(unsigned sample_idx, const std::string &factor) const
unsigned getSampleRow(const std::string &sample) const
Size getFactorColIdx(const std::string &factor) const
SampleSection(const std::vector< std::vector< std::string > > &content, const std::map< std::string, Size > &sample_to_rowindex, const std::map< std::string, Size > &columnname_to_columnindex)
bool hasSample(const std::string &sample) const
Representation of an experimental design in OpenMS. Instances can be loaded with the ExperimentalDesi...
Definition ExperimentalDesign.h:109
unsigned getNumberOfLabels() const
static void errorIfAlreadyExists(std::set< T > &container, T &item, const std::string &message)
std::map< std::pair< std::string, unsigned >, unsigned > getPathLabelToSampleMapping(bool use_basename_only) const
return <file_path, label> to sample index mapping
Size filterByBasenames(const std::set< std::string > &bns)
unsigned getNumberOfFractions() const
static ExperimentalDesign fromConsensusMap(const ConsensusMap &c)
Extract experimental design from consensus map.
unsigned getSample(unsigned fraction_group, unsigned label=1)
std::map< Size, std::string > sampleRowToName_() const
unsigned getNumberOfSamples() const
std::vector< std::vector< std::pair< std::string, unsigned > > > getConditionToPathLabelVector() const
void setSampleSection(const SampleSection &sample_section)
bool sameNrOfMSFilesPerFraction() const
unsigned getNumberOfFractionGroups() const
std::map< std::pair< std::string, unsigned >, unsigned > getPathLabelToPrefractionationMapping(bool use_basename_only) const
std::map< std::vector< std::string >, std::set< unsigned > > getConditionToSampleMapping() const
return a condition (unique combination of sample section values except replicate) to Sample index map...
std::vector< std::string > getFileNames_(bool basename) const
std::map< std::vector< std::string >, std::set< std::string > > getUniqueSampleRowToSampleMapping() const
const MSFileSection & getMSFileSection() const
std::map< std::pair< std::string, unsigned >, unsigned > getPathLabelToConditionMapping(bool use_basename_only) const
void setMSFileSection(const MSFileSection &msfile_section)
std::vector< MSFileSectionEntry > MSFileSection
Definition ExperimentalDesign.h:191
MSFileSection msfile_section_
Definition ExperimentalDesign.h:345
static ExperimentalDesign fromIdentifications(const std::vector< ProteinIdentification > &proteins)
Extract experimental design from identifications.
std::vector< unsigned > getFractions_() const
ExperimentalDesign(const MSFileSection &msfile_section, const SampleSection &sample_section)
std::vector< unsigned > getLabels_() const
std::map< std::pair< std::string, unsigned >, unsigned > getPathLabelToFractionMapping(bool use_basename_only) const
return <file_path, label> to fraction mapping
std::map< std::pair< std::string, unsigned >, unsigned > pathLabelMapper_(bool, unsigned(*f)(const ExperimentalDesign::MSFileSectionEntry &)) const
Generic Mapper (Path, Label) -> f(row)
std::map< unsigned int, std::vector< std::string > > getFractionToMSFilesMapping() const
return fraction index to file paths (ordered by fraction_group)
Size annotateColumnHeaders(ConsensusMap &cmap) const
Write this design's fraction structure onto a ConsensusMap's column headers.
std::map< std::string, unsigned > getSampleToPrefractionationMapping() const
static ExperimentalDesign fromFeatureMap(const FeatureMap &f)
Extract experimental design from feature map.
const ExperimentalDesign::SampleSection & getSampleSection() const
std::map< std::pair< std::string, unsigned >, unsigned > getPathLabelToFractionGroupMapping(bool use_basename_only) const
return <file_path, label> to fraction_group mapping
SampleSection sample_section_
Definition ExperimentalDesign.h:346
std::map< std::string, unsigned > getSampleToConditionMapping() const
unsigned getNumberOfMSFiles() const
A container for features.
Definition FeatureMap.h:78
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19