forked from kyclark/biofx_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution1_list.py
executable file
·57 lines (41 loc) · 1.4 KB
/
solution1_list.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
""" Compute GC content """
import argparse
import sys
from typing import NamedTuple, TextIO, List, Tuple
from Bio import SeqIO
class Args(NamedTuple):
""" Command-line arguments """
file: TextIO
# --------------------------------------------------
def get_args() -> Args:
""" Get command-line arguments """
parser = argparse.ArgumentParser(
description='Compute GC content',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('file',
metavar='FILE',
type=argparse.FileType('rt'),
nargs='?',
default=sys.stdin,
help='Input sequence file')
args = parser.parse_args()
return Args(args.file)
# --------------------------------------------------
def main() -> None:
""" Make a jazz noise here """
args = get_args()
seqs: List[Tuple[float, str]] = []
for rec in SeqIO.parse(args.file, 'fasta'):
# Iterate each base and compare to G or C, add 1 to counter
gc = 0
for base in rec.seq.upper():
if base in ('C', 'G'):
gc += 1
pct = (gc * 100) / len(rec.seq)
seqs.append((pct, rec.id))
high = max(seqs)
print(f'{high[1]} {high[0]:0.6f}')
# --------------------------------------------------
if __name__ == '__main__':
main()