Struct noodles_fasta::record::sequence::Sequence
source · pub struct Sequence(/* private fields */);
Expand description
A FASTA record sequence.
Implementations§
source§impl Sequence
impl Sequence
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the sequence.
§Examples
use noodles_fasta::record::Sequence;
let sequence = Sequence::default();
assert_eq!(sequence.len(), 0);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the sequence is empty.
§Examples
use noodles_fasta::record::Sequence;
let sequence = Sequence::default();
assert!(sequence.is_empty());
sourcepub fn get<I>(&self, index: I) -> Option<&I::Output>where
I: SequenceIndex<u8>,
pub fn get<I>(&self, index: I) -> Option<&I::Output>where
I: SequenceIndex<u8>,
Returns a reference to a base at or slice of bases between the given index.
§Examples
use noodles_core::Position;
use noodles_fasta::record::Sequence;
let sequence = Sequence::from(b"ACGT".to_vec());
let start = Position::try_from(2)?;
assert_eq!(sequence.get(start), Some(&b'C'));
assert_eq!(sequence.get(start..), Some(&b"CGT"[..]));
let end = Position::try_from(3)?;
assert_eq!(sequence.get(start..=end), Some(&b"CG"[..]));
sourcepub fn slice<I>(&self, interval: I) -> Option<Self>
pub fn slice<I>(&self, interval: I) -> Option<Self>
Returns a subset of the sequence within the given range.
Unlike Self::get
, this returns the slice as a Sequence
.
§Examples
use noodles_core::Position;
use noodles_fasta::record::Sequence;
let sequence = Sequence::from(b"ACGT".to_vec());
let start = Position::try_from(2)?;
let end = Position::try_from(3)?;
let actual = sequence.slice(start..=end);
let expected = Sequence::from(b"CG".to_vec());
assert_eq!(actual, Some(expected));
sourcepub fn complement(&self) -> Complement<'_> ⓘ
pub fn complement(&self) -> Complement<'_> ⓘ
Returns an iterator that complements the sequence.
§Examples
§Complement a sequence
use noodles_fasta::record::Sequence;
let sequence = Sequence::from(b"ACGT".to_vec());
let actual: Sequence = sequence.complement().collect::<Result<_, _>>()?;
let expected = Sequence::from(b"TGCA".to_vec());
assert_eq!(actual, expected);
§Reverse complement a sequence
use noodles_fasta::record::Sequence;
let sequence = Sequence::from(b"ACGT".to_vec());
let actual: Sequence = sequence.complement().rev().collect::<Result<_, _>>()?;
let expected = sequence.clone();
assert_eq!(actual, expected);
Trait Implementations§
source§impl FromIterator<u8> for Sequence
impl FromIterator<u8> for Sequence
source§impl PartialEq for Sequence
impl PartialEq for Sequence
impl Eq for Sequence
impl StructuralPartialEq for Sequence
Auto Trait Implementations§
impl !Freeze for Sequence
impl RefUnwindSafe for Sequence
impl Send for Sequence
impl Sync for Sequence
impl Unpin for Sequence
impl UnwindSafe for Sequence
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
Mutably borrows from an owned value. Read more