Beispiel #1
0
def fetch(tree):
    t = TreeNode.from_newick(open(tree))
    ranks = set(nl.RANK_ORDER)
    res = []
    error = True

    failed_nodes = []
    for n in t.non_tips():
        if n.name and n.name[0] not in ranks:
            failed_nodes.append(n)

    if failed_nodes:
        for n in failed_nodes:
            tip = list(n.tips())[0]
            tip_id = tip.name
            path = [a.name for a in tip.ancestors() if a.name is not None]
            res.append("Unknown rank: %s" % n.name)
            res.append("\tA tip ID from the clade: %s" % tip_id)
            res.append("\tCurrent lineage in tree: %s" % '; '.join(path[::-1]))

    else:
        res = nl.pull_consensus_strings(t)
        error = False

    return res, error
Beispiel #2
0
def generate_constrings(tree, tipname_map, verbose=False):
    """Assigns taxonomy to unidentified sequences in tree.

    Returns all sequence IDs on tree."""
    counts = nlevel.collect_names_at_ranks_counts(tree)
    min_count = 2
    nlevel.decorate_ntips(tree)
    nlevel.decorate_name_relative_freqs(tree, counts, min_count)
    nlevel.set_ranksafe(tree)
    nlevel.pick_names(tree)
    nlevel.name_node_score_fold(tree)

    if verbose:
        print "Tree score: ", nlevel.score_tree(tree)

    nlevel.set_preliminary_name_and_rank(tree)
    contree, contree_lookup = nlevel.make_consensus_tree(tipname_map.values())
    nlevel.backfill_names_gap(tree, contree_lookup)
    nlevel.commonname_promotion(tree)
    nlevel.make_names_unique(tree, append_suffix=False)

    constrings = nlevel.pull_consensus_strings(tree)

    return constrings