from ete3 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: # ========== # Loaded Taxa: