| OpenMS 2.5.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-2020.
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
37 #include <OpenMS/KERNEL/StandardTypes.h>
38 #include <OpenMS/DATASTRUCTURES/String.h>
39 #include <OpenMS/SYSTEM/File.h>
40 #include <OpenMS/KERNEL/ConsensusMap.h>
41 #include <OpenMS/KERNEL/FeatureMap.h>
42 #include <OpenMS/METADATA/ProteinIdentification.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
88 public:
95 class OPENMS_DLLAPI MSFileSectionEntry
96 {
97 public:
98 MSFileSectionEntry() = default;
99 unsigned fraction_group = 1;
100 unsigned fraction = 1;
101 std::string path = "UNKNOWN_FILE";
102 unsigned label = 1;
103 unsigned sample = 1;
104 };
105
106 class OPENMS_DLLAPI SampleSection
107 {
108 public:
109
110 SampleSection() = default;
111
112 SampleSection(
113 const std::vector< std::vector < String > >& content,
114 const std::map< unsigned, Size >& sample_to_rowindex,
115 const std::map< String, Size >& columnname_to_columnindex
116 );
117
118 // Get set of all samples that are present in the sample section
119 std::set< unsigned > getSamples() const;
120
121 // Add a sample as the last row
122 void addSample(unsigned sample, const std::vector<String>& content = {});
123
124 // TODO should it include the Sample ID column or not??
125 // Get set of all factors (column names) that were defined for the sample section
126 std::set< String > getFactors() const;
127
128 // Checks whether sample section has row for a sample number
129 bool hasSample(unsigned sample) const;
130
131 // Checks whether Sample Section has a specific factor (i.e. column name)
132 bool hasFactor(const String &factor) const;
133
134 // Returns value of factor for given sample and factor name
135 String getFactorValue(unsigned sample, const String &factor) const;
136
137 // Returns column index of factor
138 Size getFactorColIdx( const String &factor) const;
139
140 private:
141
142 // The entries of the Sample Section, filled while parsing
143 // the Experimental Design File
144 std::vector< std::vector < String > > content_;
145
146 // Maps the Sample Entry to the row where the sample
147 // appears in the Sample section
148 std::map< unsigned, Size > sample_to_rowindex_;
149
150 // Maps the column name of the SampleSection to the
151 // Index of the column
152 std::map< String, Size > columnname_to_columnindex_;
153 };
154
155 using MSFileSection = std::vector<MSFileSectionEntry>;
156
157 // Experimental Design c'tors
158 ExperimentalDesign() = default;
159
160 ExperimentalDesign(const MSFileSection& msfile_section, const SampleSection& sample_section);
161
162 const MSFileSection& getMSFileSection() const;
163
164 void setMSFileSection(const MSFileSection& msfile_section);
165
166 // Returns the Sample Section of the experimental design file
167 const ExperimentalDesign::SampleSection& getSampleSection() const;
168
169 void setSampleSection(const SampleSection& sample_section);
170
173 std::map<std::vector<String>, std::set<unsigned>> getUniqueSampleRowToSampleMapping() const;
174
177 std::map<unsigned, unsigned> getSampleToPrefractionationMapping() const;
178
180 //TODO this probably needs a basename parameter to be fully compatible with the other mappings!! Implicit full path.
181 std::map<unsigned int, std::vector<String> > getFractionToMSFilesMapping() const;
182
185 //TODO this probably needs a basename parameter to be fully compatible with the other mappings!! Implicit full path.
186 std::vector<std::vector<std::pair<String, unsigned>>> getConditionToPathLabelVector() const;
187
189 std::map<std::vector<String>, std::set<unsigned>> getConditionToSampleMapping() const;
190
191 /*
192 * The (Path, Label) tuples in the experimental design have to be unique, so we can map them
193 * uniquely to the sample number, fraction number, and fraction_group number
194 */
195
198 std::map< std::pair< String, unsigned >, unsigned> getPathLabelToPrefractionationMapping(bool use_basename_only) const;
199
202 std::map< std::pair< String, unsigned >, unsigned> getPathLabelToConditionMapping(bool use_basename_only) const;
203
206 std::map<unsigned, unsigned> getSampleToConditionMapping() const;
207
209 std::map< std::pair< String, unsigned >, unsigned> getPathLabelToSampleMapping(bool use_basename_only) const;
210
212 std::map< std::pair< String, unsigned >, unsigned> getPathLabelToFractionMapping(bool use_basename_only) const;
213
215 std::map< std::pair< String, unsigned >, unsigned> getPathLabelToFractionGroupMapping(bool use_basename_only) const;
216
217 // @return the number of samples measured (= highest sample index)
218 unsigned getNumberOfSamples() const;
219
220 // @return the number of fractions (= highest fraction index)
221 unsigned getNumberOfFractions() const;
222
223 // @return the number of labels per file
224 unsigned getNumberOfLabels() const;
225
226 // @return the number of MS files (= fractions * fraction groups)
227 unsigned getNumberOfMSFiles() const;
228
229 // @return the number of fraction_groups
230 // Allows to group fraction ids and source files
231 unsigned getNumberOfFractionGroups() const;
232
233 // @return sample index (depends on fraction_group and label)
234 unsigned getSample(unsigned fraction_group, unsigned label = 1);
235
237 // This is the case if we have at least one fraction group with >= 2 fractions
238 bool isFractionated() const;
239
241 bool sameNrOfMSFilesPerFraction() const;
242
244 static ExperimentalDesign fromConsensusMap(const ConsensusMap& c);
245
247 static ExperimentalDesign fromFeatureMap(const FeatureMap& f);
248
250 static ExperimentalDesign fromIdentifications(const std::vector<ProteinIdentification>& proteins);
251 //TODO create another overload here, that takes two enums outerVec and innerVec with entries Replicate, Fraction, Sample
252
253 private:
254 // MS filename column, optionally trims to basename
255 std::vector< String > getFileNames_(bool basename) const;
256
257 // returns label column
258 std::vector<unsigned> getLabels_() const;
259
260 // returns fraction column
261 std::vector<unsigned> getFractions_() const;
262
264 std::map< std::pair< String, unsigned >, unsigned> pathLabelMapper_(
265 bool,
266 unsigned (*f)(const ExperimentalDesign::MSFileSectionEntry&)) const;
267
268 // sort to obtain the default order
269 void sort_();
270
271 template<typename T>
272 static void errorIfAlreadyExists(std::set<T> &container, T &item, const String &message);
273
274 // basic consistency checks
275 void isValid_();
276
277 MSFileSection msfile_section_;
278 SampleSection sample_section_;
279 };
280 }
281
ProteinIdentification.h
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::ExperimentalDesign::MSFileSection
std::vector< MSFileSectionEntry > MSFileSection
Definition: ExperimentalDesign.h:155
OpenMS::ExperimentalDesign::SampleSection
Definition: ExperimentalDesign.h:106
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:95
StandardTypes.h
OpenMS::ExperimentalDesign::sample_section_
SampleSection sample_section_
Definition: ExperimentalDesign.h:278
ConsensusMap.h
FeatureMap.h
String.h
OpenMS::ExperimentalDesign
Representation of the Experimental Design in OpenMS. Instances can be loaded via the ExperimentalDesi...
Definition: ExperimentalDesign.h:85
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::ExperimentalDesign::SampleSection::sample_to_rowindex_
std::map< unsigned, Size > sample_to_rowindex_
Definition: ExperimentalDesign.h:148
OpenMS::Constants::c
const double c
OpenMS::ExperimentalDesign::MSFileSectionEntry
Definition: ExperimentalDesign.h:95
OpenMS::ExperimentalDesign::SampleSection::content_
std::vector< std::vector< String > > content_
Definition: ExperimentalDesign.h:144
OpenMS::ConsensusMap
A container for consensus elements.
Definition: ConsensusMap.h:79
File.h
OpenMS::ExperimentalDesign::SampleSection::columnname_to_columnindex_
std::map< String, Size > columnname_to_columnindex_
Definition: ExperimentalDesign.h:152
OpenMS::ExperimentalDesign::msfile_section_
MSFileSection msfile_section_
Definition: ExperimentalDesign.h:277
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127