Error when viewing a bam file
0
0
Entering edit mode
19 months ago
Chris ▴ 340

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"
samtools • 1.1k views
ADD COMMENT
1
Entering edit mode

Your BAM file may be missing a header. Do you see anything if you do samtools view -H Library_allAligned.out.bam?

ADD REPLY
0
Entering edit mode

No. I got the same error.

ADD REPLY
1
Entering edit mode

How did you make the BAM?

ADD REPLY
0
Entering edit mode

I used STAR. This is whole genome data with 2 libraries. I guess the error is because I merge two bam files.

ADD REPLY
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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
ADD REPLY
1
Entering edit mode

Can you try?

samtools merge -h file1.bam -o merged.bam file1.bam file2.bam
ADD REPLY
0
Entering edit mode

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?

ADD REPLY
1
Entering edit mode

merge command can use multiple threads and will also write out an index.

-@, --threads INT
               Number of additional threads to use [0]
      --write-index
               Automatically index the output files [off]
ADD REPLY
0
Entering edit mode

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?

ADD REPLY

Login before adding your answer.

Traffic: 1899 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6