forked from sc-zhang/bioscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StatAgp.py
executable file
·51 lines (46 loc) · 1.29 KB
/
StatAgp.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
#!/usr/bin/env python3
import sys
def stat_agp(in_agp):
asm_db = {}
total_tig = 0
unchor_tig = 0
unchor_tig_size = 0
asm_size = 0
with open(in_agp, 'r') as fin:
for line in fin:
data = line.strip().split()
if data[4] == 'U':
continue
chrn = data[0]
total_tig += 1
ep = int(data[2])
if chrn[:3] != 'tig':
allele = chrn[-1]
chrn = chrn[:-1]
if chrn not in asm_db:
asm_db[chrn] = {}
if allele not in asm_db[chrn]:
asm_db[chrn][allele] = ep
asm_db[chrn][allele] = ep
else:
unchor_tig += 1
unchor_tig_size += ep
for chrn in asm_db:
for allele in asm_db[chrn]:
asm_size += asm_db[chrn][allele]
print("\t%s"%('\t'.join(sorted(asm_db[chrn]))))
for chrn in sorted(asm_db):
print("%s"%chrn, end='')
for allele in sorted(asm_db[chrn]):
print("\t%s"%("{:,}".format(asm_db[chrn][allele])), end='')
print("")
print("No. of unanchored contigs\t%s"%("{:,}".format(unchor_tig)))
print("Unanchored sequences (Mb)\t%s"%("{:,}".format(unchor_tig_size*1.0/1e6)))
print("Total no. of contigs\t%s"%("{:,}".format(total_tig)))
print("Total assembled size (Mb)\t%s"%("{:,}".format(asm_size*1.0/1e6)))
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python %s <in_agp>"%sys.argv[0])
else:
in_agp = sys.argv[1]
stat_agp(in_agp)