-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathAGP_generator.py
More file actions
executable file
·83 lines (63 loc) · 2.28 KB
/
AGP_generator.py
File metadata and controls
executable file
·83 lines (63 loc) · 2.28 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# AGP_format
# <chromosome/ctg> <start-in-ctg> <end-in-ctg> <number> <type> <accession>
# this is one based system, assuming both inclusive
import sys
import argparse
import glob, os
def main():
parser = argparse.ArgumentParser(description='Reference Culling')
parser.add_argument('-o', '--out', help='Path to output directory.', required=True)
parser.add_argument('-c', '--coordinate', help='Path to coordinate file generated by align_reads.sh.', required=True)
counter=1
last_end=0
last_name=""
last_code=""
args = parser.parse_args()
out_dir = args.out
cord=args.coordinate
# ref_name=args.accession
f_w= open( out_dir+"/ref_guided_contig.agp", "w")
with open(cord) as f:
lines = []
for line in f:
line=line.replace("\n", "")
ref_name=line
line=line.split("_")
ref_code=line[0]+'_'+line[1]
start=line[2]
end=line[3]
if(last_code!=ref_code):
counter=1
# print(last_name)
# print(ref_name)
if(last_code==ref_code and last_name!=ref_name):
f_w.write(line[0]+'\t')
f_w.write(str(int(last_end)+1)+'\t')
f_w.write(str(int(start)-1)+'\t')
f_w.write(str(counter)+'\t')
f_w.write('N'+'\t')
f_w.write(str(int(start)-1-int(last_end)-1+1)+'\t')
f_w.write('contig'+'\t')
f_w.write('no'+'\t')
f_w.write('na'+'\t')
f_w.write('\n')
counter=counter + 1
f_w.write(line[0]+'\t')
f_w.write(start+'\t')
f_w.write(end+'\t')
f_w.write(str(counter)+'\t')
f_w.write('W'+'\t')
f_w.write(ref_name+'\t')
f_w.write('1'+'\t')
f_w.write(str(int(end)-int(start)+1)+'\t')
f_w.write('+'+'\t')
f_w.write('\n')
counter=counter + 1
last_name=ref_name
last_code=ref_code
# print(last_name)
last_end=end
lines.append(line)
f_w.close()
if __name__ == "__main__":
main()