|
A library for working with phylogenetic and population genetic data.
v0.27.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_POPULATION_GENOME_REGION_LIST_H_
2 #define GENESIS_POPULATION_GENOME_REGION_LIST_H_
45 namespace population {
131 std::string
const& chromosome,
137 if( chromosome.empty() ) {
138 throw std::invalid_argument(
139 "Cannot add region to GenomeRegionList with empty chromosome name, "
140 "as this denotes an invalid chromosome."
148 throw std::invalid_argument(
149 "Cannot add region to GenomeRegionList with start == " +
153 if( start == 0 || end == 0 ) {
154 throw std::invalid_argument(
155 "Cannot add region to GenomeRegionList with start == 0 or end == 0, "
156 "as these denote invalid positions."
164 regions_[ chromosome ].insert_overlap({ start, end });
166 regions_[ chromosome ].insert({ start, end });
196 throw std::invalid_argument(
197 "Cannot use two GenomeLocus instances with different chromosomes ( start == \"" +
234 for(
auto const& chr : other.regions_ ) {
235 for(
auto const& interval : chr.second ) {
236 add( chr.first, interval.low(), interval.high(), overlap );
256 void clear( std::string
const& chromosome )
258 if( regions_.count( chromosome ) == 0 ) {
259 throw std::invalid_argument(
260 "Chromosome name \"" + chromosome +
"\" not found in GenomeRegionList"
263 regions_.erase( chromosome );
276 auto const it = regions_.find( chromosome );
277 if( it == regions_.end() ) {
280 auto const& chrom_tree = it->second;
281 return chrom_tree.overlap_find( position ) != chrom_tree.end();
314 return regions_.empty();
322 return regions_.size();
330 std::vector<std::string> result;
331 for(
auto const& p : regions_ ) {
332 result.push_back( p.first );
342 return regions_.count( chromosome ) > 0;
351 return regions_.at( chromosome );
360 return regions_.at( chromosome );
368 if( regions_.count( chromosome ) == 0 ) {
369 throw std::invalid_argument(
370 "Chromosome name \"" + chromosome +
"\" not found in GenomeRegionList"
373 return regions_.at( chromosome ).size();
382 for(
auto const& reg : regions_ ) {
383 cnt += reg.second.size();
457 std::map<std::string, tree_type> regions_;
466 #endif // include guard
typename tree_type::const_iterator const_iterator
std::vector< std::string > chromosome_names() const
Get a list of all stored chromosome names.
std::map< std::string, tree_type > const & chromosome_map() const
Access the underlying container directly.
void clear(std::string const &chromosome)
Remove the regions of the specified chromosome.
size_t region_count(std::string const &chromosome) const
Return the number of regions stored for the specified chromosome.
bool empty() const
Return whether there are chromosomes with regions stored.
void add(GenomeRegionList const &other, bool overlap=false)
Add a complete GenomeRegionList to this list.
size_t chromosome_count() const
Return the number of chromosomes for which there are regions stored.
A single locus, that is, a position (or coordinate) on a chromosome.
bool has_chromosome(std::string const &chromosome) const
Return whether a chromosome is stored.
List of regions in a genome, for each chromosome.
std::string to_string(GenomeLocus const &locus)
EmptyGenomeData data_type
std::map< std::string, tree_type > & chromosome_map()
Access the underlying container directly.
Helper type to define a closed [] Interval.
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.
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 & operator=(GenomeRegionList const &)=default
void add(GenomeLocus const &start, GenomeLocus const &end, bool overlap=false)
Add an interval between two Loci on the same chromosome.
tree_type const & chromosome_regions(std::string const &chromosome) const
For a given chromosome, return the IntervalTree that stores its regions.
IntervalTreeIterator< node_type, false > iterator
void add(GenomeLocus const &locus, bool overlap=false)
Add a single Locus, that is, an interval covering one position on a chromosome.
Helper struct to define a default empty data for the classes GenomeLocus, GenomeRegion,...
GenomeRegionList()=default
IntervalTreeIterator< node_type, true > const_iterator
void add(GenomeRegion const ®ion, bool overlap=false)
Add a GenomeRegion to the list.
tree_type & chromosome_regions(std::string const &chromosome)
For a given chromosome, return the IntervalTree that stores its regions.
A region (between two positions) on a chromosome.
void clear()
Remove all stored regions from all chromosomes.
~GenomeRegionList()=default
Interval tree that enables storing and querying intervals, each containing some data.
size_t total_region_count() const
Return the number of regions stored in total, across all chromosomes.
typename tree_type::iterator iterator