How to use the prophyle.prophyle_otu_table.Rank.NO_RANK function in prophyle

To help you get started, we’ve selected a few prophyle 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 prophyle / prophyle / prophyle / prophyle_otu_table.py View on Github external
for r in target_ranks:
        for f in input_files:
            try:
                otu_tables[r][f] = Counter()
            except KeyError:
                otu_tables[r] = {}
                otu_tables[r][f] = Counter()

    for node in tree.traverse("postorder"):
        node_taxid = str(node.taxid)
        node_rank = str2rank.get(node.rank, Rank.NO_RANK)
        if node_rank in target_ranks:
            tree_ranked_ancestors[node_taxid][node_rank] = node_taxid
        for anc in node.get_ancestors():
            anc_taxid = str(anc.taxid)
            anc_rank = str2rank.get(anc.rank, Rank.NO_RANK)
            if anc_rank in target_ranks:
                tree_ranked_ancestors[node_taxid][anc_rank] = anc_taxid

    tree_ranked_ancestors['0'] = {}
    tree_ranked_ancestors['*'] = {}
    # reads found in the assignments but not in the tree
    already_ignored = set()

    for f in input_files:
        # ignore multiple reads
        reads = set()
        with open(f, 'r') as in_f:
            for line in in_f:
                # skip SAM header
                if line.startswith('@'):
                    continue
github prophyle / prophyle / prophyle / prophyle_otu_table.py View on Github external
FAMILY = 4
    ORDER = 3
    CLASS = 2
    PHYLUM = 1
    KINGDOM = 0


str2rank = {
    'species': Rank.SPECIES,
    'genus': Rank.GENUS,
    'family': Rank.FAMILY,
    'order': Rank.ORDER,
    'class': Rank.CLASS,
    'phylum': Rank.PHYLUM,
    'kingdom': Rank.KINGDOM,
    'no rank': Rank.NO_RANK
}


def build_complete_tree(tree, log):
    """Build the taxonomic tree including internal nodes (for rank dependent evaluation)

    Args:
        tree (fileobject): file name of the reference tree, without internal nodes
        log (fileobject): log file
    """
    ncbi = NCBITaxa()
    original_tree = Tree(tree, format=1)
    taxa = [n.taxid for n in original_tree.traverse('postorder')]
    built = False
    while not built:
        try: