Example #1
0
def MOODS_search(seq, motif, thresholds=0):
    """an equivalent to Motif.search_pwm()"""
    if not USE_MOODS:
        raise RuntimeError("MOODS could not be imported")
    sequence = seq
    matrix_ = MOODS.transpose([map(lambda x: x[1], sorted(x.items())) for x in motif.log_odds()])
    # Note: algorithm = 'lf' fails due to segmentation fault
    results_per_matrix = MOODS.search(
        sequence,
        [matrix_],
        thresholds,
        bg=None,
        algorithm="pla",
        q=7,
        absolute_threshold=True,
        both_strands=True,
        combine=True,
    )

    # format as Motif.search_pwm results
    search_results = results_per_matrix[0]
    # figure out direction of reverse results
    # do we need to reverse it?
    results_sorted_like_Bio_Motif = sorted(
        search_results, key=operator.itemgetter(0), cmp=lambda x, y: cmp(abs(x), abs(y))
    )
    return results_sorted_like_Bio_Motif