11 #include "io_lib_header.h"
12 #include "util_lib_header.h"
13 #include "define_header.h"
14 #include "dp_lib_header.h"
16 int compare_constraint_list_entry ( const void*vx, const void*vy);
17 int compare_constraint_list_entry4bsearch ( const void*vx, const void*vy);
18 /*********************************************************************/
23 /*********************************************************************/
24 Constraint_list * make_test_lib(Constraint_list *CL);
25 Constraint_list *fork_line_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode,Job_TC *job, FILE *loca_stderr);
26 Constraint_list *fork_cell_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode,Job_TC *job, FILE *local_stderr);
27 Constraint_list *nfork_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode,Job_TC *job, FILE *local_stderr);
28 Constraint_list *fork_subset_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode, Job_TC *job, FILE *local_stderr);
29 int job2first_seq(Job_TC *job);
30 Constraint_list *produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode)
36 store_seq_type (S->type);
37 if ( CL==NULL)CL=declare_constraint_list ( S,NULL, NULL, 0,(strm(mem_mode, "disk"))?vtmpfile():NULL, NULL);
38 local_stderr=(CL->local_stderr!=NULL)?CL->local_stderr:stderr;
40 CL->local_stderr=vfopen("/dev/null", "w");
41 job=queue2heap(method2job_list ( method,S,weight, CL->lib_list,CL->DM, CL));
44 if ( get_nproc()==1 || njob==1)return nfork_produce_list (CL, S, method, weight, mem_mode,job, local_stderr);
45 else if (strstr ( CL->multi_thread, "jobcells"))return fork_cell_produce_list (CL, S, method, weight, mem_mode,job,local_stderr);
46 else if (strstr ( CL->multi_thread, "joblines"))return fork_line_produce_list (CL, S, method, weight, mem_mode,job, local_stderr);
47 else if (strstr ( CL->multi_thread, "jobs"))return fork_subset_produce_list (CL, S, method, weight, mem_mode,job, local_stderr); //Recommended default
48 else return nfork_produce_list (CL, S, method, weight, mem_mode,job, local_stderr);
50 int job2first_seq(Job_TC *job)
56 else if ( !job->param)return -1;
57 else if ( !(job->param)->seq_c) return -1;
58 seqlist=string2num_list ((job->param)->seq_c);
59 if (seqlist[0]<2)r=-1;
65 Constraint_list *fork_subset_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode, Job_TC *job, FILE *local_stderr)
67 //forks lines of the matrix
69 Job_TC *heap,*end,*start, ***jl;
71 int n_elements_in, n_new_elements;
75 int nproc, max_nproc, submited;
76 int cseq, seq, nlines;
79 max_nproc=nproc=get_nproc();
82 A-> alignment provided in a file
83 L-> list provided in a file
84 aln-> alignment computed and provided in a file
85 list->list computed and provided in a file
94 fprintf (local_stderr, "\n\tMethod %s: No Suitable Sequences [Type: %s]\n", method,M->seq_type);
98 job=queue2heap (job_list2multi_thread_job_list (job, CL->multi_thread, CL));
101 n_elements_in=CL->ne;
103 if (M)M->PW_CL=method2pw_cl ( M, CL);
104 pid_tmpfile=vcalloc (MAX(njob,get_nproc())+1, sizeof (char*));
105 pid_list =vcalloc (MAX_N_PID, sizeof (int *));
107 fprintf ( local_stderr, "\n\tMulti Core Mode: %d processors [subset]\n", get_nproc());
109 jl=split_job_list(job,get_nproc());
118 pid_tmpfile[a]=vtmpnam(NULL);
121 if (pid==0)//child process
126 initiate_vtmpnam(NULL);
127 fp=vfopen (pid_tmpfile[a],"a");
129 while (job!=end){todo++;job=job->c;}
135 if (a==0)output_completion ( local_stderr,done,todo,1, "Submit Job");
136 job=print_lib_job (job, "io->CL=%p control->submitF=%p control->retrieveF=%p control->mode=%s",duplicate_constraint_list4lib_computation (CL),submit_lib_job, retrieve_lib_job, CL->multi_thread );
137 job=submit_job (job);
139 t=((job->io)->CL)->ne*((job->io)->CL)->entry_len;
140 for (b=0; b<t; b++)fprintf ( fp, "%d ", ((job->io)->CL)->L[b]);
156 //wait for all processes to finish
157 for (a=0; a<npid; a++)
160 CL=read_constraint_list_raw_file (CL,pid_tmpfile[pid_list[pid]]);
161 remove(pid_tmpfile[pid_list[pid]]);
168 while (job) job=delete_job (job);
169 n_new_elements=CL->ne - n_elements_in;
170 compact_list (CL, n_elements_in,n_new_elements, "best");
171 compact_list (CL, 0, CL->ne, "default");
172 CL->local_stderr=local_stderr;
178 Constraint_list *fork_line_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode, Job_TC *job, FILE *local_stderr)
180 //forks lines of the matrix
184 int n_elements_in, n_new_elements;
188 int nproc, max_nproc, submited;
189 int cseq, seq, nlines;
191 max_nproc=nproc=get_nproc();
194 A-> alignment provided in a file
195 L-> list provided in a file
196 aln-> alignment computed and provided in a file
197 list->list computed and provided in a file
206 fprintf (local_stderr, "\n\tMethod %s: No Suitable Sequences [Type: %s]\n", method,M->seq_type);
211 job=queue2heap (job_list2multi_thread_job_list (job, CL->multi_thread, CL));
215 if (M)M->PW_CL=method2pw_cl ( M, CL);
216 n_elements_in=CL->ne;
218 /* Cf. parse method for possible out_mode flags*/
221 pid_tmpfile=vcalloc (njob, sizeof (char*));
223 pid_list =vcalloc (MAX_N_PID, sizeof (int *));
224 fprintf ( local_stderr, "\n\tMulti Core Mode: %d processors [jobline]\n", get_nproc());
227 //count the number of lines
233 seq=job2first_seq(job);
237 while (job && cseq==job2first_seq(job))job=job->c;
246 seq=job2first_seq(job);
250 pid_tmpfile[npid]=vtmpnam(NULL);
254 if (pid==0)//Child Process
256 initiate_vtmpnam(NULL);
257 while (job && cseq==job2first_seq(job))
259 job=print_lib_job (job, "io->CL=%p control->submitF=%p control->retrieveF=%p control->mode=%s",duplicate_constraint_list4lib_computation (CL),submit_lib_job, retrieve_lib_job, CL->multi_thread );
260 job=submit_job (job);
262 constraint_list2raw_file ((job->io)->CL,pid_tmpfile[npid], "a");
267 else //parent process
274 if (submited>max_nproc)
277 for (a=0; a<nproc; a++)
280 local_stderr=output_completion ( local_stderr,npid,nlines,1, "Processed Job");
283 CL=read_constraint_list_raw_file (CL,pid_tmpfile[index]);
284 remove (pid_tmpfile[index]);
296 for (a=0; a<submited; a++)
299 local_stderr=output_completion ( local_stderr,npid-(submited-a),nlines,1, "Processed Job");
302 CL=read_constraint_list_raw_file (CL,pid_tmpfile[index]);
303 remove (pid_tmpfile[index]);
309 n_new_elements=CL->ne - n_elements_in;
310 compact_list (CL, n_elements_in,n_new_elements, "best");
311 compact_list (CL, 0, CL->ne, "default");
312 CL->local_stderr=local_stderr;
319 Constraint_list *fork_cell_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode, Job_TC *job, FILE *local_stderr)
321 //forks cells of the matrix
325 int n_elements_in, n_new_elements;
329 int nproc, max_nproc;
332 max_nproc=nproc=get_nproc();
335 A-> alignment provided in a file
336 L-> list provided in a file
337 aln-> alignment computed and provided in a file
338 list->list computed and provided in a file
345 fprintf (local_stderr, "\n\tMethod %s: No Suitable Sequences [Type: %s]\n", method,M->seq_type);
350 job=queue2heap (job_list2multi_thread_job_list (job, CL->multi_thread, CL));
354 if (M)M->PW_CL=method2pw_cl ( M, CL);
355 n_elements_in=CL->ne;
357 /* Cf. parse method for possible out_mode flags*/
360 pid_tmpfile=vcalloc (njob, sizeof (char*));
361 pid_list =vcalloc (MAX_N_PID, sizeof (int *));
363 fprintf ( local_stderr, "\n\tMulti Core Mode: %d processors:\n", get_nproc());
368 job=print_lib_job (job, "io->CL=%p control->submitF=%p control->retrieveF=%p control->mode=%s",duplicate_constraint_list4lib_computation (CL),submit_lib_job, retrieve_lib_job, CL->multi_thread );
369 pid_tmpfile[npid]=vtmpnam(NULL);
373 initiate_vtmpnam (NULL);
374 job=submit_job (job);
376 constraint_list2raw_file ((job->io)->CL,pid_tmpfile[npid], "w");
387 if (submited>max_nproc)
389 for (a=0; a<nproc; a++)
392 local_stderr=output_completion ( local_stderr,npid,njob,1, "Processed Job");
395 CL=read_constraint_list_raw_file (CL,pid_tmpfile[index]);
396 remove (pid_tmpfile[index]);
403 for (a=0; a<submited; a++)
406 local_stderr=output_completion ( local_stderr,npid-a, npid,1, "Processed Job");
409 CL=read_constraint_list_raw_file (CL,pid_tmpfile[index]);
410 remove (pid_tmpfile[index]);
415 n_new_elements=CL->ne - n_elements_in;
416 compact_list (CL, n_elements_in,n_new_elements, "best");
417 compact_list (CL, 0, CL->ne, "default");
418 CL->local_stderr=local_stderr;
424 Constraint_list *nfork_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode, Job_TC *job, FILE *local_stderr)
430 int n_elements_in, n_new_elements;
434 A-> alignment provided in a file
435 L-> list provided in a file
436 aln-> alignment computed and provided in a file
437 list->list computed and provided in a file
444 fprintf (local_stderr, "\n\tMethod %s: No Suitable Sequences [Type: %s]\n", method,M->seq_type);
449 job=queue2heap (job_list2multi_thread_job_list (job, CL->multi_thread, CL));
455 if (M)M->PW_CL=method2pw_cl ( M, CL);
458 n_elements_in=CL->ne;
461 /* Cf. parse method for possible out_mode flags*/
469 local_stderr=output_completion ( local_stderr, b, n_aln+1,1, "Submit Job");
470 job=print_lib_job (job, "io->CL=%p control->submitF=%p control->retrieveF=%p control->mode=%s",duplicate_constraint_list4lib_computation (CL),submit_lib_job, retrieve_lib_job, CL->multi_thread );
471 job=submit_job (job);
472 if (retrieve_job (job))
474 CL=merge_constraint_list ((job->io)->CL, CL, "default");
475 free_constraint_list4lib_computation ( (job->io)->CL);
481 fprintf ( local_stderr, "\n");
483 while (job) job=delete_job (job);
485 n_new_elements=CL->ne - n_elements_in;
486 compact_list (CL, n_elements_in,n_new_elements, "best");
487 compact_list (CL, 0, CL->ne, "default");
488 CL->local_stderr=local_stderr;
496 Job_TC *job_list2multi_thread_job_list (Job_TC* ojob, char *mt, Constraint_list *CL)
500 char *met_file, *seq_file, *lib_file, *lib_list;
501 char common[1000], command[1000], T_file[100];
506 mtv=(mt==NULL)?0:atoi (mt);
507 if ( !mtv || mtv==1)return ojob;
509 HERE ("***"); exit (0);
511 nj=(queue2n(ojob)/mtv)+1;
514 met_file=vtmpnam (NULL);
515 TC_method2method_file ((ojob->param)->TCM,met_file=vtmpnam (NULL));
517 TCM=method_file2TC_method (method_name2method_file ("tc2"));
518 sprintf (T_file,"%s",(CL->S)->template_file);
522 seq_file=vtmpnam (NULL);
523 sprintf ( common, "%s -in M%s S%s -lib_only ", TCM->executable, met_file, seq_file);
524 if ( T_file[0] && check_file_exists (T_file))
526 strcat (common, " -template_file ");strcat (common, T_file); strcat ( common , " ");
529 njob=vcalloc ( 1, sizeof (Job_TC));
535 while ( ojob && n<nj)
539 lib_file=vtmpnam ( NULL);
540 lib_list=vtmpnam ( NULL);
541 fp=vfopen (lib_list, "w");
542 sprintf ( command, "%s -out_lib=%s -lib_list=%s -quiet", common, lib_file, lib_list);
543 njob->c=print_lib_job (NULL, "param->TCM=%p param->method=%s param->aln_c=%s io->in=%s io->out=%s",TCM, "tc2", command,seq_file, lib_file);
545 njob=queue_cat (njob, njob->c);
548 fprintf ( fp, "%s\n", (ojob->param)->seq_c);
550 if ( (++n)==nj){vfclose (fp);n=0;}
553 if (fp && n)vfclose (fp);
564 Job_TC *retrieve_lib_job ( Job_TC *job)
575 if ( job->status==EXIT_SUCCESS)
577 static char *log_output;
581 else if (strm2(M->out_mode, "aln", "A"))
583 io->CL=read_constraint_list (io->CL,io->out,"aln","disk",M->weight);
585 else if (strm2(M->out_mode, "lib","L"))
587 io->CL=read_constraint_list (io->CL,io->out,"lib","disk",M->weight);
595 int add_method_output2method_log (char *l,char *command,Alignment *A, Constraint_list *CL, char *io_file)
599 static char *file, *log_file;
602 if ( set && log_file==NULL && l==NULL) return 0;
603 if (!set ){log_file=get_string_variable ("method_log");if (log_file && strm (log_file, "no"))log_file=NULL; set=1;}
604 if (!file)file=vtmpnam (NULL);
607 else if (!l && log_file) l=log_file;
611 if (!header){printf_file ( l, "w", "# CONC_MSF_FORMAT_01\n");header=1;}
612 if (command)printf_file (l, "a", "%s\n#----------------------------------------------\n#%s\n", TC_REC_SEPARATOR,command);
619 output_fasta_aln (io_file, A);
624 vfclose (save_constraint_list ( CL, 0, CL->ne,io_file, NULL, "ascii",CL->S));
627 file_cat (io_file,l);
635 Job_TC *submit_lib_job ( Job_TC *job)
646 add_method_output2method_log (NULL, p->aln_c, NULL, NULL, NULL);
647 if ( getenv4debug ("DEBUG_LIBRARY"))fprintf ( stderr, "\n[DEBUG_LIBRARY:produce_list] Instruction: %s\n", p->aln_c);
653 else if (strm4 (M->out_mode,"A", "L", "aln", "lib"))
656 seq_list2in_file ( M, (io->CL)->S, p->seq_c, io->in);
658 my_system (p->aln_c);/*Multi Threaded jobs must be sent here*/
660 add_method_output2method_log (NULL,NULL, NULL, NULL, io->out);
662 if (!evaluate_sys_call_io (io->out,p->aln_c, "") || (strm (M->out_mode, "aln") && !(is_aln (io->out) || is_seq(io->out))) )
664 add_warning (stderr, "\nFAILED TO EXECUTE:%s [SERIOUS:%s]", p->aln_c, PROGRAM);
665 job->status=EXIT_FAILURE;
666 //myexit (EXIT_FAILURE);
670 else if ( strm2 (M->out_mode, "fA", "fL"))
672 io->CL= seq2list(job);
675 add_warning (stderr, "\nFAILED TO EXECUTE:%s [SERIOUS:%s]", p->aln_c, PROGRAM);
676 job->status=EXIT_FAILURE;
681 fprintf ( stderr, "\nERROR: Unknown out_mode=%s for method[FATAL:%s]\n", M->out_mode, M->executable);
682 myexit (EXIT_FAILURE);
690 Job_TC* method2job_list ( char *method_name,Sequence *S, char *weight, char *lib_list, Distance_matrix *DM, Constraint_list *CL)
693 static char *fname, *bufS, *bufA;
702 1- a pre computed alignment out_mode=A
703 2- a precomputed Library out_mode=L
704 3- a method producing an alignment out_mode=aln
705 4- a method producing an alignment out_mode=list
706 5- a function producing an alignment out_mode=faln
707 6- a function producing a library out_mode=flist
712 fname=vcalloc ( 1000, sizeof (char));
713 bufS=vcalloc ( S->nseq*10, sizeof (char));
716 /*Make sure that fname is a method*/
719 sprintf(fname, "%s", method_name);
721 if ( fname[0]=='A' || fname[0]=='L')
723 method=method_file2TC_method("no_method");
724 sprintf ( method->out_mode, "%c", fname[0]);
726 if (!strm (weight, "default"))sprintf ( method->weight, "%s", weight);
728 return print_lib_job(NULL,"param->out=%s param->TCM=%p",fname+1, method);
730 else if ( fname[0]=='M' && is_in_pre_set_method_list (fname+1))
735 else if ( is_in_pre_set_method_list (fname))
742 if ( check_file_exists ( fname));
743 else if (fname[0]=='M' && check_file_exists(fname+1));
746 sprintf ( buf, "%s/%s", get_methods_4_tcoffee(), fname);
747 if( check_file_exists(buf)){sprintf ( fname, "%s", buf);}
750 fprintf ( stderr, "\n%s (%s) is not a valid method [FATAL:%s]\n", buf,fname, PROGRAM);
751 myexit (EXIT_FAILURE);
757 method=method_file2TC_method(fname);
758 job=print_lib_job (NULL, "param->TCM=%p", method);
761 if (!strm (weight, "default"))sprintf ( method->weight, "%s", weight);
763 sprintf ( aln_mode, "%s", method->aln_mode);
764 sprintf ( out_mode, "%s", method->out_mode);
767 if (lib_list && lib_list[0])
769 static char **lines, **list=NULL;
774 if ( lines) free_char (lines, -1);
777 if ( strstr (lib_list, "prune"))
779 lines=file2lines (list2prune_list (S,DM->similarity_matrix));
783 lines=file2lines (lib_list);
790 if (list) free_char (list, -1);
791 if (isblanc (lines[a]))continue;
793 list=string2list (lines[a]);n=atoi(list[1]);
794 if ( n> 2 && strm (aln_mode, "pairwise"))continue;
795 if ( n==2 && strm (aln_mode, "multiple"))continue;
797 for (i=2; i<n+2; i++)
799 if ( is_number (list[i]));
800 else if ((x=name_is_in_list (list[i], S->name, S->nseq, 100))!=-1)sprintf(list[i], "%d", x);
803 add_warning ( stderr, "\nWARNING: %s is not part of the sequence dataset \n", list[i]);
807 sprintf ( bufS, "%s", list[1]);
808 for ( i=2; i<n+2; i++) {strcat (bufS, " ");strcat ( bufS, list[i]);}
811 bufA=make_aln_command (method, in=vtmpnam(NULL),out=vtmpnam(NULL));
813 if (strrchr(bufA, '>')==NULL)strcat (bufA,TO_NULL_DEVICE);
814 if ( check_seq_type ( method, bufS, S))
816 job->c=print_lib_job (NULL, "param->TCM=%p param->method=%s param->aln_c=%s param->seq_c=%s io->in=%s io->out=%s ", method, fname, bufA, bufS, in, out);
817 job=queue_cat (job, job->c);
823 else if ( strcmp (aln_mode, "multiple")==0)
828 sprintf (bufS, "%d",S->nseq);
829 for (d=0; d< S->nseq; d++)
831 sprintf ( buf," %d",d);
835 bufA=make_aln_command (method, in=vtmpnam(NULL),out=vtmpnam(NULL));
837 if (strrchr(bufA, '>')==NULL)strcat (bufA,TO_NULL_DEVICE);
839 if ( check_seq_type ( method, bufS, S))
842 job->c=print_lib_job (NULL, "param->TCM=%p param->method=%s param->aln_c=%s param->seq_c=%s io->in=%s io->out=%s ", method, fname, bufA, bufS, in, out, S->template_file);
844 job=queue_cat (job, job->c);
850 else if ( strstr(aln_mode, "pairwise"))
853 int do_mirror, do_self, x, y, id;
854 do_mirror=(strstr(aln_mode, "m_"))?1:0;
855 do_self=(strstr(aln_mode, "s_"))?1:0;
858 for (x=0; x< S->nseq; x++)
859 for ( y=(do_mirror)?0:x; y< S->nseq; y++)
862 id=DM->similarity_matrix[x][y];
864 if ( x==y && !do_self);
865 else if ( !is_in_range(id,method->minid, method->maxid));
868 sprintf (bufS, "2 %d %d",x,y);
869 bufA=make_aln_command (method,in=vtmpnam(NULL),out=vtmpnam (NULL));
871 if (strrchr(bufA, '>')==NULL)strcat (bufA, TO_NULL_DEVICE);
872 if (check_seq_type (method, bufS, S))
874 job->c=print_lib_job (job->c, "param->TCM=%p param->method=%s param->aln_c=%s param->seq_c=%s io->in=%s io->out=%s ",method,fname,bufA, bufS, in, out);
875 job=queue_cat (job, job->c);
877 else if ( method->seq_type[0]=='P' && hijack_P_jobs)
879 //Hijack _P_ jobs without enough templates
880 static TC_method *proba_pairM;
882 fprintf (stderr, "\n\t Information: Method %s cannot be applied to [%s vs %s]. Use proba_pair instead", method, (CL->S)->name[x], (CL->S)->name [y]);
885 proba_pairM=method_file2TC_method(method_name2method_file ("proba_pair"));
886 proba_pairM->PW_CL=method2pw_cl(proba_pairM, CL);
888 job->c=print_lib_job (job->c, "param->TCM=%p param->method=%s param->aln_c=%s param->seq_c=%s io->in=%s io->out=%s ",proba_pairM,fname,bufA, bufS, in, out);
889 job=queue_cat (job, job->c);
900 int check_seq_type (TC_method *M, char *list,Sequence *S)
903 int s1, s2, n1, nseq, ntype, i;
908 slist=string2num_list (list);
911 ntype=strlen (M->seq_type);
916 /*Profiles and Sequences MUST NOT be distinguished so that sequences and profiles can easily be aligned*/
917 if ( tolower(t1)=='r')t1='S';
918 if ( tolower(t2)=='r')t2='S';
921 if ( strm ( M->aln_mode, "pairwise") && nseq>2)n1=0;
922 else if (strm ( M->aln_mode, "multiple" ) && ntype>1)n1=0;
926 for (n1=0, i=0; i<nseq; i++)
931 n1+=(strchr (T1->seq_type,t1) || check_profile_seq_type (S, s1, t1))?1:0;
947 s1_has_t1=(strchr ( T1->seq_type, t1) || check_profile_seq_type (S, s1, t1))?1:0;
948 s1_has_t2=(strchr ( T1->seq_type, t2) || check_profile_seq_type (S, s1, t2))?1:0;
949 s2_has_t1=(strchr ( T2->seq_type, t1) || check_profile_seq_type (S, s2, t1))?1:0;
950 s2_has_t2=(strchr ( T2->seq_type, t2) || check_profile_seq_type (S, s2, t2))?1:0;
951 n1=((s1_has_t1 && s2_has_t2) || (s1_has_t2 && s2_has_t1))?1:0;
958 int check_profile_seq_type (Sequence *S, int i, char t)
964 /*returns 1 if the sequence S is associated with a profile containing the right sequence*/
965 A=seq2R_template_profile (S, i);
966 if (A==NULL || A->S==NULL) return 0;
967 for ( a=0; a< A->nseq; a++)
971 if ( T && strchr( T->seq_type,t))return 1;
978 char **method_list2method4dna_list ( char **list, int n)
983 if ( !buf)buf=vcalloc ( 1000, sizeof (char));
985 if ( !list || n==0)return list;
986 buf=vcalloc ( 1000, sizeof (char));
988 for ( a=0; a< n; a++)
991 sprintf ( buf,"%s",list[a]);
993 if ( strm ( list[a], "4dna"));
1000 para=string2list2 (list[a], "@");
1001 sprintf ( buf, "%s4dna", para[1]);
1002 if (method_name2method_file (buf) || method_name2method_file(buf+1))
1004 sprintf ( list[a],"%s", buf);
1005 for (b=2; b< atoi (para[0]); b++)
1007 strcat (list[a], "@");
1008 strcat (list[a], para[b]);
1012 free_char (para, -1);
1018 int is_in_pre_set_method_list ( char *method)
1025 new_name=method_name2method_file (method);
1027 if ( !new_name) return 0;
1031 sprintf ( method, "%s", new_name);
1035 char *** display_method_names (char *mode, FILE *fp)
1037 char ***list, ***l2;
1038 int n=0, a, ml1=0, ml2=0, ml3=0;
1046 list=produce_method_file (NULL);
1047 l2=declare_arrayN(3,sizeof (char), 1000, 10, 100);
1049 fprintf ( fp, "\n####### Compiling the list of available methods ... (will take a few seconds)\n");
1055 sprintf (l2[a][0], "%s", method_file_tag2value (list[a][1],"ADDRESS"));
1056 sprintf (l2[a][1], "%s", method_file_tag2value (list[a][1],"PROGRAM"));
1057 sprintf (l2[a][2], "%s", method_file_tag2value (list[a][1],"ALN_MODE"));
1058 sprintf (l2[a][3], "%s", method_file_tag2value (list[a][1],"SEQ_TYPE"));
1059 ml1=MAX((strlen (list[a][0])),ml1);
1060 ml2=MAX((strlen (l2 [a][0])),ml2);
1061 ml3=MAX((strlen (l2 [a][1])),ml3);
1062 l2[a][4][0]= check_program_is_installed (l2[a][1],NULL,NULL,l2[a][0],NO_REPORT);
1063 if (l2[a][4][0])l2[a][5]=pg2path (l2[a][1]);
1067 fprintf ( fp, "\n####### Methods For which an Interface is available in T-Coffee\n");
1068 fprintf ( fp, "You must install the packages yourself when required (use the provided address)\n");
1069 fprintf ( fp, "Contact us if you need an extra method to be added [%s]\n", EMAIL);
1072 fprintf ( fp, "\n****** Pairwise Sequence Alignment Methods:\n");
1073 fprintf ( fp, "--------------------------------------------\n");
1077 if ( strm (l2[a][2], "pairwise") && !strstr (l2[a][3], "P"))
1078 fprintf ( fp, "%-*s %-*s [pg: %*s is %s Installed][%s]\n", ml1,list[a][0],ml2, l2[a][0], ml3,l2[a][1], (l2[a][4][0]==0)?"NOT":"",(l2[a][5])?l2[a][5]:"");
1082 fprintf ( fp, "\n****** Pairwise Structural Alignment Methods:\n");
1083 fprintf ( fp, "--------------------------------------------\n");
1087 if ( strm (l2[a][2], "pairwise") && strstr (l2[a][3], "P"))
1088 fprintf ( fp, "%-*s %-*s [pg: %*s is %s Installed][%s]\n", ml1,list[a][0],ml2, l2[a][0], ml3,l2[a][1], (l2[a][4][0]==0)?"NOT":"",(l2[a][5])?l2[a][5]:"");
1091 fprintf ( fp, "\n****** Multiple Sequence Alignment Methods:\n");
1092 fprintf ( fp, "--------------------------------------------\n");
1096 if ( strm (l2[a][2], "multiple"))
1097 fprintf ( fp, "%-*s %-*s [pg: %*s is %s Installed][%s]\n", ml1,list[a][0],ml2, l2[a][0], ml3,l2[a][1], (l2[a][4][0]==0)?"NOT":"",(l2[a][5])?l2[a][5]:"");
1100 fprintf ( fp, "\n####### Prediction Methods available to generate Templates\n");
1101 fprintf ( fp, "-------------------------------------------------------------\n");
1105 if ( strm (l2[a][2], "predict"))
1106 fprintf ( fp, "%-*s %-*s [pg: %*s is %s Installed][%s]\n", ml1,list[a][0],ml2, l2[a][0], ml3,l2[a][1], (l2[a][4][0]==0)?"NOT":"",(l2[a][5])?l2[a][5]:"");
1109 fprintf ( fp, "\n\n\nAll these Methods are supported by T-Coffee, but you HAVE to install them yourself [use the provided address]\n\n");
1110 fprintf ( fp, "\nThese methods were selected because they are freeware opensource, easy to install and well supported");
1111 fprintf ( fp, "\nContact us if you need an extra method to be added [%s]\n", EMAIL);
1116 char* method_name2method_file (char *method)
1124 if ( check_file_exists (method) || (toupper(method[0])==method[0] && check_file_exists (method+1)))return NULL;
1126 if ( (p=strstr (method, "@"))!=NULL && !strstr (method, "em@"))p[0]='\0';
1127 mlist=produce_method_file (method);
1134 if ( lstrstr (method,mlist[a][0])){fname=mlist[a][1];break;}
1138 if ( fname==NULL) return NULL;
1141 sprintf (address, "%s", method_file_tag2value (fname,"ADDRESS"));
1142 sprintf (program, "%s", method_file_tag2value (fname,"PROGRAM"));
1143 check_program_is_installed (program,NULL,NULL,address,INSTALL_OR_DIE);
1144 if ( (method=strstr (method, "EP@"))!=NULL)
1149 list=string2list2 ( method, "@");
1150 fp=vfopen (fname, "a");
1151 for ( a=2; a<atoi (list[0]); a+=2)
1153 fprintf (fp, "%s %s\n", list[a], list[a+1]);
1158 free_char (list, -1);
1163 char *method_file_tag2value (char *method, char *tag)
1167 static char *buf, *line;
1168 if (!buf) buf=vcalloc ( 1000, sizeof (char));
1173 line=vcalloc (LONG_STRING+1, sizeof ( char));
1176 fp=vfopen (method, "r");
1177 while ( (c=fgetc (fp))!=EOF)
1180 fgets ( line,LONG_STRING, fp);
1182 if ( (line && (line[0]=='*' || line[0]=='#' || line[0] == '$'|| line[0]==' ' || line[0]=='\0' )));
1183 else if ( (p=strstr (line, tag )))
1186 sscanf (p+strlen (tag), " %s" , buf);
1194 struct TC_method * method_file2TC_method( char *method)
1197 static char *subcommand;
1202 //<EXECUTABLE><PARAM1><IN_FLAG><seq_file><PARAM2><OUT_FLAG><outname><PARAM>
1205 line=vcalloc (LONG_STRING+1, sizeof ( char));
1206 subcommand=vcalloc ( LONG_STRING, sizeof (char));
1209 m=vcalloc ( 1, sizeof (TC_method));
1211 /*set default parameter values*/
1212 m->gop=m->gep=UNDEFINED;
1213 sprintf (m->seq_type, "S");
1214 sprintf (m->weight, "sim");
1218 fp=vfopen (method, "r");
1219 while ( (c=fgetc (fp))!=EOF)
1222 fgets ( line,LONG_STRING, fp);
1225 line=substitute (line, "\n", " ");
1226 line=substitute (line, "%s", " ");
1227 line=substitute (line, "%e", "=");
1228 line=substitute (line, "%m", "-");
1230 if ( (line && (line[0]=='*' || line[0]=='#' || line[0] == '$'|| line[0]==' ' || line[0]=='\0' )))subcommand[0]='\0';
1231 //Parse PARAM, PARM1 and PARAM2 first because they may contain keywords
1232 else if ( (p=strstr (line, "PARAM1" )))
1234 sprintf (subcommand, " %s ", p+6);
1235 strcat ( m->param1, subcommand);
1237 else if ( (p=strstr (line, "PARAM2" )))
1239 sprintf (subcommand, " %s ", p+6);
1240 strcat ( m->param2, subcommand);
1242 else if ( (p=strstr (line, "PARAM" )))
1244 sprintf (subcommand, " %s ", p+5);
1245 strcat ( m->param, subcommand);
1246 }else if ( (p=strstr (line, "EXECUTABLE2" )))
1248 sscanf (p, "EXECUTABLE2 %s", m->executable2);
1250 else if ( (p=strstr (line, "EXECUTABLE" )))
1252 sscanf (p, "EXECUTABLE %s", m->executable);
1254 else if ( (p=strstr (line, "IN_FLAG2" ))) sscanf (p, "IN_FLAG2 %s" , m->in_flag2);
1255 else if ( (p=strstr (line, "IN_FLAG" ))) sscanf (p, "IN_FLAG %s" , m->in_flag);
1256 else if ( (p=strstr (line, "OUT_FLAG" ))) sscanf (p, "OUT_FLAG %s" , m->out_flag);
1257 else if ( (p=strstr (line, "OUT_MODE" ))) sscanf (p, "OUT_MODE %s" , m->out_mode);
1258 else if ( (p=strstr (line, "ALN_MODE" ))) sscanf (p, "ALN_MODE %s" , m->aln_mode);
1259 else if ( (p=strstr (line, "SEQ_TYPE" ))) sscanf (p, "SEQ_TYPE %s" , m->seq_type);
1260 else if ( (p=strstr (line, "WEIGHT" ))) sscanf (p, "WEIGHT %s" , m->weight);
1261 else if ( (p=strstr (line, "MATRIX" ))){ sscanf (p, "MATRIX %s" , m->matrix);}
1262 else if ( (p=strstr (line, "GOP" ))) sscanf (p, "GOP %d" , &m->gop);
1263 else if ( (p=strstr (line, "GEP" ))) sscanf (p, "GEP %d" , &m->gep);
1264 else if ( (p=strstr (line, "MAXID" ))) sscanf (p, "MAXID %d" , &m->maxid);
1265 else if ( (p=strstr (line, "MINID" ))) sscanf (p, "MINID %d" , &m->minid);
1275 int TC_method2method_file( struct TC_method*m,char *fname )
1279 fp=vfopen ( fname, "w");
1280 if ( m->executable[0])fprintf (fp, "EXECUTABLE %s\n", m->executable);
1281 if (m->in_flag[0])fprintf (fp, "IN_FLAG %s\n", m->in_flag);
1282 if (m->out_flag[0])fprintf (fp, "OUT_FLAG %s\n", m->out_flag);
1283 if (m->out_mode[0])fprintf (fp, "OUT_MODE %s\n", m->out_mode);
1284 if (m->aln_mode[0])fprintf (fp, "ALN_MODE %s\n", m->aln_mode);
1285 if (m->seq_type)fprintf (fp, "SEQ_TYPE %s\n", m->seq_type);
1286 if (m->weight[0])fprintf (fp, "WEIGHT %s\n", m->weight);
1287 if (m->matrix[0])fprintf (fp, "MATRIX %s\n", m->matrix);
1288 if (m->gop!=UNDEFINED)fprintf (fp, "GOP %d\n", m->gop);
1289 if (m->gep!=UNDEFINED)fprintf (fp, "GEP %d\n", m->gep);
1290 if (m->minid!=0 )fprintf (fp, "MINID %d\n", m->minid);
1291 if (m->maxid!=100)fprintf (fp, "MAXID %d\n", m->maxid);
1292 if (m->param[0])fprintf (fp, "PARAM %s\n", m->param);
1293 if (m->param1[0])fprintf (fp, "PARAM1 %s\n", m->param1);
1294 if (m->param2[0])fprintf (fp, "PARAM1 %s\n", m->param2);
1295 if (m->in_flag2[0])fprintf (fp, "IN_FLAG2 %s\n", m->in_flag2);
1301 char *make_aln_command(TC_method *m, char *seq, char *aln)
1306 // sprintf ( buf, "%s %s %s%s %s%s %s", m->executable, m->param1, m->in_flag, seq,m->param2, m->out_flag,aln, m->param);
1307 sprintf ( buf, "%s %s %s%s %s %s%s %s", m->executable, m->param1, m->in_flag, seq,m->param2, m->out_flag,aln, m->param);
1308 command=vcalloc ( strlen (buf)+100, sizeof (char));
1309 sprintf ( command, "%s", buf);
1312 command=substitute (command, "&bnsp", " ");
1313 command=substitute (command, "no_name", "");
1322 /*********************************************************************/
1327 /*********************************************************************/
1330 int dump_constraint_list (Constraint_list *CL)
1334 if (!CL->L) return 0;
1339 for ( a=0; a<CL->ne; a++)
1340 for (b=0; b<CL->entry_len; b++)
1341 vwrite_clist (CL, a, b, L[a*CL->entry_len+b]);
1343 vfree (CL->L); CL->L=NULL;
1347 int vread_clist ( Constraint_list *CL, int a, int b )
1359 fseek (CL->fp, a*CL->el_size*CL->entry_len+b*CL->el_size, SEEK_SET);
1360 fread (&x, CL->el_size, 1, CL->fp);
1366 return CL->L[a*CL->entry_len+b];
1370 return (CL->M)[a][b];
1379 int vwrite_clist ( Constraint_list *CL, int a, int b, CLIST_TYPE x)
1383 CL->residue_indexed=0;
1388 fseek (CL->fp, a*CL->el_size*CL->entry_len+b*CL->el_size, SEEK_SET);
1389 fwrite(&x, CL->el_size, 1, CL->fp);
1396 i=a*CL->entry_len+b;
1400 p=(Memcontrol *)CL->L;
1402 l=(int)p[0].size/p[0].size_element;
1403 //read_size_int (CL->L,sizeof (int));
1408 (CL->L)=vcalloc (l,sizeof (int));
1414 (CL->L)=vrealloc ( (CL->L),l*sizeof (int));
1418 if (((a*CL->entry_len)+b)>=(CL->entry_len*CL->max_L_len))
1423 (CL->L)=vcalloc ((CL->chunk+a)*CL->entry_len+b, sizeof (int));
1427 CL->max_L_len+=CL->chunk;
1428 (CL->L)=vrealloc ( (CL->L),CL->entry_len*sizeof (int)*CL->max_L_len+b);
1439 /*********************************************************************/
1441 /* INDEXING FUNCTIONS */
1444 /*********************************************************************/
1446 Constraint_list *index_res_constraint_list ( Constraint_list *CL, int field)
1449 function documentation: start
1450 Constraint_list *index_res_constraint_list ( Constraint_list *CL, int field)
1451 This function reorganises the content of the CL->L matrix, so that a single look up gives
1452 the constraints associated with any residue
1454 1-if CL->residue_indexed=1 return
1455 2-CL->residue_index[Seq X][Res Y of Seq X][0]=Z
1456 Z=Number of residues matching X(Y)*3+1
1457 CL->residue_index[Seq X][Res Y of Seq X][0]=Z
1458 CL->residue_index[Seq X][Res Y of Seq X][c+0]=seq W
1459 CL->residue_index[Seq X][Res Y of Seq X][c+1]=res V
1460 CL->residue_index[Seq X][Res Y of Seq X][c+2]=weight W(V) Vs X(Y)
1462 NOTE: Works All right with a sequence against itself
1463 NOTE: Any modification of CL->L should result in residue_indexed to be reset
1464 function documentation: end
1466 int a, b, s1, s2, r1, r2, w;
1474 if ( CL->residue_indexed && CL->residue_field==field);
1478 if ( CL->residue_index)
1480 for ( a=0; a< (CL->S)->nseq; a++)
1481 for ( b=0; b<= (CL->S)->len[a]; b++)
1483 vfree(CL->residue_index[a][b]);
1484 CL->residue_index[a][b]=vcalloc_nomemset (1, sizeof (int));
1485 CL->residue_index[a][b][0]=1;
1488 else if ( !CL->residue_index)
1492 CL->residue_index=vcalloc_nomemset ( (CL->S)->nseq, sizeof (int**));
1493 for ( a=0; a< (CL->S)->nseq; a++)
1496 CL->residue_index[a]=vcalloc_nomemset ( ((CL->S)->len[a]+1), sizeof (int*));
1497 for ( b=0; b<= (CL->S)->len[a]; b++)
1499 CL->residue_index[a][b]=vcalloc_nomemset (1,sizeof (int));
1500 CL->residue_index[a][b][0]=1;
1504 for (a=0;a<CL->ne; a++)
1507 s1=vread_clist (CL, a, SEQ1);
1508 s2=vread_clist (CL, a, SEQ2);
1509 r1=vread_clist (CL, a, R1);
1510 r2=vread_clist (CL, a, R2);
1511 w=vread_clist (CL, a, field);
1514 CL->residue_index[s1][r1][0]+=3;
1515 CL->residue_index[s1][r1]=vrealloc ( CL->residue_index[s1][r1], CL->residue_index[s1][r1][0]*sizeof (int));
1516 CL->residue_index[s1][r1][CL->residue_index[s1][r1][0]-3]=s2;
1517 CL->residue_index[s1][r1][CL->residue_index[s1][r1][0]-2]=r2;
1518 CL->residue_index[s1][r1][CL->residue_index[s1][r1][0]-1]=w;
1520 CL->residue_index[s2][r2][0]+=3;
1521 CL->residue_index[s2][r2]=vrealloc ( CL->residue_index[s2][r2], CL->residue_index[s2][r2][0]*sizeof (int));
1522 CL->residue_index[s2][r2][CL->residue_index[s2][r2][0]-3]=s1;
1523 CL->residue_index[s2][r2][CL->residue_index[s2][r2][0]-2]=r1;
1524 CL->residue_index[s2][r2][CL->residue_index[s2][r2][0]-1]=w;
1527 CL->residue_indexed=1;
1528 CL->residue_field=field;
1533 Constraint_list *index_constraint_list ( Constraint_list *CL)
1536 Function Documentation: start
1537 Constraint_list *index_constraint_list ( Constraint_list *CL);
1538 Indexes a constraint list
1539 1-Checks the flag seq_indexed
1541 CL->start_index[seq1][seq2] indicatse the first position for seq1 Vs seq2
1542 CL->end_index[seq1][seq3] indicatse the last position for seq1 Vs seq2
1543 Any modif to CL->L should cause the flag 1 to be set to 0;
1544 Function Documentation: end
1546 int a, csA, csB, sA, sB;
1549 if ( CL->seq_indexed);
1552 if ( CL->start_index!=NULL)free_int ( CL->start_index,-1);
1553 CL->start_index=declare_int ( (CL->S)->nseq, (CL->S)->nseq);
1555 if ( CL->end_index!=NULL)free_int ( CL->end_index,-1);
1556 CL->end_index=declare_int ( (CL->S)->nseq, (CL->S)->nseq);
1558 csA=vread_clist (CL, 0, SEQ1);
1559 csB=vread_clist (CL, 0, SEQ2);
1561 CL->start_index[csA][csB]=0;
1562 CL->start_index[csB][csA]=0;
1563 for ( a=1; a<CL->ne; a++)
1565 sA=vread_clist (CL, a, SEQ1);
1566 sB=vread_clist (CL, a, SEQ2);
1567 if (sA!=csA || sB!=csB)
1569 CL->end_index[csA][csB]=a;
1570 CL->end_index[csB][csA]=a;
1573 CL->start_index[csA][csB]=a;
1574 CL->start_index[csB][csA]=a;
1577 CL->end_index[csB][csA]=CL->ne;
1578 CL->end_index[csA][csB]=CL->ne;
1585 char ** reindex_constraint_list (char **profile, int np,char **list, int *inL, Sequence *S)
1588 int ***cache, **index, *entry;
1589 char **nlist, **cons, *nlib_name;
1592 Constraint_list *CL, *NCL;
1596 /*1: Pre-Process the profiles*/
1597 cache=vcalloc (np, sizeof (int**));
1598 cons=vcalloc (np, sizeof (char*));
1599 P=vcalloc (np, sizeof (Alignment *));
1601 for ( a=0; a< np; a++)
1604 A=P[a]=main_read_aln (profile[a], NULL);
1606 ca=cache[a]=declare_int (A->nseq, A->len_aln+1);
1607 cons[a]=aln2cons_seq_mat ( A, "blosum62mt");
1608 for (b=0;b<A->nseq; b++)
1610 for (e=0,c=0; c<A->len_aln; c++)
1612 if (is_gap(A->seq_al[b][c]));
1613 else ca[b][++e]=c+1;
1618 /*2: Index The Sequences*/
1619 index=declare_int (S->nseq,2);
1620 for (a=0; a<S->nseq; a++)index[a][0]=index[a][1]=-1;
1621 for (a=0; a< S->nseq; a++)
1626 for (b=0; b< np; b++)
1628 if ((p=name_is_in_list(name, (P[b])->name, (P[b])->nseq, MAXNAMES))!=-1)
1636 /*3: Read the primary Library*/
1638 nlist=declare_char (read_array_size_new ((void *)list), read_array_size_new ((void *)list[0]));
1639 for (nl=0,a=0; a< l; a++)
1640 if ( list[a][0]=='L' || list[a][0]=='A')
1641 nlist[nl++]=list[a];
1643 CL=declare_constraint_list ( S,NULL, NULL, 0,NULL, NULL);
1644 CL=read_n_constraint_list (nlist,nl,NULL,NULL,"sim",S->type,stdout, CL, "S");
1647 NS=fill_sequence_struc (np, cons, profile);
1648 NCL=declare_constraint_list ( NS,NULL, NULL, 0,NULL, NULL);
1649 entry=vcalloc ( CL->entry_len, CL->el_size);
1650 for (a=0; a<CL->ne; a++)
1652 int s1, s2, r1, r2, ps1, ps2, pps1, pps2;
1654 entry=extract_entry (entry, a, CL);
1655 s1=entry[SEQ1]; s2=entry[SEQ2];
1656 r1=entry[R1]; r2=entry[R2];
1657 ps1=index[s1][0];ps2=index[s2][0];
1658 pps1=index[s1][1];pps2=index[s2][1];
1660 if (ps1==ps2 || ps1==-1 || ps2==-1)continue;
1664 entry[R1]=cache[ps1][pps1][r1];
1665 entry[R2]=cache[ps2][pps2][r2];
1667 add_entry2list (entry, NCL);
1671 compact_list (NCL, 0, NCL->ne, "default");
1672 nlib_name=vtmpnam(NULL);
1673 vfclose(save_constraint_list ( NCL, 0, NCL->ne,nlib_name, NULL, "lib",NCL->S));
1676 nlist=declare_char (read_array_size_new ((void *)list), read_array_size_new ((void *)list[0]));
1677 for (nl=0,a=0; a< l; a++)
1678 if ( list[a][0]!='L' && list[a][0]!='A')
1679 sprintf (nlist[nl++], "%s",list[a]);
1680 sprintf (nlist[nl++], "L%s", nlib_name);
1682 free_arrayN ((void *)cache, 3);
1683 free_arrayN ((void *)cons, 2);
1684 free_arrayN ((void *)index, 2);
1686 for (a=0;a<np; a++)free_aln (P[a]);
1688 free_constraint_list_full (CL);
1689 free_constraint_list_full (NCL);
1696 Constraint_list * progressive_index_res_constraint_list ( Alignment *A, int *ns, int **ls, Constraint_list *CL)
1700 static Constraint_list *NCL;
1702 int a, b, c, d,s,l, max_len;
1712 NCL=duplicate_constraint_list (CL);
1723 if (NCL->residue_index)
1725 free_arrayN((void*)NCL->residue_index, 3);
1726 NCL->residue_index=NULL;
1729 for ( a=0; a< S->nseq; a++)
1731 sprintf ( NS->seq[a], "%s", S->seq[a]);
1732 NS->len[a]=strlen (S->seq[a]);
1736 for ( a=0; a<2; a++)
1738 s=A->order[ls[a][0]][0];
1740 NS->seq[s]=sub_aln2cons_seq_mat (A, ns[a], ls[a], "blosum62mt");
1741 NS->len[s]=strlen (NS->seq[s]);
1743 for ( max_len=0, a=0; a<S->nseq; a++)max_len=MAX(max_len, S->len[a]);
1744 index_seq=declare_int ( NS->nseq, max_len+1);
1745 index_res=declare_int ( NS->nseq, max_len+1);
1748 for ( a=0; a< 2; a++)
1750 for (b=0; b< ns[a]; b++)
1752 s=A->order[ls[a][b]][0];
1753 seq=A->seq_al[ls[a][b]];
1756 for ( d=0, c=0; c<l; c++)
1758 if ( !is_gap(seq[c]))
1762 index_res[s][d]=c+1;
1763 index_seq[s][d]=A->order[ls[a][0]][0];
1769 for ( a=0; a< CL->ne; a++)
1771 s1=L[a*CL->entry_len+SEQ1];
1772 s2=L[a*CL->entry_len+SEQ2];
1773 r1=L[a*CL->entry_len+R1];
1774 r2=L[a*CL->entry_len+R2];
1776 if ( index_res[s1][r1])
1778 NL[a*CL->entry_len+SEQ1]=index_seq[s1][r1];
1779 NL[a*CL->entry_len+R1]=index_res[s1][r1];
1783 NL[a*CL->entry_len+SEQ1]=s1;
1784 NL[a*CL->entry_len+R1]=r1;
1787 if ( index_res[s2][r2])
1789 NL[a*CL->entry_len+SEQ2]=index_seq[s2][r2];
1790 NL[a*CL->entry_len+R2]=index_res[s2][r2];
1794 NL[a*CL->entry_len+SEQ2]=s2;
1795 NL[a*CL->entry_len+R2]=r2;
1800 NCL->residue_indexed=0;
1802 NCL=compact_list (NCL, 0, NCL->ne, "best");
1804 NCL=index_res_constraint_list (NCL, WE);
1806 free_int ( index_res, -1); free_int (index_seq, -1);
1810 /*********************************************************************/
1812 /* LIST EXTENTION */
1815 /*********************************************************************/
1816 Constraint_list *extend_list_pair (Constraint_list *CL,char *store_mode, int s1, int s2)
1819 Constraint_list *CLout;
1821 function documentation: start
1822 Constraint_list *extend_list_pair (Constraint_list *CL,char *store_mode, int s1, int s2)
1823 This function takes a pair of sequences s1, s2 and perrforms the extention
1824 It returns the incoming list CL, with CL->L[s1][s2] now extended
1825 See main documentation for store_mode
1826 function documentation: end
1829 if ( S==NULL)S=declare_sequence ((CL->S)->min_len, (CL->S)->max_len,(CL->S)->nseq);
1830 sprintf ( S->name[0], "%s",(CL->S)->name[s1]);
1831 sprintf ( S->name[1],"%s",(CL->S)->name[s2]);
1834 CLout=extend_list (CL, store_mode, CL->extend_clean_mode, CL->extend_compact_mode,CL->do_self, S);
1837 Constraint_list *extend_list (Constraint_list *CLin, char *store_mode,char *clean_mode, char *compact_mode,int do_self, Sequence *DO_LIST)
1839 int a, b, c, d, e, f;
1840 int wA, wC,w, rA, rC, miscA, miscC, misc;
1843 int start_ba, end_ba, start_bc, end_bc, start_ac, end_ac;
1848 Constraint_list *CLout=NULL;
1851 /*Do not extend if the List is a Matrix*/
1852 if ( !CLin->L && CLin->M)
1858 translation=vcalloc ( (CLin->S)->nseq, sizeof (int));
1859 for ( a=0; a<(CLin->S)->nseq; a++)
1861 translation[a]=name_is_in_list ((CLin->S)->name[a],DO_LIST->name, DO_LIST->nseq, 100);
1862 translation[a]++;/* set translation to -1+1=0 if seq not in list*/
1865 CLout=declare_constraint_list (CLin->S, NULL,NULL,0, strm("disk", store_mode)?tmpfile():NULL, NULL);
1867 for ( a=0; a<(CLin->S)->nseq-(1-do_self); a++)
1869 fprintf (CLin->local_stderr, "\nSeq %3d: %5d", a+1,CLout->ne);
1870 for ( c=a+(1-do_self); c<(CLin->S)->nseq; c++)
1872 if ( translation[a] && translation[c])
1874 get_bounds (CLin,a, c, &start_ac, &end_ac);
1875 for ( d=start_ac; d<end_ac; d++)
1877 for ( e=0; e< CLin->entry_len; e++)
1878 vwrite_clist(CLout,CLout->ne, e, vread_clist(CLin,d, e));
1882 for ( b=0; b<(CLin->S)->nseq; b++)
1884 len=strlen ( (CLin->S)->seq[b]);
1886 get_bounds (CLin,b, a, &start_ba, &end_ba);
1887 posA=fill_pos_matrix (CLin,start_ba, end_ba, len, posA, &lenA,(b>a));
1889 if ((c!=b && a!=b) ||(do_self==1))
1892 get_bounds (CLin, b, c, &start_bc, &end_bc);
1893 posC=fill_pos_matrix (CLin, start_bc, end_bc, len, posC, &lenC, (b>c));
1895 for (d=1; d<=len; d++)
1897 if ( posA[d][1]==0 || posC[d][1]==0);
1900 for (e=2; e<=posA[d][1]+1; e+=(CLin->entry_len-4))
1901 for ( f=2; f<=posC[d][1]+1; f+=(CLin->entry_len-4))
1914 misc=MAX(miscA, miscC);
1916 vwrite_clist( CLout, CLout->ne, SEQ1, a);
1917 vwrite_clist( CLout, CLout->ne, SEQ2, c);
1918 vwrite_clist( CLout, CLout->ne, R1 ,rA);
1919 vwrite_clist( CLout, CLout->ne, R2 ,rC);
1920 vwrite_clist( CLout, CLout->ne, WE , w);
1921 vwrite_clist( CLout, CLout->ne, CONS, 1);
1922 vwrite_clist( CLout, CLout->ne, MISC,misc);
1930 CLout=compact_list (CLout,0,CLout->ne,"mirror_sum");
1931 CLout=clean ( clean_mode,CLout, 0, CLout->ne);
1937 vfree (translation);
1940 void get_bounds (Constraint_list *CL, int s1, int s2, int *start, int *end)
1943 CL=index_constraint_list (CL);
1945 if ( s1>s2)SWAP(s1, s2);
1947 start[0]=CL->start_index[s1][s2];
1948 end [0]=CL->end_index [s1][s2];
1952 int ** fill_pos_matrix (Constraint_list *CL, int beg, int end, int slen, int **pos, int *len, int mirrored)
1958 small_chunck=2*CL->entry_len;
1962 pos=declare_int (slen+1, small_chunck);
1963 for ( a=0; a<=slen; a++)pos[a][0]=small_chunck;
1966 else if ( len[0]<=slen)
1968 free_int ( pos, len[0]);
1969 pos=declare_int (slen+1, small_chunck);
1970 for ( a=0; a<=slen; a++)pos[a][0]=small_chunck;
1975 for ( a=0; a<=slen; a++)pos[a][1]=0;
1981 for ( a=beg; a<end; a++)
1984 if (!mirrored) {r1=vread_clist (CL, a, R1);r2=vread_clist (CL, a, R2);}
1985 else if ( mirrored){r1=vread_clist (CL, a, R2);r2=vread_clist (CL, a, R1);}
1987 if ( ((pos[r1][1])+(CL->entry_len))>pos[r1][0])
1989 pos[r1]=vrealloc (pos[r1], (pos[r1][0]+small_chunck)*sizeof (int));
1990 pos[r1][0]+=small_chunck;
1992 pos[r1][pos[r1][1]+2]=r2;
1993 pos[r1][pos[r1][1]+3]=vread_clist(CL,a,WE);
1994 pos[r1][pos[r1][1]+4]=vread_clist(CL,a,MISC);
1995 pos[r1][1]+=(CL->entry_len-4);
1999 Constraint_list * evaluate_constraint_list_reference ( Constraint_list *CL)
2001 static CLIST_TYPE *entry;
2002 int a, b, c, s1, s2, r1, r2, w;
2009 CL->max_value=CL->max_ext_value=20;
2015 CL->max_value=CL->max_ext_value=0;
2016 max_res=vcalloc ( (CL->S)->nseq, sizeof (int**));
2018 for ( a=0; a< (CL->S)->nseq; a++)
2020 max_res[a]=vcalloc ( strlen ((CL->S)->seq[a])+1, sizeof (int*));
2021 for ( b=0; b<=(CL->S)->len[a]; b++)
2023 max_res[a][b]=vcalloc ( (CL->S)->nseq+1, sizeof (int));
2027 for ( a=0; a< CL->ne; a++)
2029 entry=extract_entry ( entry, a, CL);
2035 if ( w==UNDEFINED || ( (CL->moca) && (CL->moca)->forbiden_residues && ((CL->moca)->forbiden_residues[s1][r1]==UNDEFINED || (CL->moca)->forbiden_residues[s2][r2]==UNDEFINED)));
2039 max_res[s1][r1][s2]+=w;
2040 max_res[s2][r2][s1]+=w;
2041 CL->max_value=MAX(w, CL->max_value);
2045 for ( a=0; a< (CL->S)->nseq; a++)
2046 for ( b=1; b<=(CL->S)->len[a]; b++)
2048 for ( c=0; c< (CL->S)->nseq; c++)
2050 max_res[a][b][(CL->S)->nseq]+= max_res[a][b][c];
2052 CL->max_ext_value=MAX(max_res[a][b][c],CL->max_ext_value);
2055 for ( a=0; a< (CL->S)->nseq; a++)
2057 for ( b=0; b<=(CL->S)->len[a]; b++)
2058 vfree ( max_res[a][b]);
2061 CL->max_ext_value=MAX(1,CL->max_ext_value);
2068 CL->nomatch=(CL->nomatch*CL->normalise)/CL->max_ext_value;
2074 /*********************************************************************/
2076 /* ENTRY MANIPULATION */
2079 /*********************************************************************/
2080 Constraint_list * add_list_entry2list (Constraint_list *CL, int n_para, ...)
2087 if (n_para>LIST_N_FIELDS)
2089 crash ("Too Many Fields in List [FATAL/add_list_entry2list]");
2092 va_start (ap,n_para);
2093 entry=vcalloc (CL->entry_len, sizeof (int));
2095 for ( a=0; a<n_para; a++)
2097 field=va_arg(ap, int);
2098 val =va_arg(ap, CLIST_TYPE);
2102 add_entry2list(entry, CL);
2107 Constraint_list *add_entry2list ( CLIST_TYPE *entry, Constraint_list *CL)
2109 return insert_entry2list (entry, CL->ne++, CL);
2111 Constraint_list* insert_entry2list(CLIST_TYPE * entry, int pos, Constraint_list *CL)
2114 for ( a=0; a< CL->entry_len; a++)
2115 vwrite_clist ( CL,pos, a,entry[a]);
2118 CLIST_TYPE* extract_entry(CLIST_TYPE * entry, int pos, Constraint_list *CL)
2122 if ( entry==NULL)entry=vcalloc ( CL->entry_len, CL->el_size);
2124 for (a=0; a< CL->entry_len; a++)entry[a]=vread_clist(CL, pos, a);
2129 /*********************************************************************/
2131 /* SEARCH IN LIST (ARRAY AND FILE) */
2134 /*********************************************************************/
2135 FILE * compare_list (FILE *OUT, Constraint_list *CL1,Constraint_list *CL2)
2142 CLIST_TYPE *entry=NULL;
2145 entry_len=CL1->entry_len;
2146 qsort ( (void *)CL1->L, CL1->ne, CL1->entry_len*sizeof (int), compare_constraint_list_entry);
2147 qsort ( (void *)CL2->L, CL2->ne, CL2->entry_len*sizeof (int), compare_constraint_list_entry);
2149 entry=vcalloc ( CL1->entry_len, CL1->el_size);
2150 for ( a=0; a<CL1->ne; a++)
2152 entry=extract_entry (entry,a,CL1);
2153 if ((l=main_search_in_list_constraint (entry,&p,4,CL2))!=NULL)
2155 vwrite_clist ( CL2, p,MISC, 1);
2156 vwrite_clist ( CL1, a,MISC, 1);
2161 fprintf ( OUT, "%-15s:%d pairs (Evaluated matrix), %d pairs in the other (%s)\n", CL2->list_name, CL2->ne, CL1->ne, CL1->list_name);
2162 fprintf ( OUT, "%-15s:%d pairs\n", CL1->list_name, CL1->ne);
2163 fprintf ( OUT, "Acurracy=%.2f%%\n", (nw_score/CL1->ne)*MAXID);
2164 fprintf ( OUT, "Sensitiv=%.2f%%\n\n", (nw_score/CL2->ne)*MAXID);
2169 CLIST_TYPE *main_search_in_list_constraint ( int *key,int *p,int k_len,Constraint_list *CL)
2176 CL=index_constraint_list (CL);
2178 start=CL->start_index[key[SEQ1]][key[SEQ2]];
2179 end =CL->end_index [key[SEQ1]][key[SEQ2]];
2183 entry_len=CL->entry_len;
2184 l=bsearch (key, (CL->L)+(start*CL->entry_len), (end-start), sizeof (int)*CL->entry_len, compare_constraint_list_entry4bsearch);
2188 CLIST_TYPE return_max_constraint_list ( Constraint_list *CL, int field)
2192 for ( a=0; a< CL->ne; a++)max=MAX( vread_clist(CL,a,field), max);
2196 /*********************************************************************/
2203 /*********************************************************************/
2204 Constraint_list *sort_constraint_list_inv (Constraint_list *CL, int start, int len)
2206 CL=sort_constraint_list (CL, start,len);
2209 CL=invert_constraint_list (CL, start,len);
2210 if ( start+len==CL->ne)
2212 while (vread_clist(CL,CL->ne-1, SEQ1)==-1)CL->ne--;
2219 Constraint_list *invert_constraint_list (Constraint_list *CL, int start,int len)
2225 for ( a=start, b=start+len-1; a<=b; a++, b--)
2227 for (c=0; c< CL->entry_len; c++)
2229 tp=vread_clist(CL, a, c);
2230 vwrite_clist(CL,a, c, vread_clist(CL, b, c));
2231 vwrite_clist(CL,b, c, tp);
2237 Constraint_list * sort_constraint_list(Constraint_list *CL, int start, int len)
2240 CL=sort_constraint_list_on_n_fields (CL, start, len, 0, CL->entry_len);
2245 Constraint_list * sort_constraint_list_on_n_fields (Constraint_list *CL, int start, int len, int first_field, int n_fields)
2247 entry_len=CL->entry_len;
2252 fseek ( CL->fp, start*CL->el_size*CL->entry_len , SEEK_SET);
2253 hsort_list_file ( CL->fp, len, CL->el_size, CL->entry_len,first_field,n_fields);
2257 qsort ( (void *)CL->L, CL->ne, CL->entry_len*sizeof (int), compare_constraint_list_entry);
2258 //hsort_list_array ((void**)(CL->L)+start, len, CL->el_size, CL->entry_len,first_field,n_fields);
2262 int compare_constraint_list_entry4bsearch ( const void*vx, const void*vy)
2265 const int *x=vx, *y=vy;
2266 for (a=SEQ1; a<=R2; a++)
2268 if (x[a]<y[a])return -1;
2269 else if (x[a]>y[a]) return 1;
2273 int compare_constraint_list_entry ( const void*vx, const void*vy)
2276 const int *x=vx, *y=vy;
2278 for (a=SEQ1; a<=WE; a++)
2280 if (x[a]<y[a])return -1;
2281 else if (x[a]>y[a]) return 1;
2285 /*********************************************************************/
2290 /*********************************************************************/
2291 Constraint_list* fork_read_n_constraint_list(char **fname,int n_list, char *in_mode,char *mem_mode,char *weight_mode, char *type,FILE *local_stderr, Constraint_list *CL, char *seq_source);
2292 Constraint_list* nfork_read_n_constraint_list(char **fname,int n_list, char *in_mode,char *mem_mode,char *weight_mode, char *type,FILE *local_stderr, Constraint_list *CL, char *seq_source);
2294 Constraint_list* read_n_constraint_list(char **fname,int n_list, char *in_mode,char *mem_mode,char *weight_mode, char *type,FILE *local_stderr, Constraint_list *CL, char *seq_source)
2297 if ( get_nproc()==1 || n_list<=2)return nfork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode,type,local_stderr, CL, seq_source);
2298 else if ( strstr (CL->multi_thread, "methods"))
2299 return fork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode,type,local_stderr, CL, seq_source);
2301 return nfork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode,type,local_stderr, CL, seq_source);
2303 Constraint_list* fork_read_n_constraint_list(char **fname,int n_list, char *in_mode,char *mem_mode,char *weight_mode, char *type,FILE *local_stderr, Constraint_list *CL, char *seq_source)
2313 proclist=vcalloc (65536, sizeof (int));
2314 tmp_list=vcalloc (n_list+1, sizeof (char*));
2315 for (a=0; a<n_list; a++)tmp_list[a]=vtmpnam(NULL);
2317 if (!(CL->S) && (S=read_seq_in_n_list (fname, n_list,type,seq_source))==NULL)
2319 fprintf ( stderr, "\nNO SEQUENCE WAS SPECIFIED[FATAL]\n");
2320 myexit(EXIT_FAILURE);
2322 else if (CL->S==NULL)
2327 /*CHECK IF THERE IS A MATRIX AND GET RID OF OTHER METHODS*/
2328 for (b=0, a=0; a< n_list; a++)if (is_matrix(fname[a]) ||is_matrix(fname[a]+1) )b=a+1;
2333 else sprintf ( fname[0], "%s", fname[b-1]);
2335 return nfork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode, type,local_stderr, CL, seq_source);
2338 if (!CL)CL=declare_constraint_list ( S,NULL, NULL, 0,(strm(mem_mode, "disk"))?tmpfile():NULL, NULL);
2342 constraint_list2raw_file(CL,tmp_list[n_list], "w");
2346 CL->local_stderr=local_stderr;
2347 fprintf ( local_stderr, "\n\tMulti Core Mode: %d processors:\n", nproc);
2348 for (ns=0,a=0; a< n_list; a++)
2356 initiate_vtmpnam (NULL);
2357 CL->local_stderr=vfopen("/dev/null", "w");
2359 CL=read_constraint_list (CL, fname[a], in_mode, mem_mode,weight_mode);
2360 if (CL->ne>in)constraint_list2raw_file (CL,tmp_list[a], "w");
2361 exit (EXIT_SUCCESS);
2367 fprintf ( local_stderr, "\n\t--- Process Method/Library/Aln %s", fname[a], ns);
2371 b=proclist[vwait(NULL)];
2372 fprintf (local_stderr, "\n\txxx Retrieved %s",fname[a]);
2373 if (tmp_list[b] && check_file_exists (tmp_list[b]))
2375 CL=read_constraint_list_raw_file (CL,tmp_list[b]);
2376 compact_list (CL, 0, CL->ne, (strm (weight_mode, "cons")?"cons":"default"));
2388 fprintf (local_stderr, "\n\txxx Retrieved %s",fname[a]);
2389 if (tmp_list[a] && check_file_exists (tmp_list[a]))
2391 CL=read_constraint_list_raw_file (CL,tmp_list[a]);
2392 compact_list (CL, 0, CL->ne, (strm (weight_mode, "cons")?"cons":"default"));
2396 fprintf ( local_stderr, "\n\n\tAll Methods Retrieved\n");
2398 if (tmp_list[n_list] && check_file_exists (tmp_list[n_list]))
2400 CL=read_constraint_list_raw_file (CL,tmp_list[n_list]);
2401 compact_list (CL, 0, CL->ne, (strm (weight_mode, "cons")?"cons":"default"));
2404 CL->local_stderr=local_stderr;
2405 CL=evaluate_constraint_list_reference (CL);
2410 Constraint_list* nfork_read_n_constraint_list(char **fname,int n_list, char *in_mode,char *mem_mode,char *weight_mode, char *type,FILE *local_stderr, Constraint_list *CL, char *seq_source)
2416 if (!(CL->S) && (S=read_seq_in_n_list (fname, n_list,type,seq_source))==NULL)
2418 fprintf ( stderr, "\nNO SEQUENCE WAS SPECIFIED[FATAL]\n");
2419 myexit(EXIT_FAILURE);
2421 else if (CL->S==NULL)
2426 /*CHECK IF THERE IS A MATRIX AND GET RID OF OTHER METHODS*/
2427 for (b=0, a=0; a< n_list; a++)if (is_matrix(fname[a]) ||is_matrix(fname[a]+1) )b=a+1;
2432 else sprintf ( fname[0], "%s", fname[b-1]);
2437 if (!CL)CL=declare_constraint_list ( S,NULL, NULL, 0,(strm(mem_mode, "disk"))?tmpfile():NULL, NULL);
2438 CL->local_stderr=local_stderr;
2439 fprintf ( CL->local_stderr,"\nREAD/MAKE LIBRARIES:[%d]\n",n_list );
2441 CL=read_constraint_list (CL, fname[0], in_mode, mem_mode,weight_mode);
2442 compact_list (CL, 0, CL->ne, "default");
2443 for ( a=1; a< n_list; a++)
2445 CL=read_constraint_list (CL, fname[a], in_mode, mem_mode,weight_mode);
2446 if (strm (weight_mode, "cons"))compact_list (CL, 0, CL->ne, "cons");
2448 compact_list (CL, 0, CL->ne, "default");
2450 CL->local_stderr=local_stderr;
2452 CL=evaluate_constraint_list_reference (CL);
2456 Constraint_list* read_constraint_list(Constraint_list *CL,char *in_fname,char *in_mode, char *mem_mode,char *weight_mode)
2458 Sequence *SL=NULL, *TS=NULL;
2460 Constraint_list *SUBCL=NULL;
2461 static char *read_mode;
2465 if ( !read_mode)read_mode=vcalloc ( STRING, sizeof (char));
2467 if ( is_lib_list (in_fname))sprintf ( read_mode, "lib_list");
2468 else if ( in_mode)sprintf (read_mode, "%s", in_mode);
2469 else if ( fname[0]=='A'){sprintf ( read_mode, "aln");fname++;}
2470 else if ( fname[0]=='L'){sprintf ( read_mode, "lib");fname++;}
2471 else if ( fname[0]=='M'){sprintf ( read_mode, "method");fname++;}
2472 else if ( fname[0]=='S'){sprintf ( read_mode, "sequence");return CL;}
2473 else if ( fname[0]=='P'){sprintf ( read_mode, "pdb") ;return CL;}
2474 else if ( fname[0]=='R'){sprintf ( read_mode, "profile") ;return CL;}
2475 else if ( fname[0]=='X'){sprintf ( read_mode, "matrix");++fname;}
2476 else if ( fname[0]=='W'){sprintf ( read_mode, "structure");fname++;}
2480 fprintf ( stderr, "\nERROR: The descriptor %s could not be identified as a file or a method.[FATAL]\nIf it is a method file please indicate it with M%s\n", fname, fname);
2481 myexit (EXIT_SUCCESS);
2484 fprintf (CL->local_stderr, "\n\t%s [%s]\n", fname, read_mode);
2487 if ( strm (read_mode, "lib_list"))
2491 l=read_lib_list (fname, &n);
2492 for ( a=0; a<n; a++)
2493 CL=read_constraint_list (CL,l[a],in_mode, mem_mode,weight_mode);
2496 else if (strm(read_mode, "binary"))
2498 fprintf ( stderr, "\nERROR: Library %s: binary mode is not any more supported [FATAL:%s]\n", fname,PROGRAM);
2499 myexit (EXIT_FAILURE);
2501 else if ( strm (fname, "make_test_lib"))
2503 CL=make_test_lib (CL);
2505 else if ( strm2 (read_mode,"ascii","lib"))
2507 SUBCL=read_constraint_list_file(NULL, fname);
2509 else if (strm(read_mode, "method"))
2511 CL=produce_list ( CL, CL->S, fname,weight_mode,mem_mode);
2513 else if (strm(read_mode, "matrix"))
2517 CL->M=read_matrice ( fname);
2519 else if ( strm ( read_mode, "structure"))
2523 fprintf ( stderr, "\nERROR: Wstructure must come before Mmethod or Aaln [FATAL:%s]",PROGRAM);
2524 myexit (EXIT_FAILURE);
2527 if ( !(CL->STRUC_LIST))
2529 CL->STRUC_LIST=declare_sequence (1,1,10000);
2530 (CL->STRUC_LIST)->nseq=0;
2534 if ( check_file_exists(fname))
2536 TS=main_read_seq ( fname);
2537 for (a=0; a<TS->nseq; a++)sprintf (SL->name[SL->nseq++], "%s", TS->name[a]);
2538 free_sequence (TS, TS->nseq);
2542 sprintf (SL->name[SL->nseq++], "%s", fname);
2545 else if (strm (read_mode, "aln"))
2547 SUBCL=aln_file2constraint_list ( fname,SUBCL,weight_mode);
2551 SUBCL=read_constraint_list_file(SUBCL, fname);
2556 CL=merge_constraint_list (SUBCL, CL, "default");
2557 free_constraint_list_full (SUBCL);
2563 #define is_seq_source(Symbol,Mode,SeqMode) (Symbol==Mode && (SeqMode==NULL || strm (SeqMode, "ANY") || (SeqMode[0]!='_' && strchr (SeqMode,Symbol)) || (SeqMode[0]=='_' && !strchr (SeqMode,Symbol))))
2564 Sequence * read_seq_in_n_list(char **fname, int n, char *type, char *SeqMode)
2569 char **sequences=NULL;
2570 char **seq_name=NULL;
2577 /*THE TYPE OF EACH FILE MUST BE INDICATED*/
2578 /*SeqMode indicates the type of file that can be used as sequence sources*/
2581 SL: only sequences from Libraries and Sequences
2582 _A: anything BUT sequences from A(lignments)
2587 fprintf ( stderr, "\nERROR: NO IN FILE [FATAL:%s]\n", PROGRAM);
2588 myexit (EXIT_FAILURE);
2592 for ( a=0; a< n ; a++)
2596 if (buf)vfree (buf);
2598 buf=name2type_name(fname[a]);mode=buf[0];lname=buf+1;
2600 if (is_seq_source ('A', mode, SeqMode))
2604 A=main_read_aln (lname,NULL);
2606 S1=seq2unique_name_seq (S1);
2607 if ((S=merge_seq ( S1, S))==NULL){fprintf ( stderr, "\nERROR: Sequence Error in %s [FATAL:%s]\n",lname, PROGRAM); myexit(EXIT_FAILURE);}
2609 free_sequence (S1, S1->nseq);
2611 else if ( is_seq_source ('R', mode, SeqMode))
2613 S=add_prf2seq (lname, S);
2616 else if (is_seq_source ('P', mode, SeqMode))
2620 S1=get_pdb_sequence (lname);
2623 add_warning ( stderr, "\nWarning: Could not use PDB: %s", lname);
2627 if ((S=merge_seq ( S1, S))==NULL){fprintf ( stderr, "\nERROR: Sequence Error in %s [FATAL:%s]\n",lname, PROGRAM); myexit(EXIT_FAILURE);}
2628 i=name_is_in_list (S1->name[0], S->name, S->nseq, 100);
2629 (S->T[i])->P=fill_P_template (S->name[i], lname, S);
2631 free_sequence (S1, S1->nseq);
2633 else if ( mode=='M');
2634 else if ( mode=='X');
2635 else if ( mode=='W');
2637 else if (is_seq_source ('S', mode, SeqMode))
2639 /*1 Try with my routines (read t_coffee and MSF)*/
2640 if ( (A=main_read_aln ( lname, NULL))!=NULL)
2648 S1=main_read_seq (lname);
2651 for ( b=0; b< S1->nseq; b++)ungap(S1->seq[b]);
2652 S1=seq2unique_name_seq (S1);
2655 if ((S=merge_seq ( S1, S))==NULL){fprintf ( stderr, "\nSequence Error in %s [FATAL:%s]\n",lname,PROGRAM); myexit(EXIT_FAILURE);}
2657 free_sequence (S1,S1->nseq);
2660 else if (is_seq_source ('L', mode, SeqMode))
2663 read_seq_in_list (lname,&nseq,&sequences,&seq_name);
2665 S1=fill_sequence_struc ( nseq, sequences, seq_name);
2667 for ( b=0; b< S1->nseq; b++)sprintf ( S1->file[b], "%s", lname);
2668 nseq=0;free_char (sequences, -1); free_char ( seq_name, -1);
2671 S1=seq2unique_name_seq (S1);
2673 if ((S=merge_seq( S1, S))==NULL){fprintf ( stderr, "\nSequence Error in %s [FATAL:%s]\n",lname,PROGRAM); myexit(EXIT_FAILURE);}
2674 free_sequence(S1, S1->nseq);
2677 else if ( !strchr ( "ALSMXPRWG", mode))
2679 fprintf ( stderr, "\nERROR: %s is neither a file nor a method [FATAL:%s]\n", lname, PROGRAM);
2685 S=remove_empty_sequence (S);
2688 if ( type && type[0] )sprintf ( S->type, "%s", type);
2689 else S=get_sequence_type (S);
2691 if ( strm (S->type, "PROTEIN_DNA"))
2693 for ( a=0; a< S->nseq; a++)
2695 if (strm ( get_string_type ( S->seq[a]), "DNA") ||strm ( get_string_type ( S->seq[a]), "RNA") );
2696 else if ( strm ( get_string_type ( S->seq[a]), "PROTEIN"))
2698 S->seq[a]=thread_aa_seq_on_dna_seq (S->seq[a]);
2699 S->len[a]=strlen (S->seq[a]);
2700 S->max_len=MAX(S->max_len, S->len[a]);
2715 int read_cpu_in_list ( char *fname)
2721 fp=vfopen ( fname, "r");
2722 while ( (c=fgetc(fp))!='#');
2723 while ( (c=fgetc(fp))!='C' && c!=EOF);
2724 if ( c=='C')fscanf( fp, "PU %d\n", &cpu);
2728 char * expand_constraint_list_file ( char *file)
2736 if ( !grep_function ( "'+BLOCK+'", file))return file;
2738 new_file=vtmpnam (NULL);
2739 IN=vfopen ( file,"r");
2740 OUT=vfopen (new_file, "w");
2742 while ( (c=fgetc (IN))!=EOF)
2745 buf=vfgets (buf, IN);
2746 if ( !strstr (buf, "+BLOCK+"))
2747 fprintf (OUT, "%s", buf);
2750 list=string2list (buf);
2753 for (a=0; a< n; a++)
2755 fprintf ( OUT, "%5d %5d ",atoi(list[3])+a, atoi(list[4])+a);
2756 for (b=5; b<atoi(list[0]); b++) fprintf ( OUT, "%s ", list[b]);
2757 fprintf (OUT, "\n");
2759 free_char (list, -1);
2762 vfclose (IN); vfclose (OUT);
2767 Constraint_list * make_test_lib(Constraint_list *CL)
2771 HERE ("cncn: making artificial lib");//Keep this warning alive
2774 fprintf ( stderr, "\n");
2775 for (a=0; a< S->nseq-1; a++)
2777 fprintf ( stderr, "[%d-%d]", a, CL->ne);
2778 for ( b=a+1; b< S->nseq; b++)
2780 l1=MIN(S->len[a], S->len[b]);
2782 for (c=0; c<l1; c++)
2784 vwrite_clist( CL,CL->ne,0,a);
2785 vwrite_clist( CL,CL->ne,1,b);
2786 vwrite_clist( CL,CL->ne,2,c+1);
2787 vwrite_clist( CL,CL->ne,3,c+1);
2788 vwrite_clist( CL,CL->ne,4,100);
2795 Constraint_list * read_constraint_list_file(Constraint_list *CL, char *fname)
2804 static char *dp_mode;
2806 static int *sn_list;
2809 static CLIST_TYPE *entry;
2816 char *stripped_file1;
2817 char *stripped_file;
2823 stripped_file1=strip_file_from_comments ("!", fname);
2824 stripped_file=expand_constraint_list_file (stripped_file1);
2825 small_S=read_seq_in_n_list (&fname, 1,NULL, NULL);
2829 CL=declare_constraint_list ( small_S,NULL, NULL, 0,NULL, NULL);
2833 small_S=read_seq_in_n_list (&fname, 1, (CL->S)->type, NULL);
2835 B=seq2aln (small_S, NULL, 1);
2836 B=fix_aln_seq ( B, (CL->S));
2838 if ( CL->S!=small_S)free_sequence (small_S, B->nseq);
2840 lline=measure_longest_line_in_file (fname)+1;
2842 if ( !mat) mat=vcalloc (STRING, sizeof (char));
2843 if ( !dp_mode) dp_mode=vcalloc (STRING, sizeof (char));
2844 fp=vfopen (fname, "r");
2845 while((c=fgetc(fp))!='#')if ( c=='\n')max_nseq++;
2848 buf=vcalloc (lline, sizeof (char));
2849 sequence=vcalloc (lline, sizeof (char));
2850 if ( !name)name=vcalloc ( 100, sizeof (char));
2851 if ( !entry)entry=vcalloc ( CL->entry_len, CL->el_size);
2852 if ( !sn_list)sn_list=vcalloc (max_nseq, sizeof (int));
2855 sn_list=vrealloc (sn_list, max_nseq*sizeof (int));
2859 seq_1_to_n=((fp=find_token_in_file (fname, NULL, "SEQ_1_TO_N"))!=NULL);
2861 if ( sn_list==NULL)sn_list=vcalloc (max_nseq, sizeof (int));
2863 /*Read Constraint list*/
2864 fp=vfopen(stripped_file,"r");
2865 fscanf ( fp, "%d\n", &list_nseq);
2866 for ( a=0; a<list_nseq; a++)
2868 fscanf ( fp, "%s %d %s\n", name, &seq_len, sequence);
2870 lower_string (sequence);
2872 if ((sn=name_is_in_list (name,S->name, S->nseq, 100))==-1){continue;}
2879 while ((c=fgetc(fp))!=EOF)
2884 fscanf ( fp, "#%d %d\n", &s1, &s2);line++;
2885 /*Check If the sequence numbering is legal*/
2886 if ( seq_1_to_n){s1--; s2--;}
2890 fprintf (stderr, "ERROR: Wrong Sequence Numbering in %s [FATAL:%s]\n",fname, PROGRAM);
2891 myexit (EXIT_FAILURE);
2899 while (isdigit((c=fgetc(fp))))
2902 for ( z=0; z< CL->entry_len; z++)entry[z]=0;
2907 while ( (c=fgetc(fp))!='\n')
2914 fscanf ( fp, "%d", &entry[n]);
2918 if ( n>CL->entry_len)
2920 add_warning ( stderr, "\nWARNING:PARSING ERROR #1 (Too many Fields) IN %s AT LINE %d: C=%c n=%d\n", fname,line, c,n);
2921 for ( e=2; e<LIST_N_FIELDS; e++)
2922 fprintf ( stderr, "%d ", entry[e]);
2924 myexit (EXIT_FAILURE);
2929 if ( n<=CONS)entry[CONS]=1;
2932 /*Check The legality of the entry*/
2935 add_warning ( stderr, "\nWARNING:PARSING ERROR #2 IN %s (Not enough Fields) AT LINE %d: C=%c\n", fname,line-1, c);
2936 for ( e=2; e<LIST_N_FIELDS; e++)
2937 fprintf ( stderr, "%d ",entry[e]);
2939 myexit (EXIT_FAILURE);
2942 entry[R1]=(B->seq_cache)?B->seq_cache[entry[SEQ1]][entry[R1]]:entry[R1];
2943 entry[R2]=(B->seq_cache)?B->seq_cache[entry[SEQ2]][entry[R2]]:entry[R2];
2945 if ( entry[R1] && entry[R2])
2947 if ( entry[R1]<=0 || entry[R1]>(CL->S)->len[s1])
2949 fprintf ( stderr, "\nERROR: Seq1=%d (len=%d, name=%s), Seq2=%d (len=%d, name=%s), Res1 %d, Res2 %d\n", entry[SEQ1]+1,(CL->S)->len[s1],(CL->S)->name[s1], entry[SEQ2]+1,(CL->S)->len[s2],(CL->S)->name[s2],entry[R1], entry[R2]);
2950 fprintf ( stderr, "\nERROR: Library %s, line %d, Field 1: Bad residue numbering (%d)[FATAL:%s]\n", fname, line-1,entry[R1], PROGRAM);
2951 myexit (EXIT_FAILURE);
2953 else if (entry[R2]<=0 || entry[R2]>(CL->S)->len[s2])
2955 fprintf ( stderr, "\nERROR: Seq1=%d (len=%d, name=%s), Seq2=%d (len=%d, name=%s), Res1 %d, Res2 %d\n", entry[SEQ1]+1,(CL->S)->len[s1],(CL->S)->name[s1], entry[SEQ2]+1,(CL->S)->len[s2],(CL->S)->name[s2],entry[R1], entry[R2]);
2957 fprintf ( stderr, "\nERROR: Seq1: %d, Seq2 %d, Res1 %d, Res2 %d\n", entry[SEQ1], entry[SEQ2], entry[R1], entry[R2]);
2958 fprintf ( stderr, "\nERROR: Library %s, line %d, Field 2: Bad residue numbering (%d)[FATAL:%s]\n", fname, line-1, entry[R2],PROGRAM);
2959 myexit (EXIT_FAILURE);
2962 if ( (entry[SEQ1]>entry[SEQ2])|| (entry[SEQ1]==entry[SEQ2] && entry[R1]>entry[R2]))
2964 SWAP(entry[SEQ1],entry[SEQ2]);
2965 SWAP(entry[R1], entry[R2]);
2968 for ( z=0; z< CL->entry_len; z++)vwrite_clist( CL,CL->ne, z, entry[z]);
2976 else if ( c=='!' || c=='C' || c=='\n' || c=='\r'){while ((c=fgetc(fp))!='\n' && c!=EOF && c!='\r');}
2979 fprintf ( stderr, "\n\n PARSING ERROR 3 IN %s AT LINE %d: [%c] \n[read_constraint_list_file]", fname,line,c);
2980 while ((c=fgetc(fp))!='\n' && c!=EOF)fprintf ( stderr, "%c", c);
2981 fprintf ( stderr, "\n");
2982 printf_system ( "cp %s faulty_library.tc_lib", fname);
2983 myexit (EXIT_FAILURE);
2985 if ( c==EOF)ungetc(c, fp);
2992 remove(stripped_file);
2996 Constraint_list * read_constraint_list_raw_file(Constraint_list *CL, char *fname)
3002 if ( !entry)entry=vcalloc (CL->entry_len, sizeof (int));
3003 fp=vfopen (fname, "r");
3005 while (fscanf (fp, "%d ", &v)==1)
3007 if (n==CL->entry_len)
3009 add_entry2list (entry, CL);
3014 if (n==CL->entry_len)
3016 add_entry2list (entry, CL);
3023 Constraint_list * fast_read_constraint_list_file(Constraint_list *CL, char *in_fname)
3030 CLIST_TYPE *entry=NULL;
3031 char *buf=NULL, *buf2;
3037 fname=expand_constraint_list_file (in_fname);
3041 return read_constraint_list_file (CL,fname);
3044 entry=vcalloc (sizeof (int), CL->entry_len);
3045 NS=read_seq_in_n_list (&fname, 1,NULL, NULL);
3046 index=index_seq_name(NS,CL->S);
3049 /*Read Constraint list*/
3050 fp=vfopen(fname,"r");
3054 buf=vfgets ( buf, fp);
3055 if (buf[0]!='!')i++;
3058 while ( (c=fgetc (fp))!='#' && c!=EOF);
3063 free_sequence (NS,-1);
3066 add_warning (stderr, "Warning: incomplete library [%s]",PROGRAM);
3073 while ((buf2=vfgets ( buf, fp))!=NULL)
3075 if (buf2[0]=='!')continue;
3078 list=string2num_list2 (buf, " #\n");
3082 sscanf ( buf, "#%d %d", &entry[SEQ1], &entry[SEQ2]);
3083 entry[SEQ1]=index[entry[SEQ1]-1][0];
3084 entry[SEQ2]=index[entry[SEQ2]-1][0];
3089 sscanf (buf, "%d %d %d %d %d", &entry[R1], &entry[R2], &entry[WE], &entry[CONS], &entry[MISC]);
3096 if ( (entry[SEQ1]>entry[SEQ2])|| (entry[SEQ1]==entry[SEQ2] && entry[R1]>entry[R2]))
3098 SWAP(entry[SEQ1],entry[SEQ2]);SWAP(entry[R1], entry[R2]);
3100 add_entry2list (entry, CL);
3108 free_sequence (NS,-1);
3115 int read_seq_in_list ( char *fname, int *nseq, char ***sequences, char ***seq_name)
3123 static int max_nseq;
3124 static int *sn_list;
3130 fp=vfopen (fname, "r");
3131 fp=skip_commentary_line_in_file ('!', fp);
3132 fscanf (fp, "%d\n", &max_nseq);
3133 for ( lline=0,a=0; a<max_nseq; a++)
3136 fscanf (fp, "%*s %d %*s\n", &l);
3137 lline=MAX(lline, l);
3140 sequence=vcalloc (lline, sizeof (char)+1);
3144 if ( seq_name[0]==NULL)
3146 seq_name[0]= declare_char (max_nseq,0);
3147 sequences[0]=declare_char (max_nseq,0);
3149 if ( sn_list==NULL)sn_list=vcalloc ( max_nseq, sizeof (int));
3150 else sn_list=vrealloc (sn_list, max_nseq*sizeof (int));
3152 fp=vfopen (fname,"r");
3153 fp=skip_commentary_line_in_file ('!', fp);
3154 if (fscanf ( fp, "%d\n", &list_nseq)!=1)return 0;
3155 for ( a=0; a<max_nseq; a++)
3157 fp=skip_commentary_line_in_file ('!', fp);
3159 fscanf ( fp, "%s %d %s\n", name, &seq_len, sequence);
3160 lower_string (sequence);
3162 if ((sn=name_is_in_list (name, seq_name[0], nseq[0], 100))==-1)
3164 seq_name[0][nseq[0]]=vcalloc (strlen (name)+1, sizeof (char));
3165 sprintf (seq_name[0][nseq[0]], "%s", name);
3166 sequences[0][nseq[0]]=vcalloc (strlen (sequence)+1, sizeof (char));
3167 sprintf (sequences[0][nseq[0]], "%s", sequence);
3182 /*********************************************************************/
3184 /* EXTENDED LIST OUTPUT */
3187 /*********************************************************************/
3189 FILE * save_extended_constraint_list ( Constraint_list *CL, char *mode, FILE *fp)
3196 fp=save_list_header (fp,CL);
3199 for ( a=0; a< (CL->S)->nseq; a++)
3201 for ( b=a; b<(CL->S)->nseq; b++)
3204 if ( a==b && !CL->do_self)continue;
3205 fp=save_extended_constraint_list_pair(CL, mode, (CL->S)->name[a], (CL->S)->name[b], fp);
3208 fprintf (fp, "! SEQ_1_TO_N\n");
3213 FILE * save_extended_constraint_list_pair ( Constraint_list *CL, char *mode, char* seq1, char * seq2,FILE *fp)
3220 if ((p=strstr (mode, "THR"))!=NULL)t=atoi(p+3);
3223 s1=name_is_in_list (seq1,(CL->S)->name, (CL->S)->nseq, 100);
3224 s2=name_is_in_list (seq2,(CL->S)->name, (CL->S)->nseq, 100);
3228 fprintf ( stderr, "Output Error: %s is not a sequence [FATAL:%s]\n", seq1, PROGRAM);
3233 fprintf ( stderr, "Output Error: %s is not a sequence [FATAL:%s]\n", seq2, PROGRAM);
3237 if ( strstr (mode, "pair"))fprintf (fp, "# 1 2\n");
3238 else if ( strstr (mode, "lib"))fprintf (fp, "# %d %d\n", s1+1, s2+1);
3240 for ( a=0; a<(CL->S)->len[s1]; a++)
3242 for ( b=0; b<(CL->S)->len[s2]; b++)
3244 if ( a>=b && s1==s2)continue;
3245 if ( strstr (mode, "pc"))score=residue_pair_extended_list_pc (CL, s1,a+1, s2, b+1);
3246 else if ( strstr (mode, "raw"))score=residue_pair_extended_list_raw (CL, s1,a+1, s2, b+1);
3248 score=CL->evaluate_residue_pair (CL, s1,a+1, s2, b+1);
3250 if (score<=t) continue;
3251 fprintf (fp, "%5d %5d %5d \n", a+1, b+1, score);
3259 /*********************************************************************/
3264 /*********************************************************************/
3266 FILE *save_extended_constraint_list ( Constraint_list *CL,Sequence *S, char *fname)
3275 fp=vfopen (fname, "w");
3276 fp=save_sub_list_header(fp, S->nseq, S->name, CL);
3278 tr=vcalloc (S->nseq+1, sizeof (int));
3279 for ( b=0,a=0; a< S->nseq; a++)
3282 if ( (i=name_is_in_list(S->name[a],(CL->S)->name,(CL->S)->nseq, 100))==-1)
3284 printf_exit (EXIT_FAILURE, stderr, "\nERROR: Sequence %s is not part of the sequence dataset [FATAL:%s]", S->name[a], PROGRAM);
3294 pos0=vcalloc ( S->nseq, sizeof (int*));
3295 for (a=0; a<S->nseq; a++)
3298 l=strlen (S->seq[a]);
3299 A->seq_al[a]=S->seq[a];
3300 pos0[a]=vcalloc (l+1, sizeof (int));
3301 for (b=0; b<l; b++)pos[a][b]=b+1;
3303 l_s=declare_int (2,2);
3304 ns=vcalloc ( 2, sizeof (int));
3307 for ( a=0; a< S->nseq-1; a++)
3308 for ( b=a+1; b<S->nseq; b++)
3310 int pos_i, pos_j, s;
3311 l_s[0]=tr[a];l_s[1]=tr[b];
3312 for ( pos_i=0; pos_i< S->len[a]; pos_i++)
3313 for (pos_j=0; pos_j<S->len[b]; pos_j++)
3315 s=(CL->get_dp_cost) ( A, pos0, ns[0], l_s[0], i-1, pos0, ns[1], l_s[1],pos_j-1, CL);
3316 if (s>epsilon)fprintf (fp, "%d %d %d", i, j, s);
3323 FILE * save_constraint_list ( Constraint_list *CL,int start, int len, char *fname, FILE *fp,char *mode, Sequence *S)
3326 static int* translation;
3333 if ( translation!=NULL)vfree(translation);
3334 translation=vcalloc ( (CL->S)->nseq+1, sizeof (int));
3335 for ( b=0,a=0; a< (CL->S)->nseq; a++)
3337 if ( name_is_in_list((CL->S)->name[a],S->name,S->nseq, 100)==-1)
3349 if (strm2(mode, "lib","ascii"))
3351 if ( fp==NULL)fp=vfopen ( fname, "w");
3352 fp=save_list_header (fp,CL);
3353 fp=save_constraint_list_ascii(fp, CL, 0, CL->ne, translation);
3355 else if (strm(mode, "binary"))
3357 if ( fp==NULL)fp=vfopen ( fname, "wb");
3358 fp=save_constraint_list_bin (fp, CL, 0, CL->ne, translation);
3362 fprintf (stderr,"\nUNKOWN MODE FOR OUTPUT: %s [FATAL]\n",mode);
3368 FILE * save_sub_list_header ( FILE *OUT, int n, char **name, Constraint_list *CL)
3375 for ( a=0; a<(CL->S)->nseq; a++)
3376 for ( b=0; b<n; b++)
3377 if (strm (name[b] , (CL->S)->name[a]))
3378 nseq+=((CL->S)->len[a]!=-1);
3380 fprintf ( OUT, "! TC_LIB_FORMAT_01\n%d\n",nseq);
3381 for ( a=0; a<n; a++)
3382 for ( b=0; b<(CL->S)->nseq; b++)
3383 if (strm (name[a] , (CL->S)->name[b]))
3384 if ((CL->S)->len[b]!=-1) fprintf ( OUT, "%s %d %s\n", (CL->S)->name[b], (CL->S)->len[b],(CL->S)->seq[b]);
3388 FILE * save_list_header ( FILE *OUT,Constraint_list *CL)
3393 for ( a=0; a<(CL->S)->nseq; a++)nseq+=((CL->S)->len[a]!=-1);
3396 fprintf ( OUT, "! TC_LIB_FORMAT_01\n%d\n",nseq);
3397 for ( a=0; a<(CL->S)->nseq; a++)
3398 if ((CL->S)->len[a]!=-1)
3400 fprintf ( OUT, "%s %d %s\n", (CL->S)->name[a], (CL->S)->len[a],(CL->S)->seq[a]);
3406 FILE *save_list_footer (FILE *OUT,Constraint_list *CL)
3408 if ( CL->cpu)fprintf (OUT, "! CPU %d\n",get_time());
3409 fprintf (OUT, "! SEQ_1_TO_N\n");
3412 int constraint_list2raw_file ( Constraint_list *CL, char *fname, char *mode)
3415 if ( !CL || !CL->ne || !fname){return 0;}
3417 fp=vfopen (fname,mode);
3418 fp=save_raw_constraint_list (fp, CL, 0, CL->ne, NULL);
3422 FILE * save_raw_constraint_list ( FILE *fp,Constraint_list *CL, int start,int len, int *translation)
3425 for ( b=0; b<CL->entry_len*CL->ne; b++)
3427 fprintf ( fp, "%d ", CL->L[b]);
3433 FILE * save_constraint_list_ascii ( FILE *OUT,Constraint_list *CL, int start,int len, int *translation)
3438 if (len==start && CL->cpu!=-1)
3440 fprintf (OUT, "! CPU %d\n",get_time());
3446 s1=translation[vread_clist(CL,start,SEQ1)];
3447 s2=translation[vread_clist(CL,start,SEQ2)];
3450 if ( s1!=-1 && s2!=-1)fprintf ( OUT, "#%d %d\n", s1+1, s2+1);
3451 for ( a=start; a<(len+start); a++)
3453 x1=translation[vread_clist(CL,a,SEQ1)];
3454 x2=translation[vread_clist(CL,a,SEQ2)];
3455 if ( x1==-1 || x2==-1);
3458 if ( x1!=s1 || x2!=s2)
3462 fprintf ( OUT, "#%d %d\n", s1+1, s2+1);
3464 for ( b=2; b<CL->entry_len; b++) fprintf ( OUT, "%5d ", vread_clist(CL, a, b));
3465 fprintf (OUT, "\n");
3469 return save_list_footer (OUT, CL);
3472 FILE * save_constraint_list_bin ( FILE *OUT,Constraint_list *CL, int start,int len, int *translation)
3479 if (len==start && CL->cpu!=-1)
3486 for ( a=start; a<(len+start); a++)
3488 x1=translation[vread_clist(CL,a,SEQ1)];
3489 x2=translation[vread_clist(CL,a,SEQ2)];
3490 if ( x1==-1 || x2==-1);
3493 for ( b=2; b<CL->entry_len; b++)
3495 x1=vread_clist(CL,a,b);
3496 fwrite (&x1, CL->el_size, 1, OUT);
3504 /*********************************************************************/
3506 /* LIST CONVERTION */
3509 /*********************************************************************/
3510 Constraint_list * filter_constraint_list (Constraint_list *CL, int field, int T)
3513 if (!CL || !CL->L)return CL;
3514 for (a=0, b=0; a<CL->ne; a++)
3516 if (CL->L[a*CL->entry_len+field]<T);
3519 for (c=0; c<CL->entry_len; c++)CL->L[b*CL->entry_len+c]=CL->L[a*CL->entry_len+c];
3524 CL->residue_indexed=0;
3527 int constraint_list_is_connected ( Constraint_list *CL)
3529 int a, b, c, s1, s2;
3534 if (!CL->ne) return 1;
3538 connexions=vcalloc ((CL->S)->nseq+1, sizeof (int));
3539 for ( a=0; a< CL->ne; a++)
3541 s1=CL->L[a*CL->entry_len+SEQ1];
3542 s2=CL->L[a*CL->entry_len+SEQ2];
3546 for (a=0; a<S->nseq; a++)
3550 add_warning ( stderr, "ERROR: Sequence %s is not connected\n", (CL->S)->name[a]);
3556 Constraint_list * nfork_relax_constraint_list (Constraint_list *CL);
3557 Constraint_list * fork_relax_constraint_list (Constraint_list *CL);
3558 Constraint_list * relax_constraint_list (Constraint_list *CL)
3560 if ( get_nproc()==1)return nfork_relax_constraint_list (CL);
3561 else if (strstr ( CL->multi_thread, "relax"))return fork_relax_constraint_list (CL);
3562 else return nfork_relax_constraint_list (CL);
3565 Constraint_list * fork_relax_constraint_list (Constraint_list *CL)
3567 int a, s1, s2, r1, r2,n;
3570 int chunk, npid, job,pid;
3577 if (!CL || !CL->L)return CL;
3579 fprintf ( CL->local_stderr, "\nLibrary Relaxation: Multi_proc [%d] ", get_nproc());
3581 if ((chunk=CL->ne/get_nproc())==0)chunk=get_nproc();
3584 pid_tmpfile=vcalloc ((CL->ne/chunk)+1, sizeof (char*));
3585 pid_list =vcalloc (MAX_N_PID, sizeof (int *));
3587 for (npid=0,job=0; job<CL->ne; job+=chunk)
3589 pid_tmpfile[npid]=vtmpnam(NULL);
3595 initiate_vtmpnam (NULL);
3597 e=MIN((s+chunk),CL->ne);
3598 fp=vfopen (pid_tmpfile[npid], "w");
3601 if (job==0)output_completion (CL->local_stderr,a,chunk,1, "Submit Job");
3602 s1=CL->L[a*CL->entry_len+SEQ1];
3603 s2=CL->L[a*CL->entry_len+SEQ2];
3605 r1=CL->L[a*CL->entry_len+R1];
3606 r2=CL->L[a*CL->entry_len+R2];
3607 score=residue_pair_extended_list_pc (CL,s1, r1,s2, r2);
3608 CL->L[a*CL->entry_len+WE]=score;
3609 fprintf (fp, "%d %d ", a, score);
3612 exit (EXIT_SUCCESS);
3622 for (a=0; a<npid; a++)
3628 fp=vfopen (pid_tmpfile[pid_list[pid]], "r");
3629 while (fscanf (fp, "%d %d ",&i, &score)==2){CL->L[i*CL->entry_len+WE]=score;j++;}
3631 remove(pid_tmpfile[pid_list[pid]]);
3635 vfree (pid_tmpfile);
3639 for (n=0,a=0; a< CL->ne; a++)
3641 score=CL->L[a*CL->entry_len+WE];
3646 CL->L[n*CL->entry_len+SEQ1]=CL->L[a*CL->entry_len+SEQ1];
3647 CL->L[n*CL->entry_len+SEQ2]=CL->L[a*CL->entry_len+SEQ2];
3648 CL->L[n*CL->entry_len+R1]=CL->L[a*CL->entry_len+R1];
3649 CL->L[n*CL->entry_len+R2]=CL->L[a*CL->entry_len+R2];
3650 CL->L[n*CL->entry_len+WE]=score;
3656 CL->L=vrealloc (CL->L, n*CL->entry_len*sizeof (int));
3659 fprintf ( CL->local_stderr, "\nTotal Relaxation: [%d]--->[%d] Entries\n",in, CL->ne);
3660 CL->residue_indexed=0;
3665 Constraint_list * nfork_relax_constraint_list (Constraint_list *CL)
3667 int a, s1, s2, r1, r2;
3671 if (!CL || !CL->L)return CL;
3673 fprintf ( CL->local_stderr, "\nLibrary Relaxation:[%d] ", CL->ne);
3674 for (max=0,a=0; a<CL->ne; a++)
3677 s1=CL->L[a*CL->entry_len+SEQ1];
3678 s2=CL->L[a*CL->entry_len+SEQ2];
3680 r1=CL->L[a*CL->entry_len+R1];
3681 r2=CL->L[a*CL->entry_len+R2];
3683 score=residue_pair_extended_list_pc (CL,s1, r1,s2, r2);
3684 //HERE ("%d %d", CL->L[a*CL->entry_len+WE],score);
3685 CL->L[a*CL->entry_len+WE]=score;
3691 for (n=0,a=0; a< CL->ne; a++)
3693 score=CL->L[a*CL->entry_len+WE];
3698 CL->L[n*CL->entry_len+SEQ1]=CL->L[a*CL->entry_len+SEQ1];
3699 CL->L[n*CL->entry_len+SEQ2]=CL->L[a*CL->entry_len+SEQ2];
3700 CL->L[n*CL->entry_len+R1]=CL->L[a*CL->entry_len+R1];
3701 CL->L[n*CL->entry_len+R2]=CL->L[a*CL->entry_len+R2];
3702 CL->L[n*CL->entry_len+WE]=score;
3707 CL->L=vrealloc (CL->L, n*CL->entry_len*sizeof (int));
3710 fprintf ( CL->local_stderr, "--->[%d]\n", CL->ne);
3711 CL->residue_indexed=0;
3716 Constraint_list * shrink_constraint_list (Constraint_list *CL)
3719 Constraint_list *CL2;
3723 ns=vcalloc (2, sizeof (int));
3724 ls=declare_int ((CL->S)->nseq, 2);
3726 A=seq2aln (CL->S,NULL, RM_GAP);
3727 B=seq2aln (CL->S,NULL, RM_GAP);
3728 CL2=declare_constraint_list (CL->S,NULL, NULL, 0,NULL, NULL);
3731 fprintf ( CL->local_stderr, "\n\n\tSHRINK Constraint List [%d element(s)]", CL->ne);
3732 for (n=0,a=0; a<(CL->S)->nseq-1; a++)
3733 for (b=a+1; b<(CL->S)->nseq; b++, n++)
3735 output_completion (CL->local_stderr,n, tot, 100, "slow_pair");
3739 ungap (A->seq_al[a]);
3740 ungap (A->seq_al[b]);
3741 linked_pair_wise (A, ns, ls, CL);
3742 B->seq_al[0]=A->seq_al[a];
3743 B->seq_al[1]=A->seq_al[b];
3744 sprintf (B->name[0], "%s", A->name[a]);
3745 sprintf (B->name[1], "%s", A->name[b]);
3747 B->len_aln=strlen (B->seq_al[0]);
3748 CL2=aln2constraint_list (B, CL2, "sim");
3757 Constraint_list *aln_file2constraint_list (char *alname, Constraint_list *CL,char *weight_mode)
3760 A=main_read_aln ( alname, NULL);
3762 CL=aln2constraint_list (A, CL, weight_mode);
3767 int *seqpair2weight (int s1, int s2, Alignment *A,Constraint_list *CL, char *weight_mode, int *weight)
3770 int a,c, ref_weight;
3773 if ( !weight)weight=vcalloc (MAX(2,A->len_aln), sizeof (int));
3776 if ( weight_mode==NULL || strcmp (weight_mode, "no")==0 || is_number (weight_mode))
3779 if (is_number (weight_mode))ref_weight=atoi(weight_mode);
3781 weight[1]=ref_weight;
3784 else if ( strstr ( weight_mode, "cons"))
3786 ref_weight=weight[1]=1000;
3788 else if ( strstr ( weight_mode, "OW"))
3791 sscanf ( weight_mode, "OW%d", &ow);
3792 weight[1]=ow*get_seq_sim ( A->seq_al[s1], A->seq_al[s2], "-", NULL);
3795 else if ( strncmp ( weight_mode, "len",3)==0)
3797 weight[1]=A->len_aln;
3799 else if ( strnm ( weight_mode, "sim", 3) || strm (weight_mode, "default"))
3802 ref_weight=get_seq_sim ( A->seq_al[s1], A->seq_al[s2], "-", (strm (weight_mode, "default"))?NULL:(weight_mode+3));
3803 weight[1]=ref_weight;
3806 else if ( strnm ( weight_mode, "subset", 6))
3808 ref_weight=get_seq_sim ( A->seq_al[s1], A->seq_al[s2], "-",NULL);
3809 weight[1]=ref_weight;
3812 else if ( strncmp (weight_mode, "winsim", 6)==0)
3814 weight=get_seq_winsim ( A->seq_al[s1], A->seq_al[s2], "-", weight_mode+6, weight);
3816 else if ( strncmp ( weight_mode, "cdna", 4)==0)
3818 ref_weight=get_seq_sim ( A->seq_al[s1], A->seq_al[s2], "-", weight_mode+4);
3819 col=vcalloc ( A->len_aln+1, sizeof (int));
3821 for ( a=0; a<=A->len_aln; a++)col[a]=A->cdna_cache[0][a];
3823 for ( a=0; a<=A->len_aln; a++)col[a]=1;
3824 for ( c=0; c< A->len_aln; c++)weight[c]=ref_weight*col[c];
3827 else if ( strm ( weight_mode, "pdb"))
3829 if ( !(A->CL) || !(A->CL)->T)
3831 fprintf ( stderr, "\nCould not find the PDB structure: [FATAL:%s]\n", PROGRAM);
3835 else if ( strm (weight_mode, "overaln"))
3837 ref_weight=get_seq_sim ( A->seq_al[s1], A->seq_al[s2], "-","idmat");
3838 //weight=pw_aln2clean_aln_weight (A->seq_al[s1], A->seq_al[s2], ref_weight,0, 0, 0, 0, NULL);
3839 printf_exit (EXIT_FAILURE, stderr,"ERROR: mode overaln not currently supported [FATAL:%s]", PROGRAM);
3843 fprintf ( stderr, "\nERROR: Weight Mode %s is unknown [FATAL:%s]", weight_mode, PROGRAM);
3848 Constraint_list *aln2constraint_list (Alignment *A, Constraint_list *CL,char *in_weight_mode)
3850 Constraint_list *CLB=NULL;
3851 int a, b, c,nres1, nres2;
3854 int fixed_nres1, fixed_nres2;
3860 char weight_mode [100];
3863 sprintf ( weight_mode , "%s", (!in_weight_mode || strm (in_weight_mode, "default"))?"sim":in_weight_mode);
3871 CL=declare_constraint_list (S,NULL, NULL, 0,NULL, NULL);
3874 CLB=(Constraint_list *)A->CL;
3877 do_pdb=(strstr ( weight_mode, "pdb"))?1:0;
3878 if ( (p=strstr (weight_mode, "_subset_")))
3880 alp=strchr (weight_mode, '_')+1;
3885 for ( a=0; a<A->nseq-1; a++)
3888 for (set_misc=0,b=a+1; b< A->nseq; b++)
3890 s1=name_is_in_list (A->name[a], (CL->S)->name, (CL->S)->nseq, 100);
3891 s2=name_is_in_list (A->name[b], (CL->S)->name, (CL->S)->nseq, 100);
3893 if ( s1==-1 || s2==-1)
3895 if ( getenv4debug ("DEBUG_LIBRARY"))fprintf ( stderr, "\n[DEBUG_LIBRARY:aln2constraint_list]Could use a pair of constraints");
3897 else if ( s1!=-1 && s2!=-1)
3901 weight=seqpair2weight (a, b, A, CL, weight_mode, weight);
3903 for (nres1=A->order[a][1], nres2=A->order[b][1], c=0; c< A->len_aln; c++)
3907 isgop1=is_gop(c, A->seq_al[a]);
3908 isgop2=is_gop(c, A->seq_al[b]);
3909 nres1+=!is_gap(A->seq_al[a][c]);
3910 nres2+=!is_gap(A->seq_al[b][c]);
3912 if ( strm ( weight_mode, "pdb") && CLB)
3915 pdb_weight=MAX(0,(CLB->evaluate_residue_pair)(CLB,0, nres1,1,nres2));
3919 use_pair=use_pair && !is_gap(A->seq_al[a][c]);
3920 use_pair=use_pair && !is_gap(A->seq_al[b][c]);
3921 use_pair=use_pair && A->seq_al[b][c]!=UNDEFINED_RESIDUE;
3922 use_pair=use_pair && A->seq_al[a][c]!=UNDEFINED_RESIDUE;
3923 use_pair=use_pair && !(do_pdb && pdb_weight==0);
3924 use_pair=use_pair && ((weight[0]==FORBIDEN)?weight[1]:weight[c]);
3926 if (alp)use_pair=use_pair && is_in_set (A->seq_al[b][c], alp) && is_in_set (A->seq_al[a][c], alp);
3928 /*if ( !is_gap(A->seq_al[a][c]) && !is_gap(A->seq_al[b][c]) && A->seq_al[b][c]!=UNDEFINED_RESIDUE && A->seq_al[a][c]!=UNDEFINED_RESIDUE && !(do_pdb && pdb_weight==0))*/
3932 fixed_nres1=(!A->seq_cache)?nres1:A->seq_cache[s1][nres1];
3933 fixed_nres2=(!A->seq_cache)?nres2:A->seq_cache[s2][nres2];
3936 if ( fixed_nres1==-1 || fixed_nres2==-1)
3938 fprintf ( stderr, "\nPB: Sequence %s, Residue %d : Cache=%d",A->name[a], nres1,fixed_nres1 );
3939 fprintf ( stderr, "\nPB: Sequence %s, Residue %d : Cache=%d",A->name[b], nres2,fixed_nres2 );
3941 myexit(EXIT_FAILURE);
3944 if ( fixed_nres1 && fixed_nres2)
3950 This code was uncommented to make profile2seq simpler
3951 Must check how this affects other functions
3953 vwrite_clist (CL,CL->ne, SEQ1, (s1<s2)?s1:s2);
3954 vwrite_clist (CL,CL->ne, SEQ2, (s1<s2)?s2:s1);
3955 vwrite_clist (CL,CL->ne, R1, (s1<s2)?fixed_nres1:fixed_nres2);
3956 vwrite_clist (CL,CL->ne, R2, (s1<s2)?fixed_nres2:fixed_nres1);
3959 vwrite_clist (CL,CL->ne, SEQ1, s1);
3960 vwrite_clist (CL,CL->ne, SEQ2, s2);
3961 vwrite_clist (CL,CL->ne, R1,fixed_nres1);
3962 vwrite_clist (CL,CL->ne, R2,fixed_nres2);
3967 vwrite_clist (CL,CL->ne, WE,(NORM_F/MAXID)*pdb_weight );
3972 vwrite_clist (CL,CL->ne, WE,(NORM_F/MAXID)*((weight[0]==FORBIDEN)?weight[1]:weight[c]) );
3975 vwrite_clist (CL,CL->ne, CONS,1);
3978 vwrite_clist (CL,CL->ne, MISC,A->len_aln);
3983 vwrite_clist (CL,CL->ne, MISC,0);
3990 vwrite_clist (CL,CL->ne, SEQ1, s1);
3991 vwrite_clist (CL,CL->ne, SEQ2, s1);
3992 vwrite_clist (CL,CL->ne, R1,fixed_nres1);
3993 vwrite_clist (CL,CL->ne, R2,fixed_nres1);
3994 vwrite_clist (CL,CL->ne, WE, (weight[0]==FORBIDEN)?weight[1]:weight[c] );
3995 vwrite_clist (CL,CL->ne, CONS,1);
4001 vwrite_clist (CL,CL->ne, SEQ1, s2);
4002 vwrite_clist (CL,CL->ne, SEQ2, s2);
4003 vwrite_clist (CL,CL->ne, R1,fixed_nres2);
4004 vwrite_clist (CL,CL->ne, R2,fixed_nres2);
4005 vwrite_clist (CL,CL->ne, WE, (weight[0]==FORBIDEN)?weight[1]:weight[c] );
4006 vwrite_clist (CL,CL->ne, CONS,1);
4021 return aln2constraint_list (A->A, CL, weight_mode);
4026 double **list2mat (Constraint_list *CLin,int s1,int s2, double *min, double *max)
4031 Constraint_list *CL;
4036 if ( S==NULL)S=declare_sequence ((CLin->S)->min_len, (CLin->S)->max_len,(CLin->S)->nseq);
4037 sprintf ( S->name[0], "%s",(CLin->S)->name[s1]);
4038 sprintf ( S->name[1],"%s",(CLin->S)->name[s2]);
4041 row =(CLin->S)->len[s1];
4042 column=(CLin->S)->len[s2];
4044 if ( CLin->extend_jit)
4045 CL=extend_list(CLin,"mem",CLin->extend_clean_mode, CLin->extend_compact_mode, CLin->do_self, S);
4051 mat=declare_double ( row, column);
4053 for ( a=0; a<CL->ne; a++)
4055 r1=vread_clist(CL,a,R1)-1;
4056 r2=vread_clist(CL,a,R2)-1;
4057 if ( vread_clist(CL,a,SEQ1)==s1 &&vread_clist(CL,a,SEQ2)==s2)
4059 mat[r1][r2]=(double)vread_clist(CL,a,WE);
4068 min[0]=(min[0]<mat[r1][r2])?min[0]:mat[r1][r2];
4069 max[0]=(max[0]>mat[r1][r2])?max[0]:mat[r1][r2];
4072 else if (vread_clist(CL,a,SEQ2)==s1 &&vread_clist(CL,a,SEQ1)==s2)
4074 mat[r2][r1]=(double)vread_clist(CL,a,WE);
4083 min[0]=(min[0]<mat[r2][r1])?min[0]:mat[r2][r1];
4084 max[0]=(max[0]>mat[r2][r1])?max[0]:mat[r2][r1];
4091 Constraint_list * constraint_list2bin_file(Constraint_list *clist)
4095 clist->fp=tmpfile();
4096 for ( a=0; a< clist->ne; a++)
4097 for ( b=0; b<clist->entry_len; b++)
4099 fwrite (&clist->L[a*clist->entry_len+b],clist->el_size, 1,clist->fp);
4104 FILE * bin_file2constraint_list ( Constraint_list *CL, FILE *fp, char *name)
4109 if ( fp==NULL)fp=vfopen ( name, "w");
4110 entry=vcalloc ( CL->entry_len, CL->el_size);
4111 fprintf ( fp, "%d\n", (CL->S)->nseq);
4112 for ( a=0; a< (CL->S)->nseq; a++)fprintf (fp, "%s %d %s\n", (CL->S)->name[a], (CL->S)->len[a], (CL->S)->seq[a]);
4116 fread(entry, CL->el_size, CL->entry_len, CL->fp);
4119 fprintf (fp, "#%d %d\n", s1, s2);
4120 for ( b=2; b< CL->entry_len; b++)fprintf (fp, "%5d ",entry[b]);
4122 for ( a=1; a< (CL->ne); a++)
4124 fread(entry, CL->el_size, CL->entry_len, CL->fp);
4125 if ( entry[SEQ1]!=s1 || entry[SEQ2]!=s2)
4129 fprintf (fp, "#%d %d\n", s1, s2);
4131 for ( b=2; b< CL->entry_len; b++)fprintf (fp, "%5d ",entry[b]);
4134 fprintf (fp, "! CPU %d\n",get_time());
4138 int **list2residue_total_weight ( Constraint_list *CL)
4141 tot_weight[nseq][maxlen]
4142 where each residue is associated with the total of its weights in CL
4145 -the numbering of the residues goes from 1 to L:
4146 -the numbering of the sequences goes from 0 to N-1:
4150 int s1, s2, r1, r2, w, a;
4153 tot_weight=declare_int ( (CL->S)->nseq, (CL->S)->max_len+1);
4154 for ( a=0; a<CL->ne; a++)
4156 r1=vread_clist(CL,a,R1)-1;
4157 r2=vread_clist(CL,a,R2)-1;
4158 s1=vread_clist(CL,a,SEQ1);
4159 s2=vread_clist(CL,a,SEQ2);
4160 w=vread_clist(CL,a,WE);
4162 tot_weight[s1][r1]+=w;
4163 tot_weight[s2][r2]+=w;
4168 int **list2residue_total_extended_weight ( Constraint_list *CL)
4171 tot_extended_weight[nseq][maxlen]
4172 where each residue is associated with the total of its weights in CL
4175 -the numbering of the residues goes from 1 to L:
4176 -the numbering of the sequences goes from 0 to N-1:
4179 static int **tot_extended_weight;
4180 int s1, s2, r1, r2, w;
4182 if (CL->residue_indexed && tot_extended_weight);
4185 if (tot_extended_weight) free_int (tot_extended_weight, -1);
4186 if (CL->residue_indexed==0)index_res_constraint_list (CL,WE);
4189 tot_extended_weight=declare_int ( (CL->S)->nseq, (CL->S)->max_len+1);
4191 for ( s1=0; s1< (CL->S)->nseq-1; s1++)
4192 for ( s2=s1+1; s2< (CL->S)->nseq; s2++)
4193 for (r1=1; r1<=(CL->S)->len[s1]; r1++)
4194 for (r2=1; r2<=(CL->S)->len[s2]; r2++)
4196 w=(CL->evaluate_residue_pair)( CL, s1, r1, s2, r2);
4197 tot_extended_weight[s1][r1]+=w;
4198 tot_extended_weight[s2][r2]+=w;
4201 return tot_extended_weight;
4203 int **list2residue_partial_extended_weight ( Constraint_list *CL)
4206 tot_extended_weight[nseq][maxlen]
4207 where each residue is associated with the total of its weights in CL
4210 -the numbering of the residues goes from 1 to L:
4211 -the numbering of the sequences goes from 0 to N-1:
4214 int **tot_extended_weight;
4215 int s1, s2, r1, r2, w1, w2, a;
4218 tot_extended_weight=declare_int ( (CL->S)->nseq, (CL->S)->max_len+1);
4219 for ( a=0; a<CL->ne; a++)
4221 r1=vread_clist(CL,a,R1);
4222 r2=vread_clist(CL,a,R2);
4223 s1=vread_clist(CL,a,SEQ1);
4224 s2=vread_clist(CL,a,SEQ2);
4225 w1=(CL->evaluate_residue_pair)( CL, s1, r1, s2, r2);
4226 w2=(CL->evaluate_residue_pair)( CL, s2, r2, s1, r1);
4227 if ( w1!=w2)fprintf ( stderr, "*");
4229 tot_extended_weight[s1][r1]+=w1;
4230 tot_extended_weight[s2][r2]+=w2;
4232 return tot_extended_weight;
4236 /*******************************************************************************************/
4239 /* clean functions */
4243 /*******************************************************************************************/
4244 Constraint_list *clean ( char *clean_mode,Constraint_list *CL,int start, int len)
4247 if ( strm ( clean_mode, "shadow")) CL=clean_shadow (CL,start,len);
4248 else if ( strm5( clean_mode, "","NO","no","No","default"));
4249 else add_warning ( CL->local_stderr, "\nWARNING: The %s CLEANING MODE DOES NOT EXIST\n", clean_mode);
4255 Constraint_list * clean_shadow ( Constraint_list *CL, int start, int len)
4257 int s1, s2, r1, a, b, end;
4260 s1=vread_clist (CL, start, SEQ1);
4261 s2=vread_clist (CL, start, SEQ2);
4262 r1=vread_clist (CL, start, R1);
4265 for ( a=start; a<(start+len);)
4268 max=min=vread_clist (CL, a, WE);
4269 while ( a<CL->ne && vread_clist (CL, a, SEQ1)==s1 && vread_clist (CL, a, SEQ2)==s2 && vread_clist (CL, a, R1)==r1)
4271 max=(vread_clist (CL, a, WE)>max)?vread_clist (CL, a, WE):max;
4272 min=(vread_clist (CL, a, WE)<min)?vread_clist (CL, a, WE):min;
4279 for ( b=start; b<end; b++)
4280 if ( vread_clist (CL, b, WE)<max)vwrite_clist (CL, b, SEQ1,-1);
4285 s1=vread_clist (CL, start, SEQ1);
4286 s2=vread_clist (CL, start, SEQ2);
4287 r1=vread_clist (CL, start, R1);
4290 CL=sort_constraint_list_inv (CL, start, (CL->ne-start));
4291 CL=sort_constraint_list (CL,start,(CL->ne-start) );
4295 /*********************************************************************/
4297 /* LIST FUNCTIONS */
4300 /*********************************************************************/
4302 static Constraint_list *fast_merge_constraint_list ( Constraint_list *SL, Constraint_list *ML, char *mode);
4303 static Constraint_list *slow_merge_constraint_list ( Constraint_list *SL, Constraint_list *ML, char *mode);
4305 Constraint_list *merge_constraint_list ( Constraint_list *SL, Constraint_list *ML, char *mode)
4313 else if ( SL->S == ML->S)
4315 return fast_merge_constraint_list (SL, ML, mode);
4319 return slow_merge_constraint_list (SL, ML, mode);
4323 Constraint_list *fast_merge_constraint_list ( Constraint_list *SL, Constraint_list *ML, char *mode)
4331 ML->residue_indexed=0;
4332 if (ML->ne==0 || !ML->L)ML->L=vcalloc (l*ML->entry_len, sizeof (int));
4333 else ML->L=vrealloc (ML->L, sizeof (int)*l*ML->entry_len);
4335 memcpy (ML->L+(ML->ne*ML->entry_len), SL->L, SL->ne*sizeof (int)*SL->entry_len);
4342 Constraint_list *slow_merge_constraint_list ( Constraint_list *SL, Constraint_list *ML, char *mode)
4348 CLIST_TYPE *entry=NULL;
4354 name_index=index_seq_name(S1,S2);
4355 seq_index=index_seq_res (S1,S2, name_index);
4357 for ( a=0; a< SL->ne; a++)
4360 entry=extract_entry ( entry, a, SL);
4361 //HERE ("BEF: %d %d %d %d", entry[SEQ1], entry[SEQ2], entry[R1], entry[R2]);
4362 s1=entry[SEQ1]; s2=entry[SEQ2];
4366 add_entry2list(entry, ML);
4368 else if (name_index[s1][0]==-1 || name_index[s2][0]==-1 || !seq_index[s1] || !seq_index[s2]);
4372 r1=seq_index[s1][entry[R1]-1];
4373 r2=seq_index[s2][entry[R2]-1];
4375 entry[SEQ1]=name_index[s1][0];
4376 entry[SEQ2]=name_index[s2][0];
4377 if ( r1!=-1 && r2!=-1 && entry[SEQ1]!=entry[SEQ2])
4379 entry[R1]=r1+1; entry[R2]=r2+1;
4380 add_entry2list(entry, ML);
4382 //HERE ("AFT: %d %d %d %d", entry[SEQ1], entry[SEQ2], entry[R1], entry[R2]);
4385 free_int (name_index, -1);
4386 free_int ( seq_index, -1);
4391 Constraint_list *modify_weight( Constraint_list *CL,int start, int end, char *modify_mode)
4396 if ( strm(modify_mode, "default"))return CL;
4397 for ( a=start; a<end; a++)
4399 x=vread_clist(CL, a, WE);
4401 if (strm2 (modify_mode,"sc_eq_cons", "we_eq_cons"))
4403 vwrite_clist(CL, a, WE, vread_clist(CL, a, CONS));
4405 if (strm2(modify_mode,"sc_eq_wePcons","sc_eq_consPwe"))
4407 vwrite_clist(CL, a, WE, vread_clist(CL, a, CONS)*x);
4412 Constraint_list *compact_list (Constraint_list *CL, int start, int len, char *compact_mode)
4415 int r1, r2, rr1, rr2, s1, rs1, s2, rs2, ra;
4417 int debug_compact=0;
4419 if (debug_compact)fprintf ( stderr, "\n[In: %d %s start=%d len=%d", CL->ne, compact_mode, start, len);
4421 if ( len==0 || strm3(compact_mode, "no", "No", "NO"))return CL;
4422 else if ( strm2(compact_mode,"mirror","mirror_sum"));
4423 else if ( strm4(compact_mode, "default","shrink","shrink_best","shrink_worst"))
4426 for ( a=start; a<(start+len) ; a++)
4429 if ( vread_clist(CL, a, SEQ1)> vread_clist(CL, a, SEQ2) ||\
4430 ( vread_clist(CL, a, SEQ1)==vread_clist(CL, a, SEQ2) &&\
4431 vread_clist(CL, a, R1) > vread_clist(CL, a, R2) ))
4435 s1=vread_clist(CL, a, SEQ1);
4436 s2=vread_clist(CL, a, SEQ2);
4437 r1=vread_clist(CL, a, R1);
4438 r2=vread_clist(CL, a, R2);
4439 vwrite_clist(CL, a, SEQ1,s2);
4440 vwrite_clist(CL, a, SEQ2,s1);
4441 vwrite_clist(CL, a, R1,r2);
4442 vwrite_clist(CL, a, R2,r1);
4447 if (debug_compact)fprintf ( stderr, "\n[2: %d %s start=%d len=%d", CL->ne, compact_mode, start, len);
4449 sort_constraint_list ( CL, start, len);
4451 rs1=vread_clist(CL, start, SEQ1);
4452 rs2=vread_clist(CL, start, SEQ2);
4453 rr1=vread_clist(CL, start, R1);
4454 rr2=vread_clist(CL, start, R2);
4457 if (debug_compact)fprintf ( stderr, "\n[3: %d %s start=%d len=%d", CL->ne, compact_mode, start, len);
4460 if ( (rs1==rs2) && (rr1==rr2))vwrite_clist(CL, start, SEQ1,-1);
4461 for ( a=start+1; a<(start+len); a++)
4463 s1=vread_clist(CL, a, SEQ1);
4464 s2=vread_clist(CL, a, SEQ2);
4465 r1=vread_clist(CL, a, R1);
4466 r2=vread_clist(CL, a, R2);
4468 //if ( (s1==s2) && (r1==r2))vwrite_clist(CL, a, SEQ1, -1);
4469 if ( s1==rs1 && s2==rs2 && r1==rr1 && r2==rr2)
4471 x=vread_clist(CL, ra, WE);
4472 if (strm ( compact_mode, "shrink"));
4473 else if (strm( compact_mode,"default"))//default is set to best
4474 vwrite_clist(CL, ra, WE,MAX(vread_clist(CL, a, WE),x));
4475 else if ( strm ( compact_mode,"mirror_sum"))
4476 vwrite_clist(CL, ra, WE, vread_clist(CL, a, WE)+x);
4477 else if (strm2 ( compact_mode,"best", "shrink_best"))
4478 vwrite_clist(CL, ra, WE,MAX(vread_clist(CL, a, WE),x));
4479 else if (strm2 ( compact_mode, "worst","shrink_worst"))
4480 vwrite_clist(CL, ra, WE,MIN(vread_clist(CL, a, WE), vread_clist(CL, a, WE)));
4482 if ( strm(compact_mode, "shrink"));
4485 vwrite_clist(CL, ra, CONS, vread_clist(CL, ra, CONS)+ vread_clist(CL, a, CONS));
4486 vwrite_clist(CL, ra, MISC, vread_clist(CL, ra, MISC)+ vread_clist(CL, a, MISC));
4488 vwrite_clist(CL,a, SEQ1, -1);
4502 sort_constraint_list_inv(CL,0,CL->ne);
4504 sort_constraint_list (CL,0,CL->ne);
4507 if ( strm3 (compact_mode, "consPwe", "wePcons","cons"))
4509 for ( a=start; a<(start+len); a++)
4511 if ( strm2(compact_mode,"consPwe", "wePcons"))
4512 vwrite_clist(CL, a, WE, vread_clist(CL,a,WE)* vread_clist(CL,a,CONS));
4513 else if (strm (compact_mode, "cons"))
4514 vwrite_clist(CL, a, WE, vread_clist(CL,a,CONS)*100);
4517 if (debug_compact)fprintf ( stderr, "....OUT: %d]\n", CL->ne);
4522 Constraint_list *rescale_list_simple (Constraint_list *CL,int start, int len,int new_min, int new_max)
4526 /*Rescales between 0 and max2
4527 Any value above max1 is set to max1 first and then to max2
4532 min=max=vread_clist ( CL,start, WE);
4534 for ( a=start; a<(start+len); a++)
4536 x=(double)vread_clist ( CL,a, WE);
4537 if ( x>max)max=(int)x;
4538 if ( x< min)min=(int)x;
4541 fprintf ( CL->local_stderr, "\n[%d-%d]=>[%d-%d]", min, max, new_min, new_max);
4543 for ( a=start; a<(start+len); a++)
4546 x=vread_clist(CL,a, WE);
4548 if ((max-min)==0)x=100;
4549 else x=(((x-min)/(max-min))*new_max)+new_min;
4551 vwrite_clist(CL, a, WE,(CLIST_TYPE) x);
4555 Constraint_list *rescale_list (Constraint_list *CL,int start, int len,int max1, int max2)
4557 int a, min_val, max_val;
4560 /*Rescales between 0 and max2
4561 Any value above max1 is set to max1 first and then to max2
4570 for ( a=start; a<len; a++)
4572 if (vread_clist ( CL,a, WE)>max1)vwrite_clist(CL, a, WE, max1);
4575 for ( a=start; a<len; a++)
4577 x=vread_clist(CL,a, WE);
4578 vwrite_clist(CL, a, WE, (((x-min_val)*max2)/(max_val-min_val)));
4584 Constraint_list* filter_list (Constraint_list *CL, int start, int len,int T)
4600 for ( a=start; a<len; a++)
4601 if (vread_clist(CL, a, field)<=T)vwrite_clist(CL,a,SEQ1,-1);
4603 CL=sort_constraint_list_inv (CL, 0, CL->ne);
4604 CL=sort_constraint_list (CL, 0, CL->ne);
4612 Constraint_list *undefine_list (Constraint_list *CL)
4617 for ( a=0;a<CL->ne; a++)
4619 for ( b=0, undefined_flag=0; b< LIST_N_FIELDS; b++)
4622 if ( vread_clist (CL, a, b)==UNDEFINED)undefined_flag=1;
4623 if ( undefined_flag)
4625 for ( b=0; b< LIST_N_FIELDS; b++)
4626 if ( b!=SEQ1 && b!=SEQ2 && b!=R1 && b!=R2)
4628 vwrite_clist(CL, a, b, UNDEFINED);
4636 int ** seq2defined_residues ( Sequence *S, Constraint_list *CL)
4642 seq_count=declare_int (S->nseq, S->max_len+1);
4643 for (a=0; a< CL->ne; a++)
4645 entry=extract_entry(entry, a, CL);
4646 seq_count[entry[SEQ1]][entry[R1]]++;
4647 seq_count[entry[SEQ2]][entry[R2]]++;
4653 int ** aln2defined_residues ( Alignment *A, Constraint_list *CL)
4661 pos=aln2pos_simple(A, A->nseq);
4662 seq_count=seq2defined_residues(CL->S, CL);
4663 aln_count=declare_int (A->nseq, A->len_aln);
4664 for (a=0; a< A->nseq; a++)
4666 ra=name_is_in_list(A->name[a], (CL->S)->name, (CL->S)->nseq, 100);
4667 if ( ra==-1) continue;
4668 for ( b=0; b<A->len_aln; b++)
4669 if (pos[a][b]>0 && seq_count[ra][pos[a][b]]>0)aln_count[a][b]=1;
4672 free_int (seq_count, -1);
4677 /*********************************************************************/
4679 /* DEBUG CONSTRAINT_LIST */
4682 /*********************************************************************/
4683 void check_seq_pair_in_list(Constraint_list *CLin,int seq1, int seq2)
4685 int a, s1, s2, r1, r2;
4687 for ( a=0; a< CLin->ne; a++)
4689 s1=vread_clist(CLin,a,SEQ1);
4690 s2=vread_clist(CLin,a,SEQ2);
4691 if ( s1==seq1 && s2==seq2)
4693 r1=vread_clist(CLin,a,R1);
4694 r2=vread_clist(CLin,a,R2);
4695 fprintf ( stderr, "\n[%d][%d %d] [%d %d]",a,s1, r1, s2, r2);
4700 void print_CL_mem(Constraint_list *CL, char *function)
4702 fprintf ( stderr,"%s\n", function);
4703 if ( CL->fp==NULL && CL->L==NULL) fprintf ( stderr, "\n\tNOTHING");
4704 if ( CL->fp)fprintf ( stderr, "\n\tFILE SET");
4705 if ( CL->L)fprintf ( stderr, "\n\tMEM SET\n");
4708 int constraint_list_is_sorted ( Constraint_list *CL)
4711 for ( a=0; a< CL->ne-1; a++)
4713 for ( b=0; b< CL->entry_len; b++)
4715 x1=vread_clist( CL, a, b);
4716 x2=vread_clist( CL, a+1,b);
4720 fprintf ( stderr, "\n[%d][%d]=>%d\n[%d][%d]=>%d\n\n",a, b, x1, a+1, b, x2);
4728 /*********************************************************************/
4730 /* PRUNE CONSTRAINT_LIST */
4733 /*********************************************************************/
4734 char * list2prune_list_old ( Sequence *S, int **sm)
4737 char *aln, *seq, *file;
4744 file=vtmpnam (NULL);
4746 output_fasta_seq (seq, A=seq2aln (S,NULL,RM_GAP));
4749 printf_system ( "t_coffee %s -in Xblosum62mt -outfile=%s -msa_mode iterative_tree_aln", seq, aln);
4750 printf_system ( "t_coffee -other_pg seq_reformat -in %s -action +trim _aln_n5 -output fasta_seq > %s",aln, seq );
4751 subS=main_read_seq ( seq);
4753 fp=vfopen (file, "w");
4754 for ( a=0; a< subS->nseq; a++)
4756 i=name_is_in_list (subS->name[a], S->name, S->nseq, 100);
4757 if ( i==-1) continue;
4758 for ( b=0; b<S->nseq; b++)
4759 if (i!=b)fprintf ( fp, "\n2 %d %d",i, b);
4765 char * list2prune_list ( Sequence *S, int **sm)
4768 int **mat, *used, *keep;
4776 if (get_string_variable("prune_lib_mode"))
4777 ns=atoi(get_string_variable("prune_lib_mode"));
4781 else if (ns<0)ns=-(n*ns)/100;
4782 else if (ns>=n)ns=n;
4788 keep=vcalloc (n, sizeof (int));
4789 used=vcalloc (n, sizeof (int));
4790 mat=declare_int (n, n);
4791 file=vtmpnam (NULL);
4793 //1-Identify the seed sequence: the one on average the further away from the rest
4799 mat[a][1]+=sm[a][b];
4801 sort_int_inv (mat, 2, 1, 0, n-1);
4804 keep[nk++]=mat[0][0];
4807 for (a=1; a<ns; a++)
4812 if (used[c]){mat[c][1]=n*1000;continue;}
4813 for (b=0; b<nk; b++)
4815 mat[c][1]+=sm[c][keep[b]];
4818 sort_int (mat, 2, 1, 0,n-1);
4819 keep[nk++]=mat[0][0];
4823 fp=vfopen (file, "w");
4824 for ( a=0; a<nk; a++)
4826 for (b=0; b<S->nseq; b++)
4829 fprintf ( fp, "\n2 %d %d", keep[a], b);
4833 vfree (keep); vfree (used);free_int (mat, -1);
4839 char * list2prune_list_old3 ( Sequence *S, int **sm)
4842 int a,b,c,n,s1,s2, tot, nseq;
4848 keep=declare_int (nseq, nseq);
4850 for (a=0; a< nseq; a++)
4851 for (b=a+1; b< nseq; b++)
4855 for (c=0; c< nseq; c++)
4857 if ( c==a || c==b) continue;
4858 s2=MIN(sm[a][c], sm[c][b]);
4860 if (s2>s1 && s2>bsim)
4875 file=vtmpnam (NULL);
4876 fp=vfopen (file, "w");
4878 for (n=0,tot=0,a=0; a< nseq; a++)
4879 for ( b=a+1; b< nseq; b++)
4882 fprintf (fp, "\n 2 %d %d", a, b);
4888 /*********************************************************************/
4890 /* WEIGHT CONSTRAINT_LIST */
4893 /*********************************************************************/
4895 Constraint_list *weight_constraint_list(Constraint_list * CL, char *seq_weight)
4900 if ( CL->ne==0)return CL;
4901 else if ( strm(seq_weight, "t_coffee")) W=compute_t_coffee_weight(CL);
4902 else if (check_file_exists (seq_weight))
4904 W=read_seq_weight ((CL->S)->name, (CL->S)->nseq, seq_weight);
4909 W=declare_weights((CL->S)->nseq);
4910 sprintf ( W->mode, "no_seq_weight");
4911 for ( a=0; a<(CL->S)->nseq; a++)
4913 sprintf ( W->seq_name[a], "%s", (CL->S)->name[a]);
4920 CL=re_weight_constraint_list (CL,W);
4932 Weights* compute_t_coffee_weight(Constraint_list * CL)
4943 if (!CL->L)return NULL;
4946 W=declare_weights(nseq);
4947 sprintf ( W->mode, "t_coffee");
4948 for ( a=0; a< nseq; a++)
4950 sprintf ( W->seq_name[a], "%s", (CL->S)->name[a]);
4955 for (a=0; a< (CL->S)->nseq-1; a++)
4956 for ( b=a+1; b< (CL->S)->nseq; b++)
4959 else if ( !(CL->S)->len[b] || !(CL->S)->len[a])d=1;
4962 d=((float)(CL->DM)->similarity_matrix[a][b]/MAXID)*10;
4971 for ( p=0,b=0; b< (CL->S)->nseq; b++)
4973 if ((CL->S)->len[b]==0)W->SEQ_W[b]=0;
4974 else W->SEQ_W[b]=2/W->SEQ_W[b];
4977 for ( b=0; b< (CL->S)->nseq; b++)
4979 W->SEQ_W[b]=W->SEQ_W[b]*((float)W->nseq/p);
4986 Constraint_list *re_weight_constraint_list(Constraint_list * CL,Weights *W)
4997 if (!CL->L)return CL;
5001 for ( a=0; a< CL->ne; a++)
5003 sA=CL->L[a*CL->entry_len+SEQ1];
5004 sB=CL->L[a*CL->entry_len+SEQ2];
5006 w=MIN(weight[sA], weight[sB]);
5008 CL->L[a*CL->entry_len+WE]*=w;
5010 CL=evaluate_constraint_list_reference (CL);
5014 Distance_matrix* cl2distance_matrix (Constraint_list *CL, Alignment *A, char *in_mode, char *in_sim_mode, int print)
5018 char sim_mode [100];
5022 if ( !CL)return NULL;
5023 sprintf ( mode, "%s", (CL && in_mode==NULL)?CL->distance_matrix_mode:in_mode);
5024 sprintf ( sim_mode, "%s", (CL && in_sim_mode==NULL)?CL->distance_matrix_sim_mode:in_sim_mode);
5026 if ( !CL->DM ||!strm ((CL->DM)->mode, mode) || !strm ((CL->DM)->sim_mode, sim_mode) || A )
5028 return seq2distance_matrix (CL, A, mode, sim_mode, print);
5038 Distance_matrix *seq2distance_matrix (Constraint_list *CL, Alignment *A,char *mode, char *sim_mode, int print)
5040 /*Compute the distance matrix associated with the Constraint List and the sequences*/
5041 /*Computation only occurs if the similiraty matrix is undefined : CL->similarity_matrix*/
5042 /*Undefine CL->similarity_matrix to force computation*/
5046 Constraint_list *NCL;
5053 static float **g_matrix;
5056 Distance_matrix *DM;
5057 int **sim_table=NULL;
5059 //mode: computation mode
5060 //sim_mode: mode for computing the similarity
5064 if (strm (mode, "ktup2"))
5066 B=seq2aln ( CL->S, NULL, 1);
5067 B=very_fast_aln (B, B->nseq,NULL);
5068 sprintf ( CL->distance_matrix_mode, "aln");
5069 DM=cl2distance_matrix (CL, B, NULL, NULL, 1);
5070 sprintf ( CL->distance_matrix_mode, "ktup2");
5071 sprintf ( DM->mode, "%s", mode);
5072 sprintf ( DM->sim_mode, "%s", sim_mode);
5077 if ( !CL) return NULL;
5080 for ( max_name=0,a=0; a< (CL->S)->nseq; a++)max_name=MAX(strlen ((CL->S)->name[a]), max_name);
5083 if ( CL->DM)DM=CL->DM;
5086 DM=vcalloc ( 1, sizeof (Distance_matrix));
5087 DM->nseq=(CL->S)->nseq;
5088 DM->similarity_matrix=declare_int ( (CL->S)->nseq, (CL->S)->nseq);
5089 DM->distance_matrix =declare_int ( (CL->S)->nseq, (CL->S)->nseq);
5090 DM->score_similarity_matrix=declare_int ( (CL->S)->nseq, (CL->S)->nseq);
5093 sprintf ( DM->mode, "%s", mode);
5094 sprintf ( DM->sim_mode, "%s", sim_mode);
5096 NCL=duplicate_constraint_list_soft (CL);
5097 NCL->pw_parameters_set=1;
5101 if ( CL->tree_aln)B=CL->tree_aln;
5102 else B=seq2aln ( NCL->S, NULL, 1);
5106 B=copy_aln (A, NULL);
5107 B=reorder_aln (B, (CL->S)->name, (CL->S)->nseq);
5110 if ( strm (mode, "very_fast"))
5112 sprintf ( NCL->dp_mode, "very_fast_pair_wise");
5113 NCL->evaluate_residue_pair=evaluate_matrix_score;
5114 if ( strm ((CL->S)->type, "DNA") ||strm ((CL->S)->type, "RNA") )
5116 NCL->M=read_matrice ("idmat");
5123 NCL->M=read_matrice ("blosum62mt");
5124 NCL->gop=get_avg_matrix_mm (NCL->M, AA_ALPHABET)*10;
5128 NCL->use_fragments=1;
5129 CL->diagonal_threshold=6;
5132 else if ( strm (mode, "ktup"))
5136 sim_table=ktup_dist_mat((CL->S)->seq,(CL->S)->nseq,NCL->ktup, (CL->S)->type);
5140 else if (strm (mode, "aln"))
5143 sim_table=aln2sim_mat (A, sim_mode);
5145 else if ( strm (mode, "fast") || strm ("idscore", mode))
5147 sprintf ( NCL->dp_mode, "myers_miller_pair_wise");
5148 NCL->evaluate_residue_pair=evaluate_matrix_score;
5149 if ( strm ((CL->S)->type, "DNA") || strm ((CL->S)->type, "RNA"))
5151 NCL->M=read_matrice ("idmat");
5157 NCL->M=read_matrice ("blosum62mt");
5158 NCL->gop=get_avg_matrix_mm (NCL->M, AA_ALPHABET)*10;
5162 else if ( strm (mode, "cscore"))
5164 if (!CL || !CL->L || CL->ne==0)
5165 return seq2distance_matrix (CL, A,"idscore",sim_mode, print);
5167 else if ( strm (mode, "geometric") );
5168 else if (strm (mode, "slow"));
5169 else if (strm (mode, "clustalw"));
5170 else if (strm (mode, "no"))
5172 else if (strm (mode, "random"))
5176 fprintf ( stderr, "\nError: %s is an unknown distance_matrix_mode [FATAL:%s]", mode,PROGRAM);
5180 //Special Geometric Mode
5181 if ( strm (NCL->distance_matrix_mode, "geometric"))
5183 free_arrayN(g_matrix, 2);
5184 g_matrix=declare_float ((CL->S)->nseq, 3);
5185 n_coor=MIN(3,((CL->S)->nseq));
5187 for ( a=0; a<(CL->S)->nseq; a++)
5189 for (b=0; b<n_coor; b++)
5191 B=align_two_sequences ((CL->S)->seq[a], (CL->S)->seq[b], "pam250mt", -10, -1, "fasta_pair_wise");
5192 g_matrix[a][b]=get_seq_sim ( B->seq_al[0], B->seq_al[1], "-", NULL);
5196 ref=(float)sqrt((double)(10000*n_coor));
5200 ns=vcalloc ( 2, sizeof(int));
5201 l_s=declare_int ( 2, 1);
5206 if (CL->local_stderr && print>0)fprintf ( (CL->local_stderr), "\nCOMPUTE PAIRWISE SIMILARITY [dp_mode: %s] [distance_matrix_mode: %s][Similarity Measure: %s] \n", NCL->dp_mode,mode, sim_mode);
5208 for (a=0; a< (CL->S)->nseq; a++)
5210 if (CL->local_stderr && print>0)fprintf ( (CL->local_stderr), "\n\tSeq: %s", (CL->S)->name[a]);
5211 for ( b=a; b< (CL->S)->nseq; b++)
5213 if ( b==a){DM->similarity_matrix[a][b]=MAXID;}
5218 if ( !strm(mode, "ktup2") && ! strm (mode, "geometric"))
5220 ungap ( B->seq_al[a]);
5221 ungap ( B->seq_al[b]);
5224 if ( strm (mode, "slow"))
5227 B->score_aln=pair_wise (B, ns, l_s,NCL);
5229 id=get_seq_sim ( B->seq_al[a], B->seq_al[b], "-", sim_mode);
5232 score=(int)(((float)B->score_aln)/(B->len_aln*SCORE_K));
5233 score=(int)(CL->L && CL->normalise)?((score*MAXID)/(CL->normalise)):(score);
5235 else if ( CL->M)score=id;
5238 if ( score>MAXID)score=(int)(CL->L)?sub_aln2sub_aln_score (B, CL, CL->evaluate_mode, ns, l_s):id;
5241 else if ( strm2 (mode,"fast", "very_fast"))
5243 B->score_aln=pair_wise (B, ns, l_s,NCL);
5244 id=get_seq_sim ( B->seq_al[a], B->seq_al[b], "-", sim_mode);
5245 score=(int)(id)*SCORE_K;
5247 else if ( strm (mode, "cscore"))
5249 ungap ( B->seq_al[a]);
5250 ungap ( B->seq_al[b]);
5251 score=(int)linked_pair_wise (B, ns, l_s, NCL);
5254 score/=(B->len_aln*SCORE_K);
5257 else if ( strm (mode, "idscore"))
5259 score=id=idscore_pairseq (B->seq_al[a], B->seq_al[b], NCL->gop, NCL->gep, NCL->M, sim_mode);
5260 //HERE ("%s %d %d ->%d", sim_mode, a, b, (int)id);
5262 else if (strm (mode, "ktup"))
5268 else if (strm (mode, "aln"))
5270 score=id=sim_table[a][b];
5274 else if ( strm (mode, "geometric"))
5276 id=get_geometric_distance (g_matrix,n_coor, a, b, "euclidian");
5277 id=MAXID*(1-((id/ref)));
5278 score=(int)(id)*SCORE_K;
5280 else if ( strm (mode, "no"))
5285 else if ( strm (mode, "random"))
5292 id=B->score_aln=pair_wise (B, ns, l_s,NCL);
5296 DM->similarity_matrix[a][b]=DM->similarity_matrix[b][a]=(int)(id);
5298 DM->distance_matrix[a][b]=DM->distance_matrix[b][a]=MAXID-(int)(id);
5302 DM->score_similarity_matrix[a][b]=DM->score_similarity_matrix[b][a]=(int)score;
5304 if (CL->local_stderr && print>1) fprintf (CL->local_stderr, "\n\t%-*s %-*s identity=%3d%% score=%3d", max_name,(CL->S)->name[a], max_name,(CL->S)->name[b], id_score, (int)score);
5314 if (CL->local_stderr) fprintf (CL->local_stderr, "\n");
5315 free_constraint_list (NCL);
5324 free_int (sim_table, -1);
5330 /*********************************************************************/
5335 /*********************************************************************/
5336 char * seq2rna_lib ( Sequence *S, char *name)
5342 if (!name)name=vtmpnam (NULL);
5343 fp=vfopen (name, "w");
5344 for ( a=0; a<S->nseq; a++)
5347 fprintf (fp, "%s\n", rna_struc2rna_lib(S->name[a], S->seq[a], NULL));
5354 Constraint_list *read_rna_lib ( Sequence *S, char *fname)
5361 if (check_file_exists (fname))
5364 list=read_lib_list ( fname, &n);
5370 list=vcalloc (S->nseq, sizeof (char*));
5371 for ( a=0; a<S->nseq; a++)
5373 if ((F=seq_has_template (S, a, "_F_")))
5375 list[n++]=F->template_file;
5380 R=declare_constraint_list ( S,NULL, NULL, 0,NULL, NULL);
5382 for (a=0; a< n; a++)
5385 if (list[a])R=fast_read_constraint_list_file (R, list[a]);
5388 R=index_res_constraint_list (R,WE);
5393 Constraint_list * rna_lib_extension ( Constraint_list *CL, Constraint_list *R)
5395 CLIST_TYPE *entry=NULL;
5396 int a,b,c,n1,n2, ne,s1, s2, r1, r2,w;
5397 int list1[100], list2[100];
5400 entry=vcalloc ( CL->entry_len, CL->el_size);
5404 for ( a=0; a<ne; a++)
5408 extract_entry (entry, a, CL);
5417 for (b=1; b<R->residue_index[s1][r1][0]; b+=3)
5419 list1[n1++]=R->residue_index[s1][r1][b+1];
5422 for (b=1; b<R->residue_index[s2][r2][0]; b+=3)
5424 list2[n2++]=R->residue_index[s2][r2][b+1];
5427 for (b=1; b<n1; b++)
5428 for (c=1; c<n2; c++)
5434 add_entry2list ( entry,CL);
5441 char *** produce_method_file ( char *method)
5443 static char ***list;
5447 if (!list)list=declare_arrayN(3, sizeof (char),200,2, 100);
5451 sprintf (list[n][0], "t_coffee");
5452 sprintf (list[n][1], "%s", vtmpnam(NULL));
5453 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5454 fprintf ( fp, "EXECUTABLE t_coffee\n");
5455 fprintf ( fp, "ADDRESS built_in");
5456 fprintf ( fp, "ALN_MODE any\n");
5457 fprintf ( fp, "OUT_MODE L\n");
5458 fprintf ( fp, "IN_FLAG no_name\n");
5459 fprintf ( fp, "OUT_FLAG no_name\n");
5460 fprintf ( fp, "SEQ_TYPE S\n");
5461 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5462 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5466 /*Space holder method to analyze very large dATASETS*/
5467 sprintf (list[n][0], "test_pair");
5468 sprintf (list[n][1], "%s", vtmpnam(NULL));
5469 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5470 fprintf ( fp, "EXECUTABLE test_pair\n");
5471 fprintf ( fp, "DOC Fast alignmnents on the best diagonals\n");
5472 fprintf ( fp, "ALN_MODE pairwise\n");
5473 fprintf ( fp, "OUT_MODE fL\n");
5474 fprintf ( fp, "IN_FLAG no_name\n");
5475 fprintf ( fp, "OUT_FLAG no_name\n");
5476 fprintf ( fp, "SEQ_TYPE S\n");
5477 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5478 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5481 sprintf (list[n][0], "fast_pair");
5482 sprintf (list[n][1], "%s", vtmpnam(NULL));
5483 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5484 fprintf ( fp, "EXECUTABLE fast_pair\n");
5485 fprintf ( fp, "DOC Fast alignmnents on the best diagonals\n");
5486 fprintf ( fp, "ALN_MODE pairwise\n");
5487 fprintf ( fp, "OUT_MODE fL\n");
5488 fprintf ( fp, "IN_FLAG no_name\n");
5489 fprintf ( fp, "OUT_FLAG no_name\n");
5490 fprintf ( fp, "SEQ_TYPE S\n");
5491 if (strm (retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5493 fprintf ( fp, "MATRIX dna_idmat\n");
5494 fprintf ( fp, "GOP -50\n");
5495 fprintf ( fp, "GEP -1\n");
5497 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5498 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5501 sprintf (list[n][0], "exon3_pair");
5502 sprintf (list[n][1], "%s", vtmpnam(NULL));
5503 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5504 fprintf ( fp, "EXECUTABLE exon3_pair\n");
5505 fprintf ( fp, "ALN_MODE pairwise\n");
5506 fprintf ( fp, "OUT_MODE fL\n");
5507 fprintf ( fp, "IN_FLAG no_name\n");
5508 fprintf ( fp, "OUT_FLAG no_name\n");
5509 fprintf ( fp, "SEQ_TYPE G\n");
5510 fprintf ( fp, "MATRIX exon2mt\n");
5511 fprintf ( fp, "GOP 0\n");
5512 fprintf ( fp, "GEP -1\n");
5513 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5514 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5517 sprintf (list[n][0], "exon2_pair");
5518 sprintf (list[n][1], "%s", vtmpnam(NULL));
5519 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5520 fprintf ( fp, "EXECUTABLE exon2_pair\n");
5521 fprintf ( fp, "ALN_MODE pairwise\n");
5522 fprintf ( fp, "OUT_MODE fL\n");
5523 fprintf ( fp, "IN_FLAG no_name\n");
5524 fprintf ( fp, "OUT_FLAG no_name\n");
5525 fprintf ( fp, "SEQ_TYPE G\n");
5526 fprintf ( fp, "MATRIX exon2mt\n");
5527 fprintf ( fp, "GOP -10\n");
5528 fprintf ( fp, "GEP -1\n");
5529 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5530 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5533 sprintf (list[n][0], "exon_pair");
5534 sprintf (list[n][1], "%s", vtmpnam(NULL));
5535 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5536 fprintf ( fp, "EXECUTABLE exon_pair\n");
5537 fprintf ( fp, "ALN_MODE pairwise\n");
5538 fprintf ( fp, "OUT_MODE fL\n");
5539 fprintf ( fp, "IN_FLAG no_name\n");
5540 fprintf ( fp, "OUT_FLAG no_name\n");
5541 fprintf ( fp, "SEQ_TYPE G\n");
5542 fprintf ( fp, "MATRIX exon2mt\n");
5543 fprintf ( fp, "GOP -10\n");
5544 fprintf ( fp, "GEP -1\n");
5545 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5546 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5550 sprintf (list[n][0], "clean_slow_pair");
5551 sprintf (list[n][1], "%s", vtmpnam(NULL));
5552 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5553 fprintf ( fp, "DOC regular dynamic Programming\n");
5554 fprintf ( fp, "EXECUTABLE slow_pair\n");
5555 fprintf ( fp, "ALN_MODE pairwise\n");
5556 fprintf ( fp, "OUT_MODE fL\n");
5557 fprintf ( fp, "IN_FLAG no_name\n");
5558 fprintf ( fp, "OUT_FLAG no_name\n");
5559 fprintf ( fp, "SEQ_TYPE S\n");
5560 fprintf ( fp, "WEIGHT clean\n");
5561 if ( strm ( retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5563 fprintf ( fp, "MATRIX dna_idmat\n");
5564 fprintf ( fp, "GOP -10\n");
5565 fprintf ( fp, "GEP -1\n");
5567 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5568 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5571 sprintf (list[n][0], "slow_pair");
5572 sprintf (list[n][1], "%s", vtmpnam(NULL));
5573 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5574 fprintf ( fp, "DOC regular dynamic Programming\n");
5575 fprintf ( fp, "EXECUTABLE slow_pair\n");
5576 fprintf ( fp, "ALN_MODE pairwise\n");
5577 fprintf ( fp, "OUT_MODE fL\n");
5578 fprintf ( fp, "IN_FLAG no_name\n");
5579 fprintf ( fp, "OUT_FLAG no_name\n");
5580 fprintf ( fp, "SEQ_TYPE S\n");
5581 if ( strm ( retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5583 fprintf ( fp, "MATRIX dna_idmat\n");
5584 fprintf ( fp, "GOP -10\n");
5585 fprintf ( fp, "GEP -1\n");
5587 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5588 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5591 sprintf (list[n][0], "biphasic_pair");
5592 sprintf (list[n][1], "%s", vtmpnam(NULL));
5593 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5594 fprintf ( fp, "DOC bi-phasic dynamic Programming\n");
5595 fprintf ( fp, "EXECUTABLE biphasic_pair\n");
5596 fprintf ( fp, "ALN_MODE pairwise\n");
5597 fprintf ( fp, "OUT_MODE fL\n");
5598 fprintf ( fp, "IN_FLAG no_name\n");
5599 fprintf ( fp, "OUT_FLAG no_name\n");
5600 fprintf ( fp, "SEQ_TYPE S\n");
5601 if ( strm ( retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5603 fprintf ( fp, "MATRIX dna_idmat\n");
5604 fprintf ( fp, "GOP -10\n");
5605 fprintf ( fp, "GEP -1\n");
5607 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5608 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5611 sprintf (list[n][0], "proba_pair");
5612 sprintf (list[n][1], "%s", vtmpnam(NULL));
5613 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5614 fprintf ( fp, "DOC Probabilistic pairwise alignment\n");
5615 fprintf ( fp, "EXECUTABLE proba_pair\n");
5616 fprintf ( fp, "ALN_MODE pairwise\n");
5617 fprintf ( fp, "OUT_MODE fL\n");
5618 fprintf ( fp, "IN_FLAG no_name\n");
5619 fprintf ( fp, "OUT_FLAG no_name\n");
5620 fprintf ( fp, "SEQ_TYPE S\n");
5621 if ( strm ( retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5623 fprintf ( fp, "GOP %d\n",CODE4DNA);//code for DNA
5627 fprintf ( fp, "GOP %d\n",CODE4PROTEINS);//Code for Proteins
5629 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5630 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5634 sprintf (list[n][0], "best_pair4prot");
5635 sprintf (list[n][1], "%s", vtmpnam(NULL));
5636 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5637 fprintf ( fp, "DOC Combination of the best template methods\n");
5638 fprintf ( fp, "EXECUTABLE best_pair4prot\n");
5639 fprintf ( fp, "ALN_MODE pairwise\n");
5640 fprintf ( fp, "OUT_MODE fL\n");
5641 fprintf ( fp, "IN_FLAG no_name\n");
5642 fprintf ( fp, "OUT_FLAG no_name\n");
5643 fprintf ( fp, "SEQ_TYPE S\n");
5644 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5645 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5646 if (strm (retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5648 printf_exit (EXIT_FAILURE, stderr, "\nERROR: The mode best_pair4prot is only suited for Proteins [FATAL:%s]\n", PROGRAM);
5653 sprintf (list[n][0], "best_pair4rna");
5654 sprintf (list[n][1], "%s", vtmpnam(NULL));
5655 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5656 fprintf ( fp, "DOC Combination of the best template methods\n");
5657 fprintf ( fp, "EXECUTABLE best_pair4rna\n");
5658 fprintf ( fp, "ALN_MODE pairwise\n");
5659 fprintf ( fp, "OUT_MODE fL\n");
5660 fprintf ( fp, "IN_FLAG no_name\n");
5661 fprintf ( fp, "OUT_FLAG no_name\n");
5662 fprintf ( fp, "SEQ_TYPE S\n");
5663 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5664 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5665 // if (strm(retrieve_seq_type(), "RNA"))
5667 // printf_exit (EXIT_FAILURE, stderr, "\nERROR: The mode best_pair4rna is only suited for RNA [FATAL:%s]\n", PROGRAM);
5673 sprintf (list[n][0], "lalign_id_pair");
5674 sprintf (list[n][1], "%s", vtmpnam(NULL));
5675 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5676 fprintf ( fp, "DOC local alignment reporting the N best pairwise local alignments\n");
5677 fprintf ( fp, "EXECUTABLE lalign_id_pair\n");
5678 fprintf ( fp, "ALN_MODE pairwise\n");
5679 fprintf ( fp, "OUT_MODE fL\n");
5680 fprintf ( fp, "IN_FLAG no_name\n");
5681 fprintf ( fp, "OUT_FLAG no_name\n");
5682 if ( strm (retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5684 fprintf ( fp, "MATRIX dna_idmat\n");
5685 fprintf ( fp, "GOP -10\n");
5686 fprintf ( fp, "GEP -1\n");
5690 fprintf ( fp, "MATRIX blosum50mt\n");
5691 fprintf ( fp, "GOP -10\n");
5692 fprintf ( fp, "GEP -4\n");
5694 fprintf ( fp, "MAXID 100\n");
5695 fprintf ( fp, "SEQ_TYPE S\n");
5696 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5697 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5700 sprintf (list[n][0], "align_pdbpair");
5701 sprintf (list[n][1], "%s", vtmpnam(NULL));
5702 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5703 fprintf ( fp, "EXECUTABLE align_pdb_pair\n");
5704 fprintf ( fp, "ALN_MODE pairwise\n");
5705 fprintf ( fp, "OUT_MODE fL\n");
5706 fprintf ( fp, "IN_FLAG no_name\n");
5707 fprintf ( fp, "OUT_FLAG no_name\n");
5708 fprintf ( fp, "SEQ_TYPE P\n");
5709 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5710 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5713 sprintf (list[n][0], "lalign_pdbpair");
5714 sprintf (list[n][1], "%s", vtmpnam(NULL));
5715 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5716 fprintf ( fp, "EXECUTABLE lalign_pdb_pair\n");
5717 fprintf ( fp, "ALN_MODE pairwise\n");
5718 fprintf ( fp, "OUT_MODE fL\n");
5719 fprintf ( fp, "IN_FLAG no_name\n");
5720 fprintf ( fp, "OUT_FLAG no_name\n");
5721 fprintf ( fp, "SEQ_TYPE P\n");
5722 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5723 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5726 sprintf (list[n][0], "ktup_msa");
5727 sprintf (list[n][1], "%s", vtmpnam(NULL));
5728 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5729 fprintf ( fp, "EXECUTABLE ktup_msa\n");
5730 fprintf ( fp, "ALN_MODE multiple\n");
5731 fprintf ( fp, "OUT_MODE fL\n");
5732 fprintf ( fp, "IN_FLAG no_name\n");
5733 fprintf ( fp, "OUT_FLAG no_name\n");
5734 fprintf ( fp, "SEQ_TYPE s\n");
5735 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5736 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5739 sprintf (list[n][0], "seq_pair");
5740 sprintf (list[n][1], "%s", vtmpnam(NULL));
5741 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5742 fprintf ( fp, "EXECUTABLE seq_pair\n");
5743 fprintf ( fp, "ALN_MODE pairwise\n");
5744 fprintf ( fp, "OUT_MODE fL\n");
5745 fprintf ( fp, "IN_FLAG no_name\n");
5746 fprintf ( fp, "OUT_FLAG no_name\n");
5747 fprintf ( fp, "SEQ_TYPE s\n");
5748 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5749 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5752 sprintf (list[n][0], "extern_pdbpair");
5753 sprintf (list[n][1], "%s", vtmpnam(NULL));
5754 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5755 fprintf ( fp, "EXECUTABLE tc_P_generic_method.pl\n");
5756 fprintf ( fp, "ALN_MODE pairwise\n");
5757 fprintf ( fp, "OUT_MODE A\n");
5758 fprintf ( fp, "IN_FLAG no_name\n");
5759 fprintf ( fp, "OUT_FLAG no_name\n");
5760 fprintf ( fp, "SEQ_TYPE P\n");
5761 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5762 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5765 sprintf (list[n][0], "externprofile_pair");
5766 sprintf (list[n][1], "%s", vtmpnam(NULL));
5767 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5768 fprintf ( fp, "EXECUTABLE tc_R_generic_method\n");
5769 fprintf ( fp, "ALN_MODE pairwise\n");
5770 fprintf ( fp, "OUT_MODE A\n");
5771 fprintf ( fp, "IN_FLAG no_name\n");
5772 fprintf ( fp, "OUT_FLAG no_name\n");
5773 fprintf ( fp, "SEQ_TYPE R\n");
5774 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5775 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5778 sprintf (list[n][0], "thread_pair");
5779 sprintf (list[n][1], "%s", vtmpnam(NULL));
5780 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5781 /*This runs thread_pair@EP@EXECUTABLE2@threpg*/
5782 fprintf ( fp, "EXECUTABLE thread_pair\n");
5783 fprintf ( fp, "EXECUTABLE2 t_coffee\n");
5784 fprintf ( fp, "ALN_MODE pairwise\n");
5785 fprintf ( fp, "OUT_MODE fL\n");
5786 fprintf ( fp, "IN_FLAG -infile=\n");
5787 fprintf ( fp, "IN_FLAG2 -pdbfile1=\n");
5788 fprintf ( fp, "OUT_FLAG -outfile=\n");
5789 fprintf ( fp, "SEQ_TYPE Ps\n");
5790 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5791 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5794 sprintf (list[n][0], "fugue_pair");
5795 sprintf (list[n][1], "%s", vtmpnam(NULL));
5796 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5797 /*This runs thread_pair@EP@EXECUTABLE2@threpg*/
5798 fprintf ( fp, "EXECUTABLE thread_pair\n");
5799 fprintf ( fp, "EXECUTABLE2 fugueali\n");
5800 fprintf ( fp, "ALN_MODE pairwise\n");
5801 fprintf ( fp, "OUT_MODE fL\n");
5802 fprintf ( fp, "IN_FLAG -infile=\n");
5803 fprintf ( fp, "IN_FLAG2 -pdbfile1=\n");
5804 fprintf ( fp, "OUT_FLAG -outfile=\n");
5805 fprintf ( fp, "SEQ_TYPE Ps\n");
5806 fprintf ( fp, "ADDRESS %s\n", FUGUE_ADDRESS);
5807 fprintf ( fp, "PROGRAM %s\n", FUGUE_4_TCOFFEE);
5810 sprintf (list[n][0], "pdb_pair");
5811 sprintf (list[n][1], "%s", vtmpnam(NULL));
5812 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5813 fprintf ( fp, "EXECUTABLE pdb_pair\n");
5814 fprintf ( fp, "EXECUTABLE2 t_coffee\n");
5815 fprintf ( fp, "ALN_MODE pairwise\n");
5816 fprintf ( fp, "OUT_MODE fL\n");
5817 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5818 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5819 fprintf ( fp, "OUT_FLAG -outfile=\n");
5820 fprintf ( fp, "SEQ_TYPE P\n");
5821 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5822 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5825 sprintf (list[n][0], "hh_pair");
5826 sprintf (list[n][1], "%s", vtmpnam(NULL));
5827 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5828 fprintf ( fp, "EXECUTABLE profile_pair\n");
5829 fprintf ( fp, "EXECUTABLE2 hhalign\n");
5830 fprintf ( fp, "ALN_MODE pairwise\n");
5831 fprintf ( fp, "OUT_MODE fL\n");
5832 fprintf ( fp, "IN_FLAG -profile1=\n");
5833 fprintf ( fp, "IN_FLAG2 -profile2=\n");
5834 fprintf ( fp, "OUT_FLAG -outfile=\n");
5835 fprintf ( fp, "SEQ_TYPE R\n");
5836 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5837 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5838 fprintf ( fp, "SUPPORTED NO");
5841 sprintf (list[n][0], "profile_pair");
5842 sprintf (list[n][1], "%s", vtmpnam(NULL));
5843 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5844 fprintf ( fp, "EXECUTABLE profile_pair\n");
5845 fprintf ( fp, "EXECUTABLE2 clustalw\n");
5846 fprintf ( fp, "ALN_MODE pairwise\n");
5847 fprintf ( fp, "OUT_MODE fL\n");
5848 fprintf ( fp, "IN_FLAG -profile1=\n");
5849 fprintf ( fp, "IN_FLAG2 -profile2=\n");
5850 fprintf ( fp, "OUT_FLAG -outfile=\n");
5851 fprintf ( fp, "SEQ_TYPE R\n");
5852 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5853 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5854 fprintf ( fp, "SUPPORTED NO");
5858 //Switch to TM_align if SAP is not installed
5860 if (method && strm (method, "sap_pair") && !check_program_is_installed (SAP_4_TCOFFEE,NULL,NULL,SAP_ADDRESS,INSTALL))
5865 add_warning (stderr, "\n******************** WARNING: ****************************************\nSAP is not installed\nTMalign will be used instead\ntmalign is FASTER than SAP and *almost* as accurate\n**********************************************************************\n");
5869 sprintf (list[n][0], "sap_pair");
5870 sprintf (list[n][1], "%s", vtmpnam(NULL));
5873 fp=vfopen (list[n-1][1], "w");
5874 fprintf ( fp, "DOC: TM-Align: pairwise structural aligner [%s]\n", TMALIGN_ADDRESS);
5875 fprintf ( fp, "EXECUTABLE pdb_pair\n");
5876 fprintf ( fp, "EXECUTABLE2 TMalign\n" );
5877 fprintf ( fp, "ALN_MODE pairwise\n");
5878 fprintf ( fp, "OUT_MODE fL\n");
5879 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5880 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5881 fprintf ( fp, "OUT_FLAG -outfile=\n");
5882 fprintf ( fp, "ADDRESS %s\n", TMALIGN_ADDRESS);
5883 fprintf ( fp, "PROGRAM %s\n", TMALIGN_4_TCOFFEE);
5884 fprintf ( fp, "SEQ_TYPE P\n");
5890 sprintf (list[n][0], "sap_pair");
5891 sprintf (list[n][1], "%s", vtmpnam(NULL));
5893 if (method==NULL || strm (method, list[n-1][0]))
5895 fp=vfopen (list[n-1][1], "w");
5896 fprintf ( fp, "DOC: sap: pairwise structural aligner [%s]\n", SAP_ADDRESS);
5897 fprintf ( fp, "EXECUTABLE sap_pair\n");
5898 fprintf ( fp, "ALN_MODE pairwise\n");
5899 fprintf ( fp, "OUT_MODE fL\n");
5900 fprintf ( fp, "IN_FLAG no_name\n");
5901 fprintf ( fp, "OUT_FLAG no_name\n");
5902 fprintf ( fp, "WEIGHT 100\n");
5903 fprintf ( fp, "SEQ_TYPE P\n");
5904 fprintf ( fp, "ADDRESS %s\n", SAP_ADDRESS);
5905 fprintf ( fp, "PROGRAM %s\n", SAP_4_TCOFFEE);
5909 sprintf (list[n][0], "sara_pair");
5910 sprintf (list[n][1], "%s", vtmpnam(NULL));
5912 if (method==NULL || strm (method, list[n-1][0])){
5913 fp=vfopen (list[n-1][1], "w");
5914 fprintf ( fp, "DOC: SARA: pairwise structural RNA aligner [%s]\n", ADDRESS_BUILT_IN);
5915 fprintf ( fp, "EXECUTABLE rna_pair\n");
5916 fprintf ( fp, "EXECUTABLE2 runsara.py\n" );
5917 fprintf ( fp, "ALN_MODE pairwise\n");
5918 fprintf ( fp, "OUT_MODE fL\n");
5919 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5920 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5921 fprintf ( fp, "OUT_FLAG -outfile=\n");
5922 fprintf ( fp, "SEQ_TYPE P\n");
5923 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5924 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5928 sprintf (list[n][0], "dali_pair");
5929 sprintf (list[n][1], "%s", vtmpnam(NULL));
5931 if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5932 fprintf ( fp, "DOC: Dalilite: pairwise structural aligner [%s]\n", DALILITEc_ADDRESS);
5933 fprintf ( fp, "EXECUTABLE pdbid_pair\n");
5934 fprintf ( fp, "EXECUTABLE2 dalilite\n" );
5935 fprintf ( fp, "ALN_MODE pairwise\n");
5936 fprintf ( fp, "OUT_MODE fL\n");
5937 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5938 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5939 fprintf ( fp, "OUT_FLAG -outfile=\n");
5940 fprintf ( fp, "SEQ_TYPE P\n");
5941 fprintf ( fp, "ADDRESS %s\n", DALILITEc_ADDRESS);
5942 fprintf ( fp, "PROGRAM %s\n", DALILITEc_4_TCOFFEE);
5945 sprintf (list[n][0], "mustang_pair");
5946 sprintf (list[n][1], "%s", vtmpnam(NULL));
5947 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5948 fprintf ( fp, "DOC: Mustang: pairwise structural aligner [%s]\n", MUSTANG_ADDRESS);
5949 fprintf ( fp, "EXECUTABLE pdb_pair\n");
5950 fprintf ( fp, "EXECUTABLE2 mustang\n" );
5951 fprintf ( fp, "ALN_MODE pairwise\n");
5952 fprintf ( fp, "OUT_MODE fL\n");
5953 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5954 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5955 fprintf ( fp, "OUT_FLAG -outfile=\n");
5956 fprintf ( fp, "SEQ_TYPE P\n");
5957 fprintf ( fp, "ADDRESS %s\n", MUSTANG_ADDRESS);
5958 fprintf ( fp, "PROGRAM %s\n", MUSTANG_4_TCOFFEE);
5961 sprintf (list[n][0], "TMalign_pair");
5962 sprintf (list[n][1], "%s", vtmpnam(NULL));
5963 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5964 fprintf ( fp, "DOC: TM-Align: pairwise structural aligner [%s]\n", TMALIGN_ADDRESS);
5965 fprintf ( fp, "EXECUTABLE pdb_pair\n");
5966 fprintf ( fp, "EXECUTABLE2 TMalign\n" );
5967 fprintf ( fp, "ALN_MODE pairwise\n");
5968 fprintf ( fp, "OUT_MODE fL\n");
5969 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5970 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5971 fprintf ( fp, "OUT_FLAG -outfile=\n");
5972 fprintf ( fp, "ADDRESS %s\n", TMALIGN_ADDRESS);
5973 fprintf ( fp, "PROGRAM %s\n", TMALIGN_4_TCOFFEE);
5974 fprintf ( fp, "SEQ_TYPE P\n");
5977 sprintf (list[n][0], "cdna_fast_pair");
5978 sprintf (list[n][1], "%s", vtmpnam(NULL));
5979 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5980 fprintf ( fp, "EXECUTABLE cdna_fast_pair\n");
5981 fprintf ( fp, "ALN_MODE pairwise\n");
5982 fprintf ( fp, "OUT_MODE fL\n");
5983 fprintf ( fp, "IN_FLAG no_name\n");
5984 fprintf ( fp, "OUT_FLAG no_name\n");
5985 fprintf ( fp, "SEQ_TYPE S\n");
5986 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5987 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5990 sprintf (list[n][0], "cdna_cfast_pair");
5991 sprintf (list[n][1], "%s", vtmpnam(NULL));
5992 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5993 fprintf ( fp, "EXECUTABLE cdna_cfast_pair\n");
5994 fprintf ( fp, "ALN_MODE pairwise\n");
5995 fprintf ( fp, "OUT_MODE fL\n");
5996 fprintf ( fp, "IN_FLAG no_name\n");
5997 fprintf ( fp, "OUT_FLAG no_name\n");
5998 fprintf ( fp, "SEQ_TYPE S\n");
5999 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
6000 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
6003 sprintf (list[n][0], "blast_msa");
6004 sprintf (list[n][1], "%s", vtmpnam(NULL));
6005 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6006 fprintf ( fp, "DOC: BLAST multiple Aligner [%s]\n", NCBIBLAST_ADDRESS);
6007 fprintf ( fp, "EXECUTABLE seq_msa\n");
6008 fprintf ( fp, "EXECUTABLE2 blastpgp\n" );
6009 fprintf ( fp, "ALN_MODE multiple\n");
6010 fprintf ( fp, "OUT_MODE fL\n");
6011 fprintf ( fp, "IN_FLAG -infile=\n");
6012 fprintf ( fp, "OUT_FLAG -outfile=\n");
6013 fprintf ( fp, "SEQ_TYPE S\n");
6014 fprintf ( fp, "ADDRESS %s\n", NCBIBLAST_ADDRESS);
6015 fprintf ( fp, "PROGRAM %s\n", NCBIBLAST_4_TCOFFEE);
6018 sprintf (list[n][0], "clustalw2_pair");
6019 sprintf (list[n][1], "%s", vtmpnam(NULL));
6020 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6021 fprintf ( fp, "DOC: clustalw [%s]\n", CLUSTALW2_ADDRESS);
6022 fprintf ( fp, "EXECUTABLE clustalw\n");
6023 fprintf ( fp, "ALN_MODE pairwise\n");
6024 fprintf ( fp, "OUT_MODE aln\n");
6025 fprintf ( fp, "IN_FLAG %sINFILE=\n",CWF);
6026 fprintf ( fp, "OUT_FLAG %sOUTFILE=\n",CWF);
6027 fprintf ( fp, "PARAM %sOUTORDER=INPUT %sNEWTREE=cw.tmp.dnd %salign\n",CWF,CWF,CWF);
6028 fprintf ( fp, "SEQ_TYPE S\n");
6029 fprintf ( fp, "ADDRESS %s\n", CLUSTALW2_ADDRESS);
6030 fprintf ( fp, "PROGRAM %s\n", CLUSTALW2_4_TCOFFEE);
6033 sprintf (list[n][0], "clustalw2_msa");
6034 sprintf (list[n][1], "%s", vtmpnam(NULL));
6035 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6036 fprintf ( fp, "DOC clustalw[%s]\n", CLUSTALW2_ADDRESS);
6037 fprintf ( fp, "EXECUTABLE clustalw2\n");
6038 fprintf ( fp, "ALN_MODE multiple\n");
6039 fprintf ( fp, "OUT_MODE aln\n");
6040 fprintf ( fp, "IN_FLAG %sINFILE=\n",CWF);
6041 fprintf ( fp, "OUT_FLAG %sOUTFILE=\n", CWF);
6042 fprintf ( fp, "PARAM %sOUTORDER=INPUT %sNEWTREE=cw.tmp.dnd %salign\n",CWF,CWF,CWF);
6043 fprintf ( fp, "SEQ_TYPE S\n");
6044 fprintf ( fp, "ADDRESS %s\n", CLUSTALW2_ADDRESS);
6045 fprintf ( fp, "PROGRAM %s\n", CLUSTALW2_4_TCOFFEE);
6048 sprintf (list[n][0], "clustalw_pair");
6049 sprintf (list[n][1], "%s", vtmpnam(NULL));
6050 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6051 fprintf ( fp, "DOC: clustalw [%s]\n", CLUSTALW_ADDRESS);
6052 fprintf ( fp, "EXECUTABLE clustalw\n");
6053 fprintf ( fp, "ALN_MODE pairwise\n");
6054 fprintf ( fp, "OUT_MODE aln\n");
6055 fprintf ( fp, "IN_FLAG %sINFILE=\n", CWF);
6056 fprintf ( fp, "OUT_FLAG %sOUTFILE=\n",CWF);
6057 fprintf ( fp, "PARAM %sOUTORDER=INPUT %sNEWTREE=cw.tmp.dnd %salign\n",CWF,CWF,CWF);
6058 fprintf ( fp, "SEQ_TYPE S\n");
6059 fprintf ( fp, "ADDRESS %s\n", CLUSTALW_ADDRESS);
6060 fprintf ( fp, "PROGRAM %s\n", CLUSTALW_4_TCOFFEE);
6063 sprintf (list[n][0], "clustalw_msa");
6064 sprintf (list[n][1], "%s", vtmpnam(NULL));
6065 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6066 fprintf ( fp, "DOC clustalw[%s]\n", CLUSTALW_ADDRESS);
6067 fprintf ( fp, "EXECUTABLE clustalw\n");
6068 fprintf ( fp, "ALN_MODE multiple\n");
6069 fprintf ( fp, "OUT_MODE aln\n");
6070 fprintf ( fp, "IN_FLAG %sINFILE=\n", CWF);
6071 fprintf ( fp, "OUT_FLAG %sOUTFILE=\n", CWF);
6072 fprintf ( fp, "PARAM %sOUTORDER=INPUT %sNEWTREE=cw.tmp.dnd %salign\n",CWF,CWF,CWF);
6073 fprintf ( fp, "SEQ_TYPE S\n");
6074 fprintf ( fp, "ADDRESS %s\n", CLUSTALW_ADDRESS);
6075 fprintf ( fp, "PROGRAM %s\n", CLUSTALW_4_TCOFFEE);
6078 sprintf (list[n][0], "mafftdef_pair");
6079 sprintf (list[n][1], "%s", vtmpnam(NULL));
6080 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6081 fprintf ( fp, "EXECUTABLE mafft\n");
6082 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
6083 fprintf ( fp, "ALN_MODE pairwise\n");
6084 fprintf ( fp, "OUT_MODE aln\n");
6085 fprintf ( fp, "PARAM1 \n");
6086 fprintf ( fp, "IN_FLAG &bnsp\n");
6087 fprintf ( fp, "OUT_FLAG >\n");
6088 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6089 fprintf ( fp, "SEQ_TYPE S\n");
6090 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
6091 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
6095 sprintf (list[n][0], "mafftdef_msa");
6096 sprintf (list[n][1], "%s", vtmpnam(NULL));
6097 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6098 fprintf ( fp, "EXECUTABLE mafft\n");
6099 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
6100 fprintf ( fp, "ALN_MODE multiple\n");
6101 fprintf ( fp, "OUT_MODE aln\n");
6102 fprintf ( fp, "PARAM1 --localpair --maxiterate 1000 \n");
6103 fprintf ( fp, "IN_FLAG &bnsp\n");
6104 fprintf ( fp, "OUT_FLAG >\n");
6105 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6106 fprintf ( fp, "SEQ_TYPE S\n");
6107 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
6108 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
6111 sprintf (list[n][0], "mafft_pair");
6112 sprintf (list[n][1], "%s", vtmpnam(NULL));
6113 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6114 fprintf ( fp, "EXECUTABLE mafft\n");
6115 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
6116 fprintf ( fp, "ALN_MODE pairwise\n");
6117 fprintf ( fp, "OUT_MODE aln\n");
6118 fprintf ( fp, "PARAM1 --localpair --maxiterate 1000 \n");
6119 fprintf ( fp, "IN_FLAG &bnsp\n");
6120 fprintf ( fp, "OUT_FLAG >\n");
6121 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6122 fprintf ( fp, "SEQ_TYPE S\n");
6123 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
6124 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
6127 sprintf (list[n][0], "mafft_msa");
6128 sprintf (list[n][1], "%s", vtmpnam(NULL));
6129 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6130 fprintf ( fp, "EXECUTABLE mafft\n");
6131 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
6132 fprintf ( fp, "ALN_MODE multiple\n");
6133 fprintf ( fp, "OUT_MODE aln\n");
6134 fprintf ( fp, "PARAM1 --localpair --maxiterate 1000 \n");
6135 fprintf ( fp, "IN_FLAG &bnsp\n");
6136 fprintf ( fp, "OUT_FLAG >\n");
6137 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6138 fprintf ( fp, "SEQ_TYPE S\n");
6139 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
6140 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
6143 sprintf (list[n][0], "mafftjtt_pair");
6144 sprintf (list[n][1], "%s", vtmpnam(NULL));
6145 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6146 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
6147 fprintf ( fp, "EXECUTABLE mafft \n");
6148 fprintf ( fp, "ALN_MODE pairwise\n");
6149 fprintf ( fp, "OUT_MODE aln\n");
6150 fprintf ( fp, "IN_FLAG &bnsp\n");
6151 fprintf ( fp, "OUT_FLAG >\n");
6152 fprintf ( fp, "PARAM1 --jtt 250 --localpair --maxiterate 1000 \n");
6153 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6154 fprintf ( fp, "SEQ_TYPE S\n");
6155 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
6156 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
6159 sprintf (list[n][0], "mafftjtt_msa");
6160 sprintf (list[n][1], "%s", vtmpnam(NULL));
6161 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6162 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
6163 fprintf ( fp, "EXECUTABLE mafft \n");
6165 fprintf ( fp, "ALN_MODE multiple\n");
6166 fprintf ( fp, "OUT_MODE aln\n");
6167 fprintf ( fp, "IN_FLAG &bnsp\n");
6168 fprintf ( fp, "OUT_FLAG >\n");
6169 fprintf ( fp, "PARAM1 --jtt 250 --localpair --maxiterate 1000 \n");
6170 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6171 fprintf ( fp, "SEQ_TYPE S\n");
6172 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
6173 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
6176 sprintf (list[n][0], "mafftgins_pair");
6177 sprintf (list[n][1], "%s", vtmpnam(NULL));
6178 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6179 fprintf ( fp, "EXECUTABLE mafft\n");
6180 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
6181 fprintf ( fp, "ALN_MODE pairwise\n");
6182 fprintf ( fp, "OUT_MODE aln\n");
6183 fprintf ( fp, "PARAM1 --globalpair --maxiterate 1000 \n");
6184 fprintf ( fp, "IN_FLAG &bnsp\n");
6185 fprintf ( fp, "OUT_FLAG >\n");
6186 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6187 fprintf ( fp, "SEQ_TYPE S\n");
6188 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
6189 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
6192 sprintf (list[n][0], "mafftgins_msa");
6193 sprintf (list[n][1], "%s", vtmpnam(NULL));
6194 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6195 fprintf ( fp, "EXECUTABLE mafft\n");
6196 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
6197 fprintf ( fp, "ALN_MODE multiple\n");
6198 fprintf ( fp, "OUT_MODE aln\n");
6199 fprintf ( fp, "PARAM1 --globalpair --maxiterate 1000 \n");
6200 fprintf ( fp, "IN_FLAG &bnsp\n");
6201 fprintf ( fp, "OUT_FLAG >\n");
6202 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6203 fprintf ( fp, "SEQ_TYPE S\n");
6204 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
6205 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
6208 sprintf (list[n][0], "dialigntx_pair");
6209 sprintf (list[n][1], "%s", vtmpnam(NULL));
6210 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6211 fprintf ( fp, "DOC dialign-tx [%s]\n", DIALIGNTX_ADDRESS);
6212 fprintf ( fp, "EXECUTABLE dialign-tx\n");
6213 fprintf ( fp, "ALN_MODE pairwise\n");
6214 fprintf ( fp, "OUT_MODE aln\n");
6215 if ( isdir (DIALIGNTX_DIR))
6216 fprintf ( fp, "PARAM1 %s \n", DIALIGNTX_DIR);
6218 fprintf ( fp, "PARAM1 %s \n", get_mcoffee_4_tcoffee());
6219 fprintf ( fp, "IN_FLAG &bnsp\n");
6220 fprintf ( fp, "OUT_FLAG &bnsp\n");
6221 fprintf ( fp, "PARAM >/dev/null&bnsp2>/dev/null\n");
6222 fprintf ( fp, "SEQ_TYPE S\n");
6223 fprintf ( fp, "ADDRESS %s\n", DIALIGNTX_ADDRESS);
6224 fprintf ( fp, "PROGRAM %s\n", DIALIGNTX_4_TCOFFEE);
6227 sprintf (list[n][0], "dialigntx_msa");
6228 sprintf (list[n][1], "%s", vtmpnam(NULL));
6229 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6230 fprintf ( fp, "DOC dialign-tx [%s]\n", DIALIGNTX_ADDRESS);
6231 fprintf ( fp, "EXECUTABLE dialign-tx\n");
6232 fprintf ( fp, "ALN_MODE multiple\n");
6233 fprintf ( fp, "OUT_MODE aln\n");
6234 if ( isdir (DIALIGNTX_DIR))
6235 fprintf ( fp, "PARAM1 %s \n", DIALIGNTX_DIR);
6237 fprintf ( fp, "PARAM1 %s \n", get_mcoffee_4_tcoffee());
6238 fprintf ( fp, "IN_FLAG &bnsp\n");
6239 fprintf ( fp, "OUT_FLAG &bnsp\n");
6240 fprintf ( fp, "PARAM >/dev/null&bnsp2>/dev/null\n");
6241 fprintf ( fp, "SEQ_TYPE S\n");
6242 fprintf ( fp, "ADDRESS %s\n", DIALIGNTX_ADDRESS);
6243 fprintf ( fp, "PROGRAM %s\n", DIALIGNTX_4_TCOFFEE);
6246 sprintf (list[n][0], "dialignt_pair");
6247 sprintf (list[n][1], "%s", vtmpnam(NULL));
6248 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6249 fprintf ( fp, "DOC dialign-tx [%s]\n", DIALIGNT_ADDRESS);
6250 fprintf ( fp, "EXECUTABLE dialign-tx\n");
6251 fprintf ( fp, "ALN_MODE pairwise\n");
6252 fprintf ( fp, "OUT_MODE aln\n");
6253 if ( isdir (DIALIGNT_DIR))
6254 fprintf ( fp, "PARAM1 %s \n", DIALIGNT_DIR);
6256 fprintf ( fp, "PARAM1 %s \n", get_mcoffee_4_tcoffee());
6257 fprintf ( fp, "IN_FLAG &bnsp\n");
6258 fprintf ( fp, "OUT_FLAG &bnsp\n");
6259 fprintf ( fp, "PARAM >/dev/null&bnsp2>/dev/null\n");
6260 fprintf ( fp, "SEQ_TYPE S\n");
6261 fprintf ( fp, "ADDRESS %s\n", DIALIGNT_ADDRESS);
6262 fprintf ( fp, "PROGRAM %s\n", DIALIGNT_4_TCOFFEE);
6266 sprintf (list[n][0], "dialignt_msa");
6267 sprintf (list[n][1], "%s", vtmpnam(NULL));
6268 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6269 fprintf ( fp, "DOC dialign-tx [%s]\n", DIALIGNT_ADDRESS);
6270 fprintf ( fp, "EXECUTABLE dialign-tx\n");
6271 fprintf ( fp, "ALN_MODE multiple\n");
6272 fprintf ( fp, "OUT_MODE aln\n");
6273 if ( isdir (DIALIGNT_DIR))
6274 fprintf ( fp, "PARAM1 %s \n", DIALIGNT_DIR);
6276 fprintf ( fp, "PARAM1 %s \n", get_mcoffee_4_tcoffee());
6277 fprintf ( fp, "IN_FLAG &bnsp\n");
6278 fprintf ( fp, "OUT_FLAG &bnsp\n");
6279 fprintf ( fp, "PARAM >/dev/null&bnsp2>/dev/null\n");
6280 fprintf ( fp, "SEQ_TYPE S\n");
6281 fprintf ( fp, "ADDRESS %s\n", DIALIGNT_ADDRESS);
6282 fprintf ( fp, "PROGRAM %s\n", DIALIGNT_4_TCOFFEE);
6286 sprintf (list[n][0], "poa_pair");
6287 sprintf (list[n][1], "%s", vtmpnam(NULL));
6288 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6289 fprintf ( fp, "DOC Partial Order Graph Alignment [%s]\n", POA_ADDRESS);
6290 fprintf ( fp, "EXECUTABLE poa\n");
6291 fprintf ( fp, "ALN_MODE pairwise\n");
6292 fprintf ( fp, "OUT_MODE aln\n");
6293 fprintf ( fp, "PARAM1 -toupper \n");
6294 fprintf ( fp, "IN_FLAG -read_fasta&bnsp\n");
6295 fprintf ( fp, "OUT_FLAG -clustal&bnsp\n");
6296 if (file_exists (POA_DIR, POA_FILE1))
6297 fprintf ( fp, "PARAM %s/%s&bnsp2>/dev/null\n",POA_DIR,POA_FILE1);
6299 fprintf ( fp, "PARAM %s/%s&bnsp2>/dev/null\n", get_mcoffee_4_tcoffee(), POA_FILE1);
6300 fprintf ( fp, "SEQ_TYPE S\n");
6301 fprintf ( fp, "ADDRESS %s\n", POA_ADDRESS);
6302 fprintf ( fp, "PROGRAM %s\n",POA_4_TCOFFEE);
6306 sprintf (list[n][0], "poa_msa");
6307 sprintf (list[n][1], "%s", vtmpnam(NULL));
6308 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6309 fprintf ( fp, "DOC Partial Order Graph Alignment [%s]\n", POA_ADDRESS);
6310 fprintf ( fp, "EXECUTABLE poa\n");
6311 fprintf ( fp, "ALN_MODE multiple\n");
6312 fprintf ( fp, "OUT_MODE aln\n");
6313 fprintf ( fp, "PARAM1 -toupper \n");
6314 fprintf ( fp, "IN_FLAG -read_fasta&bnsp\n");
6315 fprintf ( fp, "OUT_FLAG -clustal&bnsp\n");
6316 if (file_exists (POA_DIR, POA_FILE1))
6317 fprintf ( fp, "PARAM %s/%s&bnsp2>/dev/null\n",POA_DIR,POA_FILE1);
6319 fprintf ( fp, "PARAM %s/%s&bnsp2>/dev/null\n", get_mcoffee_4_tcoffee(), POA_FILE1);
6320 fprintf ( fp, "SEQ_TYPE S\n");
6321 fprintf ( fp, "ADDRESS %s\n", POA_ADDRESS);
6322 fprintf ( fp, "PROGRAM %s\n",POA_4_TCOFFEE);
6325 sprintf (list[n][0], "probcons_pair");
6326 sprintf (list[n][1], "%s", vtmpnam(NULL));
6327 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6328 fprintf ( fp, "DOC probcons [%s]\n", PROBCONS_ADDRESS);
6329 fprintf ( fp, "ALN_MODE pairwise\n");
6330 fprintf ( fp, "OUT_MODE aln\n");
6331 fprintf ( fp, "IN_FLAG &bnsp\n");
6332 fprintf ( fp, "OUT_FLAG >\n");
6333 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6334 fprintf ( fp, "SEQ_TYPE S\n");
6335 if ( strm (retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))fprintf ( fp, "EXECUTABLE probconsRNA\n");
6336 else fprintf ( fp, "EXECUTABLE probcons\n");
6337 fprintf ( fp, "ADDRESS %s\n", PROBCONS_ADDRESS);
6338 fprintf ( fp, "PROGRAM %s\n",PROBCONS_4_TCOFFEE);
6341 sprintf (list[n][0], "probcons_msa");
6342 sprintf (list[n][1], "%s", vtmpnam(NULL));
6343 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6344 fprintf ( fp, "DOC probcons [%s]\n", PROBCONS_ADDRESS);
6345 fprintf ( fp, "ALN_MODE multiple\n");
6346 fprintf ( fp, "OUT_MODE aln\n");
6347 fprintf ( fp, "IN_FLAG &bnsp\n");
6348 fprintf ( fp, "OUT_FLAG >\n");
6349 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6350 fprintf ( fp, "SEQ_TYPE S\n");
6351 if ( strm (retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))fprintf ( fp, "EXECUTABLE probconsRNA\n");
6352 else fprintf ( fp, "EXECUTABLE probcons\n");
6353 fprintf ( fp, "ADDRESS %s\n", PROBCONS_ADDRESS);
6354 fprintf ( fp, "PROGRAM %s\n",PROBCONS_4_TCOFFEE);
6357 sprintf (list[n][0], "probconsRNA_pair");
6358 sprintf (list[n][1], "%s", vtmpnam(NULL));
6359 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6360 fprintf ( fp, "DOC probcons [%s]\n", PROBCONSRNA_ADDRESS);
6361 fprintf ( fp, "ALN_MODE pairwise\n");
6362 fprintf ( fp, "OUT_MODE aln\n");
6363 fprintf ( fp, "IN_FLAG &bnsp\n");
6364 fprintf ( fp, "OUT_FLAG >\n");
6365 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6366 fprintf ( fp, "SEQ_TYPE S\n");
6367 fprintf ( fp, "EXECUTABLE probconsRNA\n");
6368 fprintf ( fp, "ADDRESS %s\n", PROBCONSRNA_ADDRESS);
6369 fprintf ( fp, "PROGRAM %s\n",PROBCONSRNA_4_TCOFFEE);
6372 sprintf (list[n][0], "probconsRNA_msa");
6373 sprintf (list[n][1], "%s", vtmpnam(NULL));
6374 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6375 fprintf ( fp, "DOC probcons [%s]\n", PROBCONSRNA_ADDRESS);
6376 fprintf ( fp, "ALN_MODE multiple\n");
6377 fprintf ( fp, "OUT_MODE aln\n");
6378 fprintf ( fp, "IN_FLAG &bnsp\n");
6379 fprintf ( fp, "OUT_FLAG >\n");
6380 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6381 fprintf ( fp, "SEQ_TYPE S\n");
6382 fprintf ( fp, "EXECUTABLE probconsRNA\n");
6383 fprintf ( fp, "ADDRESS %s\n", PROBCONSRNA_ADDRESS);
6384 fprintf ( fp, "PROGRAM %s\n",PROBCONSRNA_4_TCOFFEE);
6389 sprintf (list[n][0], "muscle_pair");
6390 sprintf (list[n][1], "%s", vtmpnam(NULL));
6391 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6392 fprintf ( fp, "DOC Muscle [%s]\n", MUSCLE_ADDRESS);
6393 fprintf ( fp, "EXECUTABLE muscle\n");
6394 fprintf ( fp, "ALN_MODE pairwise\n");
6395 fprintf ( fp, "OUT_MODE aln\n");
6396 fprintf ( fp, "IN_FLAG -in&bnsp\n");
6397 fprintf ( fp, "OUT_FLAG -out&bnsp\n");
6398 fprintf ( fp, "SEQ_TYPE S\n");
6399 fprintf ( fp, "ADDRESS %s\n", MUSCLE_ADDRESS);
6400 fprintf ( fp, "PROGRAM %s\n", MUSCLE_4_TCOFFEE);
6403 sprintf (list[n][0], "muscle_msa");
6404 sprintf (list[n][1], "%s", vtmpnam(NULL));
6405 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6406 fprintf ( fp, "DOC Muscle [%s]\n", MUSCLE_ADDRESS);
6407 fprintf ( fp, "EXECUTABLE muscle\n");
6408 fprintf ( fp, "ALN_MODE multiple\n");
6409 fprintf ( fp, "OUT_MODE aln\n");
6410 fprintf ( fp, "IN_FLAG -in&bnsp\n");
6411 fprintf ( fp, "OUT_FLAG -out&bnsp\n");
6412 fprintf ( fp, "SEQ_TYPE S\n");
6413 fprintf ( fp, "ADDRESS %s\n", MUSCLE_ADDRESS);
6414 fprintf ( fp, "PROGRAM %s\n", MUSCLE_4_TCOFFEE);
6417 sprintf (list[n][0], "t_coffee_pair");
6418 sprintf (list[n][1], "%s", vtmpnam(NULL));
6419 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6420 fprintf ( fp, "EXECUTABLE t_coffee\n");
6421 fprintf ( fp, "DOC T-Coffee [%s]\n", TCOFFEE_ADDRESS);
6422 fprintf ( fp, "ALN_MODE pairwise\n");
6423 fprintf ( fp, "OUT_MODE aln\n");
6424 fprintf ( fp, "IN_FLAG -infile&bnsp\n");
6425 fprintf ( fp, "OUT_FLAG -outfile&bnsp\n");
6426 fprintf ( fp, "SEQ_TYPE S\n");
6427 fprintf ( fp, "ADDRESS %s\n", TCOFFEE_ADDRESS);
6428 fprintf ( fp, "PROGRAM %s\n", TCOFFEE_4_TCOFFEE);
6431 sprintf (list[n][0], "t_coffee_msa");
6432 sprintf (list[n][1], "%s", vtmpnam(NULL));
6433 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6434 fprintf ( fp, "EXECUTABLE t_coffee\n");
6435 fprintf ( fp, "DOC T-Coffee [%s]\n", TCOFFEE_ADDRESS);
6436 fprintf ( fp, "ALN_MODE multiple\n");
6437 fprintf ( fp, "OUT_MODE aln\n");
6438 fprintf ( fp, "IN_FLAG -infile&bnsp\n");
6439 fprintf ( fp, "OUT_FLAG -outfile&bnsp\n");
6440 fprintf ( fp, "SEQ_TYPE S\n");
6441 fprintf ( fp, "ADDRESS %s\n", TCOFFEE_ADDRESS);
6442 fprintf ( fp, "PROGRAM %s\n", TCOFFEE_4_TCOFFEE);
6445 sprintf (list[n][0], "pcma_pair");
6446 sprintf (list[n][1], "%s", vtmpnam(NULL));
6447 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6448 fprintf ( fp, "DOC PCMA [%s]\n", PCMA_ADDRESS);
6449 fprintf ( fp, "EXECUTABLE pcma\n");
6450 fprintf ( fp, "ALN_MODE pairwise\n");
6451 fprintf ( fp, "OUT_MODE aln\n");
6452 fprintf ( fp, "IN_FLAG -infile=\n");
6453 fprintf ( fp, "OUT_FLAG -outfile=\n");
6454 fprintf ( fp, "SEQ_TYPE S\n");
6455 fprintf ( fp, "ADDRESS %s\n", PCMA_ADDRESS);
6456 fprintf ( fp, "PROGRAM %s\n", PCMA_4_TCOFFEE);
6459 sprintf (list[n][0], "pcma_msa");
6460 sprintf (list[n][1], "%s", vtmpnam(NULL));
6461 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6462 fprintf ( fp, "DOC PCMA [%s]\n", PCMA_ADDRESS);
6463 fprintf ( fp, "EXECUTABLE pcma\n");
6464 fprintf ( fp, "ALN_MODE multiple\n");
6465 fprintf ( fp, "OUT_MODE aln\n");
6466 fprintf ( fp, "IN_FLAG -infile=\n");
6467 fprintf ( fp, "OUT_FLAG -outfile=\n");
6468 fprintf ( fp, "SEQ_TYPE S\n");
6469 fprintf ( fp, "ADDRESS %s\n", PCMA_ADDRESS);
6470 fprintf ( fp, "PROGRAM %s\n", PCMA_4_TCOFFEE);
6473 sprintf (list[n][0], "kalign_pair");
6474 sprintf (list[n][1], "%s", vtmpnam(NULL));
6475 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6476 fprintf ( fp, "EXECUTABLE kalign\n");
6477 fprintf ( fp, "DOC kalign [%s]\n", KALIGN_ADDRESS);
6478 fprintf ( fp, "ALN_MODE pairwise\n");
6479 fprintf ( fp, "OUT_MODE aln\n");
6480 fprintf ( fp, "IN_FLAG -i&bnsp\n");
6481 fprintf ( fp, "OUT_FLAG -o&bnsp\n");
6482 fprintf ( fp, "SEQ_TYPE S\n");
6483 fprintf ( fp, "ADDRESS %s\n", KALIGN_ADDRESS);
6484 fprintf ( fp, "PROGRAM %s\n", KALIGN_4_TCOFFEE);
6487 sprintf (list[n][0], "kalign_msa");
6488 sprintf (list[n][1], "%s", vtmpnam(NULL));
6489 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6490 fprintf ( fp, "EXECUTABLE kalign\n");
6491 fprintf ( fp, "DOC kalign [%s]\n", KALIGN_ADDRESS);
6492 fprintf ( fp, "ALN_MODE multiple\n");
6493 fprintf ( fp, "OUT_MODE aln\n");
6494 fprintf ( fp, "IN_FLAG -i&bnsp\n");
6495 fprintf ( fp, "OUT_FLAG -o&bnsp\n");
6496 fprintf ( fp, "SEQ_TYPE S\n");
6497 fprintf ( fp, "ADDRESS %s\n", KALIGN_ADDRESS);
6498 fprintf ( fp, "PROGRAM %s\n", KALIGN_4_TCOFFEE);
6501 sprintf (list[n][0], "amap_pair");
6502 sprintf (list[n][1], "%s", vtmpnam(NULL));
6503 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6504 fprintf ( fp, "EXECUTABLE amap\n");
6505 fprintf ( fp, "DOC amap [%s]\n", AMAP_ADDRESS);
6506 fprintf ( fp, "ALN_MODE pairwise\n");
6507 fprintf ( fp, "OUT_MODE aln\n");
6508 fprintf ( fp, "IN_FLAG &bnsp\n");
6509 fprintf ( fp, "OUT_FLAG >\n");
6510 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6511 fprintf ( fp, "SEQ_TYPE S\n");
6512 fprintf ( fp, "ADDRESS %s\n", AMAP_ADDRESS);
6513 fprintf ( fp, "PROGRAM %s\n", AMAP_4_TCOFFEE);
6516 sprintf (list[n][0], "amap_msa");
6517 sprintf (list[n][1], "%s", vtmpnam(NULL));
6518 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6519 fprintf ( fp, "EXECUTABLE amap\n");
6520 fprintf ( fp, "DOC amap [%s]\n", AMAP_ADDRESS);
6521 fprintf ( fp, "ALN_MODE multiple\n");
6522 fprintf ( fp, "OUT_MODE aln\n");
6523 fprintf ( fp, "IN_FLAG &bnsp\n");
6524 fprintf ( fp, "OUT_FLAG >\n");
6525 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6526 fprintf ( fp, "SEQ_TYPE S\n");
6527 fprintf ( fp, "ADDRESS %s\n", AMAP_ADDRESS);
6528 fprintf ( fp, "PROGRAM %s\n", AMAP_4_TCOFFEE);
6531 sprintf (list[n][0], "proda_pair");
6532 sprintf (list[n][1], "%s", vtmpnam(NULL));
6533 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6534 fprintf ( fp, "DOC proda [%s]\n", PRODA_ADDRESS);
6535 fprintf ( fp, "EXECUTABLE proda\n");
6536 fprintf ( fp, "ALN_MODE pairwise\n");
6537 fprintf ( fp, "OUT_MODE aln\n");
6538 fprintf ( fp, "IN_FLAG &bnsp\n");
6539 fprintf ( fp, "OUT_FLAG >\n");
6540 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6541 fprintf ( fp, "SEQ_TYPE S\n");
6542 fprintf ( fp, "ADDRESS %s\n", PRODA_ADDRESS);
6543 fprintf ( fp, "PROGRAM %s\n", PRODA_4_TCOFFEE);
6546 sprintf (list[n][0], "proda_msa");
6547 sprintf (list[n][1], "%s", vtmpnam(NULL));
6548 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6549 fprintf ( fp, "DOC proda [%s]\n", PRODA_ADDRESS);
6550 fprintf ( fp, "EXECUTABLE proda\n");
6551 fprintf ( fp, "ALN_MODE multiple\n");
6552 fprintf ( fp, "OUT_MODE aln\n");
6553 fprintf ( fp, "IN_FLAG &bnsp\n");
6554 fprintf ( fp, "OUT_FLAG >\n");
6555 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6556 fprintf ( fp, "SEQ_TYPE S\n");
6557 fprintf ( fp, "ADDRESS %s\n", PRODA_ADDRESS);
6558 fprintf ( fp, "PROGRAM %s\n", PRODA_4_TCOFFEE);
6561 sprintf (list[n][0], "prank_pair");
6562 sprintf (list[n][1], "%s", vtmpnam(NULL));
6563 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6564 fprintf ( fp, "DOC prank [%s]\n", PRANK_ADDRESS);
6565 fprintf ( fp, "EXECUTABLE tc_generic_method.pl\n");
6566 fprintf ( fp, "ALN_MODE pairwise\n");
6567 fprintf ( fp, "OUT_MODE aln\n");
6568 fprintf ( fp, "PARAM -method=%s -mode=seq_msa -tmpdir=%s\n",(getenv("PRANK_4_TCOFFEE"))?getenv("PRANK_4_TCOFFEE"):PRANK_4_TCOFFEE, get_tmp_4_tcoffee());
6569 fprintf ( fp, "IN_FLAG -infile=\n");
6570 fprintf ( fp, "OUT_FLAG -outfile=\n");
6571 fprintf ( fp, "SEQ_TYPE S\n");
6572 fprintf ( fp, "ADDRESS %s\n", PRANK_ADDRESS);
6573 fprintf ( fp, "PROGRAM %s\n", PRANK_4_TCOFFEE);
6576 sprintf (list[n][0], "prank_msa");
6577 sprintf (list[n][1], "%s", vtmpnam(NULL));
6578 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6579 fprintf ( fp, "DOC prank [%s]\n", PRANK_ADDRESS);
6580 fprintf ( fp, "EXECUTABLE tc_generic_method.pl\n");
6581 fprintf ( fp, "ALN_MODE multiple\n");
6582 fprintf ( fp, "OUT_MODE aln\n");
6583 fprintf ( fp, "PARAM -method=%s -mode=seq_msa -tmpdir=%s\n",(getenv("PRANK_4_TCOFFEE"))?getenv("PRANK_4_TCOFFEE"):PRANK_4_TCOFFEE, get_tmp_4_tcoffee());
6584 fprintf ( fp, "IN_FLAG -infile=\n");
6585 fprintf ( fp, "OUT_FLAG -outfile=\n");
6586 fprintf ( fp, "SEQ_TYPE S\n");
6587 fprintf ( fp, "ADDRESS %s\n", PRANK_ADDRESS);
6588 fprintf ( fp, "PROGRAM %s\n", PRANK_4_TCOFFEE);
6592 sprintf (list[n][0], "em");
6593 sprintf (list[n][1], "%s", vtmpnam(NULL));
6595 if (method==NULL || lstrstr (method,"em@"))
6598 fp=vfopen (list[n-1][1], "w");
6602 l2=string2list2 ( method, "@");
6603 fprintf ( fp, "PARAM -method=%s -mode=seq_msa -tmpdir=%s\n",l2[2], get_tmp_4_tcoffee());
6604 fprintf ( fp, "ALN_MODE %s\n", l2[3]);
6607 fprintf ( fp, "EXECUTABLE tc_generic_method.pl\n");
6608 fprintf ( fp, "OUT_MODE aln\n");
6609 fprintf ( fp, "IN_FLAG -infile=\n");
6610 fprintf ( fp, "OUT_FLAG -outfile=\n");
6611 fprintf ( fp, "SEQ_TYPE S\n");
6612 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
6613 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
6617 sprintf (list[n][0], "consan_pair");
6618 sprintf (list[n][1], "%s", vtmpnam(NULL));
6619 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6620 fprintf ( fp, "DOC consan (sfold) RNA pairwise sequence aligner [%s]\n", CONSAN_ADDRESS);
6621 fprintf ( fp, "EXECUTABLE fasta_seq2consan_aln.pl \n");
6622 fprintf ( fp, "ALN_MODE pairwise\n");
6623 fprintf ( fp, "OUT_MODE aln\n");
6624 fprintf ( fp, "IN_FLAG -i&bnsp\n");
6625 fprintf ( fp, "OUT_FLAG -o&bnsp\n");
6626 fprintf ( fp, "PARAM -d&bnsp%s&bnsp2>/dev/null\n",get_mcoffee_4_tcoffee());
6627 fprintf ( fp, "SEQ_TYPE S\n");
6628 fprintf ( fp, "ADDRESS %s\n", CONSAN_ADDRESS);
6629 fprintf ( fp, "PROGRAM %s\n", CONSAN_4_TCOFFEE);
6632 sprintf (list[n][0], "RNAplfold");
6633 sprintf (list[n][1], "%s", vtmpnam(NULL));
6634 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6635 fprintf ( fp, "EXECUTABLE RNAplfold \n");
6636 fprintf ( fp, "ALN_MODE predict\n");
6637 fprintf ( fp, "SEQ_TYPE RNA\n");
6638 fprintf ( fp, "ADDRESS %s\n", RNAPLFOLD_ADDRESS);
6639 fprintf ( fp, "PROGRAM %s\n", RNAPLFOLD_4_TCOFFEE);
6642 sprintf (list[n][0], "HMMtop");
6643 sprintf (list[n][1], "%s", vtmpnam(NULL));
6644 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6645 fprintf ( fp, "EXECUTABLE HMMtop \n");
6646 fprintf ( fp, "ALN_MODE predict\n");
6647 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6648 fprintf ( fp, "ADDRESS %s\n", HMMTOP_ADDRESS);
6649 fprintf ( fp, "PROGRAM %s\n", HMMTOP_4_TCOFFEE);
6652 sprintf (list[n][0], "GOR4");
6653 sprintf (list[n][1], "%s", vtmpnam(NULL));
6654 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6655 fprintf ( fp, "EXECUTABLE GORIV \n");
6656 fprintf ( fp, "ALN_MODE predict\n");
6657 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6658 fprintf ( fp, "ADDRESS %s\n", GOR4_ADDRESS);
6659 fprintf ( fp, "PROGRAM %s\n", GOR4_4_TCOFFEE);
6662 sprintf (list[n][0], "wublast_client");
6663 sprintf (list[n][1], "%s", vtmpnam(NULL));
6664 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6665 fprintf ( fp, "EXECUTABLE wublast.pl \n");
6666 fprintf ( fp, "ALN_MODE predict\n");
6667 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6668 fprintf ( fp, "ADDRESS %s\n", EBIWUBLASTc_ADDRESS);
6669 fprintf ( fp, "PROGRAM %s\n", EBIWUBLASTc_4_TCOFFEE);
6672 sprintf (list[n][0], "blastpgp_client");
6673 sprintf (list[n][1], "%s", vtmpnam(NULL));
6674 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6675 fprintf ( fp, "EXECUTABLE blastpgp.pl \n");
6676 fprintf ( fp, "ALN_MODE predict\n");
6677 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6679 fprintf ( fp, "ADDRESS %s\n", EBIBLASTPGPc_ADDRESS);
6680 fprintf ( fp, "PROGRAM %s\n", EBIBLASTPGPc_4_TCOFFEE);
6683 sprintf (list[n][0], "ncbi_netblast");
6684 sprintf (list[n][1], "%s", vtmpnam(NULL));
6685 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6686 fprintf ( fp, "EXECUTABLE blastcl3 \n");
6687 fprintf ( fp, "ALN_MODE predict\n");
6688 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6690 fprintf ( fp, "ADDRESS %s\n", NCBIWEBBLAST_ADDRESS);
6691 fprintf ( fp, "PROGRAM %s\n", NCBIWEBBLAST_4_TCOFFEE);
6694 sprintf (list[n][0], "local_ncbiblast");
6695 sprintf (list[n][1], "%s", vtmpnam(NULL));
6696 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6697 fprintf ( fp, "EXECUTABLE blastall \n");
6698 fprintf ( fp, "ALN_MODE predict\n");
6699 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6701 fprintf ( fp, "ADDRESS %s\n", NCBIBLAST_ADDRESS);
6702 fprintf ( fp, "PROGRAM %s\n", NCBIBLAST_4_TCOFFEE);
6711 /*********************************COPYRIGHT NOTICE**********************************/
6712 /*© Centro de Regulacio Genomica */
6714 /*Cedric Notredame */
6715 /*Tue Oct 27 10:12:26 WEST 2009. */
6716 /*All rights reserved.*/
6717 /*This file is part of T-COFFEE.*/
6719 /* T-COFFEE is free software; you can redistribute it and/or modify*/
6720 /* it under the terms of the GNU General Public License as published by*/
6721 /* the Free Software Foundation; either version 2 of the License, or*/
6722 /* (at your option) any later version.*/
6724 /* T-COFFEE is distributed in the hope that it will be useful,*/
6725 /* but WITHOUT ANY WARRANTY; without even the implied warranty of*/
6726 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the*/
6727 /* GNU General Public License for more details.*/
6729 /* You should have received a copy of the GNU General Public License*/
6730 /* along with Foobar; if not, write to the Free Software*/
6731 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
6732 /*............................................... |*/
6733 /* If you need some more information*/
6734 /* cedric.notredame@europe.com*/
6735 /*............................................... |*/
6739 /*********************************COPYRIGHT NOTICE**********************************/