Tool:Tool: Quick Command To Change BED file Naming Convention
0
1
Entering edit mode
2.0 years ago
Sasha ▴ 850

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 • 1.3k views
ADD COMMENT
1
Entering edit mode

shorter ?

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

or

sed '/^[0-9XY]/s/^/chr/'
ADD REPLY
0
Entering edit mode

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. :(

ADD REPLY
0
Entering edit mode

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) 
ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

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