[ create a new paste ] login | about

Link: http://codepad.org/gGcb5mdq    [ raw code | output | fork ]

Python, pasted on May 10:
import re

sf = "(((1:0.01671793,2:0.01627631):0.00455274,(3:0.02781576,4:0.05606947):0.02619237):0.08529440,5:0.16755623);"

nf = """1 \t Human
2 \t Chimp
3 \t Mouse
4 \t Rat
5 \t Fish"""

names = {}
for n in nf.split("\n"):
  n = n.split()
  names[n[0]] = n[1]

print names

def cb(m):
  return "%s%s:" % (m.group(1), names[m.group(2)])


print re.sub(r"([\(,])(\d*):", cb, sf)


Output:
1
2
{'1': 'Human', '3': 'Mouse', '2': 'Chimp', '5': 'Fish', '4': 'Rat'}
(((Human:0.01671793,Chimp:0.01627631):0.00455274,(Mouse:0.02781576,Rat:0.05606947):0.02619237):0.08529440,Fish:0.16755623);


Create a new paste based on this one


Comments: