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.
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.
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.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
samtools view with flag 2048 ?