|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
45 namespace population {
77 throw std::invalid_argument(
78 "Invalid GenomeRegion with empty chromosome."
81 if(( region.
start == 0 ) != ( region.
end == 0 )) {
82 throw std::invalid_argument(
83 "Invalid GenomeRegion with one of start and end equal to zero."
87 throw std::invalid_argument(
88 "Invalid GenomeRegion with start > end."
93 if( region.
start == 0 && region.
end == 0 ) {
95 }
else if( region.
start == region.
end ) {
112 auto throw_invalid_arg_ = [&](){
113 throw std::invalid_argument(
"Invalid genomic region string \"" + region +
"\"" );
117 auto convert_str_to_pos_ = [&]( std::string
const& str ){
120 res = utils::convert_from_string<size_t>( str,
true );
122 throw_invalid_arg_();
128 auto const chr_split =
utils::split( region,
":",
false );
129 assert( chr_split.size() > 0 );
134 throw_invalid_arg_();
138 if( chr_split.size() == 2 ) {
141 auto pos_split =
utils::split( chr_split[1],
"-",
false );
142 if( pos_split.size() == 1 ) {
147 if( pos_split.size() == 1 ) {
149 if( pos_split[0].empty() ) {
150 throw_invalid_arg_();
152 auto const pos = convert_str_to_pos_( pos_split[0] );
155 }
else if( pos_split.size() == 2 ) {
158 if( pos_split[0].empty() || pos_split[1].empty() ) {
159 throw_invalid_arg_();
161 result.
start = convert_str_to_pos_( pos_split[0] );
162 result.
end = convert_str_to_pos_( pos_split[1] );
164 throw_invalid_arg_();
172 if( end_exclusive ) {
173 if( result.
end == 0 ) {
174 throw_invalid_arg_();
181 throw_invalid_arg_();
183 }
else if( chr_split.size() > 2 ) {
185 throw_invalid_arg_();
191 std::string
const& regions,
bool zero_based,
bool end_exclusive
195 auto const region_list =
utils::split( regions,
",",
false );
196 for(
auto const& region : region_list ) {
210 throw std::runtime_error(
"Invalid GenomeRegion with start > end" );
213 if( region.
start > 0 && region.
end > 0 ) {
215 auto const chr = chromosome == region.
chromosome;
216 auto const beg = position >= region.
start;
217 auto const end = position <= region.
end;
218 return chr && beg && end;
219 }
else if( region.
start == 0 && region.
end == 0 ) {
225 assert( region.
start == 0 || region.
end == 0 );
bool operator!=(GenomeLocus const &l, GenomeLocus const &r)
Inequality comparison (!=) for two loci in a genome.
std::ostream & operator<<(std::ostream &os, SampleCounts const &bs)
Output stream operator for SampleCounts instances.
void add(std::string const &chromosome)
Add a whole chromosome to the list, so that all its positions are considered to be covered.
bool operator==(GenomeLocus const &l, GenomeLocus const &r)
Equality comparison (==) for two loci in a genome.
std::string trim(std::string const &s, std::string const &delimiters)
Return a copy of the input string, with trimmed white spaces (or any other delimiters).
List of regions in a genome, for each chromosome.
bool is_covered(GenomeRegion const ®ion, std::string const &chromosome, size_t position)
Test whether the chromosome/position is within a given genomic region.
std::vector< std::string > split(std::string const &str, char delimiter, const bool trim_empty)
Spilt a string into parts, given a delimiter char.
std::string to_string(GenomeLocus const &locus)
Provides some commonly used string utility functions.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
GenomeRegionList parse_genome_regions(std::string const ®ions, bool zero_based, bool end_exclusive)
Parse a set/list of genomic regions.
A region (between two positions) on a chromosome.
std::string to_string(GenomeRegion const ®ion)
std::vector< std::string > split_at(std::string const &str, std::string const &delimiter, const bool trim_empty)
Spilt a string into parts, given a delimiter string.
GenomeRegion parse_genome_region(std::string const ®ion, bool zero_based, bool end_exclusive)
Parse a genomic region.