-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslm.cpp
315 lines (251 loc) · 8.89 KB
/
slm.cpp
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/*
* This file is part of SLM-Transform
* Copyright (C) 2019 Muhammad Haseeb, Fahad Saeed
* Florida International University, Miami, FL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "lbe.h"
#ifdef _PROFILE
#include <gperftools/profiler.h>
#endif /* _PROFILE */
using namespace std;
Index *slm_index = NULL;
STRING dbpath;
STRING querypath;
STRING params;
/* FUNCTION: SLM_Main (main)
*
* DESCRIPTION: Driver Application
*
* INPUT: none
*
* OUTPUT
* @status: Status of execution
*/
STATUS SLM_Main(INT argc, CHAR* argv[])
{
STATUS status = SLM_SUCCESS;
/* Print start time */
auto start_tim = chrono::system_clock::now();
time_t start_time = chrono::system_clock::to_time_t(start_tim);
ULONGLONG Matches = 0;
SLM_vMods vModInfo;
/* Benchmarking */
auto start = chrono::system_clock::now();
auto end = chrono::system_clock::now();
chrono::duration<double> elapsed_seconds = end - start;
chrono::duration<double> qtime = end - start;
STRING modconditions;
/* Print Header */
LBE_PrintHeader();
cout << endl << "Start Time: " << ctime(&start_time) << endl;
if (argc < 5)
{
cout << "ERROR: Missing Params\n"
"USAGE: ./uSLM.exe /path/to/peps min_len max_len\n"
"FURTHER: Create a params.txt at the above path with mods string\n"
"params.txt: <mods_per_pep> <AA1> <per_pep> <AA2> <per_pep> ...";
status = ERR_INVLD_PARAM;
exit (status);
}
/* Database and Dataset files */
UINT minlen = atoi(argv[3]);
UINT maxlen = atoi(argv[4]);
dbpath = STRING(argv[1]);
querypath = STRING(argv[2]);
STRING extension = ".peps";
string patt = ".ms2";
DIR* dir;
dirent* pdir;
vector<STRING> queryfiles;
/* Initialize the vModInfo */
vModInfo.num_vars = 4;
vModInfo.vmods_per_pep = 2;
vModInfo.vmods[0].aa_per_peptide = 2;
vModInfo.vmods[0].modMass = 15.99 * SCALE;
vModInfo.vmods[0].residues[0] = 'M';
vModInfo.vmods[1].aa_per_peptide = 2;
vModInfo.vmods[1].modMass = 114.04 * SCALE;
vModInfo.vmods[1].residues[0] = 'C';
vModInfo.vmods[1].residues[1] = 'K';
vModInfo.vmods[2].aa_per_peptide = 2;
vModInfo.vmods[2].modMass = 0.98 * SCALE;
vModInfo.vmods[2].residues[0] = 'N';
vModInfo.vmods[2].residues[1] = 'Q';
vModInfo.vmods[3].aa_per_peptide = 2;
vModInfo.vmods[3].modMass = 79.97 * SCALE;
vModInfo.vmods[3].residues[0] = 'S';
vModInfo.vmods[3].residues[1] = 'T';
vModInfo.vmods[3].residues[2] = 'Y';
#ifdef _PROFILE
ProfilerStart("C:/work/lbe.prof");
#endif /* _PROFILE */
/* Get thread count */
UINT threads = UTILS_GetNumProcs();
/* Check for a dangling / character */
if (querypath.at(querypath.length()- 1) == '/')
{
querypath = querypath.substr(0, querypath.size() - 1);
}
/* Open all the query files */
dir = opendir(querypath.c_str());
/* Check if opened */
if (dir != NULL)
{
while ((pdir = readdir(dir)) != NULL)
{
string cfile(pdir->d_name);
/* Only add if there is a matching file */
if (cfile.find(patt) != std::string::npos)
{
queryfiles.push_back(querypath + '/' + pdir->d_name);
}
}
}
else
{
status = ERR_FILE_NOT_FOUND;
}
#ifndef _OPENMP
threads = 1;
#endif /* _OPENMP */
/* Check for a dangling / character */
if (dbpath.at(dbpath.length()- 1) == '/')
{
dbpath = dbpath.substr(0, dbpath.size() - 1);
}
STRING params = dbpath + "/param.txt";
ifstream pfile((const CHAR *)params.c_str());
getline(pfile, modconditions);
pfile.close();
slm_index = new Index[maxlen - minlen + 1];
if (slm_index == NULL)
{
status = ERR_INVLD_MEMORY;
}
for (UINT peplen = minlen; peplen <= maxlen; peplen++)
{
STRING dbfile = dbpath + "/" + std::to_string(peplen) + extension;
/* Set the peptide length in the pepIndex */
slm_index[peplen-minlen].pepIndex.peplen = peplen;
/* Count the number of ">" entries in FASTA */
if (status == SLM_SUCCESS)
{
status = LBE_CountPeps(threads, (CHAR *) dbfile.c_str(), modconditions, (slm_index + peplen-minlen));
}
/* Initialize internal structures */
if (status == SLM_SUCCESS)
{
start = chrono::system_clock::now();
/* Initialize the LBE */
status = LBE_Initialize(threads, modconditions, (slm_index + peplen-minlen));
end = chrono::system_clock::now();
/* Compute Duration */
elapsed_seconds = end - start;
cout << "Initialized with status:\t" << status << endl;
cout << "Elapsed Time: " << elapsed_seconds.count() << "s" << endl << endl;
}
/* Distribution Algorithm */
if (status == SLM_SUCCESS)
{
start = chrono::system_clock::now();
/* Distribute peptides among cores */
status = LBE_Distribute(threads, _chunk, (slm_index + peplen - minlen));
}
/* DSLIM-Transform */
if (status == SLM_SUCCESS)
{
start = chrono::system_clock::now();
/* Construct DSLIM by SLM Transformation */
status = DSLIM_Construct(threads, &vModInfo, dbpath, (slm_index + peplen - minlen));
end = chrono::system_clock::now();
/* Compute Duration */
elapsed_seconds = end - start;
cout << "SLM-Transform with status:\t" << status << endl;
cout << "Elapsed Time: " << elapsed_seconds.count() << "s" << endl << endl;
}
}
if (status == SLM_SUCCESS)
{
status = DSLIM_DeallocateSpecArr();
}
/* Query the index */
if (status == SLM_SUCCESS)
{
/* Allocate the Query Array */
UINT *QA = new UINT[QCHUNK * QALEN];
/* Initialize and process Query Spectra */
for (UINT qf = 0; qf < queryfiles.size(); qf++)
{
/* Initialize Query MS/MS file */
status = MSQuery_InitializeQueryFile((CHAR *) queryfiles[qf].c_str());
cout << "Query File: " << queryfiles[qf] << endl;
UINT spectra = 0;
/* DSLIM Query Algorithm */
if (status == SLM_SUCCESS)
{
/* Extract a chunk of MS/MS spectra and
* query against DSLIM Index */
for (; QA != NULL;)
{
/* Extract a chunk and return the chunksize */
UINT ms2specs = MSQuery_ExtractQueryChunk(QA, threads);
/* If the chunksize is zero, all done */
if (ms2specs <= 0)
{
break;
}
spectra += ms2specs;
start = chrono::system_clock::now();
/* Query the chunk */
status = DSLIM_QuerySpectrum(QA, ms2specs, Matches, threads, slm_index, (maxlen-minlen+1));
end = chrono::system_clock::now();
/* Compute Duration */
qtime += end - start;
}
}
/* Compute Duration */
cout << "Queried Spectra:\t\t" << spectra << endl;
cout << "Query Time: " << qtime.count() << "s" << endl;
cout << "Queried with status:\t\t" << status << endl << endl;
end = chrono::system_clock::now();
}
if (QA != NULL)
{
delete[] QA;
QA = NULL;
}
}
/* Print end time */
auto end_tim = chrono::system_clock::now();
time_t end_time = chrono::system_clock::to_time_t(end_tim);
cout << endl << "End Time: " << ctime(&end_time) << endl;
elapsed_seconds = end_tim - start_tim;
cout << "Total Elapsed Time: " << elapsed_seconds.count() << "s" <<endl;
for (UINT peplen = minlen; peplen <= maxlen; peplen++)
{
status = LBE_Deinitialize(slm_index + peplen - minlen);
}
/* Print final program status */
cout << "\n\nEnded with status: \t\t" << status << endl;
#ifdef _PROFILE
ProfilerFlush();
ProfilerStop();
#endif /* _PROFILE */
/* Make sure stdout is empty at the end */
fflush(stdout);
return status;
}