pub struct ReadStructure { /* private fields */ }Expand description
A read structure made up of one or more ReadSegments.
Internally, in addition to the segments themselves, we cache per-segment start
offsets (signed) and enough summary information to resolve the indefinite-length
(+) segment’s end position at extract time without another pass over the
segments.
Implementations§
Source§impl ReadStructure
impl ReadStructure
Sourcepub fn new(segments: Vec<ReadSegment>) -> Result<Self, ReadStructureError>
pub fn new(segments: Vec<ReadSegment>) -> Result<Self, ReadStructureError>
Builds a new ReadStructure from a vector of ReadSegments.
At most one segment may have an indefinite length (+); it may appear in any
position.
§Errors
- Returns
Errif no elements exist. - Returns
Errif more than one segment has an indefinite length.
Sourcepub fn extract<'rs, 'b>(
&'rs self,
bases: &'b [u8],
quals: &'b [u8],
skip_handling: SkipHandling,
) -> Result<ExtractedSegments<'rs, 'b>, ReadStructureError>
pub fn extract<'rs, 'b>( &'rs self, bases: &'b [u8], quals: &'b [u8], skip_handling: SkipHandling, ) -> Result<ExtractedSegments<'rs, 'b>, ReadStructureError>
Extracts the bases and quality scores for every segment in this read structure.
Returns a no-alloc iterator over (&ReadSegment, &[u8] bases, &[u8] quals) triples.
All error conditions are checked up front, so the returned iterator is infallible
and can be cheaply .collect()ed into a Vec when an owned collection is needed.
skip_handling controls whether SegmentType::Skip segments are emitted
(SkipHandling::Include) or silently dropped (SkipHandling::Exclude).
§Errors
ReadStructureError::MismatchingBasesAndQualsLenifbases.len() != quals.len().ReadStructureError::ReadTooShortif the read cannot accommodate every fixed segment. When the structure also has a+segment, the read must be strictly longer than the sum of the fixed-segment lengths (since+means at least one base).ReadStructureError::ReadTooLongif the structure has no+segment andbases.len()does not exactly matchlength_of_fixed_segments. Silently truncating trailing bases is almost always a bug (wrong structure, stray adapter, etc.), so we require an exact match.
Sourcepub fn has_fixed_length(&self) -> bool
pub fn has_fixed_length(&self) -> bool
Returns true if the ReadStructure has a fixed (i.e. non-variable) length,
false if any segment has an indefinite length.
Sourcepub fn fixed_length(&self) -> Option<usize>
pub fn fixed_length(&self) -> Option<usize>
Returns the fixed length if there is one.
Sourcepub fn number_of_segments(&self) -> usize
pub fn number_of_segments(&self) -> usize
Returns the number of segments in this read structure.
Sourcepub fn segments(&self) -> &[ReadSegment]
pub fn segments(&self) -> &[ReadSegment]
Returns the underlying elements in this read structure.
Sourcepub fn iter(&self) -> impl Iterator<Item = &ReadSegment>
pub fn iter(&self) -> impl Iterator<Item = &ReadSegment>
Returns an iterator over the read segments.
Sourcepub fn segments_by_type(
&self,
kind: SegmentType,
) -> impl Iterator<Item = &ReadSegment>
pub fn segments_by_type( &self, kind: SegmentType, ) -> impl Iterator<Item = &ReadSegment>
Returns the ReadSegments in this read structure of the given kind.
Sourcepub fn templates(&self) -> impl Iterator<Item = &ReadSegment>
pub fn templates(&self) -> impl Iterator<Item = &ReadSegment>
Returns the template ReadSegments in this read structure.
Sourcepub fn sample_barcodes(&self) -> impl Iterator<Item = &ReadSegment>
pub fn sample_barcodes(&self) -> impl Iterator<Item = &ReadSegment>
Returns the sample barcode ReadSegments in this read structure.
Sourcepub fn molecular_barcodes(&self) -> impl Iterator<Item = &ReadSegment>
pub fn molecular_barcodes(&self) -> impl Iterator<Item = &ReadSegment>
Returns the molecular barcode ReadSegments in this read structure.
Sourcepub fn skips(&self) -> impl Iterator<Item = &ReadSegment>
pub fn skips(&self) -> impl Iterator<Item = &ReadSegment>
Returns the skip ReadSegments in this read structure.
Sourcepub fn cellular_barcodes(&self) -> impl Iterator<Item = &ReadSegment>
pub fn cellular_barcodes(&self) -> impl Iterator<Item = &ReadSegment>
Returns the cellular barcode ReadSegments in this read structure.
Sourcepub fn first(&self) -> Option<&ReadSegment>
pub fn first(&self) -> Option<&ReadSegment>
Returns the first ReadSegment in this read structure.
Sourcepub fn last(&self) -> Option<&ReadSegment>
pub fn last(&self) -> Option<&ReadSegment>
Returns the last ReadSegment in this read structure.
Trait Implementations§
Source§impl Clone for ReadStructure
impl Clone for ReadStructure
Source§fn clone(&self) -> ReadStructure
fn clone(&self) -> ReadStructure
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ReadStructure
impl Debug for ReadStructure
Source§impl Display for ReadStructure
impl Display for ReadStructure
Source§impl From<ReadStructure> for String
impl From<ReadStructure> for String
Source§fn from(rs: ReadStructure) -> Self
fn from(rs: ReadStructure) -> Self
Renders the read structure to its canonical string form (e.g. "8B+M10T").
Source§impl FromStr for ReadStructure
impl FromStr for ReadStructure
Source§impl Index<usize> for ReadStructure
impl Index<usize> for ReadStructure
Source§fn index(&self, idx: usize) -> &Self::Output
fn index(&self, idx: usize) -> &Self::Output
Returns the ReadSegment at the given index in the read structure.
Source§type Output = ReadSegment
type Output = ReadSegment
Source§impl IntoIterator for ReadStructure
impl IntoIterator for ReadStructure
Source§impl PartialEq for ReadStructure
impl PartialEq for ReadStructure
Source§impl TryFrom<&[ReadSegment]> for ReadStructure
impl TryFrom<&[ReadSegment]> for ReadStructure
Source§fn try_from(elements: &[ReadSegment]) -> Result<Self, Self::Error>
fn try_from(elements: &[ReadSegment]) -> Result<Self, Self::Error>
Builds a new read structure from a slice of elements.