-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepipred3.0.c
319 lines (239 loc) · 6.34 KB
/
epipred3.0.c
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
315
316
317
318
319
/* M.Nielsen August 2002 [email protected] */
#include <stdio.h>
#include <math.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "utils.h"
FILENAME p_spsyn;
FILENAME p_blsyn;
FILENAME p_seq2inp;
int p_verbose;
int p_writeseq;
int p_dirty;
int p_block;
int p_sdev;
FILENAME p_tmpdir;
int p_printall;
FILENAME p_bdir;
PARAM param[] = {
"-spsyn", VFNAME p_spsyn, "Sparse synaps list",
"/home/people/mniel/epipred/data/useall_hmm+seq.4.synlist",
"-blsyn", VFNAME p_blsyn, "Blosum synaps list",
"/home/people/mniel/epipred/data/useall_hmm+bl50.3.synlist",
"-seq2inp", VFNAME p_seq2inp, "Sequence to NN input program", "seq2inp",
"-writeseq", VSWITCH p_writeseq, "Write sequence in output", "1",
"-v", VSWITCH p_verbose, "Verbose mode", "0",
"-dirty", VSWITCH p_dirty, "Dirty mode, leave tmp dir+files", "0",
"-block", VINT p_block, "Block size of predictions", "50000",
"-sdev", VSWITCH p_sdev, "Print sdev", "0",
"-tdir", VFNAME p_tmpdir, "Temporary directory (Default $$)", "/tmp",
"-bdir", VFNAME p_bdir, "Binary directory", "",
"-pa", VSWITCH p_printall, "Print all network predictions", "0",
0
};
void doit( FILENAME cmd )
{
if ( p_verbose )
printf( "# %s", cmd );
system( cmd );
}
void epipred( FILENAME filename, FILENAME dir, int noff )
{
int n;
FILENAME cmd;
float bl, seq, o;
float sseq, sbl;
LINELIST *linelist_pep, *ll, *ll_pep;
LINELIST *linelist_bl, *ll_bl;
LINELIST *linelist_sp, *ll_sp;
LINE seq_all, bl_all;
WORD pep;
LINE restofline;
float sdev;
int nseq, nbl, npep;
int i,len;
int offset;
#ifdef NOTNOW
sprintf( cmd, "%s%s -min 0 -max 1 %s | grep -v \"#\" > %s/seq.inp\n",
p_bdir, p_seq2inp, filename, dir );
doit( cmd );
#endif
#ifdef NOTNOW
sprintf( cmd, "%snnlinplayer -x %s %s %s %s/seq.inp | grep -v \"#\" > %s/bl.res\n",
#endif
sprintf( cmd, "%snnlinplayer -x -seqinp %s %s %s %s | grep -v \"#\" > %s/bl.res\n",
p_bdir,
( p_sdev ? "-sdev 1 " : " " ),
( p_printall ? "-a " : " " ),
p_blsyn, filename,
dir );
doit( cmd );
#ifdef NOTNOW
sprintf( cmd, "%snnlinplayer -x %s %s %s %s/seq.inp | grep -v \"#\" > %s/sp.res\n",
#endif
sprintf( cmd, "%snnlinplayer -x -seqinp %s %s %s %s | grep -v \"#\" > %s/sp.res\n",
p_bdir,
( p_sdev ? "-sdev 1 " : " " ),
( p_printall ? "-a " : " " ),
p_spsyn, filename,
dir );
doit( cmd );
sprintf( cmd, "cat %s/sp.res", dir );
linelist_sp = linelist_pread( cmd );
sprintf( cmd, "cat %s/bl.res", dir );
linelist_bl = linelist_pread( cmd );
if ( p_writeseq )
linelist_pep = linelist_read( filename );
else
linelist_pep = NULL;
n=0;
for ( ll=linelist_sp, nseq = 0; ll; ll=ll->next, nseq++ );
for ( ll=linelist_bl, nbl = 0; ll; ll=ll->next, nbl++ );
for ( ll=linelist_pep, npep = 0; ll; ll=ll->next, npep++ );
if ( nseq != nbl ) {
printf( "Error. nseq != nbl %i %i\n", nseq, nbl );
exit( 1 );
}
if ( p_writeseq && nseq != npep ) {
printf( "Error. nseq != npep %i %i\n", nseq, npep );
exit( 1 );
}
if ( p_writeseq && nbl != npep ) {
printf( "Error. nbl != npep %i %i\n", nbl, npep );
exit( 1 );
}
for ( ll_sp = linelist_sp, ll_bl = linelist_bl, ll_pep=linelist_pep;
ll_sp && ll_bl;
ll_sp = ll_sp->next, ll_bl = ll_bl->next ) {
if ( p_printall ) {
i = 0;
len = strlen( ll_sp->line );
while ( i<len && strncmp( ll_sp->line+i, "Target=", 7 ) != 0 )
i++;
i-=10;
strncpy( seq_all, ll_sp->line, i );
seq_all[i] = 0;
offset = i;
}
else {
offset = 0;
}
if ( p_sdev )
sscanf( ll_sp->line+offset, "%f %*s %*f %*s %f", &seq, &sseq );
else
sscanf( ll_sp->line+offset, "%f", &seq );
if ( p_printall ) {
i = 0;
len = strlen( ll_bl->line );
while ( i<len && strncmp( ll_bl->line+i, "Target=", 7 ) != 0 )
i++;
i-=10;
strncpy( bl_all, ll_bl->line, i );
bl_all[i] = 0;
offset = i;
}
else {
offset = 0;
}
if ( p_sdev )
sscanf( ll_bl->line+offset, "%f %*s %*f %*s %f", &bl, &sbl );
else
sscanf( ll_bl->line+offset, "%f", &bl );
o = 0.5*(seq + bl);
printf( "%5i ", n+noff );
if ( p_writeseq ) {
if ( !ll_pep ) {
printf( "Error. Linelist empty\n" );
exit( 1 );
}
if ( sscanf( ll_pep->line, "%s %[^\n]", pep, restofline ) == 1 ) {
strcpy( restofline, "0.0" );
}
printf( "%14s %8s ", pep, restofline );
ll_pep = ll_pep->next;
}
printf( "%8.6f", o );
if ( p_sdev ) {
sdev = sqrt( 0.5 * ( sseq * sseq + sbl * sbl ) );
printf( " %8.6f", sdev );
}
if ( p_printall ) {
printf( " Sparse %s", seq_all );
printf( " BL %s", bl_all );
}
printf( "\n" );
n++;
}
if ( linelist_pep )
linelist_free( linelist_pep );
if ( linelist_sp )
linelist_free( linelist_sp );
if ( linelist_bl )
linelist_free( linelist_bl );
printf( "# %i prediction done from file %s\n", n, filename );
}
main( int argc, char *argv[] )
{
int pid;
FILENAME filename, cmd;
LINE line;
FILE *fp, *fp1;
int fc, ff;
int nlines, n, np;
FILENAME tmpdir;
pparse( &argc, &argv, param, 1, "filename" );
if ( strlen( p_tmpdir ) == 0 ) {
pid = getpid();
sprintf( tmpdir, "%i", pid );
}
else {
sprintf( tmpdir, "%s", p_tmpdir );
}
sprintf( cmd, "mkdir -p %s\n", tmpdir);
printf( "CMD: '%s'\n", cmd );
doit( cmd );
if ( ( fp = stream_input( argv[1], &fc, &ff ) ) == NULL ) {
printf( "Error. Cannot open file %s\n", argv[1] );
exit( 1 );
}
n = 0;
np = 0;
nlines = 0;
sprintf( filename, "%s/%i.dat", tmpdir, np );
if ( ( fp1 = fopen( filename, "w" ) ) == NULL ) {
printf( "Cannot open file %s\n", filename );
exit( 1 );
}
printf( "%5s %14s %8s %8s\n", "# n", "pep", "Aff", "NN_pred" );
while ( fgets( line, sizeof line, fp ) != NULL ) {
if ( strlen( line ) <= 1 ) continue;
if ( strncmp( line, "#", 1 ) == 0 ) continue;
fprintf( fp1, "%s", line );
n++;
if ( n >= p_block ) {
n=0;
np++;
fclose( fp1 );
epipred( filename, tmpdir, (np-1)*p_block );
sprintf( filename, "%s/%i.dat", tmpdir, np );
if ( ( fp1 = fopen( filename, "w" ) ) == NULL ) {
printf( "Cannot open file %s\n", filename );
exit( 1 );
}
}
nlines++;
}
if ( n > 0 ) {
n=0;
np++;
fclose( fp1 );
epipred( filename, tmpdir, (np-1)*p_block );
}
if ( ! p_dirty ) {
sprintf( cmd, "rm -rf %s\n", tmpdir );
doit( cmd );
}
exit( 0 );
}