예제 #1
0
def preorderDTLsort(DTL, ParasiteRoot):
    """This takes in a DTL dictionary and parasite root and returns a sorted list, orderedKeysL, that is ordered
    by level from largest to smallest, where level 0 is the root and the highest level has tips."""

    keysL = Greedy.orderDTL(DTL, ParasiteRoot)
    orderedKeysL = []
    levelCounter = 0
    while len(orderedKeysL) < len(keysL):
        for mapping in keysL:
            if mapping[-1] == levelCounter:
                orderedKeysL = orderedKeysL + [mapping]
        levelCounter += 1
    
    lastLevel = orderedKeysL[-1][1]
    return orderedKeysL
def preorderDTLsort(DTL, ParasiteRoot):
    """This takes in a DTL dictionary and parasite root and returns a sorted list, orderedKeysL, that is ordered
    by level from largest to smallest, where level 0 is the root and the highest level has tips."""

    keysL = Greedy.orderDTL(DTL, ParasiteRoot)
    orderedKeysL = []
    levelCounter = 0
    while len(orderedKeysL) < len(keysL):
        for mapping in keysL:
            if mapping[-1] == levelCounter:
                orderedKeysL = orderedKeysL + [mapping]
        levelCounter += 1
    
    lastLevel = orderedKeysL[-1][1]
    return orderedKeysL
예제 #3
0
def preorderDTLsort(DTLReconGraph, ParasiteRoot):
    """This takes in a DTL dictionary and parasite root and returns a sorted
    list, orderedKeysL, that is ordered by level from smallest to largest,
    where level 0 is the root and the highest level has tips."""

    keysL = Greedy.orderDTL(DTLReconGraph, ParasiteRoot)
    uniqueKeysL = Greedy.sortHelper(DTLReconGraph, keysL)
    orderedKeysL = []
    levelCounter = 0
    while len(orderedKeysL) < len(uniqueKeysL):
        for mapping in uniqueKeysL:
            if mapping[-1] == levelCounter:
                orderedKeysL = orderedKeysL + [mapping]
        levelCounter += 1
    return orderedKeysL
예제 #4
0
def preorder_dtl_sort(dtl_recon_graph, parasite_root):
    """
    :param dtl_recon_graph: one of the outputs from DP, directly outputted by buildDTLReconGraph (see
    top of file for structure of the DTLReconGraph)
    :param parasite_root: The root node of the parasite tree, represented as a string
    :return: an ordered list of tuples, in order of increasing level. Each element is of the form ((P, H), L),
    where P is a parasite node and H is a host node, and the parasite node is mapped onto the host node in
    the first tuple in the overarching tuple. The second element is the level in the tree at which the (P,H)
    tuple occurs. Note level 0 is the root and the highest level represents tips.
    """

    keys_l = Greedy.orderDTL(dtl_recon_graph, parasite_root)
    ordered_keys_l = [
    ]  # We could marginally improve efficiency here by locking list length, but we don't do that here
    level_counter = 0
    while len(ordered_keys_l) < len(keys_l):
        to_add = []
        for mapping in keys_l:
            if mapping[-1] == level_counter:
                to_add += [mapping]
        ordered_keys_l += to_add
        level_counter += 1

    return ordered_keys_l