In [1]:
import dendropy
import pandas as pd

In [2]:
data = pd.read_csv('PyronParityData.csv', index_col=0, header=False)

In [99]:
taxa = dendropy.TaxonSet()
mle = dendropy.Tree.get_from_path('./Trees/garli_opt/pbnoterm', 'newick', taxon_set=taxa, preserve_underscores=True)

In [100]:
for idx, nd in enumerate(mle.postorder_node_iter()):
    if nd.label is None:
        lookup = '{}'.format(nd.taxon)
        nd.label = int(data.ix[lookup])
    else: 
        pass

In [101]:
putative_c = []
putative_co = []
total = []
childs = []
for index, node in enumerate(mle.postorder_node_iter()):
    total.append(index)
    if node.parent_node is None:
        pass
    elif .5 < float(node.label) < 1 or float(node.label) == 0:    #Is likely oviparous 
        if float(node.parent_node.label) < .5 : #List of nodes that demonstrate change away from oviparity. 
            if node.taxon is not None :
                putative_co.append([node.parent_node.label, node.taxon])
            else:
                putative_co.append(node.parent_node.label)
                for nd in node.child_nodes():
#                    print nd.taxon
                     pass
    elif 0 < float(node.label) < .5 or float(node.label) == 1: 
            if float(node.parent_node.label) > .5: 
                putative_c.append([node.parent_node.label,node.taxon])      
print len(putative_c), 'changes to viviparity' 
print len(putative_co), 'reversions to oviparity'


61 changes to viviparity
61 reversions to oviparity

Copyright (c) <2014> <April Wright, wright.aprilm@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


In [ ]: