This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to modify chr naming in bam file: chr -> just number

Hi,

I have a bam file that chromosome names are like chr1, chr2 etc. I want to convert it to the form where chromosome naming is just numbered e.g. 1,2,3. I don't know how to change the below code for removing chr instead of adding it?

samtools view -h $B | \
sed -e '/^@SQ/s/SN\:/SN\:chr/' -e '/^[^@]/s/\t/\tchr/2' | \
samtools view -bS - > temp.bam

Thanks Sara

rna-seq

1 answer

Try :

samtools view -h $B |  sed -e '/^@SQ/s/SN\:chr/SN\:/' -e '/^[^@]/s/\tchr/\t/2' |  samtools view -bS - > temp.bam

your solution doesn't work with the supplementary alignments and the mate data.

Log in to answer this question.