Question: [samtools reheader] Can't change chromosome name
0
gravatar for madkitty
2.9 years ago by
madkitty500
Canada
madkitty500 wrote:

I have a BAM file (containing reads mapped to only one chromosome), that has a very long header. I need to replace the long header of the chromosome by "chrM" and did the following:

 

  1. samtools view -H my.bam > header.sam
  2. sed "s/longheader/chrM/" header.sam > header_corrected.sam # (longheader stands for the long header..)
  3. samtools reheader  header_corrected.sam my.bam

 

Both header.sam and header_corrected.sam have the appropriate header. This query doesn't work and only displays a bunch of unreadable characters just as is I didn't use samtools to read the bam file.. what's wrong with my query? Is there another way to substitute "longheader" with "chrM" ? 

 

 

samtools bam reheader • 1.3k views
ADD COMMENTlink modified 2.9 years ago by cts1.5k • written 2.9 years ago by madkitty500
3
gravatar for cts
2.9 years ago by
cts1.5k
Pasadena
cts1.5k wrote:

My guess would be that samtools reheader outputs a bam file which is a binary representation of the text from a sam file. That is why you're getting all those unreadable characters on your screen. To test this out try to redirect the output to a file and then use samtools view to see the text representation.

$ samtools reheader  header_corrected.sam my.bam >new.bam

$ samtools view new.bam

ADD COMMENTlink written 2.9 years ago by cts1.5k
1

Your guess is correct. Samtools will never modify a file in place, since that would almost certainly lead to a corrupted file.

ADD REPLYlink written 2.9 years ago by Devon Ryan64k

It worked well, thanks :)

ADD REPLYlink written 2.9 years ago by madkitty500
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: 1670 users visited in the last hour