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?
-
$\begingroup$ Perhaps the input was in .sam format and output in .bam? $\endgroup$– user438383Jul 30, 2021 at 10:04
-
$\begingroup$ @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. $\endgroup$– Baran AldemirJul 30, 2021 at 10:10
-
$\begingroup$ Converting fastqs to bams is technically doable, but why? Do you mean merging the fastqs and realigning? $\endgroup$– swbarnes2Jul 30, 2021 at 16:15
-
$\begingroup$ @swbarnes Yes, exactly. $\endgroup$– Baran AldemirJul 30, 2021 at 16:18
1 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.