Question: How to remove split/broken reads from bam file
2
gravatar for BioGeek
20 months ago by
BioGeek140
BioGeek140 wrote:

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.

ADD COMMENTlink modified 20 months ago by Macspider2.9k • written 20 months ago by BioGeek140
2

samtools view with flag 2048 ?

ADD REPLYlink written 20 months ago by Pierre Lindenbaum122k
4
gravatar for Macspider
20 months ago by
Macspider2.9k
Vienna - BOKU
Macspider2.9k wrote:

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 COMMENTlink written 20 months ago by Macspider2.9k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2009 users visited in the last hour