This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Supplementary alignments in BAM-file

Dear all,

I have a bamfile which contains some reads that have supplementary alignments within them, as shown in the screenshot.

I tried to filter the bamfile with samtools using flag 2048. Luckily the supplementary alignments belonging to a specific read were gone. However, I want the whole read to be filtered out whenever it contains supplementary alignments from the bamfile and not only its supplementary alignments. is there a possible way to do this?

Best

galaxy samtools bam

for what it's worth, "supplementary alignments" can be quite interesting. they often indicate things like SVs

3 answers

add -e '![SA]' to your samtools view command ( http://www.htslib.org/doc/samtools.html#FILTER_EXPRESSIONS )

Does this address

i want the whole read to be filtered out whenever it contains supplementary alignments from the bamfile and not only its supplementary alignments.

It might take two steps: 1) using samtools to identify the read names which have supplementary alignments, then 2) filter away all lines in the bam with those read names.

In one step, you could remove every alignments with a mapping quality of 0. With most aligners, this corresponds to the reads for which there is ambiguous mapping. Note that this will also remove secondary alignments and the primary alignments from reads that also have secondary/supplementary alignments.

samtools view -q 1 -b input.bam -o output.bam

Log in to answer this question.