pub struct Record {
pub inner: bam1_t,
/* private fields */
}
Expand description
A BAM record.
Fields§
§inner: bam1_t
Implementations§
Source§impl Record
impl Record
pub fn from_inner(from: *mut bam1_t) -> Self
pub fn from_sam(header_view: &HeaderView, sam: &[u8]) -> Result<Record>
pub fn set_header(&mut self, header: Rc<HeaderView>)
pub fn inner_mut(&mut self) -> &mut bam1_t
pub fn inner(&self) -> &bam1_t
pub fn bin(&self) -> u16
pub fn set_bin(&mut self, bin: u16)
Sourcepub fn unset_flags(&mut self)
pub fn unset_flags(&mut self)
Unset all flags.
Sourcepub fn insert_size(&self) -> i64
pub fn insert_size(&self) -> i64
Get insert size.
Sourcepub fn set_insert_size(&mut self, insert_size: i64)
pub fn set_insert_size(&mut self, insert_size: i64)
Set insert size.
Sourcepub fn set(
&mut self,
qname: &[u8],
cigar: Option<&CigarString>,
seq: &[u8],
qual: &[u8],
)
pub fn set( &mut self, qname: &[u8], cigar: Option<&CigarString>, seq: &[u8], qual: &[u8], )
Set variable length data (qname, cigar, seq, qual).
The aux data is left unchanged.
qual
is Phred-scaled quality values, without any offset.
NOTE: seq.len() must equal qual.len() or this method
will panic. If you don’t have quality values use
let quals = vec![ 255 as u8; seq.len()];
as a placeholder that will
be recognized as missing QVs by samtools
.
pub fn cigar_len(&self) -> usize
Sourcepub fn raw_cigar(&self) -> &[u32]
pub fn raw_cigar(&self) -> &[u32]
Get reference to raw cigar string representation (as stored in BAM file).
Usually, the method Record::cigar
should be used instead.
Sourcepub fn cigar(&self) -> CigarStringView
pub fn cigar(&self) -> CigarStringView
Return unpacked cigar string. This will create a fresh copy the Cigar data.
pub fn cigar_cached(&self) -> Option<&CigarStringView>
Sourcepub fn cache_cigar(&mut self)
pub fn cache_cigar(&mut self)
Decode the cigar string and cache it inside the Record
pub fn seq_len(&self) -> usize
Sourcepub fn qual(&self) -> &[u8] ⓘ
pub fn qual(&self) -> &[u8] ⓘ
Get base qualities (PHRED-scaled probability that base is wrong). This does not entail any offsets, hence the qualities can be used directly without e.g. subtracting 33. Complexity: O(1).
Sourcepub fn aux(&self, tag: &[u8]) -> Result<Aux<'_>>
pub fn aux(&self, tag: &[u8]) -> Result<Aux<'_>>
Look up an auxiliary field by its tag.
Only the first two bytes of a given tag are used for the look-up of a field.
See Aux
for more details.
Sourcepub fn aux_iter(&self) -> AuxIter<'_> ⓘ
pub fn aux_iter(&self) -> AuxIter<'_> ⓘ
Returns an iterator over the auxiliary fields of the record.
When an error occurs, the Err
variant will be returned
and the iterator will not be able to advance anymore.
pub fn remove_aux(&mut self, tag: &[u8]) -> Result<()>
Sourcepub fn basemods_iter(&self) -> Result<BaseModificationsIter<'_>>
pub fn basemods_iter(&self) -> Result<BaseModificationsIter<'_>>
Access the base modifications associated with this Record through the MM tag. Example:
use rust_htslib::bam::{Read, Reader, Record};
let mut bam = Reader::from_path(&"test/base_mods/MM-orient.sam").unwrap();
let mut mod_count = 0;
for r in bam.records() {
let record = r.unwrap();
if let Ok(mods) = record.basemods_iter() {
// print metadata for the modifications present in this record
for mod_code in mods.recorded() {
if let Ok(mod_metadata) = mods.query_type(*mod_code) {
println!("mod found with code {}/{} flags: [{} {} {}]",
mod_code, *mod_code as u8 as char,
mod_metadata.strand, mod_metadata.implicit, mod_metadata.canonical as u8 as char);
}
}
// iterate over the modifications in this record
// the modifications are returned as a tuple with the
// position within SEQ and an hts_base_mod struct
for res in mods {
if let Ok( (position, m) ) = res {
println!("{} {},{}", position, m.modified_base as u8 as char, m.qual);
mod_count += 1;
}
}
};
}
assert_eq!(mod_count, 14);
Sourcepub fn basemods_position_iter(
&self,
) -> Result<BaseModificationsPositionIter<'_>>
pub fn basemods_position_iter( &self, ) -> Result<BaseModificationsPositionIter<'_>>
An iterator that returns all of the modifications for each position as a vector. This is useful for the case where multiple possible modifications can be annotated at a single position (for example a C could be 5-mC or 5-hmC)
Sourcepub fn read_pair_orientation(&self) -> SequenceReadPairOrientation
pub fn read_pair_orientation(&self) -> SequenceReadPairOrientation
Infer read pair orientation from record. Returns SequenceReadPairOrientation::None
if record
is not paired, mates are not mapping to the same contig, or mates start at the
same position.
pub fn is_paired(&self) -> bool
pub fn set_paired(&mut self)
pub fn unset_paired(&mut self)
pub fn is_proper_pair(&self) -> bool
pub fn set_proper_pair(&mut self)
pub fn unset_proper_pair(&mut self)
pub fn is_unmapped(&self) -> bool
pub fn set_unmapped(&mut self)
pub fn unset_unmapped(&mut self)
pub fn is_mate_unmapped(&self) -> bool
pub fn set_mate_unmapped(&mut self)
pub fn unset_mate_unmapped(&mut self)
pub fn is_reverse(&self) -> bool
pub fn set_reverse(&mut self)
pub fn unset_reverse(&mut self)
pub fn is_mate_reverse(&self) -> bool
pub fn set_mate_reverse(&mut self)
pub fn unset_mate_reverse(&mut self)
pub fn is_first_in_template(&self) -> bool
pub fn set_first_in_template(&mut self)
pub fn unset_first_in_template(&mut self)
pub fn is_last_in_template(&self) -> bool
pub fn set_last_in_template(&mut self)
pub fn unset_last_in_template(&mut self)
pub fn is_secondary(&self) -> bool
pub fn set_secondary(&mut self)
pub fn unset_secondary(&mut self)
pub fn is_quality_check_failed(&self) -> bool
pub fn set_quality_check_failed(&mut self)
pub fn unset_quality_check_failed(&mut self)
pub fn is_duplicate(&self) -> bool
pub fn set_duplicate(&mut self)
pub fn unset_duplicate(&mut self)
pub fn is_supplementary(&self) -> bool
pub fn set_supplementary(&mut self)
pub fn unset_supplementary(&mut self)
Trait Implementations§
Source§impl AbstractInterval for Record
impl AbstractInterval for Record
Source§fn contig(&self) -> &str
fn contig(&self) -> &str
Return contig name. Panics if record does not know its header (which happens if it has not been read from a file).
Source§fn range(&self) -> Range<Position>
fn range(&self) -> Range<Position>
Return genomic range covered by alignment. Panics if Record::cache_cigar()
has not been called first or Record::pos()
is less than zero.
Source§fn contains<L>(&self, locus: L) -> boolwhere
L: AbstractLocus,
fn contains<L>(&self, locus: L) -> boolwhere
L: AbstractLocus,
Source§impl BamRecordExtensions for Record
impl BamRecordExtensions for Record
Source§fn reference_end(&self) -> i64
fn reference_end(&self) -> i64
Calculate the rightmost base position of an alignment on the reference genome. Returns the coordinate of the first base after the alignment (0-based).
Source§fn aligned_blocks(&self) -> IterAlignedBlocks ⓘ
fn aligned_blocks(&self) -> IterAlignedBlocks ⓘ
Source§fn introns(&self) -> IterIntrons ⓘ
fn introns(&self) -> IterIntrons ⓘ
Source§fn aligned_block_pairs(&self) -> IterAlignedBlockPairs ⓘ
fn aligned_block_pairs(&self) -> IterAlignedBlockPairs ⓘ
Source§fn aligned_pairs(&self) -> IterAlignedPairs ⓘ
fn aligned_pairs(&self) -> IterAlignedPairs ⓘ
Source§fn aligned_pairs_full(&self) -> IterAlignedPairsFull ⓘ
fn aligned_pairs_full(&self) -> IterAlignedPairsFull ⓘ
Source§fn cigar_stats_nucleotides(&self) -> HashMap<Cigar, i32>
fn cigar_stats_nucleotides(&self) -> HashMap<Cigar, i32>
Source§fn cigar_stats_blocks(&self) -> HashMap<Cigar, i32>
fn cigar_stats_blocks(&self) -> HashMap<Cigar, i32>
Source§fn reference_positions(&self) -> Box<dyn Iterator<Item = i64>>
fn reference_positions(&self) -> Box<dyn Iterator<Item = i64>>
Source§fn reference_positions_full(&self) -> Box<dyn Iterator<Item = Option<i64>>>
fn reference_positions_full(&self) -> Box<dyn Iterator<Item = Option<i64>>>
Source§fn reference_start(&self) -> i64
fn reference_start(&self) -> i64
Source§impl SequenceRead for Record
impl SequenceRead for Record
impl Eq for Record
impl Send for Record
impl Sync for Record
Auto Trait Implementations§
impl Freeze for Record
impl RefUnwindSafe for Record
impl Unpin for Record
impl UnwindSafe for Record
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)