-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFAlength.py
39 lines (31 loc) · 1007 Bytes
/
FAlength.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
import sys
from Bio import SeqIO
def human(size):
step_to_greater_unit = 1000.
number_of_bytes = float(size)
unit = 'bp'
if (number_of_bytes / step_to_greater_unit) >= 1:
number_of_bytes /= step_to_greater_unit
unit = 'Kbp'
if (number_of_bytes / step_to_greater_unit) >= 1:
number_of_bytes /= step_to_greater_unit
unit = 'Mbp'
if (number_of_bytes / step_to_greater_unit) >= 1:
number_of_bytes /= step_to_greater_unit
unit = 'Gbp'
if (number_of_bytes / step_to_greater_unit) >= 1:
number_of_bytes /= step_to_greater_unit
unit = 'Tbp'
precision = 1
number_of_bytes = round(number_of_bytes, precision)
return str(number_of_bytes) + unit
FastaFile = open(sys.argv[1], 'rU')
total = 0
for rec in SeqIO.parse(FastaFile, 'fasta'):
name = rec.id
seq = rec.seq
seqLen = len(rec)
total += seqLen
print(name, seqLen, human(seqLen))
print("Total", total, human(total))
FastaFile.close()