How to trim alignments in a BAM file to a restricted genomic window?
Say I have long reads which I have aligned to hg38.
Now I want to trim my alignments to a specific region of chr20, say between position 2,000,000 and 2,000,500.
I am imagining something like
trim input.bam 'chr20:2000000-2000500' > output.bam
This is similar but not identical to this: Extract Reads From A Bam File That Fall Within A Given Region
Not identical because I do not want to extract complete alignments, I want alignments to be trimmed if necessary so they only cover the region I am interested in.
How can I do this?
• 1,430 views
•
link
1 answer
have a look at samtools ampliconclip (in a recent version of samtools)
Usage samtools ampliconclip -b bedfile <input.bam> -o <output.bam>
Option:
-b FILE bedfile of amplicons to be removed.
-o FILE output file name (default stdout).
-f FILE write stats to file name (default stderr)
-u Output uncompressed data
--soft-clip soft clip amplicons from reads (default)
--hard-clip hard clip amplicons from reads.
--both-ends clip on both ends.
(...)
• 0 views
•
link
Log in to answer this question.