forked from Shivi91/Rosalind-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
005_GC.py
41 lines (32 loc) · 1.1 KB
/
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
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
#-*- coding: UTF-8 -*-
'''
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))
'''
useage:
lambda:see this website :http://www.cnblogs.com/BeginMan/p/3178103.html
ReadFASTA:
max:max(xxx,xxx,key=lambda x:x[1])
see :https://www.oschina.net/code/snippet_111708_16478
'''
if __name__ == '__main__':
main()