forked from kyclark/biofx_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan_mem.py
executable file
·49 lines (33 loc) · 1.25 KB
/
scan_mem.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
#!/usr/bin/env python3
""" Scan for shortest, number using memory """
import argparse
from Bio import SeqIO
from typing import NamedTuple, TextIO
class Args(NamedTuple):
""" Command-line arguments """
file: TextIO
# --------------------------------------------------
def get_args() -> Args:
""" Get command-line arguments """
parser = argparse.ArgumentParser(
description='Scan for shortest, number using memory',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('file',
help='FASTA file',
metavar='FILE',
type=argparse.FileType('rt'))
args = parser.parse_args()
return Args(args.file)
# --------------------------------------------------
def main() -> None:
""" Make a jazz noise here """
args = get_args()
# Get a list of the sequences as strings
seqs = list(map(lambda s: str(s.seq), SeqIO.parse(args.file, 'fasta')))
# Find the length of the shortest sequence, total num of sequences
shortest = min(map(len, seqs))
num_seqs = len(seqs)
print(f'shortest = "{shortest}", num = "{num_seqs}"')
# --------------------------------------------------
if __name__ == '__main__':
main()