tips = tree.get_terminals()
all_species = {t.name: t for t in tips}

routes = {}
with open('fia.csv') as data_file:
    reader = csv.reader(data_file)
    reader.next()
    for lat, lon, genus, species, count in reader:
        spname = '%s %s' % (genus, species)
        if not spname in all_species: continue
        lat, lon = round(float(lat)), round(float(lon))
        count = int(count)
        route = lat, lon
        if not route in routes: routes[route] = set()
        routes[route].add(spname)

results = {}
for threshold in np.arange(0, 40, 5):
    print threshold
    results[threshold] = {}
    color_clusters(tree, threshold=threshold, draw=False, all_colors = xrange(len(tips)),
                   color_attr='group', min_clade_size=1)
    for route, spp in routes.iteritems():
        results[threshold][route] = set()
        for sp in spp:
            if sp in all_species and hasattr(all_species[sp], 'group'):
                results[threshold][route].add(all_species[sp].group)

with open('evolutionary_scale.pkl', 'w') as pickle_file:
    pkl.dump(results, pickle_file, -1)
Exemplo n.º 2
0
import Bio.Phylo as bp
import geophy.cluster as g
import sys

try: tree_file = sys.argv[1]
except: tree_file = 'bbs_granivores.new'

t = bp.read(tree_file,'newick')

g.color_clusters(t, threshold=10)