-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathChorusDraftPrebuild.py
91 lines (49 loc) · 2.01 KB
/
ChorusDraftPrebuild.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
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
84
85
86
87
88
89
90
91
from pyfasta import Fasta
import sys
import argparse
import os
def check_options(parser):
args = parser.parse_args()
if args.input:
if not os.path.exists(args.input):
print("Can not locate input file, please input input file.\n")
parser.print_help()
sys.exit(1)
return args
def get_options():
parser = argparse.ArgumentParser(description="Combine short sequence to speed up oligo search", prog="ChorusDraftPrebuild")
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
parser.add_argument('-i', '--input', dest='input', help='Fasta format input file contains short sequences',
required=True, type=str)
parser.add_argument('-o', '--output', dest='output', help='Fasta format output file with combined long sequences for speeding up oligo search. (default: output.fa)',
default='output.fa', type=str)
return parser
def main():
args = check_options(get_options())
fain = Fasta(args.input)
faout = open(args.output, 'w')
minlen = int(1e6)
print(minlen)
shortseq = 'NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN'
breacker = 'NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN'
shortlist = list()
for chrome in fain.keys():
if len(fain[chrome]) < minlen:
# print(chrome, len(fain[chrome]))
# shortseq = shortseq + str(fain[chrome]) + breacker
shortlist.append(chrome)
else:
print(chrome, len(fain[chrome]))
print('>%s' % chrome, file=faout)
print(fain[chrome], file=faout)
print('>shortsequences', file=faout)
for chrome in shortlist:
print(str(fain[chrome]),shortseq,sep='',end='', file=faout)
# print(shortseq, file=faout)
faout.close()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
sys.stderr.write("User interrupt\n")
sys.exit(0)