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
448 class OPENMS_DLLAPI ExperimentalDesign
449 {
450
451 public:
462 class OPENMS_DLLAPI MSFileSectionEntry
463 {
464 public:
470 unsigned fraction_group = 1;
471
476 unsigned fraction = 1;
477
479 std::string path = "UNKNOWN_FILE";
480
485 unsigned label = 1;
486
490 unsigned sample = 0;
491
496 std::string sample_name = "0";
497 };
498
506 class OPENMS_DLLAPI SampleSection
507 {
508 public:
509
510 SampleSection() = default;
511
513 const std::vector< std::vector < std::string > >& content,
514 const std::map< std::string, Size >& sample_to_rowindex,
515 const std::map< std::string, Size >& columnname_to_columnindex
516 );
517
519 std::set< std::string > getSamples() const;
520
522 void addSample(const std::string& sample, const std::vector<std::string>& content = {});
523
524 // TODO should it include the Sample ID column or not??
530 std::set< std::string > getFactors() const;
531
533 bool hasSample(const std::string& sample) const;
534
536 bool hasFactor(const std::string &factor) const;
537
539 std::string getFactorValue(const std::string& sample_name, const std::string &factor) const;
540
542 std::string getFactorValue(unsigned sample_idx, const std::string &factor) const;
543
549 Size getFactorColIdx(const std::string &factor) const;
550
552 std::string getSampleName(unsigned sample_row) const;
553
555 unsigned getSampleRow(const std::string& sample) const;
556
559
560 private:
561
562 // The entries of the Sample Section, filled while parsing
563 // the Experimental Design File
564 std::vector< std::vector < std::string > > content_;
565
566 // Maps the Sample Entry name to the row where the sample
567 // appears in the Sample section, its sample index
568 std::map< std::string, Size > sample_to_rowindex_;
569
570 // Maps the column name of the SampleSection to the
571 // Index of the column
572 std::map< std::string, Size > columnname_to_columnindex_;
573 };
574
575 using MSFileSection = std::vector<MSFileSectionEntry>;
576
577 // Experimental Design c'tors
579
580 ExperimentalDesign(const MSFileSection& msfile_section, const SampleSection& sample_section);
581
583
584 void setMSFileSection(const MSFileSection& msfile_section);
585
586 // Returns the Sample Section of the experimental design file
588
589 void setSampleSection(const SampleSection& sample_section);
590
596 std::map<std::vector<std::string>, std::set<std::string>> getUniqueSampleRowToSampleMapping() const;
597
601 std::map<std::string, unsigned> getSampleToPrefractionationMapping() const;
602
604 //TODO this probably needs a basename parameter to be fully compatible with the other mappings!! Implicit full path.
605 std::map<unsigned int, std::vector<std::string> > getFractionToMSFilesMapping() const;
606
609 //TODO this probably needs a basename parameter to be fully compatible with the other mappings!! Implicit full path.
610 std::vector<std::vector<std::pair<std::string, unsigned>>> getConditionToPathLabelVector() const;
611
624 std::map<std::vector<std::string>, std::set<unsigned>> getConditionToSampleMapping() const;
625
626 /*
627 * The (Path, Label) tuples in the experimental design have to be unique, so we can map them
628 * uniquely to the sample number, fraction number, and fraction_group number
629 */
630
633 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToPrefractionationMapping(bool use_basename_only) const;
634
637 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToConditionMapping(bool use_basename_only) const;
638
643 std::map<std::string, unsigned> getSampleToConditionMapping() const;
644
646 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToSampleMapping(bool use_basename_only) const;
647
649 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToFractionMapping(bool use_basename_only) const;
650
652 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToFractionGroupMapping(bool use_basename_only) const;
653
659 unsigned getNumberOfSamples() const;
660
667 unsigned getNumberOfFractions() const;
668
674 unsigned getNumberOfLabels() const;
675
680 unsigned getNumberOfMSFiles() const;
681
687
692 unsigned getSample(unsigned fraction_group, unsigned label = 1);
693
697 bool isFractionated() const;
698
702 Size filterByBasenames(const std::set<std::string>& bns);
703
706
709
728
731
733 static ExperimentalDesign fromIdentifications(const std::vector<ProteinIdentification>& proteins);
734 //TODO create another overload here, that takes two enums outerVec and innerVec with entries Replicate, Fraction, Sample
735
736 private:
737 // sample row index -> sample name; the reverse of SampleSection's name->row store
738 std::map<Size, std::string> sampleRowToName_() const;
739
740 // MS filename column, optionally trims to basename
741 std::vector< std::string > getFileNames_(bool basename) const;
742
743 // returns label column
744 std::vector<unsigned> getLabels_() const;
745
746 // returns fraction column
747 std::vector<unsigned> getFractions_() const;
748
750 std::map< std::pair< std::string, unsigned >, unsigned> pathLabelMapper_(
751 bool,
752 unsigned (*f)(const ExperimentalDesign::MSFileSectionEntry&)) const;
753
754 // sort to obtain the default order
755 void sort_();
756
757 template<typename T>
758 static void errorIfAlreadyExists(std::set<T> &container, T &item, const std::string &message);
759
760 // basic consistency checks
761 void isValid_();
762
765 };
766}
767
A container for consensus elements.
Definition ConsensusMap.h:67
One row of the MS file section: one quantitative channel of one MS file.
Definition ExperimentalDesign.h:463
The sample section: one named row per sample, one column per factor.
Definition ExperimentalDesign.h:507
std::map< std::string, Size > sample_to_rowindex_
Definition ExperimentalDesign.h:568
void addSample(const std::string &sample, const std::vector< std::string > &content={})
Add a sample as the last row.
std::set< std::string > getFactors() const
Get set of all factors (column names) defined for the sample section.
std::string getSampleName(unsigned sample_row) const
Returns the name/ID of the sample for a zero-based row index. Not the row index itself.
bool hasFactor(const std::string &factor) const
Checks whether Sample Section has a specific factor (i.e. column name)
std::map< std::string, Size > columnname_to_columnindex_
Definition ExperimentalDesign.h:572
std::set< std::string > getSamples() const
Get set of all sample NAMES (the Sample column values) present in the sample section.
Size getContentSize() const
returns the number of entries in content_ member
std::vector< std::vector< std::string > > content_
Definition ExperimentalDesign.h:564
std::string getFactorValue(const std::string &sample_name, const std::string &factor) const
Returns value of factor for given sample NAME and factor name.
std::string getFactorValue(unsigned sample_idx, const std::string &factor) const
Returns value of factor for given sample ROW INDEX (zero-based) and factor name.
unsigned getSampleRow(const std::string &sample) const
Returns the zero-based row index in the sample section for a sample name/ID.
Size getFactorColIdx(const std::string &factor) const
Returns column index of factor.
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
Checks whether the sample section has a row for a sample name.
Representation of an experimental design in OpenMS. Instances can be loaded with the ExperimentalDesi...
Definition ExperimentalDesign.h:449
unsigned getNumberOfLabels() const
Highest label index used anywhere in the design.
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
Number of distinct fraction indices used anywhere in the design.
static ExperimentalDesign fromConsensusMap(const ConsensusMap &c)
Extract experimental design from consensus map.
unsigned getSample(unsigned fraction_group, unsigned label=1)
Sample quantified in a given fraction group and label.
std::map< Size, std::string > sampleRowToName_() const
unsigned getNumberOfSamples() const
Number of samples measured (= number of rows in the sample section)
std::vector< std::vector< std::pair< std::string, unsigned > > > getConditionToPathLabelVector() const
void setSampleSection(const SampleSection &sample_section)
bool sameNrOfMSFilesPerFraction() const
unsigned getNumberOfFractionGroups() const
Number of distinct fraction groups.
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 to Sample index mapping
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:575
MSFileSection msfile_section_
Definition ExperimentalDesign.h:763
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)
bool isFractionated() const
Whether the design is fractionated.
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:764
std::map< std::string, unsigned > getSampleToConditionMapping() const
unsigned getNumberOfMSFiles() const
Number of distinct MS file paths in the design.
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