22#include <unordered_set>
76 throw std::invalid_argument(
"File not found");
112 throw std::invalid_argument(
"File not found");
137 throw std::invalid_argument(
"File not found");
157 throw std::invalid_argument(
"File not found");
185 std::vector<Gene>
genes;
187 for (
const auto&
entry : std::filesystem::directory_iterator(
dirname))
197 std::vector<Gene>
genes;
200 for (
const auto&
entry : std::filesystem::directory_iterator(
dirname))
217 for (
const auto&
entry : std::filesystem::directory_iterator(
dirname))
225 throw std::invalid_argument(
"File not found");
260 return FileType::GBK;
264 return FileType::FNA;
268 return FileType::DNA;
272 return FileType::DNA_BIN;
276 return FileType::DNA_BIN_COMBINED;
280 return FileType::UNKNOWN;
296 case FileType::DNA_BIN:
299 throw std::invalid_argument(
"Unknown file type");
325 std::vector<std::filesystem::path>
paths;
340 std::vector<std::filesystem::path>
filepaths;
341 for (
const auto&
entry : std::filesystem::directory_iterator(
dirname))
353 timer.start(
"Writing names to binary file");
357 throw std::invalid_argument(
"File not found");
369 auto name =
filepath.filename().string();
373 file.write(name.c_str(), name.size());
394 file.write(
reinterpret_cast<const char*
>(&
pos),
sizeof(
pos));
417 throw std::invalid_argument(
"File not found");
439 while (
m_file.read(&
c, 1) &&
c !=
'\0')
445 std::streampos position;
446 m_file.read(
reinterpret_cast<char*
>(&position),
sizeof(position));
467 timer.start(
"Sorting by size");
481 throw std::invalid_argument(
"File not found");
491 m_file.read(
reinterpret_cast<char*
>(&
info.size),
sizeof(
info.size));
509 throw std::invalid_argument(
"File not found");
529 std::vector<Gene>
genes;
546 static std::random_device
rd;
547 static std::mt19937
gen(
rd());
548 static std::uniform_int_distribution<size_t>
dist(0,
m_gene_infos.size() - 1);
560 std::vector<Gene>
genes;
void push_back(CHAR_T c) noexcept
Appends a single character to the end of the BitString.
static BitString from_file(const std::string &filename)
Reads a BitString from a file in binary format.
T * alloc_to_device(size_t size)
Allocates memory on the CUDA device.
std::string pretty_print(size_t nanoseconds)
Converts a duration in nanoseconds to a human-readable string format.
Defines utilities for managing performance data logging and timing.
Provides utilities for working with genetic data in various formats.
Contains utilities for working with genetic data and file formats.
Gene from_file(const std::string &filename)
Loads a gene from a file with automatic format detection.
static const std::string DNA_BIN_COMBINED_EXTENSION
File extension for combined binary DNA files.
Gene from_gbk(const std::string &filename)
Loads a gene from a GenBank format file.
static const std::string DNA_BIN_SIZES_EXTENSION
File extension for binary DNA file size information.
std::vector< std::filesystem::path > get_virus_nucleotide_paths()
Gets paths to all virus nucleotide files in the virus directory.
Gene from_dna(const std::string &filename)
Loads a gene from a plain text DNA format file.
void to_dna(const Gene &gene, const std::string &filename)
Saves a gene to a plain text DNA format file.
static const std::string GBK_EXTENSION
File extension for GenBank format files.
static const std::string DNA_EXTENSION
File extension for plain text DNA files.
static const std::string FNA_EXTENSION
File extension for FASTA nucleotide format files.
FileType get_file_type(const std::string &filename)
Determines the file type based on its filename extension.
std::vector< std::string > get_dna_strings_from_directory(const std::string &dirname)
Extracts DNA strings from all supported files in a directory.
Gene from_stream(std::istream &stream)
Loads a gene from an input stream.
static const std::string VIRUS_DIRECTORY
Path to the virus genome data directory.
Gene from_fna(const std::string &filename)
Loads a gene from a FASTA nucleotide format file.
FileType
Enumerates the supported genetic file formats.
std::vector< Gene > from_directory(const std::string &dirname)
Loads all genes from files in a directory with automatic format detection.
static const std::string DNA_BIN_EXTENSION
File extension for binary DNA files.
void combine_dna_bin_files(const std::string &dirname, const std::string &combined_filename)
Combines multiple binary DNA files into a single combined file.
bool is_valid_nucleotide(char nucleotide)
Checks if a character represents a valid nucleotide.
Defines nucleotide representation and related utility functions.
static constexpr std::array< Nucleotide, 256 > char_to_nucleotide
Lookup table for converting characters to nucleotides.
A timer class measuring wall-clock time using std::chrono::high_resolution_clock.
void start(const std::string &prompt="", bool reset=true) noexcept
Starts or resets the timer and optionally prints a starting message.
Structure to track information about a gene in the combined file.
std::string m_path
Path to the combined binary file.
void load_sizes()
Loads gene size information from the companion file.
GeneManager(const std::string &path)
Constructs a GeneManager for accessing genes in the specified path.
std::vector< GeneInfo > m_gene_infos
Index of all genes in the combined file.
std::vector< Gene > get_random_genes(size_t count) const
Retrieves a random subset of genes from the combined file.
void save_sizes()
Saves the size information of genes to a companion file.
~GeneManager()
Destructor for GeneManager.
std::ifstream m_file
File stream for reading gene data (mutable to allow const methods to read)
std::vector< Gene > all_genes() const
Retrieves all genes from the combined file.