OpenMS
Loading...
Searching...
No Matches
ExperimentalDesign::SampleSection Class Reference

The sample section: one named row per sample, one column per factor. More...

#include <OpenMS/METADATA/ExperimentalDesign.h>

Public Member Functions

 SampleSection ()=default
 
 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)
 
std::set< std::string > getSamples () const
 Get set of all sample NAMES (the Sample column values) present in the sample section.
 
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.
 
bool hasSample (const std::string &sample) const
 Checks whether the sample section has a row for a sample name.
 
bool hasFactor (const std::string &factor) const
 Checks whether Sample Section has a specific factor (i.e. column name)
 
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.
 
Size getFactorColIdx (const std::string &factor) const
 Returns column index of factor.
 
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.
 
unsigned getSampleRow (const std::string &sample) const
 Returns the zero-based row index in the sample section for a sample name/ID.
 
Size getContentSize () const
 returns the number of entries in content_ member
 

Private Attributes

std::vector< std::vector< std::string > > content_
 
std::map< std::string, Size > sample_to_rowindex_
 
std::map< std::string, Size > columnname_to_columnindex_
 

Detailed Description

The sample section: one named row per sample, one column per factor.

Holds the free-form metadata half of the design (see The sample section: factors and conditions). Every column is a factor; OpenMS never interprets factor values, it only compares them to group samples into conditions.

Constructor & Destructor Documentation

◆ SampleSection() [1/2]

SampleSection ( )
default

◆ SampleSection() [2/2]

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 
)

Member Function Documentation

◆ addSample()

void addSample ( const std::string &  sample,
const std::vector< std::string > &  content = {} 
)

Add a sample as the last row.

◆ getContentSize()

Size getContentSize ( ) const

returns the number of entries in content_ member

◆ getFactorColIdx()

Size getFactorColIdx ( const std::string &  factor) const

Returns column index of factor.

This is a storage detail, not a property of the design: a one-table design orders the sample columns alphabetically, a two-table design keeps the order of the file. Address factors by name unless the layout itself matters.

◆ getFactors()

std::set< std::string > getFactors ( ) const

Get set of all factors (column names) defined for the sample section.

For a design parsed from a file this includes the Sample column itself, which the mapping functions of ExperimentalDesign drop explicitly before comparing rows. A section built with addSample() has no columns at all and returns an empty set.

◆ getFactorValue() [1/2]

std::string getFactorValue ( const std::string &  sample_name,
const std::string &  factor 
) const

Returns value of factor for given sample NAME and factor name.

Exceptions
Exception::MissingInformationif the sample or the factor is unknown, or the row of the sample has no value for the factor (a row can be shorter than the column list, e.g. when it was added with addSample() without content)

◆ getFactorValue() [2/2]

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.

Exceptions
Exception::MissingInformationif the factor is unknown or the row has no value for it; std::out_of_range if there is no such row

◆ getSampleName()

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.

◆ getSampleRow()

unsigned getSampleRow ( const std::string &  sample) const

Returns the zero-based row index in the sample section for a sample name/ID.

◆ getSamples()

std::set< std::string > getSamples ( ) const

Get set of all sample NAMES (the Sample column values) present in the sample section.

◆ hasFactor()

bool hasFactor ( const std::string &  factor) const

Checks whether Sample Section has a specific factor (i.e. column name)

◆ hasSample()

bool hasSample ( const std::string &  sample) const

Checks whether the sample section has a row for a sample name.

Member Data Documentation

◆ columnname_to_columnindex_

std::map< std::string, Size > columnname_to_columnindex_
private

◆ content_

std::vector< std::vector < std::string > > content_
private

◆ sample_to_rowindex_

std::map< std::string, Size > sample_to_rowindex_
private