Zip and Skip Tries
Loading...
Searching...
No Matches
nucleotide.cpp
Go to the documentation of this file.
1
10#include "nucleotide.hpp"
11
12#include <fstream>
13
15{
16 // Use the lookup table approach for efficient character validation
17 // This avoids multiple comparisons by directly indexing into the table
19}
20
21std::ostream& operator<<(std::ostream& os, const Nucleotide& nucleotide)
22{
23 // Handle each nucleotide case explicitly in the switch statement
24 // Note: We could use the nucleotide_to_char array directly for valid nucleotides,
25 // but the switch approach provides clearer error handling for invalid values
26 switch (nucleotide)
27 {
28 case Nucleotide::A:
29 os << 'A';
30 break;
31 case Nucleotide::C:
32 os << 'C';
33 break;
34 case Nucleotide::G:
35 os << 'G';
36 break;
37 case Nucleotide::T:
38 os << 'T';
39 break;
40 default:
41 // Throw an exception for invalid nucleotides rather than silently outputting a placeholder
42 // This helps catch programming errors early
43 throw std::invalid_argument("Invalid nucleotide");
44 }
45
46 return os;
47}
T * alloc_to_device(size_t size)
Allocates memory on the CUDA device.
bool is_valid_nucleotide(char nucleotide)
Checks if a character represents a valid nucleotide.
std::ostream & operator<<(std::ostream &os, const Nucleotide &nucleotide)
Inserts a textual representation of a nucleotide into an output stream.
Defines nucleotide representation and related utility functions.
Nucleotide
Enumerates the four nucleotides of DNA.
@ C
Cytosine.
@ A
Adenine.
@ T
Thymine.
@ INVALID
Invalid nucleotide.
@ G
Guanine.
static constexpr std::array< Nucleotide, 256 > char_to_nucleotide
Lookup table for converting characters to nucleotides.