I have program output that looks like this (tab delim):
$ ./mycode somefile
0000000000000000000000000000000000 238671
0000000000000000000000000000000001 0
0000000000000000000000000000000002 0
0000000000000000000000000000000003 0
0000000000000000000000000000000010 0
0000000000000000000000000000000011 1548.81
0000000000000000000000000000000012 0
0000000000000000000000000000000013 937.306
What I want to do is on FIRST column only: replace 0 with A, 1 with C, 2 with G, and 3 with T. Is there a way I can transliterate that output piped directly from "mycode". Yielding this:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 238671
...
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACT 937.306
Using Perl:
C:\> ./mycode file | perl -lpe "($x,$y)=split; $x=~tr/0123/ACGT/; $_=qq{$x\t$y}" AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 238671 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAG 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAT 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACA 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACC 1548.81 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACG 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACT 937.306
You can use single quotes in Bash:
$ ./mycode file | perl -lpe '($x,$y)=split; $x=~tr/0123/ACGT/; $_="$x\t$y"'
As @ysth notes in the comments, perl
actually provides the command line options -a
and -F
:
-a autosplit mode with -n or -p (splits $_ into @F) ... -F/pattern/ split() pattern for -a switch (//'s are optional)
Using those:
perl -lawnF'\t' -e '$,="\t"; $F[0] =~ y/0123/ACGT/; print @F'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With