[main_samview] fail to read the header from sample.bam
0
0
Entering edit mode
4.7 years ago

Hi all, I get the following error when reading the sample.bam. The file was converted from sam to bam using the following command:

 samtools view -bS sample.sam > sample.bam.

[E::bgzf_read] bgzf_read_block error -1 after 194938 of 8572040 bytes
[E::bam_hdr_read] error reading BGZF stream
[main_samview] fail to read the header from sample.bam

Looking forward to get your suggestion.

thanks in advance

sam

alignment • 21k views
ADD COMMENT
0
Entering edit mode

Does your sam file have a valid header? If yes, then have you tried reconverting the file? Perhaps something happened to corrupt the file first time around.

ADD REPLY
0
Entering edit mode

Yes, a valid header is present in sam file. I could not understand about reconverting?

ADD REPLY
0
Entering edit mode

What is the output of:

samtools view -H sample.sam
samtools quickcheck -v sample.sam
ADD REPLY
0
Entering edit mode

while running samtools view -H sample.sam, it result is following: [main_samview] fail to read the header from sample.sam

ADD REPLY
0
Entering edit mode

That is your problem then. With what program was the sam file generated?

ADD REPLY
0
Entering edit mode

When i looked the same file with head command i could see the first 10 header lines. However with the above command its showed as failed to read. I have rerun the alignment once again. And now its reading the sam file. Thanks!! Shall convert to bam file now.

ADD REPLY
0
Entering edit mode

i have also tried converting using samtools view -h -b sample.sam > sample.bam

ADD REPLY
0
Entering edit mode

I am having a similar issue. I'm following the CapSim tutorial, and when I'm trying to run this command:

samtools view -bSU probes.sam | samtools sort -o probes.bam -

I'm getting the error:

samtools sort: failed to read header from "-"

I have checked the file header with the commands above, and I do see it:

[rturba@n1848 aDNA]$ samtools view -H probes.sam
@HD     VN:1.0  SO:unsorted
@SQ     SN:KF030964.1   LN:15653
@PG     ID:bowtie2      PN:bowtie2      VN:2.4.2        CL:"/u/local/apps/bowtie2/2.4.2/bowtie2-align-s --wrapper basic-0 --local --very-sensitive-local --mp 8 --rdg 10,8 --rfg 10,8 -k 10000 -f -x anatina -S probes_anatina.sam -U baits-80-20.fa"
@PG     ID:samtools     PN:samtools     PP:bowtie2      VN:1.11 CL:samtools view -H probes_anatina.sam
[rturba@n1848 aDNA]$ samtools quickcheck -v probes.sam
[rturba@n1848 aDNA]$

So what am I doing wrong here?

ADD REPLY
1
Entering edit mode

Probably you are using an ancient samtools version that did not have the -o option yet. Output of samtools --version?

ADD REPLY
0
Entering edit mode

It's samtools v1.11. Sorry, I should've added that. Does that mean I have to do the > then?

ADD REPLY
1
Entering edit mode

No, that should be fine with v1.11. I just see that there is -U (capital U) rather than -u in view. That is probably wrong. You do not need view anyway, sort can read a SAM file directly and output bam.

ADD REPLY
2
Entering edit mode

That's exactly the problem: The -U option is to Output reads not selected by filters to FILE, but the option you want is the -u to get Uncompressed BAM output, which already implies -b so you don't need to specify it. Also, the -S option to indicate that your input is SAM rather than BAM is deprecated, but samtools doesn't complain if you use it. samtools view -u probes.sam should be enough to feed any tool that would need a probes.sam in BAM format.

ATpoint you're right about not having to use a previous samtools view in order to convert SAM to BAM, as samtools sort already understands SAM, BAM and CRAM inputs. Online documentation does state this, although unfortunately samtools's man page doesn't.

ADD REPLY
0
Entering edit mode

Hey, I have one question.

What does an empty flag mean after probes.bam

Thank you!

ADD REPLY

Login before adding your answer.

Traffic: 1662 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