Question: Samtools gives "truncated file" when trying to view a "reheaded" file
0
gravatar for olavur
5 months ago by
olavur40
Tórshavn, Faroe Islands
olavur40 wrote:

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.
ADD COMMENTlink modified 5 months ago by Devon Ryan76k • written 5 months ago by olavur40
0
gravatar for Devon Ryan
5 months ago by
Devon Ryan76k
Freiburg, Germany
Devon Ryan76k wrote:

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 COMMENTlink written 5 months ago by Devon Ryan76k

Have run it several times, no difference.

ADD REPLYlink written 5 months ago by olavur40

You must be running out of disk space then.

ADD REPLYlink written 5 months ago by Devon Ryan76k

I have plenty of disk space, 100 TB available.

ADD REPLYlink written 5 months ago by olavur40

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

ADD REPLYlink written 5 months ago by Devon Ryan76k

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

ADD REPLYlink written 5 months ago by Panagiotis Moulos20

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

ADD REPLYlink written 5 months ago by Devon Ryan76k

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

ADD REPLYlink written 5 months ago by olavur40
1

Maybe this will help. https://github.com/pmoulos/samtools-reheader-fail

ADD REPLYlink written 5 months ago by Panagiotis Moulos20
1

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 REPLYlink written 5 months ago by Devon Ryan76k

I'm giving this a try now.

ADD REPLYlink written 5 months ago by Devon Ryan76k

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

ADD REPLYlink written 5 months ago by Devon Ryan76k

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 REPLYlink written 5 months ago by Devon Ryan76k
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: 657 users visited in the last hour