-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_cra_less_verbose.py
199 lines (153 loc) · 4.67 KB
/
run_cra_less_verbose.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import sys
import os
from filters.sequence_length_filter import SeqLengthFilter
from analyzers.num_seq_analyzer import NumSeqAnalyzer
from sewagesystem import SewageSystem
from filters.complexity_filter import ComplexityFilter
from filters.redundancy_filter import RedundancyFilter
from filters.simple_filter import SimpleFilter
from filters.fasta_filter import FastaCheckerFilter
from aux import logtools, fasta_fixer
iFile = None
oFile = None
dFile = None
finFile = None
tDir = "tmp/"
eAddress = None
isFirst=None
try:
iFile = sys.argv[1]
iFile_new = iFile + "fix"
oFile = sys.argv[2]
dFile = sys.argv[3]
finFile = sys.argv[4]
eAddress = sys.argv[5]
isFirst = sys.argv[6]
if isFirst == "1":
isFirst = True;
else:
isFirst = False;
except IndexError:
print "Too Few Arguments for run_cra_less_verbose.py \n"
exit(1)
if "@" not in eAddress:
print "Invalid email given to run_cra_less_verbose.py \n"
exit(1)
if not os.path.isdir(tDir):
print "Invalid temporary directory\n"
exit(1)
if not os.path.exists(iFile):
print "Invalid input fasta\n"
exit(1)
logfil = "logs/" + os.path.basename(iFile) + ".log"
try:
os.remove(logfil)
except OSError:
pass
try:
os.remove(oFile)
except OSError:
pass
try:
os.remove(dFile)
except OSError:
pass
zeroj_param = .9
cdhit_param_thresh = .7
cdhit_param_flength = .8
min_len_param = 30
max_len_param = 30000
ff_param_thresh = .7
ff_param_flength = .8
ms_check = False
xs_tolerance = 0
no_fasta = False
no_simple = False
no_len = False
no_comp = False
no_red = False
no_fusfis = False
if len(sys.argv) > 7:
if "-0j" in sys.argv[7:]:
zeroj_param = float(sys.argv[sys.argv.index("-0j")+1])
if "-ct" in sys.argv[7:]:
cdhit_param_thresh = float(sys.argv[sys.argv.index("-ct")+1])
if "-cl" in sys.argv[7:]:
cdhit_param_flength = float(sys.argv[sys.argv.index("-cl")+1])
if "-min" in sys.argv[7:]:
min_len_param = int(sys.argv[sys.argv.index("-min")+1])
if "-max" in sys.argv[7:]:
max_len_param = int(sys.argv[sys.argv.index("-max")+1])
if "-fft" in sys.argv[7:]:
ff_param_thresh = float(sys.argv[sys.argv.index("-fft")+1])
if "-ffl" in sys.argv[7:]:
ff_param_flength = float(sys.argv[sys.argv.index("-ffl")+1])
if "-ms" in sys.argv[7:]:
ms_check = True
if "-xs" in sys.argv[7:]:
xs_tolerance = int(sys.argv[sys.argv.index("-xs")+1])
# if "-nofasta" in sys.argv[5:]: #not recommended
# no_fasta = True
# if "-nosimple" in sys.argv[5:]: #not recommended
# no_simple = True
if "-nolen" in sys.argv[7:]:
no_len = True
if "-nocomp" in sys.argv[7:]:
no_comp = True
if "-nored" in sys.argv[7:]:
no_red = True
if "-noff" in sys.argv[7:]:
no_fusfis = True
logtools.start_new_log(iFile, eAddress, logfil)
fasta_fixer.fix_file(iFile, iFile_new)
iFile = iFile_new
ss = SewageSystem()
num_seq_bef_anlzr = NumSeqAnalyzer(logfil, dFile)
num_seq_aft_anlzr = NumSeqAnalyzer(logfil, dFile)
len_filter = SeqLengthFilter(min_len_param, max_len_param)
comp_filter = ComplexityFilter(zeroj_param, lfil=logfil)
red_filter = RedundancyFilter(cdhit_param_thresh, cdhit_param_flength, lfil=logfil)
simple_filter = SimpleFilter(ms_check, xs_tolerance)
fasta_filter = FastaCheckerFilter()
fusfis_filter = FusionFissionFilter(ff_param_thresh, ff_param_flength, lfil=logfil)
#ss.add_module(num_seq_bef_anlzr) #check before
#for debugging
a = []
for i in range(5):
a.append(NumSeqAnalyzer(logfil, dFile))
finCSVWriter = open(finFile, "a")
#FILTERS
ss.add_module(fasta_filter)
ss.add_module(a[0])
ss.add_module(simple_filter)
if not no_len:
ss.add_module(a[1])
ss.add_module(len_filter)
if not no_comp:
ss.add_module(a[2])
ss.add_module(comp_filter)
if not no_red:
ss.add_module(a[3])
ss.add_module(red_filter)
if not no_fusfis:
ss.add_module(a[4])
ss.add_module(fusfis_filter)
ss.add_module(num_seq_aft_anlzr) #check after
open(dFile, "w").close()
aFiles = ss.flush_the_toilet(iFile, oFile, dFile, tDir, log=logfil)
with open(aFiles[0], "r") as analysisFile:
before_seq = analysisFile.read()
with open(aFiles[-1], "r") as analysisFile:
after_seq = analysisFile.read()
crap_score = 1 - float(after_seq)/float(before_seq)
crap_score_str = "%1.5f" % crap_score
print aFiles
finCSVWriter.write(os.path.basename(iFile) + ",")
for ind in range(len(aFiles)):
with open(aFiles[ind], "r") as analysisFile:
finCSVWriter.write(analysisFile.read())
if ind < len(aFiles)-1:
finCSVWriter.write(",")
else:
finCSVWriter.write("," + crap_score_str + "\n")
finCSVWriter.close()