Skip to content

Instantly share code, notes, and snippets.

@silveira
Created March 9, 2012 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silveira/2004714 to your computer and use it in GitHub Desktop.
Save silveira/2004714 to your computer and use it in GitHub Desktop.
Substitutions in a phylogenetic tree file (http://silveiraneto.net/?p=4073)
#!/usr/bin/env python
import csv
import sys
# check parameters
if len(sys.argv) < 2:
sys.exit('Usage: %s TREE_FILE ID_FILE' % sys.argv[0])
# initiates the tree
tree = ''
f = open(sys.argv[1], 'rw')
for line in f:
tree = line
# open the ID keys and replace them in the tree
markers_file = open(sys.argv[2], 'rt')
reader = csv.DictReader(markers_file, delimiter=";")
for row in reader:
if row['FICD'] != '':
before = row['FICD']
after = row['Taxon Order']+'_'+row['Family']+'_'+row['Genus']+'_'+row['ID']
tree = tree.replace(before, after)
print tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment