Skip to content

Commit

Permalink
fix: allow leading deletions in read_pos method of CigarStringView. (#…
Browse files Browse the repository at this point in the history
…447)

* fix: allow leading deletions in read_pos method of CigarStringView.

* fix testcase

---------

Co-authored-by: Felix Mölder <felix.moelder@uk-essen.de>
  • Loading branch information
johanneskoester and FelixMoelder authored Nov 12, 2024
1 parent 01fb5b8 commit 2986713
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/bam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2997,7 +2997,7 @@ CCCCCCCCCCCCCCCCCCC"[..],
fn test_bam_header_sync() {
let reader = Reader::from_path("test/test_issue_156_no_text.bam").unwrap();
let header_hashmap = Header::from_template(reader.header()).to_hashmap();
let header_refseqs = header_hashmap.get("SQ".into()).unwrap();
let header_refseqs = header_hashmap.get("SQ").unwrap();
assert_eq!(header_refseqs[0].get("SN").unwrap(), "ref_1",);
assert_eq!(header_refseqs[0].get("LN").unwrap(), "10000000",);
}
Expand Down
13 changes: 9 additions & 4 deletions src/bam/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2097,10 +2097,15 @@ impl CigarStringView {
}
break;
},
Cigar::Del(_) => {
return Err(Error::BamUnexpectedCigarOperation {
msg: "'deletion' (D) found before any operation describing read sequence".to_owned()
});
Cigar::Del(l) => {
// METHOD: leading deletions can happen in case of trimmed reads where
// a primer has been removed AFTER read mapping.
// Example: 24M8I8D18M9S before trimming, 32H8D18M9S after trimming
// with fgbio. While leading deletions should be impossible with
// normal read mapping, they make perfect sense with primer trimming
// because the mapper still had the evidence to decide in favor of
// the deletion via the primer sequence.
rpos += l;
},
Cigar::RefSkip(_) => {
return Err(Error::BamUnexpectedCigarOperation {
Expand Down

0 comments on commit 2986713

Please sign in to comment.