I have some bam files with chromosome names like "1" instead of "chr1". I run into problems when I want to plot data from ensembl along with coverage data from these bam files. The solution this far has been to use the command below to edit the bamfile before using it in my scripts:
samtools view -H test.bam | sed -e 's/SN:\([0-9XY]\)/SN:chr\1/' -e 's/SN:MT/SN:chrM/' | samtools reheader - test.bam > test_chr.bam
I don't feel good doing that, so I would like to modify the function that reads data from the bam file somehow so that it returns the chromosome name prefixed with "chr". Is that possible? I tried editing the default import function, only editing the line giving seqnames, like this:
seqnames = if (is.null(reads$rname)) character() else paste("chr", reads$rname, sep="")
But that didn't lead me anywhere. Does anyone have suggestions?