This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Samtools reheader Numerical result out of range

Hi,
I am trying to change the header of a bam file to keep only one chromosome, using the following command:

samtools view -H align.virus.bam | awk '!/^@/ {print} !/^@SQ/ {print} $0 ~ /MN908947.3/'  | samtools reheader - align.virus.bam > mybam.bam

The issue is that, when I try to samtools view -h mybam.bam | less.

I get this error:

samtools view: error reading file "mybam.bam": Numerical result out of range

I am using samtools 1.12

Thanks

samtools header bam

1 answer

Found it,

The issue is the second pair of the read is aligned to one of the chromosomes that I want to remove.

But the error was not helping.

Log in to answer this question.