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


origin Rhacodactylus_trachyrhynchus
reversal in clade Macrovipera_schweizeri
reversal in clade Macrovipera_lebetina
reversal Azemiops_feae
reversal Deinagkistrodon_acutus
reversal Calloselasma_rhodostoma
reversal Trimeresurus_borneensis
reversal in clade Lachesis_stenophrys
reversal in clade Lachesis_muta
origin Psammodynastes_pulverulentus
origin Pseudaspis_cana
origin Liopholidophis_sexlineatus
origin Hemachatus_haemachatus
origin in clade Ahaetulla_pulverulenta
origin in clade Conopsis_nasus
origin in clade Conopsis_biserialis
origin in clade Clonophis_kirtlandii
origin Sinonatrix_annularis
reversal Calabaria_reinhardtii
reversal Eryx_jayakari
reversal Anomochilus_leonardi
origin Chamaeleo_affinis
origin in clade Phrynocephalus_forsythii
origin in clade Cophotis_dumbara
origin in clade Cophotis_ceylanica
reversal Sceloporus_lundelli
origin Liolaemus_nigroviridis
reversal Liolaemus_chiliensis
origin in clade Liolaemus_crepuscularis
origin Liolaemus_espinozai
reversal Liolaemus_calchaqui
reversal Diploglossus_bilobatus
origin Anguis_fragilis
origin in clade Eremias_przewalskii
origin in clade Eremias_multiocellata
origin Monopeltis_capensis
origin Trogonophis_wiegmanni
reversal in clade Plestiodon_chinensis
reversal in clade Calyptotis_lepidorostrum
origin Lipinia_noctua
reversal Ablepharus_pannonicus
reversal Oligosoma_suteri
origin in clade Niveoscincus_greeni
17 reversions
[['0.00787757843403834', '0.994474971588954'], ['0.00421783586044521', 1], ['0.00758591257800187', 1], ['0.00496166872511054', 1], ['0.00927146043833161', 1], ['0.000622156138128059', '0.987261222075985'], ['0.00237201466850879', 1], ['0.00126579305115785', 1], ['0.00256112020016132', 1], ['0.00664679417497085', 1], ['0.0012142515637953', 1], ['0.00068457595549517', 1], ['0.00931878076998118', 1], ['0.0016855901938417', '0.951681939165898'], ['0.00988197142574313', '0.985481782820485'], ['0.0216446531838235', 1], ['3.99237614972218e-05', 1]]
27 origins
[['0.993219160871954', '0.00162673395433503'], ['0.995179719649829', 0], ['0.988366440598484', 0], ['0.952245570947064', 0], ['0.960833772383943', 0], ['0.99895456926748', 0], ['0.993852341018983', '0.00266048195461689'], ['0.983055308472194', '0.0105011313448504'], ['0.998120314050423', '0.0359839055077887'], ['0.981056900234731', '0.00411779221074872'], ['0.981445619648509', 0], ['0.982905255642751', 0], ['0.998560292105321', '0.00201118143265881'], ['0.963150272336692', '0.0061301581978438'], ['0.968241962103618', '0.00130430607979531'], ['0.964590730341668', 0], ['0.993680295948305', '0.00188427659916126'], ['0.951837459174403', 0], ['0.965254482143646', 0], ['0.997168681460311', '0.000534931947138872'], ['0.998116202242371', 0], ['0.961120149820311', 0], ['0.98726503622811', '0.000703135996835911'], ['0.97792234348717', '0.000229649274586856'], ['0.960419990295342', '0.00160723705725872'], ['0.977957731952092', 0], ['0.999858904464587', '0.000589200524951921']]

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 [ ]: