A library for working with phylogenetic and population genetic data.
v0.32.0
function/genome_region.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_FUNCTION_GENOME_REGION_H_
2 #define GENESIS_POPULATION_FUNCTION_GENOME_REGION_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2024 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lczech@carnegiescience.edu>
23  Department of Plant Biology, Carnegie Institution For Science
24  260 Panama Street, Stanford, CA 94305, USA
25 */
26 
37 
38 #ifdef GENESIS_HTSLIB
39 
41 
42 #endif // htslib guard
43 
44 #include <iosfwd>
45 #include <string>
46 #include <vector>
47 
48 namespace genesis {
49 namespace population {
50 
51 // =================================================================================================
52 // Comparion Operators
53 // =================================================================================================
54 
58 bool operator ==( GenomeRegion const& a, GenomeRegion const& b );
59 
63 bool operator !=( GenomeRegion const& a, GenomeRegion const& b );
64 
65 // =================================================================================================
66 // Parsing & Printing
67 // =================================================================================================
68 
69 std::string to_string( GenomeRegion const& region );
70 std::ostream& operator<<( std::ostream& os, GenomeRegion const& region );
71 
81 GenomeRegion parse_genome_region(
82  std::string const& region,
83  bool zero_based = false,
84  bool end_exclusive = false
85 );
86 
94 GenomeRegionList parse_genome_regions(
95  std::string const& regions,
96  bool zero_based = false,
97  bool end_exclusive = false
98 );
99 
100 // =================================================================================================
101 // Region Coverage
102 // =================================================================================================
103 
104 // -------------------------------------------------------------------------
105 // Explicit chr and pos
106 // -------------------------------------------------------------------------
107 
111 bool is_covered( GenomeRegion const& region, std::string const& chromosome, size_t position );
112 
116 inline bool is_covered( GenomeRegionList const& regions, std::string const& chromosome, size_t position )
117 {
118  return regions.is_covered( chromosome, position );
119 }
120 
124 inline bool is_covered( GenomeLocusSet const& loci, std::string const& chromosome, size_t position )
125 {
126  return loci.is_covered( chromosome, position );
127 }
128 
129 // -------------------------------------------------------------------------
130 // Templates for structs
131 // -------------------------------------------------------------------------
132 
140 template<class T>
141 bool is_covered( GenomeRegion const& region, T const& locus )
142 {
143  return is_covered( region, locus.chromosome, locus.position );
144 }
145 
154 template<class T>
155 bool is_covered( GenomeRegionList const& regions, T const& locus )
156 {
157  return is_covered( regions, locus.chromosome, locus.position );
158 }
159 
167 template<class T>
168 bool is_covered( GenomeLocusSet const& loci, T const& locus )
169 {
170  return is_covered( loci, locus.chromosome, locus.position );
171 }
172 
173 // -------------------------------------------------------------------------
174 // VCF versions
175 // -------------------------------------------------------------------------
176 
177 #ifdef GENESIS_HTSLIB
178 
179 inline bool is_covered( GenomeRegion const& region, VcfRecord const& variant )
180 {
181  return is_covered( region, variant.get_chromosome(), variant.get_position() );
182 }
183 
184 inline bool is_covered( GenomeRegionList const& regions, VcfRecord const& variant )
185 {
186  return is_covered( regions, variant.get_chromosome(), variant.get_position() );
187 }
188 
189 inline bool is_covered( GenomeLocusSet const& loci, VcfRecord const& variant )
190 {
191  return is_covered( loci, variant.get_chromosome(), variant.get_position() );
192 }
193 
194 #endif // htslib guard
195 
196 } // namespace population
197 } // namespace genesis
198 
199 #endif // include guard
genesis::population::operator!=
bool operator!=(GenomeLocus const &l, GenomeLocus const &r)
Inequality comparison (!=) for two loci in a genome.
Definition: function/genome_locus.hpp:396
genesis::population::GenomeLocusSet::is_covered
static bool is_covered(utils::Bitvector const &bitvector, size_t position)
Return whether a given position on the provided bitvector is covered.
Definition: genome_locus_set.hpp:296
genesis::population::operator<<
std::ostream & operator<<(std::ostream &os, SampleCounts const &bs)
Output stream operator for SampleCounts instances.
Definition: population/function/functions.cpp:649
genesis::population::GenomeLocusSet
List of positions/coordinates in a genome, for each chromosome.
Definition: genome_locus_set.hpp:75
genesis::population::operator==
bool operator==(GenomeLocus const &l, GenomeLocus const &r)
Equality comparison (==) for two loci in a genome.
Definition: function/genome_locus.hpp:340
genesis::population::GenomeRegionList
List of regions in a genome, for each chromosome.
Definition: genome_region_list.hpp:95
genesis::population::is_covered
bool is_covered(GenomeRegion const &region, std::string const &chromosome, size_t position)
Test whether the chromosome/position is within a given genomic region.
Definition: genome_region.cpp:207
genesis::population::GenomeRegion::chromosome
std::string chromosome
Definition: genome_region.hpp:74
genesis::population::to_string
std::string to_string(GenomeLocus const &locus)
Definition: function/genome_locus.hpp:52
genome_region.hpp
genome_region_list.hpp
genesis::population::VcfRecord::get_chromosome
std::string get_chromosome() const
Get the name of a chromosome/contig/sequence (CHROM, first column of the line).
Definition: vcf_record.cpp:170
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::population::GenomeRegionList::is_covered
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 (intervals) that are st...
Definition: genome_region_list.hpp:300
genome_locus_set.hpp
genesis::population::parse_genome_regions
GenomeRegionList parse_genome_regions(std::string const &regions, bool zero_based, bool end_exclusive)
Parse a set/list of genomic regions.
Definition: genome_region.cpp:190
genesis::population::VcfRecord::get_position
size_t get_position() const
Get the position within the chromosome/contig (POS, second column of the line).
Definition: vcf_record.cpp:181
genesis::population::GenomeRegion
A region (between two positions) on a chromosome.
Definition: genome_region.hpp:70
genesis::population::VcfRecord
Capture the information of a single SNP/variant line in a VCF/BCF file.
Definition: vcf_record.hpp:107
vcf_record.hpp
genesis::population::parse_genome_region
GenomeRegion parse_genome_region(std::string const &region, bool zero_based, bool end_exclusive)
Parse a genomic region.
Definition: genome_region.cpp:107