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>
impl<W: Write> FastxWriter<W>
Sourcepub fn new(inner: W, format: Format) -> FastxWriter<W>
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.
Sourcepub fn line_width(self, width: usize) -> Self
pub fn line_width(self, width: usize) -> Self
Set the FASTA line width. 0 disables wrapping.
Sourcepub fn validate(self, alphabet: Alphabet) -> Self
pub fn validate(self, alphabet: Alphabet) -> Self
Validate every record against alphabet before writing it.
Sourcepub fn records_written(&self) -> u64
pub fn records_written(&self) -> u64
Number of records written so far.
Sourcepub fn write_record(&mut self, record: &Sequence) -> Result<()>
pub fn write_record(&mut self, record: &Sequence) -> Result<()>
Write one record in the writer’s format.
Sourcepub fn write_all<'a, I>(&mut self, records: I) -> Result<()>where
I: IntoIterator<Item = &'a Sequence>,
pub fn write_all<'a, I>(&mut self, records: I) -> Result<()>where
I: IntoIterator<Item = &'a Sequence>,
Write every record of an iterator.
Sourcepub fn write_fasta(
&mut self,
id: &str,
description: Option<&str>,
seq: &[u8],
) -> Result<()>
pub fn write_fasta( &mut self, id: &str, description: Option<&str>, seq: &[u8], ) -> Result<()>
Write a FASTA record from parts, without building a Sequence.
Sourcepub fn write_fastq(
&mut self,
id: &str,
description: Option<&str>,
seq: &[u8],
quality: &[u8],
) -> Result<()>
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.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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