This is a test version of Biostars. For the public version, visit https://www.biostars.org.
merge BAM files from different lanes

Hello all,

To analyze my Rna-Seq samples, I am following new Tuxedo suite pipeline (https://github.com/griffithlab/rnaseq_tutorial/wiki/Alignment)

I have paired end reads in two lanes. I used hisat2 to align the reads (of course separate for each lane) and got two sam files for the lanes.

EGG04_L004.sam
EGG04_L005.sam

Then I used

samtools sort -@ 8 -o EGG04_L004.bam EGG04_L004.sam
samtools sort -@ 8 -o EGG04_L005.bam EGG04_L005.sam

to convert the sam files to bam files and sort by aligned position. Now I am wondering whether I need to merge the files from two lanes to one using samtools merge and then merge all the bam files together as the next step to I can directly go ahead and merge all the mab files regardless to the bam files from different lanes. since the pipeline recommends to merge the files using picard.

If I need to first merge the bam files from two lanes together what would be the recommended command for samtools merge?

rna-seq

You will need to re-sort the files after you merge them.

1 answer

If the two lanes are for the same sample then merge everything using samtools merge :

samtools merge EGG04.bam EGG04_L004.bam EGG04_L005.bam

Thanks Nicolas, I was thinking about :

samtools merge -h EGG04.bam EGG04_L004.bam EGG04_L005.bam

what do you think?

As specified in the samtools documentation :

-h FILE Use the lines of FILE as `@' headers to be copied to out.bam, replacing any header lines that would otherwise be copied from in1.bam. (FILE is actually in SAM format, though any alignment records it may contain are ignored.)

You should then not use -h

Log in to answer this question.