Exemplo n.º 1
0
    def _build_tree(self, tree_file, tree_format):

        if tree_format == 'newick_string':
            self.tree_str = tree_file
            return ete3.Tree(self.tree_str, format=1)

        elif tree_format == 'newick':
            with open(tree_file, 'r') as nwk_file:
                self.tree_str = nwk_file.read()
            return ete3.Tree(self.tree_str, format=1)

        elif tree_format == 'phyloxml':
            from ete3 import Phyloxml
            project = Phyloxml()
            project.build_from_file(tree_file)
            self.tree_str = None

            tree = project.get_phylogeny()[0]

            for node in tree.traverse():

                # assign name to extant species
                if node.is_leaf():
                    node.name = self._get_name_phyloxml(
                        node, self.phyloxml_leaf_name_tag)

                # assign name to ancestral species
                elif self.use_internal_name:
                    node.name = self._get_name_phyloxml(
                        node, self.phyloxml_internal_name_tag)

            return tree
Exemplo n.º 2
0
def getTreeFromPhyloxml(xml, saveToFile="default.xml", delFile=True):
    """
    Read a phylogeny tree from a phyloxml string and return a TreeClass object
    or a list of TreeClass object
    """
    project = Phyloxml()
    fo = open(saveToFile, "w+")
    fo.write(xml)
    fo.close()
    project.build_from_file(saveToFile)
    treeList = []
    for tree in project.get_phylogeny():
        treeList.append(TreeClass.import_from_PhyloxmlTree(tree))

    if (delFile):
        os.remove(saveToFile)
    if len(treeList) == 1:
        return treeList[0]
    return treeList
Exemplo n.º 3
0
def getTreeFromPhyloxml(xml, saveToFile="default.xml", delFile=True):
    """
    Read a phylogeny tree from a phyloxml string and return a TreeClass object
    or a list of TreeClass object
    """
    project = Phyloxml()
    fo = open(saveToFile, "w+")
    fo.write(xml)
    fo.close()
    project.build_from_file(saveToFile)
    treeList = []
    for tree in project.get_phylogeny():
        treeList.append(TreeClass.import_from_PhyloxmlTree(tree))

    if(delFile):
        os.remove(saveToFile)
    if len(treeList) == 1:
        return treeList[0]
    return treeList
Exemplo n.º 4
0
def get_ete_tree(filename):    
    from ete3 import Tree, Phyloxml
    p = Phyloxml()
    p.build_from_file(filename)   
    t = p.get_phylogeny()[0]
    return t
Exemplo n.º 5
0
from ete3 import Phyloxml
project = Phyloxml()
project.build_from_file("apaf.xml")

# Each tree contains the same methods as a PhyloTree object
for tree in project.get_phylogeny():
    print tree
    # you can even use rendering options
    tree.show()
    # PhyloXML features are stored in the phyloxml_clade attribute
    for node in tree:
        print "Node name:", node.name
        for seq in node.phyloxml_clade.get_sequence():
            for domain in seq.domain_architecture.get_domain():
                domain_data = [domain.valueOf_, domain.get_from(), domain.get_to()]
                print "  Domain:", '\t'.join(map(str, domain_data))