How to trim alignments in a BAM file to a restricted genomic window?
1
0
Entering edit mode
3.0 years ago
francois ▴ 80

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?

bam alignment • 894 views
ADD COMMENT
4
Entering edit mode
3.0 years ago

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.
(...)
ADD COMMENT

Login before adding your answer.

Traffic: 2656 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6