<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>

CC BY-SA 4.0
2021-07-30T09:48:36.053Z
2021-07-30T10:39:44.283Z
2021-07-30T10:39:44.283Z
story
<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>

CC BY-SA 4.0
2021-07-30T10:04:52.843Z
Perhaps the input was in .sam format and output in .bam?
user438383
CC BY-SA 4.0
2021-07-30T10:10:50.227Z
@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.
Baran Aldemir
CC BY-SA 4.0
2021-07-30T16:15:18.330Z
Converting fastqs to bams is technically doable, but why?  Do you mean merging the fastqs and realigning?
swbarnes2
CC BY-SA 4.0
2021-07-30T16:18:24.140Z
@swbarnes Yes, exactly.
Baran Aldemir
<sam><samtools>
Is it normal to have a smaller bam file after merging bam files?
# 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**: @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.  
> **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.


---

