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
13
14#include <vector>
15#include <map>
16#include <set>
17
18namespace OpenMS
19{
20 class ConsensusMap;
21 class FeatureMap;
22 class ProteinIdentification;
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
542 std::string getFactorValue(const std::string& sample_name, const std::string &factor) const;
543
547 std::string getFactorValue(unsigned sample_idx, const std::string &factor) const;
548
554 Size getFactorColIdx(const std::string &factor) const;
555
557 std::string getSampleName(unsigned sample_row) const;
558
560 unsigned getSampleRow(const std::string& sample) const;
561
564
565 private:
566
567 // The entries of the Sample Section, filled while parsing
568 // the Experimental Design File
569 std::vector< std::vector < std::string > > content_;
570
571 // Maps the Sample Entry name to the row where the sample
572 // appears in the Sample section, its sample index
573 std::map< std::string, Size > sample_to_rowindex_;
574
575 // Maps the column name of the SampleSection to the
576 // Index of the column
577 std::map< std::string, Size > columnname_to_columnindex_;
578 };
579
580 using MSFileSection = std::vector<MSFileSectionEntry>;
581
582 // Experimental Design c'tors
584
585 ExperimentalDesign(const MSFileSection& msfile_section, const SampleSection& sample_section);
586
588
589 void setMSFileSection(const MSFileSection& msfile_section);
590
591 // Returns the Sample Section of the experimental design file
593
594 void setSampleSection(const SampleSection& sample_section);
595
601 std::map<std::vector<std::string>, std::set<std::string>> getUniqueSampleRowToSampleMapping() const;
602
606 std::map<std::string, unsigned> getSampleToPrefractionationMapping() const;
607
609 //TODO this probably needs a basename parameter to be fully compatible with the other mappings!! Implicit full path.
610 std::map<unsigned int, std::vector<std::string> > getFractionToMSFilesMapping() const;
611
614 //TODO this probably needs a basename parameter to be fully compatible with the other mappings!! Implicit full path.
615 std::vector<std::vector<std::pair<std::string, unsigned>>> getConditionToPathLabelVector() const;
616
629 std::map<std::vector<std::string>, std::set<unsigned>> getConditionToSampleMapping() const;
630
631 /*
632 * The (Path, Label) tuples in the experimental design have to be unique, so we can map them
633 * uniquely to the sample number, fraction number, and fraction_group number
634 */
635
638 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToPrefractionationMapping(bool use_basename_only) const;
639
642 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToConditionMapping(bool use_basename_only) const;
643
648 std::map<std::string, unsigned> getSampleToConditionMapping() const;
649
651 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToSampleMapping(bool use_basename_only) const;
652
654 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToFractionMapping(bool use_basename_only) const;
655
657 std::map< std::pair< std::string, unsigned >, unsigned> getPathLabelToFractionGroupMapping(bool use_basename_only) const;
658
664 unsigned getNumberOfSamples() const;
665
672 unsigned getNumberOfFractions() const;
673
679 unsigned getNumberOfLabels() const;
680
685 unsigned getNumberOfMSFiles() const;
686
692
697 unsigned getSample(unsigned fraction_group, unsigned label = 1);
698
702 bool isFractionated() const;
703
707 Size filterByBasenames(const std::set<std::string>& bns);
708
711
714
733
736
738 static ExperimentalDesign fromIdentifications(const std::vector<ProteinIdentification>& proteins);
739 //TODO create another overload here, that takes two enums outerVec and innerVec with entries Replicate, Fraction, Sample
740
741 private:
742 // sample row index -> sample name; the reverse of SampleSection's name->row store
743 std::map<Size, std::string> sampleRowToName_() const;
744
745 // MS filename column, optionally trims to basename
746 std::vector< std::string > getFileNames_(bool basename) const;
747
748 // returns label column
749 std::vector<unsigned> getLabels_() const;
750
751 // returns fraction column
752 std::vector<unsigned> getFractions_() const;
753
755 std::map< std::pair< std::string, unsigned >, unsigned> pathLabelMapper_(
756 bool,
757 unsigned (*f)(const ExperimentalDesign::MSFileSectionEntry&)) const;
758
759 // sort to obtain the default order
760 void sort_();
761
762 template<typename T>
763 static void errorIfAlreadyExists(std::set<T> &container, T &item, const std::string &message);
764
765 // basic consistency checks
766 void isValid_();
767
770 };
771}
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:573
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:577
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:569
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:580
MSFileSection msfile_section_
Definition ExperimentalDesign.h:768
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:769
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