Skip to content

Commit

Permalink
Add an hclen SAM filter function.
Browse files Browse the repository at this point in the history
See samtools/samtools#813

(Will close issue with man page update which needs applying there)
  • Loading branch information
jkbonfield committed Aug 15, 2023
1 parent 5098983 commit 3023b7e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,26 @@ static int bam_sym_lookup(void *data, char *str, char **end,
}
break;

case 'h':
if (memcmp(str, "hclen", 5) == 0) {
int hclen = 0;
uint32_t *cigar = bam_get_cigar(b);
uint32_t ncigar = b->core.n_cigar;

// left
if (ncigar > 0 && bam_cigar_op(cigar[0]) == BAM_CHARD_CLIP)
hclen = bam_cigar_oplen(cigar[0]);

// right
if (ncigar > 1 && bam_cigar_op(cigar[ncigar-1]) == BAM_CHARD_CLIP)
hclen += bam_cigar_oplen(cigar[ncigar-1]);

*end = str+5;
res->d = hclen;
return 0;
}
break;

case 'l':
if (memcmp(str, "library", 7) == 0) {
*end = str+7;
Expand Down
1 change: 1 addition & 0 deletions test/sam_filter/filter.tst
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ P func4.out $tv -i 'filter=avg(qual) >= 20 && avg(qual) <= 30' ../ce#1000.sam
P func5.out $tv -i 'filter=sclen>=20' ../realn02.sam | grep -E -v '^@'
P func6.out $tv -i 'filter=rlen<50' ../realn02.sam | grep -E -v '^@'
P func7.out $tv -i 'filter=qlen>100' ../realn02.sam | grep -E -v '^@'
P func8.out $tv -i 'filter=hclen>=4' ../c1#clip.sam | grep -E -v '^@'
1 change: 1 addition & 0 deletions test/sam_filter/func8.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s0C 0 c1 3 0 2H6M2H * 0 0 CCGCGG ******

0 comments on commit 3023b7e

Please sign in to comment.