Skip to content

Commit

Permalink
Fix CRAM region queries when CIGAR isn't being decoded.
Browse files Browse the repository at this point in the history
If using the required_fields option to select columns for decoding,
excluding CIGAR, then the sequence end position (cr->apos to cr->aend)
is not set correctly.

With CIGAR computed, ref_pos is increased by each CIGAR option.
Without it it'll end up being equivalent to cr->apos-1.  Now it is
always minimum cr->apos itself (ie covers apos to apos inclusive).

The impact of this is filtering for the entirety of a single
chromosome could leave a sequence as pos 1 with apos=1 aend=0, which
then rejected the sequence as aend < 1 (for region chr:1-LEN).

I think this also fixes samtools/samtools#1574, but cannot be sure without
confirmation.
  • Loading branch information
jkbonfield authored and daviesrob committed Jan 10, 2022
1 parent 7d3eeec commit 965a90c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cram/cram_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ static int cram_decode_seq(cram_fd *fd, cram_container *c, cram_slice *s,
}

cr->ncigar = ncigar - cr->cigar;
cr->aend = ref_pos;
cr->aend = ref_pos > cr->apos ? ref_pos : cr->apos;

//printf("2: %.*s %d .. %d\n", cr->name_len, DSTRING_STR(name_ds) + cr->name, cr->apos, ref_pos);

Expand Down

0 comments on commit 965a90c

Please sign in to comment.