Samtools gives "truncated file" when trying to view a "reheaded" file
1
1
Entering edit mode
7.2 years ago
olavur ▴ 150

I have a BAM file that works fine, but after using samtools reheader, I cannot view it in samtools. The new file has the same size as the original.

I run the command: samtools reheader -P header.sam input.bam > output.bam

Where header.sam contains:

@HD VN:1.5 SO:coordinate
@SQ SN:10X_hg19_ucsc_v2.1.0 LN:3199910119
@CO Whole-exome sequencing of one individual.

input.bam is a BAM file with no existing header, which I can view as samtools view input.bam | less with no problem.

The reheader command finishes without giving any error. Then I try to view the file, using samtools view output.bam | less and

[main_samview] truncated file.

If I use the -h option (samtools view -h output.bam | less) I get:

[main_samview] truncated file.
@HD VN:1.5 SO:coordinate
@SQ SN:10X_hg19_ucsc_v2.1.0 LN:3199910119
@CO Whole-exome sequencing of one individual.
software error next-gen sequence samtools • 11k views
ADD COMMENT
0
Entering edit mode
7.2 years ago

Reheader the file again, apparently there was an error the first time. The error means that the "magic number" at the end of all BAM files isn't there. That could indicate that there are alignments missing at the end of the reheadered file as well.

ADD COMMENT
0
Entering edit mode

Have run it several times, no difference.

ADD REPLY
0
Entering edit mode

You must be running out of disk space then.

ADD REPLY
0
Entering edit mode

I have plenty of disk space, 100 TB available.

ADD REPLY
0
Entering edit mode

Then you have some sort of hardware issue. This isn't a reproducible problem by others.

ADD REPLY
0
Entering edit mode

I can confirm this. I face a similar problem with samtools 1.5.

ADD REPLY
0
Entering edit mode

One of you will need to post a file that reproduces this issue somewhere.

ADD REPLY
0
Entering edit mode

Panagiotis, are you able to do this? The data I'm working on is confidential.

ADD REPLY
1
Entering edit mode
ADD REPLY
3
Entering edit mode

BTW, if you need to remove chromosomes that aren't at the end of the header then you need to either use cat (cat header <(samtools view file_with_alignment_removed.bam) | samtools view -bo reheadered.bam -) or a different tool (maybe something from Picard).

ADD REPLY
2
Entering edit mode

Your reheader command removed a chromosome that wasn't the last one, so you ended up with orphaned reads. That samtools sort then threw an error is more of a feature than a bug, since you wouldn't have known that you'd lost chrX (and reassigned its alignments in an illegal manner to chrY) otherwise.

ADD REPLY
0
Entering edit mode

I'm giving this a try now.

ADD REPLY
0
Entering edit mode

I can reproduce this example, I'll track down the issue.

ADD REPLY

Login before adding your answer.

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