Esempio n. 1
0
def mult(f, match_score=0, mismatch_score= -1, gap_score= -1, debug=False):
    '''Main driver to solve this problem.'''
    s = ro.fafsa_values(f)
    score = lambda x, y: match_score if x == y else mismatch_score
    c = align4(s, score, gap_score=gap_score)
    # print c
    print ro.join_list([c[-1, -1, -1, -1][0]] + list(alignment4(s, c)), delimiter='\n')
Esempio n. 2
0
def oap(f, debug=False):
    '''Main driver to solve this problem.'''
    x, y = ro.fafsa_values(f)
    score = lambda x, y: 1 if x == y else -2
    c, I, J = semi_global_alignment((x, y), score, -2, debug=debug)
    row_max = (np.argmax(c[:, -1]), len(y))
    col_max = (len(x), np.argmax(c[-1, :]))
    print c
    print row_max, col_max
    overall_max = row_max if c[row_max[0], row_max[1]] > c[col_max[0], col_max[1]] else col_max
    print c[overall_max[0], overall_max[1]]
    print ro.join_list(alignment_from_matrix((x, y), overall_max, c, I, J), delimiter='\n')
Esempio n. 3
0
def laff(f, debug=0):
    '''Main driver to solve the LOCA problem.'''
    x, y = ro.fafsa_values(f)
    d, (xx, yy) = optimal_alignment_array_form(x, y, ra.BLOSUM62, -11, -1, debug=debug, gap_symbol='-')
    if debug:
        print x
        print y 
        print ra.score_of(xx, yy, ra.BLOSUM62, -11, -1)  # , debug=True)
    return ro.join_list((d, xx, yy), delimiter='\n')
Esempio n. 4
0
def smgb(f, debug=False):
    """Main driver to solve this problem."""
    x, y = ro.fafsa_values(f)  # [r.seq for r in SeqIO.parse('rosalind_smgb.dat', 'fasta')]

    c, p = semi_global_alignment((x, y), debug=debug)
    # row_max = (np.argmax(c[:, -1]), len(y))
    # col_max = (len(x), np.argmax(c[-1, :]))
    m, n = len(x), len(y)
    row_max = (np.argmax([c[i][n] for i in xrange(m + 1)]), n)
    col_max = (m, np.argmax(c[-1]))
    overall_max = row_max if c[row_max[0]][row_max[1]] > c[col_max[0]][col_max[1]] else col_max
    if debug >= 2:
        print np.array(c)
        print np.array(p)
        # print row_max, col_max
        print overall_max
    print c[overall_max[0]][overall_max[1]]
    print ro.join_list(alignment_from_matrix((x, y), overall_max, c, p), delimiter="\n")
Esempio n. 5
0
        (gap_symbol if ip == i else x[i - 1]) + s, \
        (gap_symbol if jp == j else y[j - 1]) + t, \
        (gap_symbol if kp == k else z[k - 1]) + u, \
        (gap_symbol if lp == l else w[l - 1]) + v
        i, j, k, l = ip, jp, kp, lp
        # print i, j, k,l 
    return s, t, u, v

def test_align2(f, (i, j), match_score=0, mismatch_score= -1, gap_score= -1, debug=False):
    '''Two-string test.'''
    s = ro.fafsa_values(f)
    score = lambda x, y: match_score if x == y else mismatch_score
    print (s[i], s[j])
    c = ra.global_alignment_matrix((s[i], s[j]), score, gap_score=gap_score)
    # print c
    print ro.join_list([c[-1, -1][0]] + list(ra.alignment_from_matrix((s[i], s[j]), c)), delimiter='\n')

def test_align3(f, (i, j, k), match_score=0, mismatch_score= -1, gap_score= -1, debug=False):
    '''Three-string test.'''
    s = ro.fafsa_values(f)
    score = lambda x, y: match_score if x == y else mismatch_score
    print (s[i], s[j], s[k])
    c = align3((s[i], s[j], s[k]), score, gap_score=gap_score)
    # print c
    print ro.join_list([c[-1, -1, -1][0]] + list(alignment3((s[i], s[j], s[k]), c)), delimiter='\n')
    
def mult(f, match_score=0, mismatch_score= -1, gap_score= -1, debug=False):
    '''Main driver to solve this problem.'''
    s = ro.fafsa_values(f)
    score = lambda x, y: match_score if x == y else mismatch_score
    c = align4(s, score, gap_score=gap_score)
Esempio n. 6
0
def mend(f):
    '''Main driver to solve this problem.'''
    return ro.join_list(geno_prob(rt.parse_newick(ro.read_str(f))))
Esempio n. 7
0
def loca(f, debug=False):
    '''Main driver to solve the LOCA problem.'''
    x, y = ro.fafsa_values(f)
    d, (xx, yy) = ra.optimal_alignment(x, y, ra.PAM250, -5, -5, align='local', debug=debug, gap_symbol='')
    return ro.join_list((d, xx, yy), delimiter='\n')
Esempio n. 8
0
def one_g(f):
    '''Main driver for solving this problem.'''
    lines = ro.read_lines(f)
    s, (k, d) = lines[0], map(int, lines[1].split())
    return ro.join_list(ro.most_frequent_approx(s, k, d))
Esempio n. 9
0
def ddeg(f):
    '''Main driver to solve this problem.'''
    return ro.join_list(double_deg(rg.read_edgelist(ro.iterlines(f))))
Esempio n. 10
0
def indc(f):
    '''Main driver to solve this problem. We use exact arithmetic for binomials
    instead of the betainc function to avoid round-off.'''
    n = 2 * ro.read_int(f)
    # return ro.join_list('%.5f' % (np.log10(1 - ro.cumbin(n, 0.5, k - 1)),) for k in xrange(1, n + 1))
    return ro.join_list('%.3f' % (x,) for x in np.log10(map(float, np.cumsum(it.islice(ro.binom(), n, n + 1).next())))[-2::-1] - n * np.log10(2))
Esempio n. 11
0
def cstr(f):
    '''Main driver to solve this problem.'''
    for y in char_table(char_array(np.loadtxt(open(f, 'rb'), dtype=str))):
        print ro.join_list(map(int, y), delimiter='')
Esempio n. 12
0
def ebin(f):
    '''Main driver to solve this problem.'''
    lines = ro.read_lines(f)
    n = int(lines[0])
    p = map(float, lines[1].split())
    return ro.join_list((n * x for x in p))
Esempio n. 13
0
def grep(f):
    '''Main driver to solve this problem.'''
    return ro.join_list(possible_assemblies(ro.read_lines(f)), delimiter='\n')
Esempio n. 14
0
def solve_maj(f):
    return ro.join_list(it.imap(majority_element, it.imap(ro.to_int_list, ro.skip(ro.iterlines(f), 1))))
Esempio n. 15
0
def one_f(f):
    p, s, d = ro.read_lines(f)
    return ro.join_list(apm(s, p, int(d)))
Esempio n. 16
0
def afrq(f):
    '''Main driver to solve this problem.'''
    return ro.join_list(np.apply_along_axis(carriers, 0, np.loadtxt(f)))
Esempio n. 17
0
def mend(f):
    '''Main driver to solve this problem.'''
    return ro.join_list(geno_prob(rt.read_newick(f).root))
Esempio n. 18
0
def pdpl(f):
    L = restriction_map(ro.read_ints_str(f))
    return ro.join_list(sorted(L))  # Main driver to solve this problem.
Esempio n. 19
0
def prsm(f):
    '''Main driver to solve this problem.'''
    return ro.join_list(closest_protein(*read_data(f)), delimiter='\n')
Esempio n. 20
0
def cbtl(f):
    '''Main driver to solve this problem.'''
    for s in char_splits(aug_num_terminals(rt.read_newick(f))): print ro.join_list((int(x) for x in s), delimiter='')
Esempio n. 21
0
def one_e(f):
    return ro.join_list(prefix_skew_argmax(ro.read_str(f)))
Esempio n. 22
0
def conv(f, tol=1e-10):
    '''Main driver to solve this problem.'''
    lines = ro.read_lines(f)
    s1, s2 = np.loadtxt(StringIO.StringIO(lines[0])), np.loadtxt(StringIO.StringIO(lines[1]))
    return ro.join_list(max_multiplicity(s1, s2), delimiter='\n')
Esempio n. 23
0
def one_h(f):
    '''Main driver for solving this problem.'''
    lines = ro.read_lines(f)
    s, (k, d) = lines[0], map(int, lines[1].split())
    c = ro.possible_kmers_counter(s, k, d)
    return ro.join_list(ro.most_frequent(c + Counter(dict((ro.revc(x), v) for x, v in c.iteritems()))))
Esempio n. 24
0
def one_a(f):
    lines = ro.read_lines(f)
    s, k = lines[0], int(lines[1])
    return ro.join_list(ro.most_frequent_kmers(s, k))