from ete2 import Nexml # Create an empty Nexml project nexml_project = Nexml() # Load content from NeXML file nexml_project.build_from_file("trees.xml") # All XML elements are within the project instance. # exist in each element to access their attributes. print "Loaded Taxa:" for taxa in nexml_project.get_otus(): for otu in taxa.get_otu(): print "OTU:", otu.id # Extracts all the collection of trees in the project tree_collections = nexml_project.get_trees() # Select the first collection collection_1 = tree_collections[0] # print the topology of every tree for tree in collection_1.get_tree(): # trees contain all the nexml information in their "nexml_node", # "nexml_tree", and "nexml_edge" attributes. print "Tree id", tree.nexml_tree.id print tree for node in tree.traverse(): print "node", node.nexml_node.id, "is associated with", node.nexml_node.otu, "OTU" # Output: # ==========
from ete2 import Nexml # Creates and empty NeXML project p = Nexml() # Fill it with the tolweb example p.build_from_file("tolweb.xml") # extract the first collection of trees tree_collection = p.trees[0] # and all the tree instances in it trees = tree_collection.tree # For each loaded tree, prints its structure and some of its # meta-properties for t in trees: print t print print "Leaf node meta information:\n" print for meta in t.children[0].nexml_node.meta: print meta.property, ":", (meta.content) # Output # ========== # # ---- /-node3(Eurysphindus) # # Leaf node meta information: # #
'--dpi', nargs=1, default=[300], type=int, help='The dots-per-inch (DPI) in the output file.' ) args = argparser.parse_args() # Change single-list items into single items. args.output = args.output[0] args.dpi = args.dpi[0] args.width = args.width[0] args.height = args.height[0] args.source = args.source[0] nexml = Nexml() nexml.build_from_file(args.source) def build_tree_style(tree): # use our simple TSS cascade to prepare an ETE TreeStyle object sheets = gather_tss_stylesheets(tree) if len(sheets) == 0: return None # Some styles can be applied to the entire tree ts = TreeStyle() # For nodes (and other elements?), build an ordered set of TSS rules # to apply to each element in our layout function node_rules = [] for s in sheets: