Crate nucgen

Crate nucgen 

Source
Expand description

§nucgen

A minimal library for generating random nucleotide sequences.

§Example

use nucgen::{write_fasta, write_fastq, Format, Sequence};
use std::io::Cursor;

fn main() -> anyhow::Result<()> {
   // Use any RNG you like
   let mut rng = rand::rng();

   // Initialize the sequence buffer
   let mut seq = Sequence::new();

   // Initialize a quality score buffer (you can implement this however youd like.)
   let qual = vec![b'?'; 100];

   // Fill the sequence buffer with random nucleotides
   seq.fill_buffer(&mut rng, 100);  // 100 nucleotides

   // Cursor to simulate IO
   let mut out_fa = Cursor::new(Vec::new());
   let mut out_fq = Cursor::new(Vec::new());

   // Write the sequence to a FASTA file
   //
   // The internal index is used to generate the sequence ID (e.g., `seq.0`)
   write_fasta(&mut out_fa, 0, seq.bytes())?;

   // Or write the sequence to a FASTQ file
   write_fastq(&mut out_fq, 0, seq.bytes(), &qual)?;

   Ok(())
}

Structs§

Sequence

Enums§

Format

Functions§

gzip_passthrough
match_output
write_fasta
write_fastq