Struct bam::record::Record [−][src]
pub struct Record { /* fields omitted */ }Expand description
BAM Record.
Allows to get and set name, sequence, qualities, CIGAR, flag, tags and all other BAM/SAM record fields.
You can use aligned_pairs and matching_pairs to iterate over record/reference aligned positions.
If the record has an MD tag, you can use alignment_entries to get record/reference positions and corresponding nucleotides.
Implementations
Fills the record from a stream of uncompressed BAM contents.
Returns false, if the file ended and the record was not read.
Use BamReader or IndexedReader instead of this function whenever possible.
Fills the record from SAM. If an error is return, the record may be corrupted.
Shrinks record contents. The more records were read into the same Record instance, the
bigger would be inner vectors (to save time on memory allocation).
Use this function if you do not plan to read into this record in the future.
Returns record name as bytes.
Returns record sequence. You can check if sequence is present in the record using sequence().available().
Returns record qualities. You can check if qualities are present in the record using qualities().available().
Returns 0-based left-most aligned reference position. Same as POS - 1 in SAM specification. Returns -1 for unmapped records.
For a mapped record aligned to reference positions [start-end), the function returns end.
The first calculation takes O(n), where n is the length of Cigar.
Consecutive calculations take O(1).
If the record was fetched from a specific region, it should have end already calculated.
Returns zero for unmapped records.
Returns query length. The function returns the length of the sequence if it is present. Otherwise, the function returns the length calculated from the CIGAR. Unmapped records without sequence would get length 0.
Returns the index of the first aligned base in the record. Returns the length of the query for unmapped records.
Returns the index after the last aligned base in the record. Returns zero for unmapped records.
Returns BAI bin. If the bin is unknown and the end has not been calculated,
the bin will be calculated in O(n_cigar), otherwise O(1).
Returns 4680 for unmapped reads.
Returns 0-based reference index for the pair record. Returns -1 for unmapped records, and records without a pair.
Returns 0-based left-most aligned reference position for the pair record. Same as PNEXT - 1 in SAM specification. Returns -1 for unmapped records and records without a pair.
Observed template length (TLEN in SAM specification).
Returns TagViewer, which provides operations of tags.
Returns mutable TagViewer, which provides operations of tags.
Write the record in SAM format to f. The function needs
header, as the record itself does not store reference
names.
Sets record name (only first 254 letters will be used).
Returns record flag.
It supports predicates like record.flag().is_paired(). You can compare with flags directly
using record.flag().0 & RECORD_PAIRED != 0.
Sets reference id. Panics if less than -1. This function does not update record flag.
Sets record 0-based start. Panics if less than -1.
If the end position was already calculated, it is updated.
Sets reference id of the mate record. Panics if argument is less than -1. This function does not update record flag.
Sets record 0-based start of the mate record. Panics if less than -1.
pub fn set_seq_qual<T, U>(
&mut self,
sequence: T,
qualities: U
) -> Result<(), String> where
T: IntoIterator<Item = u8>,
U: IntoIterator<Item = u8>,
pub fn set_seq_qual<T, U>(
&mut self,
sequence: T,
qualities: U
) -> Result<(), String> where
T: IntoIterator<Item = u8>,
U: IntoIterator<Item = u8>,
Sets a sequence and qualities for a record. If you do not need to set qualities, use
std::iter::empty for qualities. If qualities are non-empty,
both iterators should have the same length.
Arguments
- sequence - in text format (for example
b"ACGT"), - qualities - in raw format (without +33 added).
If the function returns an error, the sequence and qualities are cleared.
Sets raw sequence and qualities for a record. If you do not need to set qualities, use
std::iter::empty for qualities.
Arguments
- sequence - in raw format: each nucleotide takes 4 bits,
- qualities - in raw format (without +33 added).
- len - number of nucleotides. If qualities are non-empty, they should have the same number of bytes.
If the function returns an error, the sequence and qualities are cleared.
Sets record cigar from u8 iterator. This resets end position and BAI bin.
Sets raw record cigar. This resets end position and BAI bin.
pub fn aligned_pairs(&self) -> AlignedPairs<'_>ⓘNotable traits for AlignedPairs<'a>impl<'a> Iterator for AlignedPairs<'a> type Item = (Option<u32>, Option<u32>);
pub fn aligned_pairs(&self) -> AlignedPairs<'_>ⓘNotable traits for AlignedPairs<'a>impl<'a> Iterator for AlignedPairs<'a> type Item = (Option<u32>, Option<u32>);
impl<'a> Iterator for AlignedPairs<'a> type Item = (Option<u32>, Option<u32>);Returns an iterator over pairs (Option<u32>, Option<u32>).
The first element contains a sequence index, and the second element contains a
reference index. If the current operation is an insertion or a deletion, the respective
element will be None.
If the record is unmapped, returns an empty iterator.
pub fn matching_pairs(&self) -> MatchingPairs<'_>ⓘNotable traits for MatchingPairs<'a>impl<'a> Iterator for MatchingPairs<'a> type Item = (u32, u32);
pub fn matching_pairs(&self) -> MatchingPairs<'_>ⓘNotable traits for MatchingPairs<'a>impl<'a> Iterator for MatchingPairs<'a> type Item = (u32, u32);
impl<'a> Iterator for MatchingPairs<'a> type Item = (u32, u32);Returns an iterator over pairs (u32, u32).
The first element represents a sequence index, and the second element represents a
reference index. This iterator skips insertions and deletions.
If the record is unmapped, returns an empty iterator.
Returns an iterator over AlignmentEntry, which stores information about a single position in the record-reference alignment.
The function returns EntriesError if the record does not have a sequence or an MD tag.
for entry in record.alignment_entries().unwrap() {
if let Some((record_pos, record_nt)) = entry.record_pos_nt() {
print!("{} {}", record_pos, record_nt as char);
} else {
print!("-");
}
print!(", ");
if let Some((ref_pos, ref_nt)) = entry.ref_pos_nt() {
println!("{} {}", ref_pos, ref_nt as char);
} else {
println!("-");
}
}Iterator may panic if the MD tag does not match the alignment.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Record
impl UnwindSafe for Record
Blanket Implementations
Mutably borrows from an owned value. Read more
