Exemple #1
0
def detect_local_minimum_two(fc, structure):
    """
    Take a local minimum and detect nearby local minimum via extended gradient walks.
    If a lower energy structure within radius 2 is detected (lower than the local minimum
    of a normal gradient walk), then another gradient walk is applied for the lower structure.
    """
    deepest_neighbor = None
    deepest_neighbor_ddG = 1
    pt = RNA.IntVector(RNA.ptable(structure))
    neigh = fc.neighbors(pt, RNA.MOVESET_DELETION | RNA.MOVESET_INSERTION)

    for nb in neigh:
        dG_nb = fc.eval_move_pt(pt, nb.pos_5, nb.pos_3)
        pt_nb = RNA.IntVector(move_apply(pt, nb))
        neigh_2 = fc.neighbors(pt_nb,
                               RNA.MOVESET_DELETION | RNA.MOVESET_INSERTION)

        for nb_2 in neigh_2:
            dG_nb2 = fc.eval_move_pt(pt_nb, nb_2.pos_5, nb_2.pos_3)
            ddG = dG_nb + dG_nb2
            if ddG < 0 and ddG < deepest_neighbor_ddG:
                deepest_neighbor_ddG = ddG
                deepest_neighbor = move_apply(pt_nb, nb_2)

    if deepest_neighbor:
        deepest_neighbor = detect_local_minimum(
            fc, RNA.db_from_ptable(deepest_neighbor))
        return detect_local_minimum_two(fc, deepest_neighbor)
    else:
        return structure
def detect_local_minimum(fc, structure):
    # perform gradient walk from sample to determine direct local minimum
    pt = RNA.IntVector(RNA.ptable(structure))
    fc.path(pt, 0, RNA.PATH_DEFAULT | RNA.PATH_NO_TRANSITION_OUTPUT)
    return RNA.db_from_ptable(list(pt))
Exemple #3
0
# read a list of sample structures and produce list of local minima for it
if nonredundant_sample_file:
    lmin_nonred_file = "local_minima_nonred.txt"
    nonredundant_samples = []
    with open(nonredundant_sample_file) as f:
        nonredundant_samples = f.readlines()

    nonredundant_samples = [x.strip() for x in nonredundant_samples]

    nonredundant_samples.pop(0)

    nonredundant_minima = dict()

    for s in nonredundant_samples:
        pt = RNA.IntVector(RNA.ptable(s))
        fc_base.path(pt, 0, RNA.PATH_DEFAULT | RNA.PATH_NO_TRANSITION_OUTPUT)
        ss = RNA.db_from_ptable(list(pt))
        if ss not in nonredundant_minima:
            nonredundant_minima[ss] = {
                'count': 1,
                'energy': fc_base.eval_structure(ss)
            }
            new_minima = new_minima + 1
        else:
            nonredundant_minima[ss][
                'count'] = nonredundant_minima[ss]['count'] + 1

    f = open(lmin_nonred_file, 'w')
    f.write("     %s\n" % sequence)
    for i, s in enumerate(