Skip to main content

FastxWriter

Struct FastxWriter 

Source
pub struct FastxWriter<W: Write> { /* private fields */ }
Expand description

A writer for FASTA and FASTQ records.

FASTA sequence lines are wrapped at DEFAULT_LINE_WIDTH unless configured otherwise. Writing a FASTQ record without quality scores is an error rather than a silent fabrication of quality values; writing a FASTQ record to a FASTA writer simply drops the quality, which is the usual fq2fa conversion.

use fastx::{FastxWriter, Format, Sequence};

let mut out = Vec::new();
{
    let mut writer = FastxWriter::new(&mut out, Format::Fasta).line_width(4);
    writer.write_record(&Sequence::fasta("a", b"ACGTAC"))?;
    writer.flush()?;
}
assert_eq!(out, b">a\nACGT\nAC\n");

Implementations§

Source§

impl<W: Write> FastxWriter<W>

Source

pub fn new(inner: W, format: Format) -> FastxWriter<W>

A writer for format, wrapping FASTA at DEFAULT_LINE_WIDTH.

Wrap inner in a BufWriter yourself for best throughput, or use create which does it for you.

Source

pub fn line_width(self, width: usize) -> Self

Set the FASTA line width. 0 disables wrapping.

Source

pub fn validate(self, alphabet: Alphabet) -> Self

Validate every record against alphabet before writing it.

Source

pub fn format(&self) -> Format

The output format.

Source

pub fn records_written(&self) -> u64

Number of records written so far.

Source

pub fn write_record(&mut self, record: &Sequence) -> Result<()>

Write one record in the writer’s format.

Source

pub fn write_all<'a, I>(&mut self, records: I) -> Result<()>
where I: IntoIterator<Item = &'a Sequence>,

Write every record of an iterator.

Source

pub fn write_fasta( &mut self, id: &str, description: Option<&str>, seq: &[u8], ) -> Result<()>

Write a FASTA record from parts, without building a Sequence.

Source

pub fn write_fastq( &mut self, id: &str, description: Option<&str>, seq: &[u8], quality: &[u8], ) -> Result<()>

Write a FASTQ record from parts, without building a Sequence.

Source

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

Flush buffered bytes to the underlying writer.

Source

pub fn finish(self) -> Result<W>

Flush and return the underlying writer.

Always prefer this over dropping the writer: for gzip output it is the only way to learn that finishing the stream failed.

Source

pub fn get_ref(&self) -> &W

Borrow the underlying writer.

Trait Implementations§

Source§

impl<W: Write> Debug for FastxWriter<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for FastxWriter<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for FastxWriter<W>
where W: RefUnwindSafe,

§

impl<W> Send for FastxWriter<W>
where W: Send,

§

impl<W> Sync for FastxWriter<W>
where W: Sync,

§

impl<W> Unpin for FastxWriter<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for FastxWriter<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for FastxWriter<W>
where W: 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.