/** Simple FASTA file format reader * * @author The BioloGeeks Team * @date 2023-09-30 */ #pragma once #include #include #include class Record { public: Record(std::string name, std::string seq) { this->name = name; this->seq = seq; } std::string name, seq; }; namespace fasta { /** * @see https://www.rosettacode.org/wiki/FASTA_format?section=10#C++ * */ std::vector read_file(std::ifstream &input) { std::string line, name, content; std::vector Records; // Read fasta file lines and append each FASTA records // to the Records vector. while (input.good()) { std::getline(input, line); if (line[0] == '>') { if (!name.empty()) { Record Record(name, content); Records.push_back(Record); name.clear(); content.clear(); } name = line.substr(1); } else { content += line; } } if (!name.empty()) { Record Record(name, content); Records.push_back(Record); } return Records; } }