| 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 |
#include "pwm_search.h" |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
int |
| 44 |
announce(msg) |
| 45 |
char *msg; |
| 46 |
{ |
| 47 |
int retval = 0; |
| 48 |
|
| •49 |
fprintf(stderr,"%s",msg); |
| 50 |
|
| 51 |
return(retval); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
void |
| 64 |
err_log(msg) |
| 65 |
char *msg; |
| 66 |
{ |
| 67 |
if ( __DEBUG__ ) |
| 68 |
announce("+++\nEntering err_log\n+++\n"); |
| 69 |
|
| 70 |
NUM_ERRS++; |
| 71 |
if ( (__ERR__[NUM_ERRS-1] = (char *) malloc( 1+strlen(msg) ) ) == NULL ) |
| 72 |
__ERR__[NUM_ERRS - 1] = PANIC; |
| 73 |
else |
| 74 |
strcpy( __ERR__[NUM_ERRS - 1],msg ); |
| 75 |
|
| 76 |
if ( __DEBUG__ ) |
| 77 |
announce("+++\nLeaving err_log\n+++\n"); |
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
void |
| 82 |
err_show() |
| 83 |
{ |
| 84 |
int err_num; |
| 85 |
for ( err_num=0; err_num<NUM_ERRS; ++err_num ) |
| 86 |
fprintf(stderr,"%s\n",__ERR__[err_num]); |
| 87 |
return; |
| 88 |
} |
| 89 |
|
| •90 |
|
| 91 |
|
| •92 |
|
| 93 |
|
| •94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| •98 |
int |
| 99 |
save_hit(base,strand,score,hits,pnhit) |
| 100 |
long base; |
| 101 |
int strand; |
| 102 |
double score; |
| 103 |
struct HIT *hits; |
| 104 |
long *pnhit; |
| 105 |
{ |
| 106 |
int retval = 0; |
| 107 |
|
| •108 |
if ( *pnhit == MAXHITS ) |
| 109 |
{ |
| 110 |
err_log("SAVE_HIT: MAXHITS limit reached."); |
| 111 |
retval = -1; |
| 112 |
} |
| 113 |
|
| •114 |
hits[*pnhit].base = base; |
| 115 |
hits[*pnhit].strand = strand; |
| 116 |
hits[*pnhit].score = score; |
| 117 |
*pnhit = *pnhit + 1; |
| 118 |
|
| 119 |
return(retval); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
int |
| 129 |
get_matrix(struct arguments* pargs, double* pwm) |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
{ |
| 134 |
double counts[2*MAXCOUNTS]; |
| 135 |
double max_log; |
| 136 |
double min_log; |
| 137 |
double scratch[1+MAXCOUNTS]; |
| 138 |
int done = 0; |
| 139 |
int nt; |
| 140 |
int num_counts; |
| 141 |
int pos; |
| 142 |
int retval=0; |
| 143 |
FILE *fp; |
| 144 |
|
| 145 |
if ( __DEBUG__ ) |
| 146 |
announce("+++\nEntering get_matrix\n+++\n"); |
| 147 |
|
| 148 |
|
| 149 |
if ( (fp=fopen(pargs->counts_file,"r")) == NULL ) |
| 150 |
{ |
| 151 |
err_log("GET_MATRIX: could not open specified file."); |
| 152 |
retval = -1; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
else |
| 157 |
{ |
| 158 |
for ( num_counts=0; !done && num_counts<MAXCOUNTS; ++num_counts ) |
| 159 |
{ |
| 160 |
if ( fscanf(fp,"%lf,%*c",scratch+num_counts) == EOF ) |
| 161 |
done = 1; |
| 162 |
} |
| 163 |
if ( !done ) |
| 164 |
{ |
| 165 |
err_log("GET_MATRIX: too many counts."); |
| 166 |
retval = -1; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
fclose(fp); |
| 171 |
if ( !retval ) |
| 172 |
{ |
| 173 |
|
| 174 |
|
| 175 |
pargs->width = num_counts/4; |
| 176 |
for ( pos=0; pos<pargs->width; ++pos ) |
| 177 |
{ |
| 178 |
for ( nt=0; nt<4; ++nt ) |
| 179 |
{ |
| 180 |
pwm[5*pos + nt] = scratch[(pargs->width)*nt + pos]; |
| 181 |
} |
| 182 |
|
| 183 |
pwm[5*pos + 4] = |
| 184 |
(pwm[5*pos + 0] + |
| 185 |
pwm[5*pos + 1] + |
| 186 |
pwm[5*pos + 2] + |
| 187 |
pwm[5*pos + 3] |
| 188 |
) / 4; |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
pargs->max_score = 0; |
| 194 |
pargs->min_score = 0; |
| 195 |
for ( pos=0; pos<pargs->width; ++pos ) |
| 196 |
{ |
| 197 |
max_log = -10.0; |
| 198 |
min_log = 10.0; |
| 199 |
for ( nt=0; nt<4; ++nt ) |
| 200 |
{ |
| 201 |
max_log = ( max_log>pwm[5*pos+nt] ) ? max_log : pwm[5*pos+nt]; |
| 202 |
min_log = ( min_log<pwm[5*pos+nt] ) ? min_log : pwm[5*pos+nt]; |
| 203 |
} |
| 204 |
pargs->max_score += max_log; |
| 205 |
pargs->min_score += min_log; |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
if ( __DEBUG__ ) |
| 210 |
announce("+++\nLeaving get_matrix\n+++\n"); |
| 211 |
|
| 212 |
return (retval); |
| 213 |
} |
| 214 |
|
| 215 |
|
| •216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
int get_cmd_args(argc,argv,pargs) |
| 223 |
int argc; |
| 224 |
char **argv; |
| 225 |
struct arguments *pargs; |
| 226 |
{ |
| 227 |
int retval = 0; |
| 228 |
int arg_count = 4; |
| 229 |
|
| 230 |
if ( __DEBUG__ ) |
| 231 |
announce("+++\nEntering get_cmd_args\n+++\n"); |
| 232 |
|
| 233 |
|
| 234 |
if ( argc < 4 ) |
| 235 |
{ retval = -1; |
| 236 |
err_log("GET_CMD_ARGS: Too few arguments."); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
else |
| 241 |
{ strcpy(pargs->counts_file,argv[1]); |
| 242 |
strcpy(pargs->seq_file,argv[2]); |
| 243 |
pargs->threshold = atof(argv[3]); |
| 244 |
pargs->best_only = 0; |
| 245 |
pargs->print_all = 0; |
| 246 |
pargs->mask_file[0] = '\0'; |
| 247 |
while (arg_count < argc) |
| 248 |
{ |
| 249 |
if ( argv[arg_count][0]=='-' && argv[arg_count][1]=='b' ) |
| 250 |
{ |
| 251 |
pargs->best_only = 1; |
| 252 |
arg_count++; |
| 253 |
} |
| 254 |
else if ( argv[arg_count][0]=='-' && argv[arg_count][1]=='a' ) |
| 255 |
{ |
| 256 |
pargs->print_all = 1; |
| 257 |
arg_count++; |
| 258 |
} |
| 259 |
else if ( arg_count<argc-1 && |
| 260 |
argv[arg_count][0]=='-' && argv[arg_count][1]=='m' && |
| 261 |
argv[arg_count+1][0]!='\0' |
| 262 |
) |
| 263 |
{ |
| 264 |
strcpy(pargs->mask_file,argv[arg_count+1]); |
| 265 |
arg_count = arg_count+2; |
| 266 |
} |
| 267 |
else if ( arg_count<argc-1 && |
| 268 |
argv[arg_count][0]=='-' && argv[arg_count][1]=='n' && |
| 269 |
argv[arg_count+1][0]!='\0' |
| 270 |
) |
| 271 |
{ |
| 272 |
strcpy(pargs->name,argv[arg_count+1]); |
| 273 |
arg_count = arg_count+2; |
| 274 |
} |
| 275 |
else if ( arg_count<argc-1 && |
| 276 |
argv[arg_count][0]=='-' && argv[arg_count][1]=='c' && |
| 277 |
argv[arg_count+1][0]!='\0' |
| 278 |
) |
| 279 |
{ |
| 280 |
strcpy(pargs->class,argv[arg_count+1]); |
| 281 |
arg_count = arg_count+2; |
| 282 |
} |
| 283 |
else |
| 284 |
{ |
| 285 |
arg_count++; |
| 286 |
} |
| 287 |
} |
| 288 |
} |
| 289 |
if ( __DEBUG__ ) |
| 290 |
announce("+++\nLeaving get_cmd_args\n+++\n"); |
| 291 |
return( retval ); |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| •303 |
int get_sequence(fp,seq_id,sequence) |
| 304 |
FILE *fp; |
| 305 |
char *seq_id; |
| 306 |
char *sequence; |
| 307 |
{ |
| 308 |
char msg[2*MAX_LINE]; |
| 309 |
int c; |
| 310 |
int done=0; |
| 311 |
int position; |
| 312 |
int retval = 0; |
| 313 |
int word = 0; |
| 314 |
int count = 0; |
| 315 |
long base = 0L; |
| 316 |
char line[MAX_LINE]; |
| 317 |
int at_eof = 0; |
| 318 |
int first_time=1; |
| 319 |
|
| 320 |
if ( __DEBUG__ ) |
| 321 |
{ |
| 322 |
announce("+++\nEntering Get_sequence\n+++\n"); |
| 323 |
} |
| 324 |
|
| 325 |
if ( first_time ) |
| 326 |
{ |
| 327 |
first_time=0; |
| 328 |
if ( fgets(line,MAX_LINE,fp)==NULL ) |
| 329 |
{ |
| 330 |
at_eof = 1; |
| 331 |
} |
| 332 |
} |
| 333 |
if ( at_eof ) |
| 334 |
{ |
| 335 |
retval = 1; |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
if ( !retval ) |
| 341 |
{ |
| 342 |
strcpy(seq_id,line+1); |
| 343 |
seq_id[ strlen(seq_id) -1 ] = '\0'; |
| 344 |
while (count < strlen(seq_id) && !word) |
| 345 |
{ |
| 346 |
if (seq_id[count] == ' ') |
| 347 |
{ |
| 348 |
word++; |
| 349 |
seq_id[count]= '\0'; |
| 350 |
} |
| 351 |
count++; |
| 352 |
} |
| 353 |
|
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
while ( !retval && !done ) |
| 358 |
{ |
| 359 |
if ( __DEBUG__ ) |
| 360 |
{ |
| 361 |
announce("+++\nReading in...\n+++\n"); |
| 362 |
} |
| 363 |
|
| 364 |
if ( fgets(line,MAX_LINE,fp) == NULL ) |
| 365 |
{ |
| 366 |
at_eof = 1; |
| 367 |
done = 1; |
| 368 |
} |
| 369 |
else if ( line[0] == '>' ) |
| 370 |
{ |
| 371 |
done = 1; |
| 372 |
} |
| 373 |
else |
| 374 |
{ |
| 375 |
for ( position=0; !retval && line[position]!='\0'; ++position) |
| 376 |
{ |
| 377 |
c = line[position]; |
| 378 |
if ( !isdigit( c ) && !isspace( c ) ) |
| 379 |
{ |
| 380 |
if ( base >= SEQLEN ) |
| 381 |
{ |
| 382 |
err_log("GET_SEQUENCE: Sequence too long."); |
| 383 |
retval = -1; |
| 384 |
} |
| 385 |
else |
| 386 |
{ |
| 387 |
sequence[base++] = c; |
| 388 |
} |
| 389 |
} |
| 390 |
} |
| 391 |
} |
| 392 |
} |
| 393 |
sequence[base] = '\0'; |
| 394 |
|
| 395 |
if ( __DEBUG__ ) |
| 396 |
{ |
| 397 |
announce("+++\nLeaving Get_sequence\n+++\n"); |
| 398 |
sprintf(msg,"seq_id=%s\nlength=%ld\n", |
| 399 |
seq_id, base |
| 400 |
); |
| 401 |
announce(msg); |
| 402 |
} |
| 403 |
|
| 404 |
return(retval); |
| 405 |
} |
| 406 |
|
| 407 |
|
| •408 |
|
| 409 |
|
| •410 |
|
| 411 |
|
| •412 |
|
| 413 |
|
| •414 |
int best_pull(pargs,pbase,pstrand,pscore) |
| 415 |
struct arguments *pargs; |
| •416 |
long *pbase; |
| 417 |
int *pstrand; |
| 418 |
double *pscore; |
| 419 |
{ |
| •420 |
*pbase = pargs->best_base; |
| 421 |
if ( pargs->best_base >= 0 ) |
| 422 |
{ |
| •423 |
*pscore = pargs->best_score; |
| 424 |
*pstrand = pargs->best_strand; |
| 425 |
} |
| •426 |
return(0); |
| 427 |
} |
| 428 |
|
| •429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
int best_save(struct arguments* pargs, long base, int strand, double score) |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
{ |
| 442 |
if ( pargs->best_base < 0 || score > pargs->best_score ) |
| 443 |
{ |
| 444 |
pargs->best_base = base; |
| 445 |
pargs->best_score = score; |
| 446 |
pargs->best_strand = strand; |
| 447 |
} |
| 448 |
|
| •449 |
return(0); |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
int |
| 460 |
mark(width) |
| 461 |
int width; |
| 462 |
{ |
| 463 |
int pos; |
| 464 |
|
| 465 |
for ( pos=0; pos<width; ++pos ) |
| 466 |
putchar('-'); |
| 467 |
putchar('\n'); |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
int |
| 478 |
output(pargs,seqid,base,seq,strand,score, outfp) |
| 479 |
struct arguments *pargs; |
| 480 |
char *seqid; |
| 481 |
long base; |
| 482 |
char *seq; |
| 483 |
int strand; |
| 484 |
double score; |
| 485 |
FILE *outfp; |
| 486 |
{ |
| 487 |
int pos; |
| 488 |
int retval = 0; |
| 489 |
|
| 490 |
if ( __DEBUG__ ) |
| 491 |
announce("+++\nEntering output\n+++\n"); |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
fprintf(outfp, "%s\tTFBS\t%s\t%s\t",seqid,pargs->name,pargs->class); |
| 506 |
|
| 507 |
if (strand) |
| 508 |
{ |
| 509 |
fprintf(outfp, "-\t"); |
| 510 |
} |
| 511 |
else fprintf(outfp, "+\t"); |
| 512 |
|
| 513 |
fprintf(outfp, "%6.3f\t%6.1f\t", score, |
| 514 |
100*(score - pargs->min_score)/(pargs->max_score - pargs->min_score)); |
| 515 |
|
| 516 |
fprintf(outfp, "%ld\t%ld\t",base+1,base+pargs->width); |
| 517 |
|
| 518 |
for ( pos=0; pos<pargs->width; ++pos ) |
| 519 |
{ |
| 520 |
putc(seq[base+pos], outfp); |
| 521 |
} |
| 522 |
putc('\n', outfp); |
| 523 |
|
| 524 |
|
| 525 |
if ( __DEBUG__ ) |
| 526 |
announce("+++\nLeaving output\n+++\n"); |
| 527 |
|
| 528 |
return( retval ); |
| 529 |
} |
| 530 |
|
| 531 |
|
| •532 |
|
| 533 |
|
| •534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
int |
| •539 |
do_seq(pargs,pwm,seqid,seq,outfp) |
| 540 |
struct arguments *pargs; |
| 541 |
double *pwm; |
| 542 |
char *seqid; |
| 543 |
char *seq; |
| 544 |
FILE *outfp; |
| 545 |
{ |
| •546 |
double backward_score; |
| 547 |
double forward_score; |
| 548 |
double score; |
| 549 |
long base; |
| 550 |
int done = 0; |
| 551 |
int nt; |
| 552 |
int pos; |
| 553 |
int retval = 0; |
| •554 |
int strand; |
| 555 |
long l; |
| 556 |
long nhit=0L; |
| 557 |
struct HIT hits[MAXHITS]; |
| 558 |
|
| •559 |
if ( __DEBUG__ ) |
| 560 |
announce("+++\nEntering do_seq.\n+++\n"); |
| 561 |
|
| 562 |
|
| 563 |
for ( base=0; base < pargs->width; ++base ) |
| 564 |
{ |
| •565 |
if ( seq[base] == '\0' ) |
| 566 |
done = 1; |
| 567 |
} |
| 568 |
|
| •569 |
|
| 570 |
pargs->best_base = -1; |
| 571 |
for ( base=0; !retval && !done && seq[base+pargs->width-1]; ++base ) |
| 572 |
{ |
| 573 |
forward_score = 0.0; |
| 574 |
backward_score = 0.0; |
| 575 |
for ( pos=0; pos<pargs->width; ++pos ) |
| 576 |
{ |
| 577 |
nt = TRANS[seq[base+pos]]; |
| 578 |
forward_score += pwm[5*pos + nt]; |
| 579 |
nt = ( nt==4 ) ? 4 : 3-nt; |
| 580 |
backward_score += pwm[5*(pargs->width - pos -1) + nt]; |
| 581 |
} |
| 582 |
if ( forward_score > pargs->threshold ) |
| 583 |
{ |
| 584 |
if ( pargs->print_all ) |
| 585 |
{ |
| 586 |
if ( save_hit(base,0,forward_score,hits,&nhit) ) |
| 587 |
{ |
| 588 |
err_log("DO_SEQ: save_hit failed"); |
| 589 |
retval = -1; |
| 590 |
} |
| 591 |
} |
| 592 |
else if ( pargs->best_only ) |
| 593 |
{ |
| 594 |
best_save(pargs,base,0,forward_score); |
| 595 |
} |
| 596 |
else if ( output(pargs,seqid,base,seq,0,forward_score,outfp) ) |
| 597 |
{ |
| 598 |
err_log("DO_SEQ: output failed"); |
| 599 |
retval = -1; |
| 600 |
} |
| 601 |
} |
| 602 |
if ( backward_score > pargs->threshold ) |
| 603 |
{ |
| 604 |
if ( pargs->print_all ) |
| 605 |
{ |
| 606 |
if ( save_hit(base,1,backward_score,hits,&nhit) ) |
| 607 |
{ |
| 608 |
err_log("DO_SEQ: save_hit failed"); |
| 609 |
retval = -1; |
| 610 |
} |
| 611 |
} |
| 612 |
else if ( pargs->best_only ) |
| 613 |
{ |
| 614 |
best_save(pargs,base,1,backward_score); |
| 615 |
} |
| 616 |
else if ( output(pargs,seqid,base,seq,1,backward_score, outfp) ) |
| 617 |
{ |
| 618 |
err_log("DO_SEQ: output failed"); |
| 619 |
retval = -1; |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
} |
| 624 |
|
| 625 |
if ( pargs->print_all ) |
| 626 |
{ |
| 627 |
for ( l=0; l<nhit; ++l ) |
| 628 |
printf("%ld %.3f\n",1+hits[l].base,hits[l].score); |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
} |
| 644 |
|
| 645 |
else |
| 646 |
{ |
| 647 |
best_pull(pargs,&base,&strand,&score); |
| 648 |
if ( base>=0 ) |
| 649 |
{ |
| 650 |
if ( output(pargs,seqid,base,seq,strand,score,outfp) ) |
| 651 |
{ |
| 652 |
err_log("DO_SEQ: output failed"); |
| 653 |
retval = -1; |
| 654 |
} |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
if ( __DEBUG__ ) |
| 659 |
announce("+++\nLeaving do_seq.\n+++\n"); |
| 660 |
|
| 661 |
return(retval); |
| •662 |
|
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
int |
| 674 |
loop_on_seqs(pargs,pwm,fp, outfp) |
| 675 |
struct arguments *pargs; |
| 676 |
double *pwm; |
| 677 |
FILE *fp; |
| 678 |
FILE *outfp; |
| 679 |
{ |
| 680 |
char seq[SEQLEN+1]; |
| 681 |
char seqid[SEQNAMELEN+1]; |
| 682 |
int done = 0; |
| 683 |
int retval=0; |
| 684 |
if ( __DEBUG__ ) |
| 685 |
announce("+++\nEntering loop_on_seqs\n+++\n"); |
| 686 |
|
| 687 |
|
| 688 |
while ( !retval && !done ) |
| 689 |
{ |
| 690 |
done = get_sequence(fp,seqid,seq); |
| 691 |
if ( done == -1 ) |
| 692 |
{ |
| 693 |
err_log("LOOP_ON_SEQS: get_sequence failed."); |
| 694 |
retval = -1; |
| 695 |
} |
| 696 |
else if ( done == 0 ) |
| 697 |
{ |
| 698 |
if ( do_seq(pargs,pwm,seqid,seq,outfp) ) |
| 699 |
{ |
| 700 |
err_log("LOOP_ON_SEQS: do_seq failed."); |
| 701 |
retval = -1; |
| 702 |
} |
| 703 |
} |
| 704 |
} |
| 705 |
|
| 706 |
if ( __DEBUG__ ) |
| 707 |
announce("+++\nLeaving loop_on_seqs\n+++\n"); |
| 708 |
|
| 709 |
return (retval); |
| 710 |
} |
| 711 |
|
| 712 |
int do_search(char* matrixfile, |
| 713 |
char* seqfile, |
| 714 |
float threshold, |
| 715 |
char* tfname, |
| 716 |
char* tfclass, |
| 717 |
char* outfile) |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
{ |
| 722 |
double pwm[2*MAXCOUNTS]; |
| 723 |
|
| 724 |
int exitval = -1; |
| 725 |
struct arguments args; |
| 726 |
FILE *fp; |
| 727 |
FILE *outfp; |
| 728 |
NUM_ERRS = 0; |
| 729 |
if (__DEBUG__) fprintf(stderr, "%s %s %f %s %s %s\n", matrixfile, seqfile, threshold, tfname, tfclass, outfile); |
| 730 |
if ( __DEBUG__ ) |
| 731 |
announce("+++\nEntering main.\n+++\n"); |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
strcpy(args.counts_file, matrixfile); |
| 742 |
strcpy(args.seq_file, seqfile); |
| 743 |
args.threshold = threshold; |
| 744 |
strcpy(args.name, tfname); |
| 745 |
strcpy(args.class, tfclass); |
| 746 |
args.print_all = 0; |
| 747 |
args.best_only= 0; |
| 748 |
|
| 749 |
|
| 750 |
if ( get_matrix(&args,pwm) ) |
| 751 |
{ |
| 752 |
err_log("MAIN: get_matrix failed."); |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
else if ( (fp=fopen(args.seq_file,"r")) == NULL ) |
| 757 |
{ |
| 758 |
err_log("MAIN: open_seq_file failed."); |
| 759 |
} |
| 760 |
else if ( (outfp=fopen(outfile,"w")) == NULL ) |
| 761 |
{ |
| 762 |
err_log("MAIN: open_outfile failed."); |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
else if ( loop_on_seqs(&args,pwm,fp,outfp) ) |
| 767 |
{ |
| 768 |
err_log("MAIN: loop_on_seqs failed."); |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
else |
| 773 |
{ |
| 774 |
exitval = 0; |
| 775 |
} |
| 776 |
|
| 777 |
|
| 778 |
err_show(); |
| 779 |
fclose(fp); |
| 780 |
fclose(outfp); |
| 781 |
if ( __DEBUG__ ) |
| 782 |
announce("+++\nLeaving main.\n+++\n"); |
| 783 |
|
| 784 |
return(exitval); |
| 785 |
} |