-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathn50.py
More file actions
executable file
·49 lines (37 loc) · 1.11 KB
/
n50.py
File metadata and controls
executable file
·49 lines (37 loc) · 1.11 KB
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
import sys
import argparse
import glob, os
def main():
parser = argparse.ArgumentParser(description='Reference Culling')
parser.add_argument('-i', '--insize', help='Path to output directory.', required=True)
parser.add_argument('-r', '--ref_file', help='Path to coordinate file generated by align_reads.sh.', required=True)
args = parser.parse_args()
ref=args.ref_file
in_file=args.insize
size_list=[]
with open(in_file) as file:
for line in file:
line=line.replace("\n", "")
temp=line.split('\t')
size_list.append(int(temp[1]))
size_ref=[]
with open(ref) as file:
for line in file:
line=line.replace("\n", "")
temp=line.split('\t')
size_ref.append(int(temp[1]))
calc_n50(size_list,sum(size_ref))
def calc_n50(array,ref_size):
array.sort(reverse = True)
#print(array)
n50 = 0
n = 0
half = ref_size/2
for val in array:
n50 += val
if n50 >= half:
n = val
break
print("\n NG50:\n"+str(n))
if __name__ == "__main__":
main()