pub struct Writer<W: Write, R: Read + Seek> { /* private fields */ }Expand description
Writes QcChecks into a BufWriter
§Examples
use std::io;
use atglib::tests;;
use atglib::qc::Writer;
use atglib::fasta::FastaReader;
use atglib::models::TranscriptWrite;
let transcripts = vec![tests::transcripts::standard_transcript()];
let output = Vec::new(); // substitute this with proper IO (io::stdout())
let mut writer = Writer::new(output);
writer.fasta_reader(FastaReader::from_file("tests/data/small.fasta").unwrap());
writer.write_transcript_vec(&transcripts);
let written_output = String::from_utf8(writer.into_inner().unwrap()).unwrap();
assert_eq!(written_output, "Test-Gene\tTest-Transcript\tOK\tNOK\tOK\tOK\tOK\tOK\tOK\n");Implementations§
Source§impl<W: Write, R: Read + Seek> Writer<W, R>
impl<W: Write, R: Read + Seek> Writer<W, R>
Sourcepub fn new(writer: W) -> Self
pub fn new(writer: W) -> Self
Creates a new generic Writer for any `std::io::Read`` object
Use this method when you want to write to stdout or a remote source, e.g. via HTTP
Sourcepub fn with_capacity(capacity: usize, writer: W) -> Self
pub fn with_capacity(capacity: usize, writer: W) -> Self
Constructs a new, empty Writer with the specified capacity.
Sourcepub fn fasta_reader(&mut self, r: FastaReader<R>)
pub fn fasta_reader(&mut self, r: FastaReader<R>)
Specify a [FastaReader'](crate::fasta::FastaReader`) to retrieve
the reference genome sequence.
You must set a fasta_reader, since the Writer does not have any
information about the reference genome to use.
use atglib::qc::Writer;
use atglib::fasta::FastaReader;
let output = Vec::new(); // substitute this with proper IO (io::stdout())
let mut writer = Writer::new(output);
// specify the reference genome fasta file
writer.fasta_reader(FastaReader::from_file("tests/data/small.fasta").unwrap());Sourcepub fn default_genetic_code(&mut self, code: GeneticCode)
pub fn default_genetic_code(&mut self, code: GeneticCode)
Changes the default genetic code to a custom one
By default, the standard genetic code is used for translating to AminoAcids
Sourcepub fn add_genetic_code(&mut self, chrom: String, code: GeneticCode)
pub fn add_genetic_code(&mut self, chrom: String, code: GeneticCode)
Add a custom genetic code that will be used for all transcripts on chrom
For example, when using QC for human genomes, you should specify to use
the vertebrate_mitochondria genetic code for all transcripts on the mitochondrial
chromsome.
§Examples
use atglib::qc::Writer;
use atglib::fasta::FastaReader;
use atglib::models::GeneticCode;
let output = Vec::new(); // substitute this with proper IO (io::stdout())
let mut writer = Writer::new(output);
// specify the reference genome fasta file
writer.fasta_reader(FastaReader::from_file("tests/data/small.fasta").unwrap());
// use vertebrate_mitochondria genetic code for chrM transcripts
writer.add_genetic_code("chrM".to_string(), GeneticCode::vertebrate_mitochondrial());
let codes = writer.genetic_codes();
assert_eq!(codes[0].0, "*");
assert_eq!(codes[1].0, "chrM");
// The mitochondrial genetic code contains 4 Stop codons, the standard genetic code has 3:
assert_eq!(codes[0].1.stop_codons().len(), 3);
assert_eq!(codes[1].1.stop_codons().len(), 4);§Note
The matching of chromosomes to genetic codes is implemented for use-cases with a maximum of 1 or 2
additional genetic codes. If you have use-cases where you need many different genetic codes
it would be better to split your Transcripts beforehand.
It is optimized for vertebrate genomes (i.e. standard code + vertebrate mitochondrial code)
Sourcepub fn genetic_codes(&self) -> Vec<(&str, &GeneticCode)>
pub fn genetic_codes(&self) -> Vec<(&str, &GeneticCode)>
List all genetic codes that are linked to the QCWriter
There is no real use for this method, other than for testing during development
pub fn flush(&mut self) -> Result<(), AtgError>
pub fn into_inner(self) -> Result<W, AtgError>
Sourcepub fn write_header(&mut self) -> Result<(), Error>
pub fn write_header(&mut self) -> Result<(), Error>
Writes the header row for the tab-separated QC results
Trait Implementations§
Source§impl<W: Write, R: Read + Seek> TranscriptWrite for Writer<W, R>
impl<W: Write, R: Read + Seek> TranscriptWrite for Writer<W, R>
Source§fn writeln_single_transcript(
&mut self,
transcript: &Transcript,
) -> Result<(), Error>
fn writeln_single_transcript( &mut self, transcript: &Transcript, ) -> Result<(), Error>
Writes a single transcript formatted as RefGene with an extra newline
This method adds an extra newline at the end of the row to allow writing multiple transcripts continuosly