I have a file with such list:
100
101
102
103
What I want to do is to replace every 0 into A, 1 into C, 2 into G, 3 into T. Hence we hope to get
CAA
CAC
CAG
CAT
I have a file with such list:
100
101
102
103
What I want to do is to replace every 0 into A, 1 into C, 2 into G, 3 into T. Hence we hope to get
CAA
CAC
CAG
CAT
You've practically worked out the answer yourself. Simply:
tr 0123 ACGT <input_file >output_file
or:
echo 2033010 | tr 0123 ACGT
Here:
perl -p -e 'tr/0123/ACGT/'
Verification:
$ perl -p -e 'tr/0123/ACGT/' <~/input
CAA
CAC
CAG
CAT
$ echo 3210 | tr 0123 ACGT
TGCA
When not using any options, tr
takes two sets of characters, and makes a 1:1 mapping from the first set to the second set. So, as written above, 0 maps to A, 1 maps to C, 2 maps to G, and 3 maps to T.
$ awk -vFS="" 'BEGIN{_["1"]="C";_["2"]="G";_["3"]="T";_["0"]="A"}{for(i=1;i<=NF;i++){printf _[$i]}print ""}' file
CAA
CAC
CAG
CAT