This code is similar to Change_Counter, but has a stricter cut-off for when we consider an evolutionary change to viviparity.
In [30]:
import dendropy
import pandas as pd
In [31]:
data = pd.read_csv('../Data/PyronParityData.csv', index_col=0, header=False)
In [32]:
taxa = dendropy.TaxonSet()
mle = dendropy.Tree.get_from_path('../2598364_1', 'newick', taxon_set=taxa, preserve_underscores=True)
In [33]:
for idx, nd in enumerate(mle.leaf_iter()):
if nd.label is None:
lookup = '{}'.format(nd.taxon)
nd.label = int(data.ix[lookup])
else:
pass
In [35]:
putative_c = [] #changes to viviparity
putative_co = [] #reversions to oviparity
total = []
childs = []
for index, node in enumerate(mle.preorder_node_iter()):
total.append(index) # print total to check that you have the right number of nodes in tree
if node.child_nodes() is None:
pass
elif 0.95 < float(node.label): #Is likely oviparous
node.annotations.add_new(name = '!color', value = '#0000FF')
for child in node.child_nodes():
if 0.05 > float(child.label):
node.annotations.add_new(name = '!color', value = '#ff0000')
putative_c.append([node.label, child.label])
if child.taxon:
print 'origin', child.taxon
else:
for chil in child.child_nodes():
if chil.taxon:
print 'origin in clade', chil.taxon
else:
if len(node.annotations) == 0:
node.annotations.add_new(name = '!color', value = '#0000FF')
elif 0.05 > float(node.label): #Is likely viviparous
node.annotations.add_new(name = '!color', value = '#ff0000') #Dark blue, zeroes
for child in node.child_nodes():
if 0.95 <= float(child.label):
putative_co.append([node.label, child.label])
node.annotations.add_new(name = '!color', value = '#0000FF') #Dark blue, zeroes
if child.taxon:
print 'reversal', child.taxon
else:
for chil in child.child_nodes():
if chil.taxon:
print 'reversal in clade', chil.taxon
else:
if len(node.annotations) == 0:
node.annotations.add_new(name = '!color', value = '#ff0000')
elif 0.95 >float(node.label) > 0.05:
node.annotations.add_new(name = '!color', value = '#0000FF')
print len(putative_co), 'reversions'
print putative_co
print len(putative_c), 'origins'
print putative_c
mle
In [53]:
mle.write_to_path('colored', 'nexus', suppress_annotations = False, annotations_as_nhx=False,
suppress_taxa_block=True,suppress_internal_taxon_labels=True)
In [34]:
In [ ]: