2 /* Code by anonomous and Ethan Wolf 1995. */
4 /************************************************************************/
5 /* get_defaults() is called in main() of sc2seq.c to get the default */
6 /* values for parameters of the program, such as input/output files and */
8 /************************************************************************/
15 #include "interface.h"
18 /** Returns pointer to first occurance of chrs[0]. If that not present,
19 * returns pointer to first occurance of chrs[1]... If none of
20 * characters in chrs[] are present then it returns NULL.
21 * This is used to remove whitspace, tabs, returns.
23 static char *strchrs(char *str, char *chrs) {
27 if(ret=strchr(str,*chrs)) return ret;
33 /************************************************************************/
34 /* Reads in .paircoil file of default values that are normally input to */
35 /* sc2seq in the command line. */
36 /* Any required value not read in here is expected on the command line. */
37 void get_defaults(char *command_line_config,
38 char *input_location, int *mode, double *bound,
39 FILE **fgin, FILE **fpin,
40 FILE **ftotal_like, FILE **fout,
44 char likelihoods[MAX_TABLE_NUMBER][MAXLINE],
45 char *pir_name, char *lib,
46 char multi_lib[MAX_TABLE_NUMBER][MAXFUNCTNUM],
48 int combine_dist[MAX_TABLE_NUMBER],
49 char *print, int *main_method,
50 int *main_preprocessor_method, int *main_table,
55 char class_sc_filenames[2][MAX_CLASS_NUMBER][MAXLINE],
56 char gaussian_parameters[2][MAXLINE],
57 int num_dist[MAX_TABLE_NUMBER],
58 double init_class_prob[MAX_CLASS_NUMBER],
59 int *table_to_remove_from,
61 int window_length[MAX_TABLE_NUMBER],
62 double scale0s[MAX_TABLE_NUMBER],
63 double scale0p[MAX_TABLE_NUMBER])
65 char buf[500], *tmp, name[500];
66 FILE *config; FILE *printfile;
67 int i, number_likelihoods=0;
71 /******** A hack so I don't have to eliminate all the stuff using these ****/
72 /******** pointers, since no longer pass them into function. ****/
73 int num_tab=0, *number_tables, number_classes=0, number_max_classes=0;
75 number_tables= &num_tab;
76 /****************************************************************************/
78 strcpy(gaussian_parameters[0], "~/MULTICOIL/CONVERSION_FILES/gauss_param28+");
80 if (command_line) { /* Don't use options in config file. */
81 if (!strcmp(command_line,"dimer")) {
82 *table_to_remove_from = 0;
83 printf("Input data is all removed from table 1\n");
87 else if (!strcmp(command_line,"trimer")) {
88 *table_to_remove_from = 1;
89 printf("Input data is all removed from table 2\n");
93 else if (!strcmp(command_line, "dimer-1")) {
95 printf("Input is data from table 1\n");
99 else if (!strcmp(command_line, "trimer-1")) {
101 printf("Input is data from table 2\n");
105 else if (!strcmp(command_line, "negatives")) {
106 printf("Not doing pos mode");
108 else if (!strcmp(command_line, "config_file")) {
109 printf("Doing pos options as in config file\n");
112 else { /* Bad command line input. **/
119 /************************** For Automating output file name. ****/
120 /** Strip off directories to get just the program name. **/
121 i=strlen(input_location);
122 while ((i>=0) && (input_location[i] != '/') )
124 input_name= &input_location[i+1];
125 /***************************/
128 /* What directory to look for paircoil defauts in. Set environment */
129 /* variable MULTICOIL_CONFIG to be a path to this file. */
131 if (command_line_config) { /** Read config location at command line. **/
132 strcpy(buf, command_line_config);
133 fprintf(stderr,"config = %c",buf);
136 if (tmp=getenv("MULTICOIL_CONFIG")) {
140 strcpy(buf,getenv("HOME"));
141 strcat(buf,"/MULTICOIL/multicoil_config");
144 if (config=fopen(buf,"r")) {
145 printf("Config file %s\n", buf);
146 while (fgets(buf,500,config)) {
148 if (!command_line) { /** Read from file since it wasn't **/
149 /** a command line param. **/
150 if(!strncmp(buf,"pos",3)) { /* If "pos" is in the .paircoil */
151 *mode |= POS_MODE; /* default file, then the test */
152 printf("pos\n"); /* file is assumed to be a .pos */
153 } /* file, where each seq has its */
155 else if(!strncmp(buf,"remove all input from table",27)) {
156 sscanf(buf,"remove all input from table %d",table_to_remove_from);
157 (*table_to_remove_from)--;
158 printf("Input is data is all removed from table %d\n",
159 (*table_to_remove_from) +1);
162 else if(!strncmp(buf,"input pos1",10)) {
164 printf("Input is data from table 1\n");
166 else if(!strncmp(buf,"input pos2",10)) {
168 printf("Input is data from table 2\n");
174 /**** Now do the rest of the possible non-command line options. *****/
176 if(!strncmp(buf,"genbnk",6)) { /* Get location of genbnk file */
177 sscanf(buf,"genbnk = %s",name); /* and open it. */
178 *fgin = sopen(name,"r");
180 printf("genbnk = %s\n",name);
183 else if(!strncmp(buf,"table",5)) { /* Get location of postable file */
184 sscanf(buf,"table %d = %s",&i, name);
185 fpin[i-1] = sopen(name,"r");
187 printf("table %d = %s\n",i,name);
192 else if(!strncmp(buf,"pir",3)) { /* Get location of pir file */
193 sscanf(buf,"pir = %s",pir_name);
195 printf("pir = %s\n",pir_name);
198 else if(!strncmp(buf,"printfile",9)) { /* File to output printouts to*/
199 sscanf(buf,"printfile = %s",print);
200 printf("printfile = %s\n",print);
201 printfile=sopen(print,"w"); /* We are going to append to this, */
202 sclose(printfile); /* So first make it empty. */
204 else if(!strncmp(buf,"likelihoods",11)) {
205 sscanf(buf,"likelihoods %d = %s",&i, likelihoods[number_likelihoods]);
207 printf("likelihoods %d = %s\n",number_likelihoods,
208 likelihoods[number_likelihoods]); ***/ /* likelihood lines. */
209 number_likelihoods++;
210 likelihoods[number_likelihoods][0]= ',';
214 else if(!strncmp(buf,"class scores combo",18)) {
215 sscanf(buf,"class scores combo %d with init prob %lf = %s",&i,
216 &init_class_prob[number_classes],
217 class_sc_filenames[0][number_classes]);
218 printf("combo class scores %d = %s with init prob %lf\n",
219 i,class_sc_filenames[0][number_classes],
220 init_class_prob[number_classes]); /* likelihood lines. */
225 else if(!strncmp(buf,"class scores max",16)) {
226 sscanf(buf,"class scores max %d with init prob %lf = %s",&i,
227 &init_class_prob[number_max_classes],
228 class_sc_filenames[1][number_max_classes]);
229 printf("max class scores %d = %s with init prob %lf\n",
230 i,class_sc_filenames[1][number_max_classes],
231 init_class_prob[number_max_classes]); /* likelihood lines. */
232 number_max_classes++;
235 else if(!strncmp(buf,"gauss_param =",13))
236 sscanf(buf,"gauss_param = %s",gaussian_parameters[0]);
238 else if(!strncmp(buf,"gauss_param combo",17)) {
239 sscanf(buf,"gauss_param combo = %s",gaussian_parameters[0]);
241 printf("gauss_param combo = %s\n",gaussian_parameters[0]);
245 else if(!strncmp(buf,"gauss_param max",15)) {
246 sscanf(buf,"gauss_param max = %s",gaussian_parameters[1]);
248 printf("gauss_param max = %s\n",gaussian_parameters[1]);
252 else if(!strncmp(buf,"no GUI",6)) {
258 else if(!strncmp(buf,"pair_lib",8)) { /* Read in a variable number */
259 char *end; /* of distances to be used in */
260 int val; /* pair scores. The number */
261 /* of variables is stored in */
262 printf("pair_lib = "); /* in the global variable */
263 tmp = strchr(buf, '='); /* functnum. The distances */
264 tmp++; /* are stored in */
265 /* strip leading whitespace */ /* lib[0],...,lib[functnum-1]. */
266 while(!isdigit(*tmp)&&*tmp) tmp++;
267 while(end = strchrs(tmp, " \t\n\r")) {
270 /* strip leading whitespace */
271 while(*tmp&&!isdigit(*tmp)) tmp++;
274 lib[(*functnum)++] = val-1; /** scscore.c needs takes residues **/
275 /** at dist lib +1 apart. **/
285 else if(!strncmp(buf,"multi_lib",9)) { /* Read in a variable number */
286 if (! (*mode & LIB_AT_COMMAND_LINE)) { /* This flags that **/
287 /** got it at command line. **/
288 int first_table, last_table;
290 int combine_distances =1;
292 if (!strncmp(buf,"multi_lib dim",13)) {
293 combine_distances = 0;
295 if (!strncmp(buf,"multi_lib dim =",15)) {
296 first_table=0; last_table=NUMBER_TABLES;
297 } /* All tables get same lib. **/
299 sscanf(buf,"multi_lib dim %d", &last_table);
300 first_table = last_table-1;
303 else if (!strncmp(buf,"multi_lib =",11)) {
304 combine_distances = 0;
305 first_table=0; last_table= NUMBER_TABLES;
306 } /* All tables get same lib. **/
308 sscanf(buf,"multi_lib %d", &last_table);
309 first_table = last_table-1;
312 for (the_table=first_table; the_table<last_table; the_table++) {
313 combine_dist[the_table]= combine_distances;
314 num_dist[the_table]=0;
317 if (!strncmp(buf,"multi_lib = all",15))
319 /* For scscore.c will go through each dist on own*/
320 for (the_table=first_table; the_table<last_table; the_table++)
321 for (i=0; i<7; i++) {
322 multi_lib[the_table][i] = i;
323 num_dist[the_table] = 7;
324 combine_dist[the_table] = 0;
329 char *end; /* of distances to be used in */
330 int val; /* pair scores. The number */
331 /* of variables is stored in */
332 printf("multi_lib = "); /* in the global variable */
333 tmp = strchr(buf, '='); /* functnum. The distances */
334 tmp++; /* are stored in */
335 /* strip leading whitespace */ /* lib[0],...,lib[functnum-1]. */
336 while(!isdigit(*tmp)&&*tmp) tmp++;
337 while(end = strchrs(tmp, " \t\n\r")) {
340 /* strip leading whitespace */
341 while(*tmp&&!isdigit(*tmp)) tmp++;
344 for (the_table=first_table; the_table<last_table; the_table++){
345 multi_lib[the_table][num_dist[the_table]] = val-1;
346 /** scscore.c needs takes residues at dist lib +1 apart. **/
347 num_dist[the_table]+= 1;
348 /** combine_dist[the_table] = combine_distances; **/
354 for (the_table=first_table; the_table<last_table; the_table++)
355 if (num_dist[the_table] ==1) combine_dist[the_table] =0;
364 else if(!strncmp(buf,"Maximize total like",4)) {
365 sscanf(buf,"Maximize total like = %s",name); /* Compute the sum */
366 *ftotal_like = sopen(name,"w"); /* over classes of */
367 printf("ftotal_like = %s\n",name); /* the gauss value */
368 /* for the score for various settings */
369 /* of the initial class parameters, so*/
370 /* we can choose values max total like*/
372 else if(!strncmp(buf,"out",3)) {
373 if (!strncmp(buf,"out dir",7)) { /** automate the name **/
374 sscanf(buf,"out dir = %s",name);
375 strcat(name,input_name);
378 else sscanf(buf,"out = %s",name); /* Read in the filename in which */
379 /* to output the residue scores */
380 *fout = sopen(name,"w"); /* and open it. */
381 printf("out = %s\n",name);
384 else if(!strncmp(buf,"sparse_out",10)) {
385 if (!strncmp(buf,"sparse_out dir",14)) { /** automate the name **/
386 sscanf(buf,"sparse_out dir = %s",name);
387 strcat(name,input_name);
390 else sscanf(buf,"sparse_out = %s",name); /*Read in filename in which */
391 /* to output the residue scores */
392 *fout = sopen(name,"w"); /* and open it. */
393 printf("sparse_out = %s\n",name);
394 *mode ^= WEB_OUT_MODE; /* Don't want web output mode. */
398 else if(!strncmp(buf,"raw_out",7)) {
400 if (!strncmp(buf,"raw_out dir",11)) { /** automate the name **/
401 sscanf(buf,"raw_out dir = %s",name);
402 strcat(name,input_name);
403 strcat(name,".raw_out");
405 else sscanf(buf,"raw_out = %s",name);
407 *fout= sopen(name,"w");
408 printf("Opened %s for output of raw scores\n",name);
411 else if(!strncmp(buf,"log",3)) {
412 if (!strncmp(buf,"log dir",7)){ /* automate the name **/
413 sscanf(buf,"log dir = %s",name);
414 strcat(name,input_name);
417 /**** Apend on the library distances. ***/
418 if (combine_dist[0] == 0) { /* make sure do dimension scores */
420 while (lib_numb < num_dist[0]) {
421 sprintf(&buf[lib_numb],"%d",multi_lib[0][lib_numb]);
423 sprintf(&buf[lib_numb],"_");
424 strncat(name,buf,num_dist[0]+1);
427 while (lib_numb < num_dist[1]) {
428 sprintf(&buf[lib_numb],"%d",multi_lib[1][lib_numb]);
430 strncat(name,buf,num_dist[1]);
433 } /* Read in the filename in which */
434 else sscanf(buf,"log = %s",name); /* to output the sequences which */
435 *flog = sopen(name,"w"); /* score above the PRN_MODE */
436 printf("log = %s\n",name); /* threshhold. This file will */
437 /* get human readable output. */
440 else if (!strncmp(buf,"Log Like Pos",12))
441 *mode |= POS_STYLE_LOG;
445 else if (!strncmp(buf,"By seq pos regions",18))
448 /*************************************************************************/
449 /*******Two Ways of doing same command: "coil scores" and "seq scores" **/
450 /*** Although slightly diff't since they modify "by_coil_or_seq" diff'tly**/
452 else if(!strncmp(buf,"coil scores",11)) {
453 *by_coil_or_seq =0; /** Do coil scores. **/
454 if (!strncmp(buf,"coil scores dir",15)) { /* automate the name **/
455 sscanf(buf,"coil scores dir = %s",name);
456 strcat(name,input_name);
457 strcat(name,".coil_scores");
458 if (*mode & VER_MODE)
459 strcat(name,"_NoTxt");
461 /**** Apend on the library distances. ***/
462 if (combine_dist[0] == 0) { /* make sure do dimension scores */
464 while (lib_numb < num_dist[0]) {
465 sprintf(&buf[lib_numb],"%d",multi_lib[0][lib_numb]);
467 sprintf(&buf[lib_numb],"_");
468 strncat(name,buf,num_dist[0]+1);
471 while (lib_numb < num_dist[1]) {
472 sprintf(&buf[lib_numb],"%d",multi_lib[1][lib_numb]);
474 strncat(name,buf,num_dist[1]);
477 else sscanf(buf,"coil scores = %s",name);
478 *fout_coils = sopen(name,"w"); /* For just choosing 1 score */
479 printf("coil scores = %s\n",name); /* per pos file coil, or seq */
482 else if(!strncmp(buf,"seq scores",10)) {
483 *by_coil_or_seq =2; /** Do seq scores. **/
484 if (!strncmp(buf,"seq scores dir",14)) { /* automate the name **/
485 sscanf(buf,"seq scores dir = %s",name);
486 strcat(name,input_name);
487 strcat(name,".seq_scores");
488 if (*mode & VER_MODE)
489 strcat(name,"_NoTxt");
491 /**** Apend on the library distances. ***/
492 if (combine_dist[0] == 0) { /* make sure do dimension scores */
494 while (lib_numb < num_dist[0]) {
495 sprintf(&buf[lib_numb],"%d",multi_lib[0][lib_numb]);
497 sprintf(&buf[lib_numb],"_");
498 strncat(name,buf,num_dist[0]+1);
501 while (lib_numb < num_dist[1]) {
502 sprintf(&buf[lib_numb],"%d",multi_lib[1][lib_numb]);
504 strncat(name,buf,num_dist[1]);
507 else sscanf(buf,"seq scores = %s",name);
508 *fout_coils = sopen(name,"w"); /* For just choosing 1 score */
509 printf("seq scores = %s\n",name); /* per pos file coil, or seq */
512 /*************************/
514 else if(!strncmp(buf,"ps res per line",15)) {/* Reads in the length of */
515 sscanf(buf,"ps res per line = %d", ps_res_per_line); /* print line */
516 fprintf(stderr,"res per line = %d\n", *ps_res_per_line);
518 else if(!strncmp(buf,"one print line",14)) {
519 *ps_res_per_line = -1; /* Flag to print on just one line. */
520 fprintf(stderr,"Sequences will be printed on one line in ps file.\n");
523 else if(!strncmp(buf,"max window then combine dist",28)) {
524 *mode |= MAX_WINDOW_BEFORE_COMBINE_MODE; /* In scseqadj in */
525 printf("max window before combine distances\n"); /* scscore.c, this */ /* defines how to compute score. */
528 else if(!strncmp(buf,"only coiled classes",19)) {
529 *mode |= ONLY_COILED_CLASSES;
530 printf("The paircoil like will be fraction of all positive classes likelihoods (no pdb- class.\n");
533 else if(!strncmp(buf,"ScoresAboveBound",16)) { /** Only output scores */
534 *mode |= ABOVE_BOUND_MODE; /* to score/out/txt files */
535 printf("Above Bound Mode\n"); /* that are above bound. */
538 #ifdef TEST_VERSION /** Only for testing..... ***/
539 else if(!strncmp(buf,"Prolines",8)) {
540 *mode ^= PROLINE_FREE_MODE; /* Score Prolines */
541 printf("Score Prolines\n");
545 else if(!strncmp(buf,"Show Seq",8)) {
546 *mode |= DEBUG_MODE; /* Option to get seq printed in */
547 /** printf("Show Sequences in log file\n"); **/ /* log file. */
548 *mode |= PRN_MODE; /* Print scores above bound */
550 else if(!strncmp(buf,"view",4)) {
551 *mode |= VIEW_MODE; /* Option to get a picture of */
552 printf("view\n"); /* STOCKS and PairCoils predicted*/
553 } /* coil regions in the seq. */
554 else if(!strncmp(buf,"ver",3)) {
555 *mode |= VER_MODE; /* Outputs 2 columns of maxseq */
556 printf("ver\n"); /* scores, first STOCK, then us */
557 *main_method = STOCK_PAIR;
560 else if(!strncmp(buf,"Just Scores",11)) {
562 printf ("The coil scores output will contain just scores, no text.");
565 #ifdef TEST_VERSION /** Only want release to do pairs. */
566 else if (!strncmp(buf,"singles",7))
567 *mode ^= PAIRCOIL_PAIRS; /* Since default is 1, just XOR it. */
569 else if (!strncmp(buf,"pairs",5))
570 *mode |= PAIRCOIL_PAIRS;
573 else if(!strncmp(buf,"prn",3)) {
574 *mode |= PRN_MODE; /* Print region scores above */
575 sscanf(buf,"prn = %lf", bound); /* threshhold prn to logfile. */
581 else if(!strncmp(buf,"bound",5)) {
582 *mode |= PRN_MODE; /* Print region scores above */
583 sscanf(buf,"bound = %lf", bound); /* threshhold prn to logfile. */
590 else if(!strncmp(buf,"window length",13)) {
592 if (!strncmp(buf,"window length =",15)) {
593 sscanf(buf,"window length = %d", &window_length[0]);
594 for (the_table =0; the_table < MAX_TABLE_NUMBER; the_table++) {
595 window_length[the_table] =window_length[0];
596 printf("window length %d = %d\n", the_table,
597 window_length[the_table]);
599 } /* All tables get same windowlength. **/
601 sscanf(buf,"window length %d", &the_table);
602 sscanf(buf,"window length %d = %d", &the_table,
603 &window_length[the_table-1]);
604 printf("window length %d = %d\n",the_table,window_length[the_table-1]);
608 else if(!strncmp(buf,"scale0s",7)) {
610 if (!strncmp(buf,"scale0s =",9)) {
611 sscanf(buf,"scale0s = %lf", &scale0s[0]);
612 for (the_table =0; the_table < MAX_TABLE_NUMBER; the_table++) {
613 scale0s[the_table] =scale0s[0];
614 printf("scale0s %d = %lf\n", the_table,
617 } /* All tables get same scale0. **/
619 sscanf(buf,"scale0s %d", &the_table);
620 sscanf(buf,"scale0s %d = %lf", &the_table,
621 &scale0s[the_table-1]);
622 printf("scale0s %d = %lf\n",the_table,scale0s[the_table-1]);
627 else if(!strncmp(buf,"scale0p",7)) {
629 if (!strncmp(buf,"scale0p =",9)) {
630 sscanf(buf,"scale0p = %lf", &scale0p[0]);
631 for (the_table =0; the_table < MAX_TABLE_NUMBER; the_table++) {
632 scale0p[the_table] =scale0s[0];
633 printf("scale0p %d = %lf\n", the_table,
636 } /* All tables get same scale0. **/
638 sscanf(buf,"scale0p %d", &the_table);
639 sscanf(buf,"scale0p %d = %lf", &the_table,
640 &scale0p[the_table-1]);
641 printf("scale0p %d = %lf\n",the_table,scale0p[the_table-1]);
644 /***************************************************************/
645 /***********************************************************/
649 else if(!strncmp(buf,"method",6)) { /* Reads in the method that */
650 sscanf(buf,"method = %s", name); /* should output to fout. */
652 printf("method = %s\n",name);
654 if (!strcmp(name,"PairCoil")) sprintf(name,"Coil");
655 for (i=0; i<NUMBER_METHODS;i++)
656 if (!strcmp(name,methodname[i]))
659 else if(!strncmp(buf,"preprocessor",12)) {/* Reads in the method that */
660 sscanf(buf,"preprocessor = %s", name); /* should output to fout. */
662 printf("preprocessor = %s\n",name);
664 if (!strcmp(name,"PairCoil")) sprintf(name,"Coil");
665 for (i=0; i<NUMBER_PREPROCESSORS;i++)
666 if (!strcmp(name,methodname[i]))
667 *main_preprocessor_method = i;
671 else if(!strncmp(buf,"default table",13)) {
672 sscanf(buf,"default table = %s", name);
673 printf ("default table = %s",name);
674 if (!strcmp(name, "dimer"))
675 *main_table =0; /* Table 0 should be dimer. */
676 else if (!strcmp(name, "trimer"))
677 *main_table =1; /* Table 1 should be trimer. */
678 else if (!strcmp(name, "combination"))
679 *main_table =2; /* Table 2 should be combination of table 0+1. */
680 else { /* Just get a table number. */
681 sscanf(name,"%d", main_table);
682 (*main_table)--; /* Human table number starts at 1, computer at 0 */
688 /***************The following options are for dimer-trimer likelihoods******/
689 else if(!strncmp(buf,"avg_max", 7)) {
690 sscanf(buf,"avg_max = %s", name);
691 if (!strcmp(name,"avg")) *avg_max=0;
692 else if (!strcmp(name,"max")) *avg_max=1;
693 else if (!strcmp(name,"both")) *avg_max=2;
695 fprintf(stderr, "avg_max = %d\n", *avg_max);
697 else if(!strncmp(buf,"offset", 6)) { /* -1 means every offset. */
698 sscanf(buf,"offset = %d", offset_to_use); /* 7 means max like offset */
699 fprintf(stderr, "offset for TableDiff = %d\n", *offset_to_use);
701 else if (!strncmp(buf,"use like line", 13)) {
702 *mode |= USE_LIKE_LINE;
703 fprintf(stderr,"Using likelihood line in Pair/SingleCoil computations, not the actual prob. formula.");
705 else if (!strncmp(buf,"weighted paircoil", 17)) {
706 *mode |= WEIGHTED_PROBS;
707 fprintf(stderr,"Using weights in paircoil computation.");
710 else if (!strncmp(buf,"do coil avg score", 17)) {
712 fprintf(stderr,"\nDoing Coil avg score\n");
715 else if (!strncmp(buf,"do coil max score", 17)) {
717 fprintf(stderr,"\nDoing Coil max score\n");
723 fprintf(stderr,"\nCouldn't find paircoil_config file.");
724 fprintf(stderr,"\n Assumed it would be located in %s.",buf);
725 fprintf(stderr,"\n You should either place it there, or set the environment");
726 fprintf(stderr,"\n variable PAIRCOIL_CONFIG to its location.\n");