-
Notifications
You must be signed in to change notification settings - Fork 0
/
falen.py
25 lines (21 loc) · 832 Bytes
/
falen.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
#!/usr/bin/env python3
import argparse
from Bio import SeqIO
def falen_main(argv=None):
"""Tabulate the lengths of sequences in a FASTA file"""
ap = argparse.ArgumentParser()
ap.add_argument("-t", "--total", action="store_true",
help="Output only a total length per file")
ap.add_argument("fastas", help="FASTA file of contigs", nargs="+")
args = ap.parse_args(argv)
for infile in args.fastas:
with open(infile) as fh:
file_total = 0
for seq in SeqIO.parse(fh, 'fasta'):
file_total += len(seq.seq)
if not args.total:
print(infile, seq.name, len(seq.seq), sep="\t")
if args.total:
print(infile, file_total, sep="\t")
if __name__ == "__main__":
falen_main()