diff --git a/src/bam/mod.rs b/src/bam/mod.rs index ddf1d3221..b79bd89a2 100644 --- a/src/bam/mod.rs +++ b/src/bam/mod.rs @@ -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",); } diff --git a/src/bam/record.rs b/src/bam/record.rs index ced3cc8aa..bae3742b6 100644 --- a/src/bam/record.rs +++ b/src/bam/record.rs @@ -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 {