### Build and Install RabbitFX as a Shared Library Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Steps to build and install RabbitFX using CMake and compile a program against the installed library. Ensure correct include and library paths are used. ```bash mkdir build && cd build cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local make && make install # Compile your program against the installed library g++ -std=c++11 myprogram.cpp \ -I/usr/local/include \ -L/usr/local/lib \ -lrabbitfx -lz -lpthread -o myprogram ``` -------------------------------- ### Install RabbitFX-Ktrim Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Compile RabbitFX-Ktrim from source. Requires git, cmake, and make. ```bash git https://github.com/RabbitBio/RabbitFX-Casestudy.git cd RabbitFX-Casestudy/RabbitFX-Ktrim mkdir build cd build cmake .. make ``` -------------------------------- ### Build and Run RabbitFX Examples Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/tutorial.md Steps to build the RabbitFX project and run its test executables. This includes navigating to the project directory, configuring with CMake, making the build, and executing 'test' and 'testcount'. ```bash cd RabbitFX mkdir build && cd build cmake .. make #then there is an test file in build file time ./test time ./testcount ``` -------------------------------- ### Run RabbitFX-Ktrim (Paired-end, Custom) Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Example usage for paired-end data with custom adapters, multiple lanes, and specific quality/size thresholds. Uses 4 threads. ```bash ./RabbitFX-Ktrim -1 /path/to/lane1.read1.fq.gz,/path/to/lane2.read1.fq.gz,/path/to/lane3.read1.fq \ -2 /path/to/lane1.read2.fq.gz,/path/to/lane2.read2.fq.gz,/path/to/lane3.read2.fq \ -t 4 -p 35 -q 30 -s 50 -o /path/to/output/dir \ -a READ1_ADAPTER_SEQUENCE -b READ2_ADAPTER_SEQUENCE ``` -------------------------------- ### Run RabbitFX-Ktrim (Single-end) Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Example usage for single-end data with Illumina TruSeq kit. Specify input read 1 and output prefix. ```bash ./RabbitFX-Ktrim -U /path/to/read1.fq -o /path/to/output/dir ``` -------------------------------- ### Build RabbitFX Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Build the RabbitFX project from source. Ensure dependencies like Cap'n Proto, GSL, Zlib, and GCC >= 5 are installed. Use 'make -j4' for parallel compilation. ```bash cd RabbitFX-Mash ./bootstrap.sh ./configure [--prefix=...] [--with-capnp=...] [--with-gsl=...] [--with-simd=yes/no] make -j4 #optional make install #optional make test ``` -------------------------------- ### Build RabbitFX with ISA-L Acceleration Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Build RabbitFX with ISA-L for optimized gzip decompression. This requires installing ISA-L separately and specifying its installation path during the CMake configuration. ```bash # Step 1 – install ISA-L (https://github.com/intel/isa-l) mkdir build && cd build cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \ -DIGZIP_PREFIX=/path/to/isa-l-install make && make install ``` -------------------------------- ### Install Build Dependencies on CentOS 8.1 Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Install necessary build dependencies for RabbitFX on CentOS 8.1 using dnf. Requires root privileges. ```bash sudo dnf install capnproto capnproto-devel gsl gsl-devel ``` -------------------------------- ### Build and Link RabbitFX Library Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/tutorial.md Instructions for building the RabbitFX library using CMake and linking it with your C++ project. Specify the installation path and link necessary libraries. ```bash mkdir build cmake .. -DCMAKE_INSTALL_PREFIX=/your/install/path make && make install g++ -std=c++11 YOURFILE.cpp -I/your/install/path/include -L/your/install/path/lib -lrabbitfx -lz -lpthread ``` -------------------------------- ### Paired-end FASTQ ATCG Counter using FXReader Source: https://context7.com/rabbitbio/rabbitfx/llms.txt This example demonstrates how to use `FXReader` for paired-end FASTQ files to count nucleotide occurrences (A, T, G, C) across multiple threads. Ensure the input files and thread count are provided as command-line arguments. ```cpp #include "io/RabbitFX.h" #include // Paired-end FASTQ ATCG counter using FXReader (from TestCount2.cpp) int main(int argc, char **argv) { std::string f1 = argv[1], f2 = argv[2]; int nthreads = std::stoi(argv[3]); FXReader reader(f1, f2); // producer starts automatically struct Counter { uint64_t A = 0, T = 0, G = 0, C = 0; }; auto worker = [&](Counter *cnt) { while (true) { auto data = reader.get_formated_reads_nocp(); if (data.first.chunk_p == nullptr) break; for (const neoReference &r : data.first.vec) { for (uint64_t i = 0; i < r.lseq; i++) { switch (r.base[r.pseq + i]) { case 'A': cnt->A++; break; case 'T': cnt->T++; break; case 'G': cnt->G++; break; case 'C': cnt->C++; break; } } } // same loop for data.second.vec (read 2) reader.release_chunk(data); } }; std::vector counters(nthreads); std::vector threads; for (int i = 0; i < nthreads; i++) threads.emplace_back(worker, &counters[i]); reader.join_producer(); for (auto &t : threads) t.join(); uint64_t A = 0, T = 0, G = 0, C = 0; for (auto &c : counters) { A += c.A; T += c.T; G += c.G; C += c.C; } std::cout << "A=" << A << " T=" << T << " G=" << G << " C=" << C << "\n"; } // Compile: g++ -std=c++11 -O3 main.cpp io/*.cpp -lz -lpthread -o counter // Run: ./counter reads_1.fq reads_2.fq 8 ``` -------------------------------- ### Build RabbitFX with ISA-L for Gzip Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/tutorial.md Build RabbitFX with support for faster gzip file processing by enabling the ISA-L library. This requires installing ISA-L first and then configuring the CMake build with the correct prefix. ```bash mkdir build cmake .. -DCMAKE_INSTALL_PREFIX=/your/install/path -DIGZIP_PREFIX=/path/to/libisal make && make install g++ -std=c++11 YOURFILE.cpp -I/your/install/path/include -L/your/install/path/lib -lrabbitfx -lz -lpthread ``` -------------------------------- ### Define Single-End FASTQ Processing Task Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/tutorial.md Example C++ code demonstrating how to set up a multi-threading task for processing single-end FASTQ files using RabbitFX. It includes command-line argument parsing with CLI11 and initializes data pools and queues. ```cpp int test_fastq_se(int argc, char** argv){ std::string file = "/home/old_home/haoz/workspace/QC/out_1.fq"; //---------------cmd parser---------------- CLI::App app{"Wellcome to RabbitFX"}; CLI::Option* opt; std::string filename ; int th; app.add_option("-f, --file", filename, "input file name") ->default_val(file); app.add_option("-t, --threads", th, "worktreads") ->default_val(2); //---------------------------------------- CLI11_PARSE(app, argc, argv); if(app.count("-f")) std::cout << "filename: " << filename << std::endl; else{ std::cout << "-f not find, use default: " << filename << std::endl; } rabbit::fq::FastqDataPool *fastqPool = new rabbit::fq::FastqDataPool(32, 1<<22); rabbit::core::TDataQueue queue1(64, 1); std::thread producer(producer_fastq_task, filename, fastqPool, std::ref(queue1)); std::thread** threads = new std::thread*[th]; for(int t = 0; t < th; t++){ threads[t] = new std::thread(std::bind(consumer_fastq_task, fastqPool, std::ref(queue1))); } producer.join(); for(int t = 0; t < th; t++){ threads[t]->join(); } //-----free delete fastqPool; delete[] threads; return 0; } ``` -------------------------------- ### Build RabbitFX-fastp Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Compile the Linux version of RabbitFX-fastp. ```bash cd RabbitFX-fastp && make ``` -------------------------------- ### Run RabbitFX-fastp (Paired-end) Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Basic usage for paired-end data. Specify number of threads, input R1/R2, and output R1/R2 files. ```bash RabbitFX-fastp -w nthreads -i in.R1.fq -I in.R2.fq -o out.R1.fq -O out.R2.fq ``` -------------------------------- ### Run RabbitFX-fastp (Single-end) Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Basic usage for single-end data. Specify number of threads, input, and output files. ```bash RabbitFX-fastp -w nthreads -i in.fq -o out.fq ``` -------------------------------- ### Single-end FASTQ Reader with Multi-threaded Consumers (C++) Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Use `FQ_SE` to read single-end FASTQ files with multiple consumer threads. `get_formated_reads_nocp` provides zero-copy access, requiring `release_chunk` afterwards. ```cpp #include "io/RabbitFX.h" #include #include // --- Single-end FASTQ with multiple consumer threads --- void count_bases_se(const std::string &file, int nthreads) { FQ_SE reader(file); reader.start_producer(); auto worker = [&]() { while (true) { // get_formated_reads_nocp(): zero-copy, must call release_chunk() auto data = reader.get_formated_reads_nocp(); if (data.chunk_p == nullptr) break; for (const neoReference &r : data.vec) { for (uint64_t i = 0; i < r.lseq; i++) { char b = r.base[r.pseq + i]; // direct buffer access } } reader.release_chunk(data); } }; std::vector threads; for (int i = 0; i < nthreads; i++) threads.emplace_back(worker); reader.producer_->join(); for (auto &t : threads) t.join(); } ``` -------------------------------- ### Build Dependency-Free RabbitFX Binary Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Build a dependency-free binary for RabbitFX. This option allows for static linking of GSL and C++ libraries. Use 'make -j4' for parallel compilation. ```bash cd RabbitMash ./bootstrap.sh ./configure [--prefix=...] [--with-capnp=...] [--with-gsl=...] [--with-simd=yes/no] [--enable-static-gsl=yes] [--enable-static-cpp=yes] make -j4 #optional make install #optional make test ``` -------------------------------- ### Single-End FASTQ File Reader (`FastqFileReader`) Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Reads single-end FASTQ files, supporting both plain and gzip-compressed formats. Ensure the FastqDataPool is initialized for memory management. ```cpp #include "io/FastxStream.h" #include "io/FastxChunk.h" #include "io/Formater.h" // Single-end FASTQ reading (plain or .gz) void read_fastq_se(const std::string &filename) { rabbit::fq::FastqDataPool pool(256, 1 << 22); bool is_gzip = filename.size() > 3 && filename.substr(filename.size()-3) == ".gz"; rabbit::fq::FastqFileReader reader(filename, pool, is_gzip); rabbit::fq::FastqDataChunk *chunk = nullptr; while ((chunk = reader.readNextChunk()) != nullptr) { std::vector reads; int n = rabbit::fq::chunkFormat(chunk, reads); for (auto &r : reads) { // zero-copy access to name and sequence std::string name(reinterpret_cast(r.base + r.pname), r.lname); // process ... } pool.Release(chunk); } } ``` -------------------------------- ### Paired-end FASTQ Reader with Multi-threaded Consumers (C++) Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Use `FQ_PE` to process paired-end FASTQ files with multiple consumer threads. The reader returns a pair of formatted chunks, one for each file, requiring `release_chunk` after processing. ```cpp #include "io/RabbitFX.h" #include #include // --- Paired-end FASTQ --- void process_pe(const std::string &f1, const std::string &f2, int nthreads) { FQ_PE reader(f1, f2); reader.start_producer(); auto worker = [&]() { while (true) { auto data = reader.get_formated_reads_nocp(); // returns pair if (data.first.chunk_p == nullptr) break; // data.first.vec → reads from f1 // data.second.vec → reads from f2 for (size_t i = 0; i < data.first.vec.size(); i++) { // process paired reads data.first.vec[i] & data.second.vec[i] } reader.release_chunk(data); } }; std::vector threads; for (int i = 0; i < nthreads; i++) threads.emplace_back(worker); reader.producer_->join(); for (auto &t : threads) t.join(); } ``` -------------------------------- ### Sketch Genome with RabbitFX Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Generate a sketch file for a given genome. Specify the number of threads with '-p' and the output file with '-o'. ```bash ./mash sketch -i test/genome1.fna -p nthreads -o test/genome1.fna.msh ``` -------------------------------- ### Parse FASTQ/FASTA Chunks to Records (C++) Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Use `chunkFormat` to parse raw data chunks into `Reference` (copy) or `neoReference` (zero-copy) records. Overloads support FASTQ/FASTA and different record types. ```cpp #include "io/Formater.h" // FASTQ → neoReference (zero-copy, fastest) rabbit::fq::FastqDataChunk *chunk = /* from reader */; std::vector neo_reads; int count = rabbit::fq::chunkFormat(chunk, neo_reads); ``` ```cpp // FASTQ → Reference (copy, easier to use) std::vector reads; int count2 = rabbit::fq::chunkFormat(chunk, reads, /*copy=*/true); ``` ```cpp // FASTA chunk-list → Reference (handles multi-chunk sequences) rabbit::fa::FastaChunk *fachunk = /* from reader */; std::vector fa_seqs; int n = rabbit::fa::chunkListFormat(*fachunk, fa_seqs); ``` ```cpp // FASTA single chunk → Reference int n2 = rabbit::fa::chunkFormat(*fachunk, fa_seqs); ``` ```cpp // FASTA with k-mer context (provides overlap halo) int kmerSize = 21; int n3 = rabbit::fa::chunkFormat(*fachunk, fa_seqs, kmerSize); ``` -------------------------------- ### FASTA File Reader by File Descriptor (`FastaFileReader`) Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Initializes `FastaFileReader` using a file descriptor instead of a filename, useful for reading from pipes or other non-file sources. Subsequent reading uses `readNextChunkList()`. ```cpp #include "io/FastxStream.h" #include "io/FastxChunk.h" #include "io/Formater.h" // Open by file descriptor instead of filename void read_fasta_fd(int fd) { rabbit::fa::FastaDataPool pool(256, 1 << 22); rabbit::fa::FastaFileReader reader(fd, &pool, /*isGzip=*/false); // use readNextChunkList() as above ... } ``` -------------------------------- ### Build RabbitFX Library Source: https://github.com/rabbitbio/rabbitfx/blob/master/io/CMakeLists.txt This section collects all source files in the current directory and adds them to the rabbitfx library. It also links the zlib library. ```cmake aux_source_directory(. SOURCE_LIST) add_library(rabbitfx ${SOURCE_LIST}) target_link_libraries(rabbitfx z) ``` -------------------------------- ### Screen Reads with RabbitFX Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/casestudy.md Screen sequencing reads against a genome sketch. Output is redirected to 'scr.out'. ```bash ./mash screen test/genome1.fna.msh test/reads1.fastq -p nthreads > scr.out ``` -------------------------------- ### Paired-End FASTQ File Reader (`FastqFileReader`) Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Reads paired-end FASTQ files from two input files, providing interleaved chunks. Use `readNextPairChunk1()` for processing pairs. ```cpp #include "io/FastxStream.h" #include "io/FastxChunk.h" #include "io/Formater.h" // Paired-end FASTQ reading (one thread, interleaved chunks) void read_fastq_pe(const std::string &f1, const std::string &f2) { rabbit::fq::FastqDataPool pool(256, 1 << 22); rabbit::fq::FastqFileReader reader(f1, pool, false, f2); rabbit::fq::FastqDataPairChunk *pair = nullptr; while ((pair = reader.readNextPairChunk1()) != nullptr) { std::vector left_reads, right_reads; rabbit::fq::chunkFormat( static_cast(pair->left_part), left_reads); rabbit::fq::chunkFormat( static_cast(pair->right_part), right_reads); // process left_reads[i] and right_reads[i] together ... pool.Release(pair->left_part); pool.Release(pair->right_part); } } ``` -------------------------------- ### Integrate RabbitFX with CMake Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/tutorial.md Add RabbitFX as a library in your CMake project by copying the 'io' folder and linking against it. Ensure zlib is also linked. ```cmake AUX_SOURCE_DIRECTORY(. SOURCE_LIST) ADD_LIBRARY(rabbitfx ${SOURCE_LIST}) TARGET_LINK_LIBRAIES(rabbitfx z) ``` -------------------------------- ### Using neoReference for Zero-Copy Sequence Records Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Illustrates the `neoReference` struct for zero-copy access to sequence data. It uses byte offsets and lengths into a base buffer, avoiding string allocations. The base buffer must remain valid. ```cpp #include "io/Reference.h" // Access sequence data through the base pointer + offset: void process_neoref(const neoReference &ref) { // Read name (without '@') std::string name(reinterpret_cast(ref.base + ref.pname), ref.lname); // Iterate nucleotides without any string copy for (uint64_t i = 0; i < ref.lseq; i++) { char base = ref.base[ref.pseq + i]; // process base... } // Access quality scores for (uint64_t i = 0; i < ref.lqual; i++) { char q = ref.base[ref.pqual + i]; int phred = q - 33; // Phred+33 encoding // process quality... } } // Trim a neoReference subsequence [from, to] in-place (no copy) cutseq_neoref(ref, 10, 50); // keep bases 10..50 ``` -------------------------------- ### Integrate RabbitFX with CMake Source: https://github.com/rabbitbio/rabbitfx/blob/master/README.md Add RabbitFX as a library to your CMake project. Ensure zlib is linked. ```cmake AUX_SOURCE_DIRECTORY(. SOURCE_LIST) ADD_LIBRARY(rabbitfx ${SOURCE_LIST}) TARGET_LINK_LIBRARIES(rabbitfx z) ``` -------------------------------- ### Embed RabbitFX io/ Folder in Project (CMake) Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Instructions for embedding the 'io/' directory directly into your project using CMake. This method adds the source files to a library and links it with zlib. ```cmake # In your CMakeLists.txt AUX_SOURCE_DIRECTORY(io SOURCE_LIST) ADD_LIBRARY(rabbitfx ${SOURCE_LIST}) TARGET_LINK_LIBRARIES(rabbitfx z) add_executable(myprogram myprogram.cpp) target_link_libraries(myprogram rabbitfx z pthread) ``` -------------------------------- ### Using Reference Struct for Sequence Records Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Demonstrates the usage of the `Reference` struct, which holds copy-based string representations of sequence data. Access fields directly after chunk formatting. ```cpp #include "io/Reference.h" // Reference is filled by chunkFormat(); access fields directly. Reference ref; // ref.name -> read name (without '@'/'>' prefix) // ref.comment -> inline comment after the name // ref.seq -> nucleotide sequence string // ref.quality -> quality string (FASTQ only) // ref.length -> sequence length // ref.gid -> monotonically increasing global read id void print_reference(const Reference &ref) { std::cout << "Name: " << ref.name << "\n" << "Seq: " << ref.seq << "\n" << "Quality: " << ref.quality << "\n" << "Length: " << ref.length << "\n"; } ``` -------------------------------- ### Process FASTA File in Single Thread Source: https://github.com/rabbitbio/rabbitfx/blob/master/README.md This C++ code demonstrates how to read and process a FASTA file using a single thread. It counts the number of chunks and lines in the input file. Ensure the FastaDataPool and FastaFileReader are properly initialized. ```c++ int proces_fasta_task(std::string file) { rabbit::fa::FastaDataPool fastaPool(256, 1 << 22); rabbit::fa::FastaFileReader faFileReader(file, *fastaPool, false); int n_chunks = 0; int line_sum = 0; while (true) { rabbit::fa::FastaChunk *fachunk = faFileReader.readNextChunkList(); if (fachunk == NULL) break; n_chunks++; //-----relaease rabbit::fa::FastaDataChunk *tmp = fachunk->chunk; do { fastaPool->Release(tmp); tmp = tmp->next; } while (tmp != NULL); // line_sum += rabbit::fa::chunkFormat(*fachunk, data); } std::cout << "file " << file << " has " << line_sum << " lines" << std::endl; return 0; } int test_fasta(int argc, char** argv){ producer_fasta_task("/home/old_home/haoz/workspace/data/hg19/hg19.fa"); return 0; } ``` -------------------------------- ### Process FASTA File with Single Thread Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/tutorial.md This C++ code demonstrates how to read and process a FASTA file using a single thread. It initializes a FastaDataPool and FastaFileReader, then iterates through the file chunk by chunk, counting the number of chunks and lines. Memory is released after each chunk is processed. ```cpp int proces_fasta_task(std::string file) { rabbit::fa::FastaDataPool *fastaPool = new rabbit::fa::FastaDataPool(256, 1 << 22); rabbit::fa::FastaFileReader *faFileReader; faFileReader = new rabbit::fa::FastaFileReader(file, *fastaPool, false); int n_chunks = 0; int line_sum = 0; while (true) { rabbit::fa::FastaChunk *fachunk = new rabbit::fa::FastaChunk; fachunk = faFileReader->readNextChunkList(); if (fachunk == NULL) break; n_chunks++; //-----relaease rabbit::fa::FastaDataChunk *tmp = fachunk->chunk; do { fastaPool->Release(tmp); tmp = tmp->next; } while (tmp != NULL); // line_sum += rabbit::fa::chunkFormat(*fachunk, data); } std::cout << "file " << file << " has " << line_sum << " lines" << std::endl; return 0; } int test_fasta(int argc, char** argv){ producer_fasta_task("/home/old_home/haoz/workspace/data/hg19/hg19.fa"); return 0; } ``` -------------------------------- ### FASTA File Reader (`FastaFileReader`) Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Reads FASTA files into linked-list chunks, recommended for handling long sequences that may span buffer boundaries. Uses `readNextChunkList()` for robust sequence handling. ```cpp #include "io/FastxStream.h" #include "io/FastxChunk.h" #include "io/Formater.h" void read_fasta(const std::string &filename) { rabbit::fa::FastaDataPool pool(256, 1 << 22); rabbit::fa::FastaFileReader reader(filename, &pool, /*isGzip=*/false); rabbit::fa::FastaChunk *fachunk = nullptr; while ((fachunk = reader.readNextChunkList()) != nullptr) { std::vector seqs; int n = rabbit::fa::chunkListFormat(*fachunk, seqs); for (const Reference &seq : seqs) { std::cout << seq.name << "\t" << seq.length << "\n"; } // Release entire linked-list of sub-chunks rabbit::fa::FastaDataChunk *tmp = fachunk->chunk; do { rabbit::fa::FastaDataChunk *next = tmp->next; pool.Release(tmp); tmp = next; } while (tmp != nullptr); } } ``` -------------------------------- ### FASTA Reader with Template-based Multi-threaded Processing (C++) Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Use the `FA` reader class for FASTA files, enabling template-based multi-threaded processing with `process_data_mt`. This method applies a provided function to each sequence in parallel. ```cpp #include "io/RabbitFX.h" #include #include // --- FASTA with template-based multi-threaded processing --- void process_fasta_mt(const std::string &file, int nthreads) { FA reader(file); reader.start_producer(); // process_data_mt applies func_ptr to each Reference in parallel auto compute_gc = [](Reference &seq) -> double { int gc = 0; for (char c : seq.seq) if (c == 'G' || c == 'C') gc++; return seq.length > 0 ? (double)gc / seq.length : 0.0; }; std::vector> results(nthreads); reader.process_data_mt(nthreads, +compute_gc, results); reader.producer_->join(); // results[t] contains per-thread GC ratio values } ``` -------------------------------- ### TDataPool for Thread-Safe Memory Management Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Shows how to use `TDataPool` to manage a fixed-size pool of reusable data chunks, eliminating heap allocations. `Acquire()` blocks if the pool is empty, and `Release()` returns a chunk. ```cpp #include "io/DataPool.h" #include "io/FastxChunk.h" // defines FastqDataChunk, FastaDataChunk // Create a pool: up to 256 chunks, each 4 MB rabbit::fq::FastqDataPool pool(256, 1 << 22); // Acquire a chunk (blocks if pool is exhausted) rabbit::fq::FastqDataChunk *chunk = nullptr; pool.Acquire(chunk); // ... fill chunk with data ... // Return chunk to pool when done processing pool.Release(chunk); // For FASTA: rabbit::fa::FastaDataPool faPool(256, 1 << 22); ``` -------------------------------- ### Set C++ Standard and Compiler Flags Source: https://github.com/rabbitbio/rabbitfx/blob/master/io/CMakeLists.txt Configures the C++ standard to C++11 and sets optimization and debugging flags for the compiler. ```cmake set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS "-O3 -g -ffast-math ${CMAKE_CXX_FLAGS}") ``` -------------------------------- ### Define FASTQ Consumer Task Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/tutorial.md C++ function defining the consumer task for processing FASTQ data chunks. It pops chunks from a data queue, formats them, and releases them back to the data pool. ```cpp void consumer_fastq_task(rabbit::fq::FastqDataPool* fastqPool, rabbit::core::TDataQueue &dq){ long line_sum = 0; rabbit::int64 id = 0; std::vector data; rabbit::fq::FastqDataChunk* fqdatachunk;// = new rabbit::fq::FastqDataChunk; data.resize(10000); while(dq.Pop(id, fqdatachunk)){ line_sum += rabbit::fq::chunkFormat(fqdatachunk, data); fastqPool->Release(fqdatachunk); } std::cout << "line_sum: " << line_sum << std::endl; } ``` -------------------------------- ### Define FASTQ Producer Task Source: https://github.com/rabbitbio/rabbitfx/blob/master/doc/sphinx/API/tutorial.md C++ function defining the producer task for reading FASTQ files. It reads data in chunks using `FastqFileReader` and pushes them onto a thread-safe data queue. ```cpp int producer_fastq_task(std::string file, rabbit::fq::FastqDataPool* fastqPool, rabbit::core::TDataQueue &dq){ rabbit::fq::FastqFileReader *fqFileReader; fqFileReader = new rabbit::fq::FastqFileReader(file, *fastqPool); rabbit::int64 n_chunks = 0; while(true){ rabbit::fq::FastqDataChunk* fqdatachunk;// = new rabbit::fq::FastqDataChunk; fqdatachunk = fqFileReader->readNextChunk(); if (fqdatachunk == NULL) break; n_chunks++; //std::cout << "readed chunk: " << n_chunks << std::endl; dq.Push(n_chunks, fqdatachunk); } dq.SetCompleted(); std::cout << "file " << file << " has " << n_chunks << " chunks" << std::endl; return 0; } ``` -------------------------------- ### Configure OpenMP Support in CMake Source: https://github.com/rabbitbio/rabbitfx/blob/master/io/CMakeLists.txt This block finds and configures OpenMP support. It sets compiler flags and linker flags if OpenMP is found, and specifies the output path for executables. ```cmake find_package(OpenMP REQUIRED) if(OPENMP_FOUND) message("OPENMP FOUND") set(CMAKE_CXX_COMPILER "/usr/bin/g++") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") set(EXECUTABLE_OUTPUT_PATH .) endif() ``` -------------------------------- ### Define FASTQ Consumer Task Source: https://github.com/rabbitbio/rabbitfx/blob/master/README.md Implements the consumer task for processing FASTQ data chunks from a queue. It aggregates line counts and releases data chunks. ```c++ void consumer_fastq_task(rabbit::fq::FastqDataPool& fastqPool, rabbit::core::TDataQueue &dq){ long line_sum = 0; rabbit::int64 id = 0; std::vector data; rabbit::fq::FastqDataChunk* fqdatachunk;// = new rabbit::fq::FastqDataChunk; data.resize(10000); while(dq.Pop(id, fqdatachunk)){ line_sum += rabbit::fq::chunkFormat(fqdatachunk, data); fastqPool.Release(fqdatachunk); } std::cout << "line_sum: " << line_sum << std::endl; } ``` -------------------------------- ### Thread-Safe Producer-Consumer Queue (`TDataQueue`) Source: https://context7.com/rabbitbio/rabbitfx/llms.txt Use TDataQueue for synchronizing multiple producer and consumer threads. Push operations block when the queue is full, and Pop operations block until data is available or producers signal completion. ```cpp #include "io/DataQueue.h" #include "io/FastxChunk.h" // Queue holding up to 64 chunks; 1 producer thread rabbit::core::TDataQueue queue(64, 1); // --- Producer side --- rabbit::int64 chunk_id = 0; queue.Push(++chunk_id, chunk_ptr); // blocks if queue is full queue.SetCompleted(); // signal no more data // --- Consumer side --- rabbit::int64 id = 0; rabbit::fq::FastqDataChunk *chunk = nullptr; while (queue.Pop(id, chunk)) { // returns false when done // process chunk ... pool.Release(chunk); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.