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

                  • SEQadmin2
                    Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
                    by SEQadmin2



                    Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

                    Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
                    ...
                    10-14-2026, 09:55 AM
                  • SEQadmin2
                    New Genomics Technologies Take Aim at Long-Standing Limits
                    by SEQadmin2


                    Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

                    We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
                    ...
                    09-28-2026, 10:25 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by SEQadmin2, 10-22-2026, 11:13 AM
                  0 responses
                  27 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 10-22-2026, 10:48 AM
                  0 responses
                  20 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 10-15-2026, 10:52 AM
                  0 responses
                  38 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 10-14-2026, 05:39 AM
                  0 responses
                  44 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...