1 #ifndef GENESIS_POPULATION_FUNCTION_GENOME_LOCUS_H_
2 #define GENESIS_POPULATION_FUNCTION_GENOME_LOCUS_H_
46 namespace population {
56 throw std::invalid_argument(
"Invalid GenomeLocus with empty chromosome." );
90 #define ADD_LOCUS_COMPARISON_OVERLOADS( CMP_FUNC ) \
92 inline int CMP_FUNC( \
93 GenomeLocus const& l, \
94 std::string const& r_chromosome, size_t r_position \
96 return CMP_FUNC( l.chromosome, l.position, r_chromosome, r_position ); \
100 inline int CMP_FUNC( \
101 std::string const& l_chromosome, size_t l_position, \
102 GenomeLocus const& r \
104 return CMP_FUNC( l_chromosome, l_position, r.chromosome, r.position ); \
108 inline int CMP_FUNC( \
109 GenomeLocus const& l, \
110 GenomeLocus const& r \
112 return CMP_FUNC( l.chromosome, l.position, r.chromosome, r.position ); \
116 inline int CMP_FUNC( \
117 GenomeLocus const& l, \
118 std::string const& r_chromosome, size_t r_position, \
119 genesis::sequence::SequenceDict const& sequence_dict \
121 return CMP_FUNC( l.chromosome, l.position, r_chromosome, r_position, sequence_dict ); \
125 inline int CMP_FUNC( \
126 std::string const& l_chromosome, size_t l_position, \
127 GenomeLocus const& r, \
128 genesis::sequence::SequenceDict const& sequence_dict \
130 return CMP_FUNC( l_chromosome, l_position, r.chromosome, r.position, sequence_dict ); \
134 inline int CMP_FUNC( \
135 GenomeLocus const& l, \
136 GenomeLocus const& r, \
137 genesis::sequence::SequenceDict const& sequence_dict \
139 return CMP_FUNC( l.chromosome, l.position, r.chromosome, r.position, sequence_dict ); \
143 inline int CMP_FUNC( \
144 std::string const& l_chromosome, size_t l_position, \
145 std::string const& r_chromosome, size_t r_position, \
146 std::shared_ptr<genesis::sequence::SequenceDict> const& sequence_dict \
148 if( sequence_dict ) { \
149 return CMP_FUNC( l_chromosome, l_position, r_chromosome, r_position, *sequence_dict ); \
151 return CMP_FUNC( l_chromosome, l_position, r_chromosome, r_position ); \
156 inline int CMP_FUNC( \
157 GenomeLocus const& l, \
158 std::string const& r_chromosome, size_t r_position, \
159 std::shared_ptr<genesis::sequence::SequenceDict> const& sequence_dict \
161 if( sequence_dict ) { \
162 return CMP_FUNC( l.chromosome, l.position, r_chromosome, r_position, *sequence_dict ); \
164 return CMP_FUNC( l.chromosome, l.position, r_chromosome, r_position ); \
169 inline int CMP_FUNC( \
170 std::string const& l_chromosome, size_t l_position, \
171 GenomeLocus const& r, \
172 std::shared_ptr<genesis::sequence::SequenceDict> const& sequence_dict \
174 if( sequence_dict ) { \
175 return CMP_FUNC( l_chromosome, l_position, r.chromosome, r.position, *sequence_dict ); \
177 return CMP_FUNC( l_chromosome, l_position, r.chromosome, r.position ); \
182 inline int CMP_FUNC( \
183 GenomeLocus const& l, \
184 GenomeLocus const& r, \
185 std::shared_ptr<genesis::sequence::SequenceDict> const& sequence_dict \
187 if( sequence_dict ) { \
188 return CMP_FUNC( l.chromosome, l.position, r.chromosome, r.position, *sequence_dict ); \
190 return CMP_FUNC( l.chromosome, l.position, r.chromosome, r.position ); \
233 std::string
const& l_chromosome,
size_t l_position,
234 std::string
const& r_chromosome,
size_t r_position
238 auto const chr_cmp = std::strcmp( l_chromosome.c_str(), r_chromosome.c_str() );
242 assert( l_chromosome == r_chromosome );
250 std::string
const& l_chromosome,
size_t l_position,
251 std::string
const& r_chromosome,
size_t r_position,
257 if( l_chromosome == r_chromosome ) {
264 auto const l_chr_idx = sequence_dict.
index_of( l_chromosome );
265 auto const r_chr_idx = sequence_dict.
index_of( r_chromosome );
267 assert( chr_cmp != 0 );
277 #if __cplusplus >= 202002L
287 #endif // __cplusplus >= 202002L
301 std::string
const& l_chromosome,
size_t l_position,
302 std::string
const& r_chromosome,
size_t r_position
304 return l_chromosome == r_chromosome && l_position == r_position;
312 std::string
const& r_chromosome,
size_t r_position
321 std::string
const& l_chromosome,
size_t l_position,
357 std::string
const& l_chromosome,
size_t l_position,
358 std::string
const& r_chromosome,
size_t r_position
360 return !
locus_equal( l_chromosome, l_position, r_chromosome, r_position );
368 std::string
const& r_chromosome,
size_t r_position
377 std::string
const& l_chromosome,
size_t l_position,
415 std::string
const& l_chromosome,
size_t l_position,
416 std::string
const& r_chromosome,
size_t r_position
418 return l_chromosome < r_chromosome || ( l_chromosome == r_chromosome && l_position < r_position );
425 std::string
const& l_chromosome,
size_t l_position,
426 std::string
const& r_chromosome,
size_t r_position,
432 if( l_chromosome == r_chromosome ) {
434 return l_position < r_position;
439 auto const l_chr_idx = sequence_dict.
index_of( l_chromosome );
440 auto const r_chr_idx = sequence_dict.
index_of( r_chromosome );
441 assert( l_chr_idx != r_chr_idx );
442 return l_chr_idx < r_chr_idx;
453 return locus_less( l.chromosome, l.position, r.chromosome, r.position );
466 std::string
const& l_chromosome,
size_t l_position,
467 std::string
const& r_chromosome,
size_t r_position
470 return locus_less( r_chromosome, r_position, l_chromosome, l_position );
477 std::string
const& l_chromosome,
size_t l_position,
478 std::string
const& r_chromosome,
size_t r_position,
482 return locus_less( r_chromosome, r_position, l_chromosome, l_position, sequence_dict );
493 return locus_greater( l.chromosome, l.position, r.chromosome, r.position );
506 std::string
const& l_chromosome,
size_t l_position,
507 std::string
const& r_chromosome,
size_t r_position
511 return l_chromosome < r_chromosome || ( l_chromosome == r_chromosome && l_position <= r_position );
518 std::string
const& l_chromosome,
size_t l_position,
519 std::string
const& r_chromosome,
size_t r_position,
523 if( l_chromosome == r_chromosome ) {
524 return l_position <= r_position;
526 auto const l_chr_idx = sequence_dict.
index_of( l_chromosome );
527 auto const r_chr_idx = sequence_dict.
index_of( r_chromosome );
528 assert( l_chr_idx != r_chr_idx );
529 return l_chr_idx < r_chr_idx;
553 std::string
const& l_chromosome,
size_t l_position,
554 std::string
const& r_chromosome,
size_t r_position
564 std::string
const& l_chromosome,
size_t l_position,
565 std::string
const& r_chromosome,
size_t r_position,
569 return locus_less_or_equal( r_chromosome, r_position, l_chromosome, l_position, sequence_dict );
588 #undef ADD_LOCUS_COMPARISON_OVERLOADS
593 #endif // include guard