Answers.Body: <p>If you merge a lot of BAM files you lose the overhead of the header which depending on the size of your BAM files this can be a significant difference or not.</p>
  <p>With FASTQ files there should be less difference (as they don't have an overall header). However, the compression ratio can change depending on how you zip your files. [EDIT: I just tested it merging two fastq.gz that were 357MB and 562MB - the result was fastq.gz that was smaller than the sum at only 826MB]</p>
  <p>No, the BAM header information would be lost in the conversion from BAM -&gt; FASTQ -&gt; BAM.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-30T09:48:36.053Z
Answers.LastActivityDate: 2021-07-30T10:39:44.283Z
Answers.LastEditDate: 2021-07-30T10:39:44.283Z
Answers.UserDisplayName: story
Body: <p>I have 2 bam files that belong to the same sample and I merged them with <code>samtools merge</code>. And after merging, I realized that the merged version is a bit smaller than the sum of the other two separate files' size. I also wonder if I merged &quot;the fastq&quot; files of this sample first and convert it to bam would the result be the same?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-07-30T10:04:52.843Z
Comments.Text: Perhaps the input was in .sam format and output in .bam?
Comments.UserDisplayName: user438383
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-07-30T10:10:50.227Z
Comments.Text: @user438383 No, I had "the fastq" files but before getting ".bam files" I didn't know they belong to the same sample. So I converted them to ".sam" and then to ".bam" respectively. And now that I learned that they actually belong to the same sample I have to merge them.
Comments.UserDisplayName: Baran Aldemir
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-07-30T16:15:18.330Z
Comments.Text: Converting fastqs to bams is technically doable, but why?  Do you mean merging the fastqs and realigning?
Comments.UserDisplayName: swbarnes2
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-07-30T16:18:24.140Z
Comments.Text: @swbarnes Yes, exactly.
Comments.UserDisplayName: Baran Aldemir
Tags: <sam><samtools>
Title: Is it normal to have a smaller bam file after merging bam files?
ThreadText: # Is it normal to have a smaller bam file after merging bam files?
  
  (Asked by: username_0 on 2021-07-30)
  
  I have 2 bam files that belong to the same sample and I merged them with `samtools merge`. And after merging, I realized that the merged version is a bit smaller than the sum of the other two separate files' size. I also wonder if I merged "the fastq" files of this sample first and convert it to bam would the result be the same?
  
  **Tags:** sam, samtools
  
  > **Comments:**
  > **username_1**: Perhaps the input was in .sam format and output in .bam?  
  > **username_0**: @username_1 No, I had "the fastq" files but before getting ".bam files" I didn't know they belong to the same sample. So I converted them to ".sam" and then to ".bam" respectively. And now that I learned that they actually belong to the same sample I have to merge them.  
  > **username_2**: Converting fastqs to bams is technically doable, but why?  Do you mean merging the fastqs and realigning?  
  > **username_0**: @swbarnes Yes, exactly.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2021-07-30. Score: 1 | Accepted answer
  
  If you merge a lot of BAM files you lose the overhead of the header which depending on the size of your BAM files this can be a significant difference or not.
  
  With FASTQ files there should be less difference (as they don't have an overall header). However, the compression ratio can change depending on how you zip your files. [EDIT: I just tested it merging two fastq.gz that were 357MB and 562MB - the result was fastq.gz that was smaller than the sum at only 826MB]
  
  No, the BAM header information would be lost in the conversion from BAM -> FASTQ -> BAM.
  
  
  ---
  
  