|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
75 read( source, result );
91 if( line.name ==
"" ) {
99 taxopath_parser_.
parse( line.name ),
104 taxon.rank( line.rank );
116 auto get_field = [&] (
int field_pos, std::string field_name ) {
118 if( field_pos < 0 ) {
119 return std::string();
123 assert( field_pos >= 0 );
124 auto pos =
static_cast< size_t >( field_pos );
127 if( pos >= fields.size() ) {
128 throw std::out_of_range(
129 "Invalid position for taxonomy " + field_name +
" field while reading. Expect "
130 + field_name +
" at position " +
std::to_string( pos ) +
" (zero-based), "
137 assert( pos < fields.size() );
138 return fields[ pos ];
143 result.
name = get_field( name_field_position_,
"name" );
144 result.
rank = get_field( rank_field_position_,
"rank" );
145 result.
id = get_field( id_field_position_,
"ID" );
161 return taxopath_parser_;
169 throw std::out_of_range(
170 "Cannot set TaxonomyReader::name_field_position to a value below zero."
173 name_field_position_ = value;
179 return name_field_position_;
184 rank_field_position_ = value;
190 return rank_field_position_;
195 id_field_position_ = value;
201 return id_field_position_;
206 expect_strict_order_ = value;
212 return expect_strict_order_;
void read(std::shared_ptr< utils::BaseInputSource > source, Taxonomy &target) const
Read taxonomy data from an input source, and add the contents to a Taxonomy.
std::vector< std::string > parse_line(utils::InputStream &input_stream) const
Parse one line of the CSV data and return it.
CsvReader & separator_chars(std::string const &chars)
Set the chars used to separate fields of the CSV data.
bool expect_strict_order() const
Return whether currently the reader expects a strict order of taxa.
Provides functions for accessing the file system.
Read Taxonomy file formats.
Internal helper structure that stores the relevant data of one line while reading.
int name_field_position() const
Get the currently set position of the field in each line where the taxon name is located.
Provides some valuable additions to STD.
int id_field_position() const
Get the currently set position of the field in each line where the ID is located.
std::string to_string(GenomeLocus const &locus)
Provides some commonly used string utility functions.
Taxopath parse(std::string const &taxopath) const
Parse a taxonomic path string into a Taxopath object and return it.
TaxonomyReader()
Default constructor.
int rank_field_position() const
Get the currently set position of the field in each line where the rank name is located.
utils::CsvReader & csv_reader()
Get the CsvReader used for reading a taxonomy file.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Taxon & add_from_taxopath(Taxonomy &taxonomy, Taxopath const &taxopath, bool expect_parents)
Add a Taxon to a Taxonomy, using the taxonomic elements of a Taxopath.
Store a Taxonomy, i.e., a nested hierarchy of Taxa.
Line parse_line(utils::InputStream &it) const
Read a single line of a taxonomy file and return the contained name and rank.
void parse_document(utils::InputStream &it, Taxonomy &tax) const
Parse all data from an InputStream into a Taxonomy object.
Helper class to parse a string containing a taxonomic path string into a Taxopath object.
TaxopathParser & taxopath_parser()
Get the TaxopathParser used for parsing taxonomic path strings.
Read Comma/Character Separated Values (CSV) data and other delimiter-separated formats.