Normalizing Tree Support Values From [0-1] To [0-100]
1
3
Entering edit mode
10.8 years ago
Pappu ★ 2.1k

I am trying to convert the tree support values like 0.555 to 55 in the tree file. For example:

(sp|P56726|SMO_MOUSE:0.00978,sp|P97698|SMO_RAT:0.00708,(sp|Q99835|SMO_HUMAN:0.03115,(sp|O42224|SMO_CHICK:0.13084,(sp|P91682|SMO_DROME:1.27659,(tr|Q90YY4|Q90YY4_DANRE:0.00055,tr|Q90X26|Q90X26_DANRE:0.00254)0.997:0.17060)0.982:0.11965)1.000:0.12313)0.990:0.03506);

0.99 will change to 99

(sp|P56726|SMO_MOUSE:0.00978,sp|P97698|SMO_RAT:0.00708,(sp|Q99835|SMO_HUMAN:0.03115,(sp|O42224|SMO_CHICK:0.13084,(sp|P91682|SMO_DROME:1.27659,(tr|Q90YY4|Q90YY4_DANRE:0.00055,tr|Q90X26|Q90X26_DANRE:0.00254)99:0.17060)0.982:0.11965)1.000:0.12313)99:0.03506);

Could you tell me about a good regular expression or software to do it?

Thanks.

python • 2.5k views
ADD COMMENT
8
Entering edit mode
10.7 years ago

Here you go:

from ete2 import Tree

pappu_tree = "(sp|P56726|SMO_MOUSE:0.00978,sp|P97698|SMO_RAT:0.00708,(sp|Q99835|SMO_HUMAN:0.03115,(sp|O42224|SMO_CHICK:0.13084,(sp|P91682|SMO_DROME:1.27659,(tr|Q90YY4|Q90YY4_DANRE:0.00055,tr|Q90X26|Q90X26_DANRE:0.00254)0.997:0.17060)0.982:0.11965)1.000:0.12313)0.990:0.03506);"

t = Tree(pappu_tree)

for node in t.traverse():
    node.support *= 100.0

print t.write()

It will give you:

(sp|P56726|SMO_MOUSE:0.00978,sp|P97698|SMO_RAT:0.00708,(sp|Q99835|SMO_HUMAN:0.03115,(sp|O42224|SMO_CHICK:0.13084,(sp|P91682|SMO_DROME:1.27659,(tr|Q90YY4|Q90YY4_DANRE:0.00055,tr|Q90X26|Q90X26_DANRE:0.00254)99.7:0.1706)98.2:0.11965)100:0.12313)99:0.03506);
ADD COMMENT
1
Entering edit mode

note that you don't need to use the internal _set_support() function. float conversion occurs transparently if you just use the 'node.support *= 100.0' syntax

ADD REPLY
0
Entering edit mode

You're right. I updated my answer.

ADD REPLY

Login before adding your answer.

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