Question: getting error when indexing bam files
1
gravatar for Sara
4 weeks ago by
Sara40
Sara40 wrote:

I have aligned my fastq files to hg19 using this command:

bwa mem hg19.fa /DATA/myfile.fastq.gz

then I made bam files from sam files using:

samtools view -Sb myfile.sam > myfile.bam

then I sorted the bam files using:

samtools sort myfile.bam myfile.sorted.bam

and now I am trying to index the sorted bam files using:

samtools index myfile.sorted.bam

but I got this error:

[bam_header_read] EOF marker is absent. The input is probably truncated.
[bam_header_read] invalid BAM binary header (this is not a BAM file).
[bam_index_core] Invalid BAM header.[bam_index_build2] fail to index the BAM file.

do you know what the problem is?

alignment genome • 124 views
ADD COMMENTlink modified 4 weeks ago by swbarnes26.0k • written 4 weeks ago by Sara40
2

What you should actually be doing is:

bwa mem hg19.fa /DATA/myfile.fastq.gz | samtools sort -o myfile.sorted.bam

and avoid all manual intermediate steps and unnecessary intermediate files.

ADD REPLYlink written 4 weeks ago by WouterDeCoster40k

Should add -h to every samtools view to get the headers. Not sure about the truncation

ADD REPLYlink written 4 weeks ago by Asaf6.1k
0
gravatar for swbarnes2
4 weeks ago by
swbarnes26.0k
United States
swbarnes26.0k wrote:

What version of samtools are you using? Newer versions do not just have the output file name dangling, it has to be either -o sort.bam or > sort.bam.

Anyway, the first thing to check is a quick samtools view sort.bam | head to confirm that your file at least looks sane at the beginning. That error means either you aren't giving it a real bam, or your file is for some reason truncated. If it looks okay at the beginning, its must have gotten garbled during the sort, so just redo that. But do like Wouster suggested with no intermediate files. Newer versions of samtools will sort a sam file and output a bam.

ADD COMMENTlink written 4 weeks ago by swbarnes26.0k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1347 users visited in the last hour