Exemple #1
0
def rvco(f):
    '''Main driver to solve this problem.'''
    return sum(1 for x in ro.fafsa_itervalues(f) if x == ro.revc(x))
Exemple #2
0
def splc(f):
    s = list(ro.fafsa_itervalues(f))
    return splice(s[0], sorted(s[1:], key=lambda x: s[0].find(x)))
Exemple #3
0
def pdst(f):
    s = list(ro.fafsa_itervalues(f))
    print '\n'.join(' '.join(repr(D(x, y)) for y in s) for x in s)
Exemple #4
0
def cons(file_name):
    print_cons(*consensus(fafsa_itervalues(file_name)))
Exemple #5
0
def revp(file_name, min_len, max_len):
    print '\n'.join(' '.join(map(str, x)) for x in palindromes(fafsa_itervalues(file_name).next(), min_len, max_len))        
Exemple #6
0
                #print 'i', i, 'c', c
                if c == DNA_START_CODON:
                    #i_start = i
                    starts.append(relative_index)
                    #print 'start', 'i', i, t[i:], 'starts', starts
                    translate = True
                if translate:
                    if c in DNA_STOP_CODONS:
                        #print 'stop ', 'i', i, t[i_start:i + 3]
                        #print 'p', p
                        for relative_index in starts:
                            #print 'yielding p[%d:] = %s' % (relative_index, p[relative_index:])  
                            yield p[relative_index:]
                        translate, relative_index, p = False, 0, ''
                        del starts[0:len(starts)]
                    else:
                        p = ''.join((p, DNA_TRANSLATION[c]))
                        #print 'translating', c, 'to', DNA_TRANSLATION[c], 'relative_index', relative_index
                        relative_index += 1
                i += 3

def distinct_protein_strings(s):
    return set(protein_strings(s))

if __name__ == "__main__":
#     for k, v in DNA_TRANSLATION.iteritems():
#         print k, ':', v
#     print DNA_START_CODON, DNA_STOP_CODONS
    #print '\n'.join(distinct_protein_strings(fafsa_itervalues('rosalind_orf_sample.dat').next()))
    print '\n'.join(distinct_protein_strings(fafsa_itervalues('rosalind_orf.dat').next()))
    
Exemple #7
0
def solve_lcsm(file_name):
    '''Solve the LCSM problem.'''
    T = lcsm(fafsa_itervalues(file_name))
    return iter(T).next() if T else ''