Replace Nexus File Gene Names By Another Defintion Using Grep Awk Sed
2
1
Entering edit mode
11.9 years ago
macmath ▴ 170

Replace the Nexus file containing o387128170 by MJ respectively any suggestions The file1 is tab separated file and column one contains definitions, column two contains the respective names used in nexus file

FILE1

MJ    o387128170
NH    s292492417
PA    t253987822
PS    m392982075
RB    b91205976
RG    RG01000991
SD    d90020574
ST    l386717214
TD    T74316419
XA    x285017316
XY    X15839219

FILE2 Nexus

(LLO0482:0.0000019366,(LDG0360:0.0238905115,lp120326:0.0375485241)47:0.0419092189,((CB0429:0.3826265892,(D407893918:0.0583236501,RG01000991:0.0697907269)100:0.3489578738)32:0.0611129429,((t253987822:0.2364978839,((T74316419:0.0510072829,(v34499645:0.1213113809, u115350318:0.0776373720,p257095044:0.2395600298)44:0.0475754004)41:0.0605790634)80:0.1876842046,((m392982075:0.0594239626,((j192359877:0.0996057049,d90020574:0.0702371354)94:0.0939405031,(h83648856:0.1084254524,i385330117:0.0921078862)71:0.0360845353)62:0.0707594471)39:0.0613591919,(a110833242:0.0876612450,g304310012:0.1180135527)36:0.0371960189)30:0.0092030244)30:0.0647396824)18:0.0596473294,(o387128170:0.3064131143,(s292492417:0.1321821856,((e114319615:0.1906247302,(y53803544:0.1912864499,(n261854946:0.2068051096,(x285017316:0.0059190806,(X15839219:0.0683993704,l386717214:0.0457517668)56:0.0096790977)96:0.1853531541)61:0.1004069057)32:0.0604903866)7:0.0272158370,(c340781343:0.2602538492,(f222056709:0.4208238724,(z392383016:0.2288751890,b91205976:0.8011560891)67:0.0937313749)44:0.1020863459)11:0.0683604161)5:0.0903466856)7:0.0333376307)6:0.0374790692)37:0.0675670265)100:0.3661461042);
awk • 2.5k views
ADD COMMENT
3
Entering edit mode
11.9 years ago

transform FILE1 to a set of patterns for sed

awk '{printf("s/%s/%s/g\n",$2,$1);}' FILE1 > patterns.txt

and then use those patterns to transform FILE2.

sed -f patterns.txt FILE2
ADD COMMENT
0
Entering edit mode

Merci beaucoup Pierre

ADD REPLY
0
Entering edit mode
11.9 years ago

Far from being elegant, but should work:

while read line; do echo $line>temp; a=`cut -d ' ' -f 1 temp`; b=`cut -d ' ' -f 2 temp`; eval "sed -i -e's/$b/$a/g' file2"; done < file1
ADD COMMENT
0
Entering edit mode

Thank you for your suggestion I will surely try

ADD REPLY
0
Entering edit mode

I am sorry. I forgot it was tab-delimited. Will edit in a minute - now I use spaces.

ADD REPLY
0
Entering edit mode

If i have several nexus files and one file containing the tab separated list as above where the first column remains same but second, third, fourth... to n column representing for the number of files... any suggestion for the script?

ADD REPLY
0
Entering edit mode

Could you pls explain it more? Do you have pairs (one tab separated file and one nexus) or what? Thanks.

ADD REPLY
0
Entering edit mode

The tab separated file contains all the list of names used in Nexus file and the first column in the tab separated file contains something like MJ NH PA PS RB....n In the above example I used two columns and one nexus file respectively I have one tab separated file and respectively several nexus files was my explanation a little better/ helpful to understand?

ADD REPLY

Login before adding your answer.

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