Writer

Struct Writer 

Source
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<R: Read + Seek> Writer<File, R>

Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, ReadWriteError>

Source§

impl<W: Write, R: Read + Seek> Writer<W, R>

Source

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

Source

pub fn with_capacity(capacity: usize, writer: W) -> Self

Constructs a new, empty Writer with the specified capacity.

Source

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());
Source

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

Source

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)

Source

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

Source

pub fn flush(&mut self) -> Result<(), AtgError>

Source

pub fn into_inner(self) -> Result<W, AtgError>

Source

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>

Source§

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

Source§

fn write_single_transcript( &mut self, transcript: &Transcript, ) -> Result<(), Error>

Source§

fn write_transcript_vec( &mut self, transcripts: &[Transcript], ) -> Result<(), Error>

Source§

fn write_transcripts(&mut self, transcripts: &Transcripts) -> Result<(), Error>

Auto Trait Implementations§

§

impl<W, R> Freeze for Writer<W, R>
where W: Freeze, R: Freeze,

§

impl<W, R> RefUnwindSafe for Writer<W, R>

§

impl<W, R> Send for Writer<W, R>
where W: Send, R: Send,

§

impl<W, R> Sync for Writer<W, R>
where W: Sync, R: Sync,

§

impl<W, R> Unpin for Writer<W, R>
where W: Unpin, R: Unpin,

§

impl<W, R> UnwindSafe for Writer<W, R>
where W: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.