A library for working with phylogenetic and population genetic data.
v0.32.0
alphabet.hpp
Go to the documentation of this file.
1
#ifndef GENESIS_SEQUENCE_KMER_ALPHABET_H_
2
#define GENESIS_SEQUENCE_KMER_ALPHABET_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 <lucas.czech@sund.ku.dk>
23
University of Copenhagen, Globe Institute, Section for GeoGenetics
24
Oster Voldgade 5-7, 1350 Copenhagen K, Denmark
25
*/
26
34
#include "
genesis/sequence/kmer/kmer.hpp
"
35
#include "
genesis/utils/text/char.hpp
"
36
37
#include <array>
38
#include <cassert>
39
#include <cstdint>
40
#include <iostream>
41
#include <stdexcept>
42
#include <string>
43
#include <type_traits>
44
45
namespace
genesis
{
46
namespace
sequence {
47
48
// =================================================================================================
49
// Nucleotide Alphabet
50
// =================================================================================================
51
52
class
NucleotideAlphabet
53
{
54
static
const
std::array<uint8_t, 256> ascii_to_nt4;
55
56
inline
uint8_t char_to_rank(
char
c )
57
{
58
c =
utils::to_upper
( c );
59
if
(( c !=
'A'
) && ( c !=
'C'
) && ( c !=
'G'
) && ( c !=
'T'
) && ( c !=
'N'
)) {
60
throw
std::invalid_argument(
61
"Cannot use char "
+
utils::char_to_hex
( c ) +
" to construct ACGT k-mer"
62
);
63
}
64
return
0 * ( c ==
'A'
) + 1 * ( c ==
'C'
) + 2 * ( c ==
'G'
) + 3 * ( c ==
'T'
);
65
66
// auto const r = ascii_to_nt4[c];
67
// if( r > 3 ) {
68
// // ...
69
// }
70
// return ;
71
}
72
};
73
74
}
// namespace sequence
75
}
// namespace genesis
76
77
#endif // include guard
kmer.hpp
genesis::sequence::NucleotideAlphabet
Definition:
alphabet.hpp:52
genesis::utils::to_upper
constexpr char to_upper(char c) noexcept
Return the upper case version of a letter, ASCII-only.
Definition:
char.hpp:230
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
char.hpp
genesis::utils::char_to_hex
std::string char_to_hex(char c, bool full)
Return the name and hex representation of a char.
Definition:
char.cpp:118
lib
genesis
sequence
kmer
alphabet.hpp
Generated on Mon Aug 5 2024 16:57:51 for genesis by
1.8.17