Zip and Skip Tries
Loading...
Searching...
No Matches
Functions
nucleotide.cpp File Reference

Implementation of nucleotide utility functions. More...

#include "nucleotide.hpp"
#include <fstream>
Include dependency graph for nucleotide.cpp:

Go to the source code of this file.

Functions

bool is_valid_nucleotide (char nucleotide)
 Checks if a character represents a valid nucleotide.
 
std::ostreamoperator<< (std::ostream &os, const Nucleotide &nucleotide)
 Inserts a textual representation of a nucleotide into an output stream.
 

Detailed Description

Implementation of nucleotide utility functions.

This file implements the functions declared in nucleotide.hpp for nucleotide validation and stream output operations. It provides efficient implementations for handling nucleotide conversions and validation.

See also
nucleotide.hpp

Definition in file nucleotide.cpp.

Function Documentation

◆ is_valid_nucleotide()

bool is_valid_nucleotide ( char  nucleotide)

Checks if a character represents a valid nucleotide.

Determines whether the provided character is a valid nucleotide representation (A, C, G, T in either uppercase or lowercase).

Parameters
nucleotideThe character to check.
Returns
true if the character is a valid nucleotide representation, false otherwise.
See also
char_to_nucleotide

Definition at line 14 of file nucleotide.cpp.

15{
16 // Use the lookup table approach for efficient character validation
17 // This avoids multiple comparisons by directly indexing into the table
19}
T * alloc_to_device(size_t size)
Allocates memory on the CUDA device.
@ INVALID
Invalid nucleotide.
static constexpr std::array< Nucleotide, 256 > char_to_nucleotide
Lookup table for converting characters to nucleotides.

◆ operator<<()

std::ostream & operator<< ( std::ostream os,
const Nucleotide nucleotide 
)

Inserts a textual representation of a nucleotide into an output stream.

Converts the Nucleotide enum value to its character representation and inserts it into the provided output stream. Uses a switch statement to handle each nucleotide type explicitly and throws an std::invalid_argument exception for Nucleotide::INVALID rather than silently outputting a placeholder. This allows Nucleotide objects to be used directly with stream operators.

Parameters
osThe output stream to insert into.
nucleotideThe nucleotide to insert.
Returns
Reference to the output stream for chaining.
Exceptions
std::invalid_argumentif nucleotide is Nucleotide::INVALID.
See also
nucleotide_to_char

Definition at line 21 of file nucleotide.cpp.

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}
@ C
Cytosine.
@ A
Adenine.
@ T
Thymine.
@ G
Guanine.