This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Differences between two SAM/BAM files with samtools

Hi everyone. I'd like to compare two bam files from two different aligners to find overlaps, multiple alignments, unique reads in each bam file etc. I was looking for simple tutorial of samtools to do that, but it is still unclear for me (there are to many options and flags and I'm puzzled with it).

Could someone help me? What is the best way to compare outputs of different aligners?

Thanks a lot

snp alignment

1 answer

comparing the first in pair using the RNAME,CHROM,POS, columns:

samtools view -f 64 -F 2304 method1.bam | cut -f1,3,4 | LC_ALL=C sort -t '\t' -k1,1 > method1.txt
samtools view -f 64 -F 2304 method2.bam | cut -f1,3,4 | LC_ALL=C sort -t '\t' -k1,1 > method2.txt
join -t '\t' -1 1 -2 1 method1.txt method2.txt > R1.comparaison

I performed this but got empty file at each steps. Could you help me?

'\t' in sort is a TAB. Did you replace this?

I wrote this way t$'\t'. Sorry for interrupting you. There is something wrong with my file. It works fine on another .bam file. Thanks.

Hi Pierre, I am trying to compare two bam files just like dsulgin did, but I am getting empty file out of this step -

samttools view -f 64 -F 2304 input1.bam | cut -f1,3,4 | LC_ALL=C sort -t `\t` -k1,1  > method1.txt

Can you please share what columns should I expect in this method1.txt file? I am also getting this error -

sort: multi-character tab `\\t'

thanks!

Log in to answer this question.