def test_rosalind_prob(): solution = '-5.737 -5.217 -5.263 -5.360 -5.958 -6.628 -7.009' test_path = Path('{}/../rosalind_prob_test.txt'.format(__file__)).resolve() test_data = get_rosalind_data(test_path) # test every individual value prob_solution = prob_solve(test_data) for prob_sol, test_sol in zip(prob_solution.split(), solution.split()): assert is_close(float(prob_sol), float(test_sol))
from collections import Counter import sys from rosalind_utils import DNA_ALPHABET, get_rosalind_data def solve_problem(sequence_data): sequence = sequence_data[0] nt_counts = dict(Counter(sequence).most_common()) nt_counts_str = ' '.join([str(nt_counts[nt]) for nt in DNA_ALPHABET]) print(nt_counts_str) return nt_counts_str if __name__ == '__main__': args = list(sys.argv) if len(args) != 2: raise ValueError( 'Must provide a single argument which is the data file path') solve_problem(get_rosalind_data(args[-1]))
def test_rosalind_splc(): solution = '1.21428571429' test_path = Path('{}/../rosalind_tran_test.txt'.format(__file__)).resolve() test_data = get_rosalind_data(test_path) assert is_close(float(tran_solve(test_data)), float(solution))
def test_rosalind_splc(): solution = 'MVYIADKQHVASREAYGHMFKVCA' test_path = Path('{}/../rosalind_splc_test.txt'.format(__file__)).resolve() test_data = get_rosalind_data(test_path) assert splc_solve(test_data) == solution
def test_rosalind_orf(): solution = 'MLLGSFRLIPKETLIQVAGSSPCNLS\nM\nMGMTPRLGLESLLE\nMTPRLGLESLLE' test_path = Path('{}/../rosalind_orf_test.txt'.format(__file__)).resolve() test_data = get_rosalind_data(test_path) # account for rearranging assert sorted(orf_solve(test_data).split()) == sorted(solution.split())
def test_rosalind_mprt(): solution = '''B5ZC00\n85 118 142 306 395\nP07204_TRBM_HUMAN\n47 115 116 382 409 \nP20840_SAG1_YEAST\n79 109 135 248 306 348 364 402 485 501 614''' test_path = Path('{}/../rosalind_mprt_test.txt'.format(__file__)).resolve() test_data = get_rosalind_data(test_path) assert sorted(mprt_solve(test_data).split()) == sorted(solution.split())
def test_rosalind_long(): solution = 'ATTAGACCTGCCGGAATAC' test_path = Path('{}/../rosalind_long_test.txt'.format(__file__)).resolve() test_data = get_rosalind_data(test_path) assert long_solve(test_data) == solution
def test_rosalind_corr(): solution = 'TTCAT->TTGAT\nGAGGA->GATGA\nTTTCC->TTTCA' test_path = Path('{}/../rosalind_corr_test.txt'.format(__file__)).resolve() test_data = get_rosalind_data(test_path) # account for rearranging assert sorted(corr_solve(test_data).split()) == sorted(solution.split())
import sys from rosalind_utils import get_rosalind_data # memoize fib_dict = {1: 1, 2: 1} def solve_problem(n, k): if n <= 2: return fib_dict[n] else: # here is the critical factor that is different from usual Fibonacci-- k in front of second sum fib_dict[n] = solve_problem(n-1, k) + k*solve_problem(n-2, k) return fib_dict[n] if __name__ == '__main__': args = list(sys.argv) if len(args) != 2: raise ValueError('Must provide a single argument which is the data file path') n, k = map(int, get_rosalind_data(args[-1])[0].split()) final_count = solve_problem(n, k) print(final_count)