This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Tool: Tool: Quick Command To Change BED file Naming Convention

Hi,

I recently ran into an issue where my bed files were using the incorrect chromosome naming convention and I had to change them from '1' naming to convention 'chr1' naming. Here is the command I used:

awk '{if ($1 ~ /^[0-9]/) print "chr"$0; else if ($1 ~ /^X/) print "chr"$0; else if ($1 ~ /^Y/) print "chr"$0; else print $0}' peaks2.bed > peaks2_chr.bed

Cheers!

bed awk

shorter ?

awk -F '\t' '{print ($1 ~ /^[0-9XY]/?"chr":"")$0}'

or

sed '/^[0-9XY]/s/^/chr/'

Beautiful. Any ideas on how to make it work with MT to chrM as well. I tried to get it to work with gsub but it did not work. :(

Any ideas on how to make it work with MT to chrM as well. I

  • create a file (old-name) (new-name)
  • sort both fils on chromosome
  • use join
join -t $'\t' -1 1 -2 1 -o '1.1,2.2,2.3' <(sort -t $'\t' -k1,1 convert.tsv)  <(sort -t $'\t' -k1,1 in.bed) 

Great !!! Thankyou . Really saved alot of time for me .

0 answers

No answers yet.

Log in to answer this question.