Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hthl85
    Junior Member
    • Oct 2014
    • 9

    #1

    Compare two BAM file

    Hello everyone,

    I have some questions about BAM file.
    I used samtools to convert BAM file to CRAM, then I used samtools convert CRAM file back to BAM. The size of the new BAM file is larger than the old one. Why the BAM file increase the size? I also want to compare the two BAM files to see are they different or not. Thank you.
  • GenoMax
    Senior Member
    • Feb 2008
    • 7142

    #2
    Have you tried comparing md5sums (after freshly sorting the files)?

    Are both versions on the same storage partition?

    Comment

    • hthl85
      Junior Member
      • Oct 2014
      • 9

      #3
      Originally posted by GenoMax View Post
      Have you tried comparing md5sums (after freshly sorting the files)?

      Are both versions on the same storage partition?
      I didn't check md5sum when I posted the question. But the size increase significantly.
      For example:
      Old BAM Size(byte) | New BAM Size(byte) | Space Increase(byte) | %
      8398197 | 8442685 | 44488 | 0.53
      1595537237 | 1605593870 | 10056633 | 0.63
      3944613 | 4031703 | 87090 | 2.21
      1975987646 | 1989339186 | 13351540 | 0.68

      From your suggest, I check md5sums they are different. The old and new BAM files in the same directory.

      Comment

      • dpryan
        Devon Ryan
        • Jul 2011
        • 3478

        #4
        Try piping both as SAM to md5sum.

        Comment

        • gandalf886
          Member
          • Feb 2013
          • 11

          #5
          If I understand correctly, the md5 should be different anyway even if the two bam file are of the same size? Because they are created by different programs.

          Comment

          • hthl85
            Junior Member
            • Oct 2014
            • 9

            #6
            Originally posted by gandalf886 View Post
            If I understand correctly, the md5 should be different anyway even if the two bam file are of the same size? Because they are created by different programs.
            Do you have any idea? or Why the two BAM files are different? I found a blog mention something similar about the size of BAM file. http://davetang.org/muse/2014/09/26/bam-to-cram/

            Comment

            • Brian Bushnell
              Super Moderator
              • Jan 2014
              • 2709

              #7
              As Devon said, compare them as sam files.

              Convert both of them to sam and compare them. You can't get trustworthy results from comparing compressed files. If they both yield identical sam files, they are identical. If not, they differ.

              Comment

              • jkbonfield
                Senior Member
                • Jul 2008
                • 146

                #8
                There is a compare_sam (not bam, but that's a trivial conversion) script in the htslib test harness.



                It's pretty crufty and not really designed for use outside the test system, but if you're familiar with perl then you should be able to drive the different options easily enough.

                As for why the size is larger, it may come down to NM and MD auxiliary tags. These are not stored verbatim in CRAM, but worked out on-the-fly from the sequence delta to the reference. It doesn't store a flag to indicate whether there were present in the original input data, so by default you'll get them whether you wanted them or not.

                Comment

                • hthl85
                  Junior Member
                  • Oct 2014
                  • 9

                  #9
                  Thank you jkbonfield and everyone. I used the script jkbonfield suggested to compare two SAM file. The one generated from CRAM had extra MD tags and that caused the file increased its size.

                  Originally posted by jkbonfield View Post
                  There is a compare_sam (not bam, but that's a trivial conversion) script in the htslib test harness.



                  It's pretty crufty and not really designed for use outside the test system, but if you're familiar with perl then you should be able to drive the different options easily enough.

                  As for why the size is larger, it may come down to NM and MD auxiliary tags. These are not stored verbatim in CRAM, but worked out on-the-fly from the sequence delta to the reference. It doesn't store a flag to indicate whether there were present in the original input data, so by default you'll get them whether you wanted them or not.

                  Comment

                  Latest Articles

                  Collapse

                  • kinpict.com
                    Reply to 16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
                    by kinpict.com
                    The part about this topic feels surprisingly grounded, and the details on the page is the bit that made me slow down. I’d keep <a href="https://kinpict.com/">ai family photo generator</a> bookmarked for later.
                    Today, 06:37 PM
                  • SEQadmin2
                    16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
                    by SEQadmin2





                    NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification,...
                    10-30-2026, 06:46 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by SEQadmin2, 11-12-2026, 07:59 AM
                  0 responses
                  27 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 11-05-2026, 09:25 AM
                  0 responses
                  35 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 11-03-2026, 11:54 AM
                  2 responses
                  56 views
                  0 reactions
                  Last Post kinpict.com  
                  Started by SEQadmin2, 10-28-2026, 09:57 AM
                  0 responses
                  175 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...