-
Notifications
You must be signed in to change notification settings - Fork 1
/
nlrexpress.py
210 lines (151 loc) · 9.22 KB
/
nlrexpress.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
198
199
200
import click
from src.ModuleData import *
from src.util import *
import logging
from datetime import datetime
import os
sys.path.insert(0, os.path.abspath("."))
@click.group(chain=True, invoke_without_command=True)
def cli():
pass
@click.command()
@click.option('--input', required=True, help='Input FASTA file ')
@click.option('--outdir', required=True, help='Output folder')
@click.option('--module', required=True, help="""\b
Predifined prediction modules :
- cc : CCexpress contains motif predictors for the CC domain:
extEDVID: rdhhhdhEDVID
- tir : TIRexpress contains motif predictors for the TIR domain:
bA: FLSFRGEDTR
aA: KNFTSHL
bC: SRISIVVF
aC: WCLDEL
bDaD1: VLPVFYDVDPSDVRKQ
aD3: WREALTEVANLSG
- nbs : NBSexpress contains motif predictors for the NBS/NBARC domain:
VG: bbGRx
P-loop: GbGGbGKTT
RNBS-A: FDbrhWhshs
Walker-B: KRbbbbDD
RNBS-B: KbbbTTR
RNBS-C: LseeeSWeLF
RNBS-D: CFLYCSLFP
GLPL: GLPLA
MHD: bHD
- lrr : LRRexpress contains motif predictors for the NBS/NBARC domain:
LRR pattern: LxxLxL
- all : All modules above: CC, TIR, NBS and LRR express
""")
@click.option('--outformat', required=False, default="all", help="""\b
Output format layout :
- short : Only the hits with more than 20% probability will be printed ( one line per motif )
- long : All predicted residues will be printed ( one line per residue )
- all [default] : Both short and long output formats are generated """)
@click.option('--cpunum', required=False, default=4, help="""\b
Set the number of CPU threads to be used. """)
@click.option('--writeinputfile', required=False, default=True, help="""\b
Write input file to be used in case of job intreruption. """)
@click.option('--skipjhmmer', required=False, default="False", hidden=True)
def predict( input: Path, outdir: Path, module: str, outformat:str, cpunum:int, skipjhmmer:bool, writeinputfile:bool ):
"""Predict NLR-related motifs"""
setupLogger(input, outdir)
logger = logging.getLogger("")
logger.info(datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + '############ NLRexpress started ############ ')
logger.info(datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Input FASTA: ' + str(input) )
scriptDir = Path(__file__).resolve().parent
if module == 'cc':
motifs = {key: allMotifs[key] for key in ['extEDVID']}
elif module == 'tir':
motifs = { key: allMotifs[key] for key in
["bA", "aA", "bC", "aC", "bDaD1", "aD3"] }
elif module == 'nbs':
motifs = { key: allMotifs[key] for key in
["VG", "P-loop", "Walker-B", "RNSB-A", "RNSB-B", "RNSB-C", "RNSB-D", "GLPL", "MHD" ] }
elif module == 'lrr':
motifs = { key: allMotifs[key] for key in ['LxxLxL'] }
elif module == 'all':
motifs = allMotifs
else:
print("No such module present. Please use one of the following: cc, nbs, lrr, all")
raise()
inputData = generateFeatures( inputFasta=Path(input), outdir=Path(outdir), motifs=motifs, skipJhmmer=skipjhmmer, cpuNum=cpunum, annotations={}, writeInputFile=writeinputfile)
results = {}
if module in ("cc", "all") :
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running CCexpress : started')
CCexpress = ModuleData.loadModels(
modelsPath = { 'extEDVID': str(scriptDir) + '/models/MLP_CC_extEDVID.pkl' })
for p in CCexpress.predictors:
X = generateXmat( inputData, p)
results[p] = CCexpress.predictors[p].model.predict_proba( X )
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running CCexpress : Running ' + p + ' predictor: ...done')
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running CCexpress : done')
if module in ("tir", "all") :
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running TIRexpress : started')
TIRexpress = ModuleData.loadModels(
modelsPath={
'bA': str(scriptDir) + '/models/MLP_TIR_bA.pkl',
'aA': str(scriptDir) + '/models/MLP_TIR_aA.pkl',
'bC': str(scriptDir) + '/models/MLP_TIR_bC.pkl',
'aC': str(scriptDir) + '/models/MLP_TIR_aC.pkl',
'bDaD1': str(scriptDir) + '/models/MLP_TIR_bD-aD1.pkl',
'aD3': str(scriptDir) + '/models/MLP_TIR_aD3.pkl'
})
for p in TIRexpress.predictors:
X = generateXmat(inputData, p)
results[p] = TIRexpress.predictors[p].model.predict_proba( X )
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running TIRexpress : Running ' + p + ' predictor: ...done')
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running TIRexpress ...done')
if module in ("nbs", "all") :
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running NBSexpress : started')
NBSexpress = ModuleData.loadModels(
modelsPath={
'VG': str(scriptDir) + '/models/MLP_NBS_VG.pkl',
'P-loop': str(scriptDir) + '/models/MLP_NBS_P-loop.pkl',
'RNSB-A': str(scriptDir) + '/models/MLP_NBS_RNSB-A.pkl',
'RNSB-B': str(scriptDir) + '/models/MLP_NBS_RNSB-B.pkl',
'RNSB-C': str(scriptDir) + '/models/MLP_NBS_RNSB-C.pkl',
'RNSB-D': str(scriptDir) + '/models/MLP_NBS_RNSB-D.pkl',
'Walker-B': str(scriptDir) + '/models/MLP_NBS_Walker-B.pkl',
'GLPL': str(scriptDir) + '/models/MLP_NBS_GLPL.pkl',
'MHD': str(scriptDir) + '/models/MLP_NBS_MHD.pkl'
})
for p in NBSexpress.predictors:
X = generateXmat(inputData, p)
results[p] = NBSexpress.predictors[p].model.predict_proba( X )
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running NBSexpress : Running ' + p + ' predictor: ...done')
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running NBSexpress ...done')
if module in ("lrr", "all") :
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running LRRexpress ...started')
LRRexpress = ModuleData.loadModels(
modelsPath={'LxxLxL': str(scriptDir) + '/models/MLP_LRR_LxxLxL.pkl'})
for p in LRRexpress.predictors:
X = generateXmat(inputData, p)
results[p] = LRRexpress.predictors[p].model.predict_proba( X )
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running LRRexpress : Running ' + p + ' predictor: ...done')
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Running LRRexpress ...done')
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Printing final results...started')
printResultsOutput(Path(input).stem, outdir, inputData, results, outformat)
logger.info(
datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + 'Printing final results...done')
logger.info( datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ':\t' + '############ NLRexpress finished ############ ')
def setupLogger(input: Path, outdir: Path) :
logging.basicConfig(filename= str(outdir) + '/' + Path(input).stem + '.log', level=logging.DEBUG)
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
logger = logging.getLogger('').addHandler(console)
return logger
if __name__ == '__main__':
predict()