How to use the newick.parse_tree function in newick

To help you get started, we’ve selected a few newick examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chapmanb / bcbb / rest_apis / ensembl_remote_rest.py View on Github external
def main(organism, gene_id):
    write_fasta = False
    cache_dir = os.path.join(os.getcwd(), "cache")
    ensembl_rest = EnsemblComparaRest(cache_dir)
    orthologs = ensembl_rest.orthologs(organism, gene_id)
    compara_tree = ensembl_rest.compara_tree(organism, gene_id)
    compara_tree = '(' + compara_tree[:-1] + ');'
    tree_rec = newick.parse_tree(compara_tree.strip())
    d_vis = DistanceVisitor()
    tree_rec.dfs_traverse(d_vis)
    tree_proteins = [l.identifier for l in tree_rec.leaves]
    orthologs = [(organism, gene_id)] + orthologs
    out_recs = []
    root_id = None
    all_items = []
    for o_organism, o_id in orthologs:
        transcripts = ensembl_rest.transcripts(o_organism, o_id)
        tx, p = [(tx, p) for (tx, p) in transcripts if p in
                tree_proteins][0]
        cur_item = EnsemblComparaTranscript(o_organism, o_id, tx, p)
        if root_id is None:
            root_id = p
        cur_item.distance = networkx.dijkstra_path_length(d_vis.graph,
                "'%s'" % root_id, "'%s'" % p)
github esaskar / CoReCo / bin / model_training_scripts / tree.py View on Github external
def newickToTree(s):
    from newick import parse_tree #http://www.brics.dk/~mailund/newick.html
    t = parse_tree(s)
    v = NewickVisitor()
    t.dfs_traverse(v)
    A = v.getAdjMap()
    return A

newick

A python module to read and write the Newick format

Apache-2.0
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis

Similar packages