change name of scaffold to chromosome in .bam file
1
0
Entering edit mode
3.8 years ago

Hi,

I have scaffold level data, and I know the chromosomal assignment of each scaffold, and am trying to rename each scaffold to each chromosome it belongs to.

Here's the command I tried to rename one scaffold to chromosome 1 as a test:

samtools view -h s2907.bam |sed -e 's/SN:QRBIO1000092.1/SN:chr1/' | samtools reheader - s2907.bam > test_s2907.bam

It appears to work, but then when I check the test_s2907.bam file, the original scaffold name (QRBIO1000092.1) is still there, not the new chromosome name (chr1) I tried to assign.

I'd appreciate any help.

Thanks.

genome • 1.2k views
ADD COMMENT
0
Entering edit mode

Any help is appreciated.

ADD REPLY
0
Entering edit mode
3.8 years ago
seidel 11k

Giving the -c option to samtools reheader seems to work:

samtools reheader -c 'sed -e "s/SN:QRBIO1000092.1/SN:chr1/"' s2907.bam > test_s2907.bam

While this worked for me it doesn't seem to be the most efficient way to do it. Rather the reheader docs say you can use a SAM file with a template header to replace the header in your BAM file in place, which seems like it would be much more efficient (if you need that).

ADD COMMENT

Login before adding your answer.

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