forked from Shivi91/Rosalind-1
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path005_GC.py
31 lines (24 loc) · 906 Bytes
/
005_GC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
'''
A solution to a ROSALIND bioinformatics problem.
Problem Title: Computing GC Content
Rosalind ID: GC
Rosalind #: 005
URL: http://rosalind.info/problems/gc/
'''
from scripts import ReadFASTA
def max_gc_content(seq_list):
gc_content = lambda seq: sum([100.0 for base in seq if base in ('G', 'C')])/len(seq) # 100 to scale result to %.
gc_list = [[seq_name, gc_content(seq)] for seq_name, seq in seq_list]
return max(gc_list, key=lambda x: x[1])
def main():
'''Main call. Parses, runs, and saves problem specific data.'''
# Parse the input data.
seq_list = ReadFASTA('data/rosalind_gc.txt')
highest_gc = map(str, max_gc_content(seq_list))
# Print and save the answer.
print '\n'.join(highest_gc)
with open('output/005_GC.txt', 'w') as output_data:
output_data.write('\n'.join(highest_gc))
if __name__ == '__main__':
main()