[Solved] File reformat

I am using the code below to reformat the input (hp.txt). The output (newhp.txt) is not in the desired format and I can not seem to figure it out. I have attached both. Thank you.

 perl -aF/\\t/ -lne 'print join(" ",@F[0,1,2,$_,5]) for ("0 A","0 G","0 C","0 T","A 0","G 0","C 0","T 0")' hp.txt > newhp.txt 

So in hp.txt the file looks like:

2    39224622    3922462       -       T         intron_7homopolymer
3    12632440    12632440     -        C        CDS_4homopolymer

Desired Output of newhp.txt

2  39224622  39224622   0   A  intron_7homopolymer 
2  39224622  39224622   0   T intron_7homopolymer
2  39224622  39224622   0   C intron_7homopolymer
2  39224622  39224622   0   G intron_7homopolymer
2  39224622  39224622   A   0 intron_7homopolymer
2  39224622  39224622   T   0 intron_7homopolymer
2  39224622  39224622   C   0 intron_7homopolymer
2  39224622  39224622   G   0 intron_7homopolymer
3  12632440  12632440   0   A CDS_4homopolymer
3  12632440  12632440   0   T CDS_4homopolymer
3  12632440  12632440   0   C CDS_4homopolymer
3  12632440  12632440   0   G CDS_4homopolymer
3  12632440  12632440   A   0 CDS_4homopolymer
3  12632440  12632440   T   0 CDS_4homopolymer
3  12632440  12632440   C   0 CDS_4homopolymer
3  12632440  12632440   G   0 CDS_4homopolymer

Try:

perl -ne 'for $i ("0 A","0 G","0 C","0 T","A 0","G 0","C 0","T 0") {$x=$_;$x=~s/-\t\w\t/$i\t/;print $x}' hp.txt > newhp.txt

Seemed to do the trick, but can the output be tab-delimineted?

1 115251260 115251260 0 A CDS_4homopolymer

Thanks.

perl -ne 'for $i ("0\tA","0\tG","0\tC","0\tT","A\t0","G\t0","C\t0","T\t0") {$x=$_;$x=~s/-\t\w\t/$i\t/;print $x}' hp.txt > newhp.txt
1 Like

Thank you very much.