Struct fxread::record::Record

source ·
pub struct Record { /* private fields */ }
Expand description

An instance of a Fastx Record. This is a two attribute object containing the sequence ID and the Sequence.

Implementations§

source§

impl Record

source

pub fn new() -> Self

Usage

Creates a new instance of a [Record]

let record = fxread::Record::new();
assert!(record.empty());
source

pub fn new_fasta(data: Vec<u8>, id: usize, seq: usize) -> Self

Usage

Creates a new instance of a [Record] from a preinitialized [Vec<u8>] with the id and seq endpoints calculated. These endpoints are inclusive of the ‘\n’ terminator and the data is expected to exclude the prefix ‘>’ marker.

let data = b">seq.0\nACGT\n".to_vec();
let id = 6;
let seq = 5;
let fasta = fxread::Record::new_fasta(data, id, seq);
assert_eq!(fasta.id(), b"seq.0");
assert_eq!(fasta.seq(), b"ACGT");
source

pub fn new_fastq( data: Vec<u8>, id: usize, seq: usize, plus: usize, qual: usize ) -> Self

Usage

Creates a new instance of a [Record] from a preinitialized [Vec<u8>] with the id, seq, plus, and qual endpoints calculated. These endpoints are inclusive of the ‘\n’ terminator and the data is expected to exclude the prefix ‘@’ marker.

let data = b"@seq.0\nACGT\n+\n1234\n".to_vec();
let id = 6;
let seq = 5;
let plus = 2;
let qual = 5;
let fasta = fxread::Record::new_fastq(data, id, seq, plus, qual);
assert_eq!(fasta.id(), b"seq.0");
assert_eq!(fasta.seq(), b"ACGT");
assert_eq!(fasta.plus().unwrap(), b"+");
assert_eq!(fasta.qual().unwrap(), b"1234");
source

pub fn new_fasta_from_parts(id: &[u8], seq: &[u8]) -> Result<Self>

Usage

Creates a new instance of a [Record] from its raw parts and calculates the endpoints. The id and seq are required and expected to be the raw data excluding the prefix ‘>’ marker.

let id = b"seq.0";
let seq = b"ACGT";
let record = fxread::Record::new_fasta_from_parts(id, seq).unwrap();
assert_eq!(record.id(), b"seq.0");
assert_eq!(record.seq(), b"ACGT");
source

pub fn new_fastq_from_parts(id: &[u8], seq: &[u8], qual: &[u8]) -> Result<Self>

Usage

Creates a new instance of a [Record] from its raw parts and calculates the endpoints. The id and seq and qual are required and expected to be the raw data excluding the prefix ‘>’ or ‘@’ markers. The plus is not required and is expected to be the raw data excluding the prefix ‘+’.

let id = b"seq.0";
let seq = b"ACGT";
let qual = b"1234";
let record = fxread::Record::new_fastq_from_parts(id, seq, qual).unwrap();
assert_eq!(record.id(), b"seq.0");
assert_eq!(record.seq(), b"ACGT");
assert_eq!(record.qual().unwrap(), b"1234");
source

pub fn is_fasta(&self) -> bool

Checks if [Record] is a fasta

source

pub fn is_fastq(&self) -> bool

Checks if [Record] is a fastq

source

pub fn valid_header(&self) -> bool

Checks if [Record] has a valid header

source

pub fn empty(&self) -> bool

Checks if [Record] is empty

source

pub fn id_range(&self) -> Range<usize>

Returns the Range of the ID

source

pub fn seq_range(&self) -> Range<usize>

Returns the Range of the sequence

source

pub fn plus_range(&self) -> Option<Range<usize>>

Returns the Range of the ‘+’ region of a fastq

source

pub fn qual_range(&self) -> Option<Range<usize>>

Returns the Range of the quality score if it exists

source

pub fn id(&self) -> &[u8]

Returns a reference of the sequence ID

source

pub fn seq(&self) -> &[u8]

Returns a reference of the sequence

source

pub fn seq_mut(&mut self) -> &mut [u8]

Returns a mutable reference of the sequence

source

pub fn plus(&self) -> Option<&[u8]>

Returns a reference of the ‘+’ region of a fastq

source

pub fn qual(&self) -> Option<&[u8]>

Returns a reference of the sequence

source

pub fn qual_mut(&mut self) -> Option<&mut [u8]>

Returns a mutable reference of the quality score if it exists

source

pub fn data(&self) -> &[u8]

Returns a reference to the raw data underlying the record

source

pub fn valid(&self) -> bool

Validates that the record is not partially constructed or composed of unexpected nucleotides

source

pub fn seq_upper(&self) -> Vec<u8>

Converts the sequence to uppercase

source

pub fn seq_rev_comp(&self) -> Vec<u8>

Reverse Complements the sequence

source

pub fn fix(&mut self)

Converts all non-ACGTN nucleotides to N

source

pub fn upper(&mut self)

Converts the sequence to uppercase in place

source

pub fn rev_comp(&mut self)

Reverse Complements the sequence in place Also reverses the quality scores if present

source

pub fn insert_seq(&mut self, seq: &[u8], pos: usize) -> Result<()>

Inserts nucleotides into the sequence at the specified index and the corresponding quality scores if present Returns an error if the index is greater than the sequence length

source

pub fn insert_seq_left(&mut self, seq: &[u8]) -> Result<()>

Convenience function to insert nucleotides at the beginning of a sequence

source

pub fn insert_seq_right(&mut self, seq: &[u8]) -> Result<()>

Convenience function to insert nucleotides at the end of a sequence

source

pub fn trim_left(&mut self, size: usize) -> Result<()>

Trims the nucleotides from the left of the sequence and the corresponding quality scores if present Returns an error if the size is greater than the sequence length

source

pub fn trim_right(&mut self, size: usize) -> Result<()>

Trims the nucleotides from the right of the sequence and the corresponding quality scores if present Returns an error if the size is greater than the sequence length

source

pub fn as_str_checked(&self) -> Result<&str, Utf8Error>

Underlying record as str

source

pub fn id_str_checked(&self) -> Result<&str, Utf8Error>

ID as str

source

pub fn seq_str_checked(&self) -> Result<&str, Utf8Error>

Sequence as str

source

pub fn qual_str_checked(&self) -> Option<Result<&str, Utf8Error>>

Quality as str

source

pub fn as_str(&self) -> &str

Underlying record as str unchecked (may panic if invalid utf8)

source

pub fn id_str(&self) -> &str

ID as str unchecked (may panic if invalid utf8)

source

pub fn seq_str(&self) -> &str

Sequence as str unchecked (may panic if invalid utf8)

source

pub fn qual_str(&self) -> Option<&str>

Quality as str unchecked (may panic if invalid utf8)

Trait Implementations§

source§

impl Debug for Record

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Record

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Into<String> for Record

source§

fn into(self) -> String

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

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>,

§

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>,

§

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.