def my_tree_loader(tree): """ This function is used to load trees within the WebTreeApplication object. """ t = PhyloTree(tree, sp_naming_function=None) #Check one leaf to see if species information is included if t.get_leaves()[0].species == "Unknown": t.set_species_naming_function(extract_species_code) return t
def main(): fn=sys.argv[1] nw=open(fn).readline() species={} t=PhyloTree(nw) #set species naming function t.set_species_naming_function(_get_spcode) for l in t.get_leaves(): spCode=l.species try: species[spCode]+=1 except: species[spCode] =1 for spCode in sorted( species, key=lambda x: species[x], reverse=True ): print '%s\t%s' % ( spCode,species[spCode] )
def main(): fn = sys.argv[1] nw = open(fn).readline() species = {} t = PhyloTree(nw) #set species naming function t.set_species_naming_function(_get_spcode) for l in t.get_leaves(): spCode = l.species try: species[spCode] += 1 except: species[spCode] = 1 for spCode in sorted(species, key=lambda x: species[x], reverse=True): print '%s\t%s' % (spCode, species[spCode])
'28': 'HR2', '30': 'G11012', '24': 'Pm1' } # for i in range(len(nos)): # dt[nos[i]] = dataorder[i] def get_species_name(node_name_string): # Species code is the first part of leaf name (separated by an # underscore character) spcode = node_name_string # We could even translate the code to complete names code2name = dt return code2name[spcode] t.set_species_naming_function(get_species_name) for node in t.iter_search_nodes(): if node.name == "43": node.dist = 5e-05 #t.show(tree_style=ts) # t.render("/Volumes/MP_HD/CI_GENOME_SEQ/CI_gene_coverage (generate stat for sig diff cov)/gene_copy_no_tree/CI_gain_loss_tree.pdf",tree_style=ts,w=3200,h=4800,dpi=200) t.render( "/Volumes/MP_HD/CI_GENOME_SEQ/CI_orthomcl_data/gain_loss_tree_frm_orthogroups/CI_denovo_gene_gain_loss_tree.pdf", tree_style=ts, w=3200, h=4800, dpi=200)
# node's name as argument and return its corresponding species name. def get_species_name(node_name_string): # Species code is the first part of leaf name (separated by an # underscore character) spcode = node_name_string.split("_")[0] # We could even translate the code to complete names code2name = { "Dme":"Drosophila melanogaster", "Hsa":"H**o sapiens", "Ptr":"Pan troglodytes", "Mms":"Mus musculus", "Cfa":"Canis familiaris" } return code2name[spcode] # Now, let's ask the tree to use our custom species naming function t.set_species_naming_function(get_species_name) print "Custom mode:" for n in t.get_leaves(): print "node:", n.name, "Species name:", n.species # node: Dme_001 Species name: Drosophila melanogaster # node: Dme_002 Species name: Drosophila melanogaster # node: Hsa_001 Species name: H**o sapiens # node: Ptr_001 Species name: Pan troglodytes # node: Cfa_001 Species name: Canis familiaris # node: Mms_001 Species name: Mus musculus # # Of course, you can disable the automatic generation of species # names. To do so, you can set the species naming function to # None. This is useful to set the species names manually or for # reading them from a newick file. Other wise, species attribute would # be overwriten