How to remove split/broken reads from bam file
1
2
Entering edit mode
6.2 years ago
BioGeek ▴ 170

Is there any flag to remove broken (ONT reads split and map to different locations) reads from bam file.

Note: The ONT reads mapped with gap should not remove.

split samtools graphmap nanopore minimap2 • 3.6k views
ADD COMMENT
2
Entering edit mode

samtools view with flag 2048 ?

ADD REPLY
4
Entering edit mode
6.2 years ago

As Pierre Lindenbaum said in the comment, samtools view -F 2048 will remove all those reads that have supplementary alignment. Be sure that the alignment program you use specifies those (like bwa mem does, for example).

If you also want to remove reads that have secondary alignments, there is no flag to do so but you can work around it with awk. Combining it with the one above:

samtools view -h -F 2048 file.bam | awk 'substr($1, 0, 1)=="@" || $0 !~ /ZS:/' | samtools view -h -b > filtered_file.bam

Be careful: ZS: is a tag of HISAT2. If you're using another program, check which tag is used for secondary alignments. I think it is AS: in Bowtie2, and I don't know what it is in bwa. Usually, it is specified in the manual.

ADD COMMENT

Login before adding your answer.

Traffic: 2000 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