Hi all, would you please tell me what is wrong in this case? Thank you.
samtools view Library_allAligned.out.bam | head -n 10
[main_samview] fail to read the header from "Library_allAligned.out.bam"
Your BAM file may be missing a header. Do you see anything if you do samtools view -H Library_allAligned.out.bam?
samtools view -H Library_allAligned.out.bam
No. I got the same error.
How did you make the BAM?
I used STAR. This is whole genome data with 2 libraries. I guess the error is because I merge two bam files.
Can you run the view -H command on the two original files? Merging should preserve the header unless you tried to merge files aligned to two different genomes.
Yes, view -H worked on the two original files. I used the same reference genome. Would you please suggest what wrong in this case? I sorted before merging.
samtools merge finalBamFile2.bam sorted_sample1.bam sorted_sample2.bam
Can you try?
samtools merge -h file1.bam -o merged.bam file1.bam file2.bam
I am running your command. The first bam file is light but the second is 66 Gb so I took quite a long time to finish. Do you think using batch submit with more CPU makes it finish faster?
merge command can use multiple threads and will also write out an index.
-@, --threads INT
Number of additional threads to use 
Automatically index the output files [off]
So the command will be something like:
samtools merge --threads 2 --write-index -h file1.bam -o merged.bam file1.bam file2.bam
Is that correct?
Login before adding your answer.
Use of this site constitutes acceptance of our User Agreement and Privacy