I wanted to use samtools mileup, but it only gives me nucleotide resolution abundance unfortunately and samtools view "ref:630-640" only gives me full length reads originating somewhere within the region. Is there maybe a tool for this purpose available?
This is an old thread but I faced a similar problem so I wrote a CIGAR-aware python utility named xumi (https://github.com/Fravadona/xumi) to do so, using pysam for SAM/BAM/CRAM IO.
Here's how you can extract the region with it:
xumi -r ref:630-640 input.bam
Remark: I didn't require sorted+indexed BAM input, to facilitate xumi use in shell pipes; if needed you can easily get that functionality with an upstream samtools view -u -h:
samtools view -u -h input.bam ref:630-640 |
xumi -r ref:630-640
Cheers
Whatever you want to do, i'm sure it can be done with pysam, but I'm not quite sure what you want? What is wrong with what samtools view is doing?
I used
samtools viewto get the reads which overlap with my region of interest, but I then had to crop the sequences within the bam files, so that I always get the variation of the epitop of interrest within the reads. At the end, I usedsam2pairwise, as cmdcolin suggested, and used the annotation within the output with the annotation of the alignment, to acces the respecitve sequences.