How to compare compare two Sam files to check mapping
2
2
Entering edit mode
7.0 years ago
madhu.9124 ▴ 60

Hi, I have two output reads in Sam format generated from mapping to a reference genome, I would like to know if any tools or command available to compare the two generated sam files. This comparison is done to check if the mappings are same in both the sam files. Kindly help.

Thanks Madhu

alignment • 3.9k views
ADD COMMENT
0
Entering edit mode

This is going to be always tricky but this recent thread may be of help: BAM file comparison

ADD REPLY
2
Entering edit mode
7.0 years ago

I happened to write something a while back to compare equivalently sorted files from different aligners (or with different settings, or with/without post-processing) to see which alignments differ and why. It currently compares chromosome, position, and the cigar string and prints out information about the differences. If you happen to know C then this could be modified to return something else.

Aside from that, you can at least use bamhash to see if both files have the same reads (though the alignments themselves aren't checked).

ADD COMMENT
0
Entering edit mode

I tried it, it was throwing up lot of errors.

ADD REPLY
0
Entering edit mode

It was likely printing a lot of output (assuming you got it compiled).

ADD REPLY
0
Entering edit mode
6 months ago
DavidStreid ▴ 90

Curious if others have also benefited from Picard's CompareSAMs tool. Seems to do exactly what Madhu has requested.

If the headers are identical, this would generate SAM files match if the mappings are the same

java -jar picard.jar CompareSAMs \
      file_1.bam \
      file_2.bam \
      O=comparison.tsv

I have used the LENIENT_HEADER=true option to compare SAM files where the headers differ, which has saved a lot of time

ADD COMMENT

Login before adding your answer.

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