|
A library for working with phylogenetic and population genetic data.
v0.27.0
|
|
Go to the documentation of this file.
42 namespace population {
74 throw std::invalid_argument(
75 "Invalid GenomeRegion with empty chromosome."
78 if(( region.
start == 0 ) != ( region.
end == 0 )) {
79 throw std::invalid_argument(
80 "Invalid GenomeRegion with one of start and end equal to zero."
84 throw std::invalid_argument(
85 "Invalid GenomeRegion with start > end."
90 if( region.
start == 0 && region.
end == 0 ) {
92 }
else if( region.
start == region.
end ) {
109 auto throw_invalid_arg_ = [&](){
110 throw std::invalid_argument(
"Invalid genomic region string \"" + region +
"\"" );
114 auto const chr_split =
utils::split( region,
":",
false );
115 assert( chr_split.size() > 0 );
120 throw_invalid_arg_();
124 if( chr_split.size() == 2 ) {
127 auto pos_split =
utils::split( chr_split[1],
"-",
false );
128 if( pos_split.size() == 1 ) {
133 if( pos_split.size() == 1 ) {
135 auto const pos = utils::convert_from_string<size_t>( pos_split[0],
true );
138 }
else if( pos_split.size() == 2 ) {
141 if( pos_split[0].empty() || pos_split[1].empty() ) {
142 throw_invalid_arg_();
144 result.
start = utils::convert_from_string<size_t>( pos_split[0],
true );
145 result.
end = utils::convert_from_string<size_t>( pos_split[1],
true );
147 throw_invalid_arg_();
155 if( end_exclusive ) {
156 if( result.
end == 0 ) {
157 throw_invalid_arg_();
163 if( ! result.
valid() ) {
164 throw_invalid_arg_();
166 }
else if( chr_split.size() > 2 ) {
168 throw_invalid_arg_();
174 std::string
const& regions,
bool zero_based,
bool end_exclusive
178 auto const region_list =
utils::split( regions,
",",
false );
179 for(
auto const& region : region_list ) {
193 throw std::runtime_error(
"Invalid GenomeRegion with start > end" );
196 if( region.
start > 0 && region.
end > 0 ) {
198 auto const chr = chromosome == region.
chromosome;
199 auto const beg = position >= region.
start;
200 auto const end = position <= region.
end;
201 return chr && beg && end;
202 }
else if( region.
start == 0 && region.
end == 0 ) {
208 assert( region.
start == 0 || region.
end == 0 );
214 return regions.
is_covered( chromosome, position );
217 #ifdef GENESIS_HTSLIB
229 #endif // htslib guard
bool operator!=(GenomeLocus const &l, GenomeLocus const &r)
Inequality comparison (!=) for two loci in a genome.
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.
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::ostream & operator<<(std::ostream &os, BaseCounts const &bs)
Output stream operator for BaseCounts instances.
std::string to_string(GenomeLocus const &locus)
Provides some commonly used string utility functions.
void add(std::string const &chromosome, numerical_type start, numerical_type end, bool overlap=false)
Add a GenomeRegion to the list, given its chromosome, and start and end positions.
std::string get_chromosome() const
Get the name of a chromosome/contig/sequence (CHROM, first column of the line).
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
bool is_covered(std::string const &chromosome, numerical_type position) const
Return whether a given position on a chromosome is part of any of the regions stored.
GenomeRegionList parse_genome_regions(std::string const ®ions, bool zero_based, bool end_exclusive)
Parse a set/list of genomic regions.
size_t get_position() const
Get the position within the chromosome/contig (POS, second column of the line).
A region (between two positions) on a chromosome.
std::string to_string(GenomeRegion const ®ion)
Capture the information of a single SNP/variant line in a VCF/BCF file.
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.
std::vector< std::string > split(std::string const &str, std::string const &delimiters, const bool trim_empty)
Spilt a string into parts, given a delimiters set of chars.
GenomeRegion parse_genome_region(std::string const ®ion, bool zero_based, bool end_exclusive)
Parse a genomic region.