A library for working with phylogenetic and population genetic data.
v0.27.0
genome_locus.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_GENOME_LOCUS_H_
2 #define GENESIS_POPULATION_GENOME_LOCUS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2022 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 
34 #include <stdexcept>
35 #include <string>
36 
37 namespace genesis {
38 namespace population {
39 
40 // =================================================================================================
41 // Genome Locus
42 // =================================================================================================
43 
57 {
58  std::string chromosome;
59  size_t position = 0;
60 
61  GenomeLocus( std::string const& chr = "", size_t pos = 0 )
62  : chromosome( chr )
63  , position( pos )
64  {}
65 
66  ~GenomeLocus() = default;
67 
68  GenomeLocus( GenomeLocus const& ) = default;
69  GenomeLocus( GenomeLocus&& ) = default;
70 
71  GenomeLocus& operator= ( GenomeLocus const& ) = default;
72  GenomeLocus& operator= ( GenomeLocus&& ) = default;
73 
74  bool empty() const
75  {
76  return chromosome == "" && position == 0;
77  }
78 
79  bool valid() const
80  {
81  return chromosome != "" && position != 0;
82  }
83 };
84 
85 // Alternative version that also has a data field.
86 //
87 // // =================================================================================================
88 // // Genome Locus
89 // // =================================================================================================
90 //
91 // /**
92 // * @brief A single locus, that is, a position on a chromosome.
93 // *
94 // * For our purposes, we define a locus to be one position on one chromosome exactly.
95 // * We use 1-based positions, in order to comply with common chromosome annotation formats.
96 // * Furthermore, we use an empty chromosome string and/or position 0 as indicators of an empty or
97 // * default constructed locus.
98 // *
99 // * When working with multiple loci, we often expect their chromosome names to be sorted in
100 // * lexicographical order. Hence, for example, when comparing two loci on different chromosomes,
101 // * we also take the ordering of their chromosome names into account, see the `locus_...()`
102 // * compare functions for example.
103 // *
104 // * The class takes an extra data type as template parameter, which can be used to store
105 // * arbitrary data for this locus.
106 //
107 // * @see GenomeRegion
108 // * @see GenomeRegionList
109 // */
110 // template<class DataType = EmptyGenomeData>
111 // class GenomeLocus
112 // {
113 // public:
114 //
115 // // -------------------------------------------------------------------------
116 // // Typedefs
117 // // -------------------------------------------------------------------------
118 //
119 // using data_type = DataType;
120 //
121 // // -------------------------------------------------------------------------
122 // // Constructors and Rule of Five
123 // // -------------------------------------------------------------------------
124 //
125 // /**
126 // * @brief Default construct an empty locus.
127 // */
128 // GenomeLocus() = default;
129 //
130 // /**
131 // * @brief Construct a locus with a chromosome and position.
132 // */
133 // GenomeLocus( std::string const& chr, size_t pos )
134 // : GenomeLocus( chr, pos, DataType{} )
135 // {}
136 //
137 // /**
138 // * @brief Construct a locus with a chromosome and position, and copy the data.
139 // */
140 // GenomeLocus( std::string const& chr, size_t pos, DataType const& data )
141 // : GenomeLocus( chr, pos, DataType{ data })
142 // {}
143 //
144 // /**
145 // * @brief Construct a locus with a chromosome and position, and move the data.
146 // */
147 // GenomeLocus( std::string const& chr, size_t pos, DataType&& data )
148 // : chromosome_( chr )
149 // , position_( pos )
150 // , data_( std::move( data ))
151 // {
152 // if( chr.empty() || pos == 0 ) {
153 // throw std::invalid_argument(
154 // "Cannot construct GenomeLocus with empty chromosome or position zero."
155 // );
156 // }
157 // }
158 //
159 // ~GenomeLocus() = default;
160 //
161 // GenomeLocus( GenomeLocus const& ) = default;
162 // GenomeLocus( GenomeLocus&& ) = default;
163 //
164 // GenomeLocus& operator= ( GenomeLocus const& ) = default;
165 // GenomeLocus& operator= ( GenomeLocus&& ) = default;
166 //
167 // // -------------------------------------------------------------------------
168 // // Accessors
169 // // -------------------------------------------------------------------------
170 //
171 // std::string const& chromosome() const
172 // {
173 // return chromosome_;
174 // }
175 //
176 // size_t position() const
177 // {
178 // return position_;
179 // }
180 //
181 // data_type& data()
182 // {
183 // return data_;
184 // }
185 //
186 // data_type const& data() const
187 // {
188 // return data_;
189 // }
190 //
191 // bool empty() const
192 // {
193 // return chromosome_ == "" && position_ == 0;
194 // }
195 //
196 // // -------------------------------------------------------------------------
197 // // Operators
198 // // -------------------------------------------------------------------------
199 //
200 // operator std::string() const
201 // {
202 // return to_string();
203 // }
204 //
205 // std::string to_string() const
206 // {
207 // return chromosome_ + ":" + std::to_string( position_ );
208 // }
209 //
210 // // -------------------------------------------------------------------------
211 // // Member Variables
212 // // -------------------------------------------------------------------------
213 //
214 // private:
215 //
216 // std::string chromosome_;
217 // size_t position_ = 0;
218 //
219 // data_type data_;
220 //
221 // };
222 
223 } // namespace population
224 } // namespace genesis
225 
226 #endif // include guard
genesis::population::GenomeLocus::empty
bool empty() const
Definition: genome_locus.hpp:74
genesis::population::GenomeLocus::~GenomeLocus
~GenomeLocus()=default
genesis::population::GenomeLocus::position
size_t position
Definition: genome_locus.hpp:59
genesis::population::GenomeLocus
A single locus, that is, a position (or coordinate) on a chromosome.
Definition: genome_locus.hpp:56
genesis::population::GenomeLocus::chromosome
std::string chromosome
Definition: genome_locus.hpp:58
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::GenomeLocus::valid
bool valid() const
Definition: genome_locus.hpp:79
genesis::population::GenomeLocus::operator=
GenomeLocus & operator=(GenomeLocus const &)=default
genesis::population::GenomeLocus::GenomeLocus
GenomeLocus(std::string const &chr="", size_t pos=0)
Definition: genome_locus.hpp:61