Skip to content

Commit

Permalink
cram/record: Skip unnecessary sequence resolution
Browse files Browse the repository at this point in the history
The reference sequence is not needed if the record is unmapped or has no
sequence.
  • Loading branch information
zaeleus committed Feb 18, 2025
1 parent 087a68b commit d712d0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions noodles-cram/src/io/reader/container/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ impl<'c> Slice<'c> {

record.header = Some(header);

record.reference_sequence = if reference_sequence_context.is_many() {
get_record_reference_sequence(&reference_sequence_repository, header, record)?
} else {
slice_reference_sequence.clone()
};

record.substitution_matrix = substitution_matrix.clone();
if !record.bam_flags.is_unmapped() && !record.cram_flags.sequence_is_missing() {
record.reference_sequence = if reference_sequence_context.is_many() {
get_record_reference_sequence(&reference_sequence_repository, header, record)?
} else {
slice_reference_sequence.clone()
};

record.substitution_matrix = substitution_matrix.clone();
}
}

resolve_mates(&mut records)?;
Expand Down
6 changes: 3 additions & 3 deletions noodles-cram/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ impl sam::alignment::Record for Record<'_> {
}

fn sequence(&self) -> Box<dyn sam::alignment::record::Sequence + '_> {
if self.sequence.is_empty() {
if self.bam_flags.is_unmapped() || self.cram_flags.sequence_is_missing() {
Box::new(Bases(self.sequence))
} else {
let (reference_sequence, alignment_start) = match self.reference_sequence.as_ref() {
Some(ReferenceSequence::Embedded {
reference_start,
Expand All @@ -168,8 +170,6 @@ impl sam::alignment::Record for Record<'_> {
alignment_start,
self.read_length,
))
} else {
Box::new(Bases(self.sequence))
}
}

Expand Down

0 comments on commit d712d0b

Please sign in to comment.