OpenMS  2.4.0
ExperimentalDesign.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-2018.
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 #pragma once
36 
39 #include <OpenMS/SYSTEM/File.h>
43 
44 #include <vector>
45 #include <map>
46 #include <set>
47 #include <algorithm>
48 
49 namespace OpenMS
50 {
85  class OPENMS_DLLAPI ExperimentalDesign
86  {
87  public:
94  class OPENMS_DLLAPI MSFileSectionEntry
95  {
96  public:
97  MSFileSectionEntry() = default;
98  unsigned fraction_group = 1;
99  unsigned fraction = 1;
100  std::string path = "UNKNOWN_FILE";
101  unsigned label = 1;
102  unsigned sample = 1;
103  };
104 
105  class OPENMS_DLLAPI SampleSection
106  {
107  public:
108 
109  SampleSection() = default;
110 
112  const std::vector< std::vector < String > >& content,
113  const std::map< unsigned, Size >& sample_to_rowindex,
114  const std::map< String, Size >& columnname_to_columnindex
115  );
116 
117  // Get set of all samples that are present in the sample section
118  std::set< unsigned > getSamples() const;
119 
120  // Get set of all factors (column names) that were defined for the sample section
121  std::set< String > getFactors() const;
122 
123  // Checks whether sample section has row for a sample number
124  bool hasSample(unsigned sample) const;
125 
126  // Checks whether Sample Section has a specific factor (i.e. column name)
127  bool hasFactor(const String &factor) const;
128 
129  // Returns value of factor for given sample and factor name
130  String getFactorValue(unsigned sample, const String &factor);
131 
132  private:
133 
134  // The entries of the Sample Section, filled while parsing
135  // the Experimental Design File
136  std::vector< std::vector < String > > content_;
137 
138  // Maps the Sample Entry to the row where the sample
139  // appears in the Sample section
140  std::map< unsigned, Size > sample_to_rowindex_;
141 
142  // Maps the column name of the SampleSection to the
143  // Index of the column
144  std::map< String, Size > columnname_to_columnindex_;
145  };
146 
147  using MSFileSection = std::vector<MSFileSectionEntry>;
148 
149  // Experimental Design c'tors
150  ExperimentalDesign() = default;
151 
152  ExperimentalDesign(const MSFileSection& msfile_section, const SampleSection& sample_section);
153 
154  const MSFileSection& getMSFileSection() const;
155 
156  void setMSFileSection(const MSFileSection& msfile_section);
157 
158  // Returns the Sample Section of the experimental design file
159  const ExperimentalDesign::SampleSection& getSampleSection() const;
160 
161  void setSampleSection(const SampleSection& sample_section);
162 
163 
165  std::map<unsigned int, std::vector<String> > getFractionToMSFilesMapping() const;
166 
167  /*
168  * The (Path, Label) tuples in the experimental design have to be unique, so we can map them
169  * uniquely to the sample number, fraction number, and fraction_group number
170  */
172  std::map< std::pair< String, unsigned >, unsigned> getPathLabelToSampleMapping(bool) const;
173 
175  std::map< std::pair< String, unsigned >, unsigned> getPathLabelToFractionMapping(bool) const;
176 
178  std::map< std::pair< String, unsigned >, unsigned> getPathLabelToFractionGroupMapping(bool) const;
179 
180  // @return the number of samples measured (= highest sample index)
181  unsigned getNumberOfSamples() const;
182 
183  // @return the number of fractions (= highest fraction index)
184  unsigned getNumberOfFractions() const;
185 
186  // @return the number of labels per file
187  unsigned getNumberOfLabels() const;
188 
189  // @return the number of MS files (= fractions * fraction groups)
190  unsigned getNumberOfMSFiles() const;
191 
192  // @return the number of fraction_groups
193  // Allows to group fraction ids and source files
194  unsigned getNumberOfFractionGroups() const;
195 
196  // @return sample index (depends on fraction_group and label)
197  unsigned getSample(unsigned fraction_group, unsigned label = 1);
198 
200  // This is the case if we have at least one fraction group with >= 2 fractions
201  bool isFractionated() const;
202 
204  bool sameNrOfMSFilesPerFraction() const;
205 
207  static ExperimentalDesign fromConsensusMap(const ConsensusMap& c);
208 
210  static ExperimentalDesign fromFeatureMap(const FeatureMap& f);
211 
213  static ExperimentalDesign fromIdentifications(const std::vector<ProteinIdentification> & proteins);
214 
215  private:
216  // MS filename column, optionally trims to basename
217  std::vector< String > getFileNames_(bool basename) const;
218 
219  // returns label column
220  std::vector<unsigned> getLabels_() const;
221 
222  // returns fraction column
223  std::vector<unsigned> getFractions_() const;
224 
226  std::map< std::pair< String, unsigned >, unsigned> pathLabelMapper_(
227  bool,
228  unsigned (*f)(const ExperimentalDesign::MSFileSectionEntry&)) const;
229 
230  // sort to obtain the default order
231  void sort_();
232 
233  template<typename T>
234  static void errorIfAlreadyExists(std::set<T> &container, T &item, const String &message);
235 
236  // basic consistency checks
237  void isValid_();
238 
241  };
242 }
243 
A more convenient string class.
Definition: String.h:57
A container for features.
Definition: FeatureMap.h:93
MSFileSection msfile_section_
Definition: ExperimentalDesign.h:239
A container for consensus elements.
Definition: ConsensusMap.h:75
const double c
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
std::map< unsigned, Size > sample_to_rowindex_
Definition: ExperimentalDesign.h:140
Representation of the Experimental Design in OpenMS. Instances can be loaded via the ExperimentalDesi...
Definition: ExperimentalDesign.h:85
Definition: ExperimentalDesign.h:94
std::map< String, Size > columnname_to_columnindex_
Definition: ExperimentalDesign.h:144
SampleSection sample_section_
Definition: ExperimentalDesign.h:240
Definition: ExperimentalDesign.h:105
std::vector< std::vector< String > > content_
Definition: ExperimentalDesign.h:136
std::vector< MSFileSectionEntry > MSFileSection
Definition: ExperimentalDesign.h:147