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);
19 /*********************************************************************/
21 /* Post Process Constraint_list */
24 /*********************************************************************/
26 /*********************************************************************/
31 /*********************************************************************/
32 Constraint_list *make_test_lib (Constraint_list *CL);
35 Constraint_list *fork_line_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode,Job_TC *job, FILE *local_stderr);
36 Constraint_list *fork_cell_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode,Job_TC *job, FILE *local_stderr);
37 Constraint_list *nfork_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode,Job_TC *job, FILE *local_stderr);
38 Constraint_list *fork_subset_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode, Job_TC *job, FILE *local_stderr);
39 int job2first_seq(Job_TC *job);
40 Constraint_list *produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode)
47 store_seq_type (S->type);
48 if ( CL==NULL)CL=declare_constraint_list ( S,NULL, NULL, 0,(strm(mem_mode, "disk"))?vtmpfile():NULL, NULL);
49 local_stderr=(CL->local_stderr!=NULL)?CL->local_stderr:stderr;
51 CL->local_stderr=vfopen("/dev/null", "w");
52 job=queue2heap(method2job_list ( method,S,weight, CL->lib_list,CL->DM, CL));
56 if ( get_nproc()==1 || njob==1)return nfork_produce_list (CL, S, method, weight, mem_mode,job, local_stderr);
57 else if (strstr ( CL->multi_thread, "jobcells"))return fork_cell_produce_list (CL, S, method, weight, mem_mode,job,local_stderr);
58 else if (strstr ( CL->multi_thread, "joblines"))return fork_line_produce_list (CL, S, method, weight, mem_mode,job, local_stderr);
59 else if (strstr ( CL->multi_thread, "jobs"))return fork_subset_produce_list (CL, S, method, weight, mem_mode,job, local_stderr); //Recommended default
60 else return nfork_produce_list (CL, S, method, weight, mem_mode,job, local_stderr);
62 int job2first_seq(Job_TC *job)
68 else if ( !job->param)return -1;
69 else if ( !(job->param)->seq_c) return -1;
70 seqlist=string2num_list ((job->param)->seq_c);
71 if (seqlist[0]<2)r=-1;
77 Constraint_list *fork_subset_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode, Job_TC *job, FILE *local_stderr)
79 //forks lines of the matrix
81 Job_TC *heap,*end,*start, ***jl;
86 int nproc, max_nproc, submited;
87 int cseq, seq, nlines;
90 max_nproc=nproc=get_nproc();
93 A-> alignment provided in a file
94 L-> list provided in a file
95 aln-> alignment computed and provided in a file
96 list->list computed and provided in a file
105 fprintf (local_stderr, "\n\tMethod %s: No Suitable Sequences [Type: %s]\n", method,M->seq_type);
109 job=queue2heap (job);
114 if (M)M->PW_CL=method2pw_cl ( M, CL);
115 pid_tmpfile=vcalloc (MAX(njob,get_nproc())+1, sizeof (char*));
116 pid_list =vcalloc (MAX_N_PID, sizeof (int *));
118 fprintf ( local_stderr, "\n\tMulti Core Mode: %d processors [subset]\n", get_nproc());
120 jl=split_job_list(job,get_nproc());
129 pid_tmpfile[a]=vtmpnam(NULL);
132 if (pid==0)//child process
136 freeze_constraint_list (CL);//record the current state, so as not to dump everything
137 initiate_vtmpnam(NULL);
138 vfclose(vfopen (pid_tmpfile[a],"w"));
141 while (job!=end){todo++;job=job->c;}
147 if (a==0)output_completion ( local_stderr,done,todo,1, "Submit Job");
148 job=print_lib_job (job, "io->CL=%p control->submitF=%p control->retrieveF=%p control->mode=%s",CL,submit_lib_job, retrieve_lib_job, CL->multi_thread );
150 job=submit_job (job);
156 dump_constraint_list (CL, pid_tmpfile[a], "a");
157 freeze_constraint_list (CL);
158 myexit (EXIT_SUCCESS);
169 //wait for all processes to finish
170 for (a=0; a<npid; a++)
174 CL=undump_constraint_list (CL, pid_tmpfile[pid_list[pid]]);
175 remove(pid_tmpfile[pid_list[pid]]);
182 while (job) job=delete_job (job);
183 CL->local_stderr=local_stderr;
189 Constraint_list *fork_line_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode, Job_TC *job, FILE *local_stderr)
191 //forks lines of the matrix
199 int nproc, max_nproc, submited;
200 int cseq, seq, nlines;
202 max_nproc=nproc=get_nproc();
205 A-> alignment provided in a file
206 L-> list provided in a file
207 aln-> alignment computed and provided in a file
208 list->list computed and provided in a file
217 fprintf (local_stderr, "\n\tMethod %s: No Suitable Sequences [Type: %s]\n", method,M->seq_type);
222 job=queue2heap (job);
226 if (M)M->PW_CL=method2pw_cl ( M, CL);
229 /* Cf. parse method for possible out_mode flags*/
232 pid_tmpfile=vcalloc (njob, sizeof (char*));
234 pid_list =vcalloc (MAX_N_PID, sizeof (int *));
235 fprintf ( local_stderr, "\n\tMulti Core Mode: %d processors [jobline]\n", get_nproc());
238 //count the number of lines
244 seq=job2first_seq(job);
248 while (job && cseq==job2first_seq(job))job=job->c;
257 seq=job2first_seq(job);
261 pid_tmpfile[npid]=vtmpnam(NULL);
265 if (pid==0)//Child Process
267 initiate_vtmpnam(NULL);
268 while (job && cseq==job2first_seq(job))
270 job=print_lib_job (job, "io->CL=%p control->submitF=%p control->retrieveF=%p control->mode=%s",CL,submit_lib_job, retrieve_lib_job, CL->multi_thread );
271 job=submit_job (job);
273 dump_constraint_list ((job->io)->CL,pid_tmpfile[npid], "a");
276 myexit (EXIT_SUCCESS);
278 else //parent process
285 if (submited>max_nproc)
288 for (a=0; a<nproc; a++)
291 local_stderr=output_completion ( local_stderr,npid,nlines,1, "Processed Job");
294 CL=undump_constraint_list (CL,pid_tmpfile[index]);
295 remove (pid_tmpfile[index]);
307 for (a=0; a<submited; a++)
310 local_stderr=output_completion ( local_stderr,npid-(submited-a),nlines,1, "Processed Job");
313 CL=undump_constraint_list(CL,pid_tmpfile[index]);
314 remove (pid_tmpfile[index]);
320 CL->local_stderr=local_stderr;
327 Constraint_list *fork_cell_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode, Job_TC *job, FILE *local_stderr)
329 //forks cells of the matrix
337 int nproc, max_nproc;
340 max_nproc=nproc=get_nproc();
343 A-> alignment provided in a file
344 L-> list provided in a file
345 aln-> alignment computed and provided in a file
346 list->list computed and provided in a file
353 fprintf (local_stderr, "\n\tMethod %s: No Suitable Sequences [Type: %s]\n", method,M->seq_type);
358 job=queue2heap (job);
362 if (M)M->PW_CL=method2pw_cl ( M, CL);
365 /* Cf. parse method for possible out_mode flags*/
368 pid_tmpfile=vcalloc (njob, sizeof (char*));
369 pid_list =vcalloc (MAX_N_PID, sizeof (int *));
371 fprintf ( local_stderr, "\n\tMulti Core Mode: %d processors:\n", get_nproc());
376 job=print_lib_job (job, "io->CL=%p control->submitF=%p control->retrieveF=%p control->mode=%s",CL,submit_lib_job, retrieve_lib_job, CL->multi_thread );
377 pid_tmpfile[npid]=vtmpnam(NULL);
381 initiate_vtmpnam (NULL);
382 job=submit_job (job);
384 dump_constraint_list ((job->io)->CL,pid_tmpfile[npid], "w");
385 myexit (EXIT_SUCCESS);
395 if (submited>max_nproc)
397 for (a=0; a<nproc; a++)
400 local_stderr=output_completion ( local_stderr,npid,njob,1, "Processed Job");
403 CL=undump_constraint_list (CL,pid_tmpfile[index]);
404 remove (pid_tmpfile[index]);
411 for (a=0; a<submited; a++)
414 local_stderr=output_completion ( local_stderr,npid-a, npid,1, "Processed Job");
417 CL=undump_constraint_list (CL,pid_tmpfile[index]);
418 remove (pid_tmpfile[index]);
423 CL->local_stderr=local_stderr;
429 Constraint_list *nfork_produce_list ( Constraint_list *CL, Sequence *S, char * method,char *weight,char *mem_mode, Job_TC *job, FILE *local_stderr)
434 int n_elements_in, n_new_elements;
438 A-> alignment provided in a file
439 L-> list provided in a file
440 aln-> alignment computed and provided in a file
441 list->list computed and provided in a file
448 fprintf (local_stderr, "\n\tMethod %s: No Suitable Sequences [Type: %s]\n", method,M->seq_type);
453 job=queue2heap (job);
460 if (M)M->PW_CL=method2pw_cl ( M, CL);
461 n_elements_in=CL->ne;
466 local_stderr=output_completion ( local_stderr, b, n_aln+1,1, "Submit Job");
467 job=print_lib_job (job, "io->CL=%p control->submitF=%p control->retrieveF=%p control->mode=%s",CL,submit_lib_job, retrieve_lib_job, CL->multi_thread );
469 job=submit_job (job);
470 if (retrieve_job (job))
472 CL=merge_constraint_list ((job->io)->CL, CL, "default");
478 fprintf ( local_stderr, "\n");
480 while (job) job=delete_job (job);
483 CL->local_stderr=local_stderr;
498 Job_TC *retrieve_lib_job ( Job_TC *job)
509 if ( job->status==EXIT_SUCCESS)
511 static char *log_output;
515 else if (strm2(M->out_mode, "aln", "A"))
517 io->CL=read_constraint_list (io->CL,io->out,"aln","disk",M->weight);
519 else if (strm2(M->out_mode, "lib","L"))
522 io->CL=read_constraint_list (io->CL,io->out,"lib","disk",M->weight);
531 int add_method_output2method_log (char *l,char *command,Alignment *A, Constraint_list *CL, char *io_file)
535 static char *file, *log_file;
538 if ( set && log_file==NULL && l==NULL) return 0;
539 if (!set ){log_file=get_string_variable ("method_log");if (log_file && strm (log_file, "no"))log_file=NULL; set=1;}
540 if (!file)file=vtmpnam (NULL);
543 else if (!l && log_file) l=log_file;
547 if (!header){printf_file ( l, "w", "# CONC_MSF_FORMAT_01\n");header=1;}
548 if (command)printf_file (l, "a", "%s\n#----------------------------------------------\n#%s\n", TC_REC_SEPARATOR,command);
555 output_fasta_aln (io_file, A);
560 vfclose (save_constraint_list ( CL, 0, CL->ne,io_file, NULL, "ascii",CL->S));
563 file_cat (io_file,l);
571 Job_TC *submit_lib_job ( Job_TC *job)
582 add_method_output2method_log (NULL, p->aln_c, NULL, NULL, NULL);
583 if ( getenv4debug ("DEBUG_LIBRARY"))fprintf ( stderr, "\n[DEBUG_LIBRARY:produce_list] Instruction: %s\n", p->aln_c);
589 else if (strm4 (M->out_mode,"A", "L", "aln", "lib"))
591 seq_list2in_file ( M, (io->CL)->S, p->seq_c, io->in);
592 printf_system ("%s ::IGNORE_FAILURE::", p->aln_c);
593 add_method_output2method_log (NULL,NULL, NULL, NULL, io->out);
594 if (!evaluate_sys_call_io (io->out,p->aln_c, "") || (strm (M->out_mode, "aln") && !(is_aln (io->out) || is_seq(io->out))) )
596 job->status=EXIT_FAILURE;
597 //myexit (EXIT_FAILURE);
601 else if ( strm2 (M->out_mode, "fA", "fL"))
604 io->CL= seq2list(job);
607 add_warning (stderr, "\nFAILED TO EXECUTE:%s [SERIOUS:%s]", p->aln_c, PROGRAM);
608 job->status=EXIT_FAILURE;
613 myexit(fprintf_error ( stderr, "\nERROR: Unknown out_mode=%s for method[FATAL:%s]\n", M->out_mode, M->executable));
621 Job_TC* method2job_list ( char *method_name,Sequence *S, char *weight, char *lib_list, Distance_matrix *DM, Constraint_list *CL)
624 static char *fname, *bufS, *bufA;
633 1- a pre computed alignment out_mode=A
634 2- a precomputed Library out_mode=L
635 3- a method producing an alignment out_mode=aln
636 4- a method producing an alignment out_mode=list
637 5- a function producing an alignment out_mode=faln
638 6- a function producing a library out_mode=flist
643 fname=vcalloc ( 1000, sizeof (char));
644 bufS=vcalloc ( S->nseq*10, sizeof (char));
647 /*Make sure that fname is a method*/
650 sprintf(fname, "%s", method_name);
652 if ( fname[0]=='A' || fname[0]=='L')
654 method=method_file2TC_method("no_method");
655 sprintf ( method->out_mode, "%c", fname[0]);
657 if (!strm (weight, "default"))sprintf ( method->weight, "%s", weight);
659 return print_lib_job(NULL,"param->out=%s param->TCM=%p",fname+1, method);
661 else if ( fname[0]=='M' && is_in_pre_set_method_list (fname+1))
666 else if ( is_in_pre_set_method_list (fname))
673 if ( check_file_exists ( fname));
674 else if (fname[0]=='M' && check_file_exists(fname+1));
677 sprintf ( buf, "%s/%s", get_methods_4_tcoffee(), fname);
678 if( check_file_exists(buf)){sprintf ( fname, "%s", buf);}
681 myexit (fprintf_error ( stderr, "%s is not a valid method", fname));
687 method=method_file2TC_method(fname);
688 job=print_lib_job (NULL, "param->TCM=%p", method);
691 if (!strm (weight, "default"))sprintf ( method->weight, "%s", weight);
693 sprintf ( aln_mode, "%s", method->aln_mode);
694 sprintf ( out_mode, "%s", method->out_mode);
697 if (lib_list && lib_list[0])
699 static char **lines, **list=NULL;
704 if ( lines) free_char (lines, -1);
707 if ( strstr (lib_list, "prune"))
709 lines=file2lines (list2prune_list (S,DM->similarity_matrix));
713 lines=file2lines (lib_list);
720 if (list) free_char (list, -1);
721 if (isblanc (lines[a]))continue;
723 list=string2list (lines[a]);n=atoi(list[1]);
724 if ( n> 2 && strm (aln_mode, "pairwise"))continue;
725 if ( n==2 && strm (aln_mode, "multiple"))continue;
727 for (i=2; i<n+2; i++)
729 if ( is_number (list[i]));
730 else if ((x=name_is_in_list (list[i], S->name, S->nseq, 100))!=-1)sprintf(list[i], "%d", x);
733 add_warning ( stderr, "\nWARNING: %s is not part of the sequence dataset \n", list[i]);
737 sprintf ( bufS, "%s", list[1]);
738 for ( i=2; i<n+2; i++) {strcat (bufS, " ");strcat ( bufS, list[i]);}
741 bufA=make_aln_command (method, in=vtmpnam(NULL),out=vtmpnam(NULL));
743 if (strrchr(bufA, '>')==NULL)strcat (bufA,TO_NULL_DEVICE);
744 if ( check_seq_type ( method, bufS, S))
746 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);
747 job=queue_cat (job, job->c);
753 else if ( strcmp (aln_mode, "multiple")==0)
758 sprintf (bufS, "%d",S->nseq);
759 for (d=0; d< S->nseq; d++)
761 sprintf ( buf," %d",d);
765 bufA=make_aln_command (method, in=vtmpnam(NULL),out=vtmpnam(NULL));
766 if (strrchr(bufA, '>')==NULL)strcat (bufA,TO_NULL_DEVICE);
768 if ( check_seq_type ( method, bufS, S))
770 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);
772 job=queue_cat (job, job->c);
777 else if ( strstr(aln_mode, "o2a"))
783 int byte=CL->o2a_byte;
786 for (x=0; x<(CL->S)->nseq; x++)max+=(CL->master[x]);
788 if (CL->o2a_byte>=max)byte=(max/get_nproc())+1;
790 if (!tmpf)tmpf=vtmpnam (NULL);
792 fp=vfopen (tmpf, "w");
793 for (n=0,x=0; x<(CL->S)->nseq; x++)
795 if (CL->master[x]){fprintf (fp, "%d ", x);n++;}
796 if (n==byte || (n && x==(CL->S)->nseq-1))
799 sprintf (bufS, "%d %s", n,file2string (tmpf));n=0;
801 bufA=make_aln_command (method, in=vtmpnam(NULL),out=vtmpnam(NULL));
802 if (strrchr(bufA, '>')==NULL)strcat (bufA,TO_NULL_DEVICE);
803 if ( check_seq_type ( method, bufS, S))
805 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);
806 job=queue_cat (job, job->c);
809 fp=vfopen (tmpf, "w");
815 else if ( strstr(aln_mode, "old_o2a"))
819 for (x=0; x< S->nseq; x++)
821 if (!CL->master[x])continue;
822 sprintf (bufS, "%d %d", S->nseq, x);
823 for ( y=0; y< S->nseq; y++)
827 sprintf (buf, " %d",y);
830 bufA=make_aln_command (method, in=vtmpnam(NULL),out=vtmpnam(NULL));
831 if (strrchr(bufA, '>')==NULL)strcat (bufA,TO_NULL_DEVICE);
832 if ( check_seq_type ( method, bufS, S))
835 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);
837 job=queue_cat (job, job->c);
842 else if ( strstr(aln_mode, "pairwise"))
844 int do_mirror, do_self, x, y, id;
845 do_mirror=(strstr(aln_mode, "m_"))?1:0;
846 do_self=(strstr(aln_mode, "s_"))?1:0;
848 for (x=0; x< S->nseq; x++)
850 if (!CL->master[x])continue;
851 for ( y=(do_mirror)?0:x; y< S->nseq; y++)
854 id=DM->similarity_matrix[x][y];
856 if ( x==y && !do_self);
857 else if ( !is_in_range(id,method->minid, method->maxid));
860 sprintf (bufS, "2 %d %d",x,y);
861 bufA=make_aln_command (method,in=vtmpnam(NULL),out=vtmpnam (NULL));
863 if (strrchr(bufA, '>')==NULL)strcat (bufA, TO_NULL_DEVICE);
864 if (check_seq_type (method, bufS, S))
866 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);
867 job=queue_cat (job, job->c);
869 else if ( method->seq_type[0]=='P' && hijack_P_jobs)
871 //Hijack _P_ jobs without enough templates
872 static TC_method *proba_pairM;
874 add_information(stderr, "Method %s cannot be applied to [%s vs %s], proba_pair will be used instead",(method->executable2)?method->executable2:method->executable, (CL->S)->name[x], (CL->S)->name [y]);
877 proba_pairM=method_file2TC_method(method_name2method_file ("proba_pair"));
878 proba_pairM->PW_CL=method2pw_cl(proba_pairM, CL);
880 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);
881 job=queue_cat (job, job->c);
893 int check_seq_type (TC_method *M, char *list,Sequence *S)
896 int s1, s2, n1, nseq, ntype, i;
901 slist=string2num_list (list);
904 ntype=strlen (M->seq_type);
909 /*Profiles and Sequences MUST NOT be distinguished so that sequences and profiles can easily be aligned*/
910 if ( tolower(t1)=='r')t1='S';
911 if ( tolower(t2)=='r')t2='S';
914 if ( strm ( M->aln_mode, "pairwise") && nseq>2)n1=0;
915 else if (strm ( M->aln_mode, "multiple" ) && ntype>1)n1=0;
919 for (n1=0, i=0; i<nseq; i++)
924 n1+=(strchr (T1->seq_type,t1) || check_profile_seq_type (S, s1, t1))?1:0;
940 s1_has_t1=(strchr ( T1->seq_type, t1) || check_profile_seq_type (S, s1, t1))?1:0;
941 s1_has_t2=(strchr ( T1->seq_type, t2) || check_profile_seq_type (S, s1, t2))?1:0;
942 s2_has_t1=(strchr ( T2->seq_type, t1) || check_profile_seq_type (S, s2, t1))?1:0;
943 s2_has_t2=(strchr ( T2->seq_type, t2) || check_profile_seq_type (S, s2, t2))?1:0;
944 n1=((s1_has_t1 && s2_has_t2) || (s1_has_t2 && s2_has_t1))?1:0;
951 int check_profile_seq_type (Sequence *S, int i, char t)
957 /*returns 1 if the sequence S is associated with a profile containing the right sequence*/
958 A=seq2R_template_profile (S, i);
959 if (A==NULL || A->S==NULL) return 0;
960 for ( a=0; a< A->nseq; a++)
964 if ( T && strchr( T->seq_type,t))return 1;
971 char **method_list2method4dna_list ( char **list, int n)
976 if ( !buf)buf=vcalloc ( 1000, sizeof (char));
978 if ( !list || n==0)return list;
979 buf=vcalloc ( 1000, sizeof (char));
981 for ( a=0; a< n; a++)
984 sprintf ( buf,"%s",list[a]);
986 if ( strm ( list[a], "4dna"));
993 para=string2list2 (list[a], "@");
994 sprintf ( buf, "%s4dna", para[1]);
995 if (method_name2method_file (buf) || method_name2method_file(buf+1))
997 sprintf ( list[a],"%s", buf);
998 for (b=2; b< atoi (para[0]); b++)
1000 strcat (list[a], "@");
1001 strcat (list[a], para[b]);
1005 free_char (para, -1);
1011 int is_in_pre_set_method_list ( char *method)
1018 new_name=method_name2method_file (method);
1020 if ( !new_name) return 0;
1024 sprintf ( method, "%s", new_name);
1028 char *** display_method_names (char *mode, FILE *fp)
1030 char ***list, ***l2;
1031 int n=0, a, ml1=0, ml2=0, ml3=0;
1039 list=produce_method_file (NULL);
1040 l2=declare_arrayN(3,sizeof (char), 1000, 10, 100);
1042 fprintf ( fp, "\n####### Compiling the list of available methods ... (will take a few seconds)\n");
1049 sprintf (l2[a][0], "%s", method_file_tag2value (list[a][1],"ADDRESS"));
1050 sprintf (l2[a][1], "%s", method_file_tag2value (list[a][1],"PROGRAM"));
1051 sprintf (l2[a][2], "%s", method_file_tag2value (list[a][1],"ALN_MODE"));
1052 sprintf (l2[a][3], "%s", method_file_tag2value (list[a][1],"SEQ_TYPE"));
1053 ml1=MAX((strlen (list[a][0])),ml1);
1054 ml2=MAX((strlen (l2 [a][0])),ml2);
1055 ml3=MAX((strlen (l2 [a][1])),ml3);
1056 l2[a][4][0]= check_program_is_installed (l2[a][1],NULL,NULL,l2[a][0],NO_REPORT);
1057 if (strm (l2[a][0], "built_in")){sprintf (l2[a][5], "built_in");}
1058 else if (l2[a][4][0])l2[a][5]=pg2path (l2[a][1]);
1062 fprintf ( fp, "\n####### Methods For which an Interface is available in T-Coffee\n");
1063 fprintf ( fp, "You must install the packages yourself when required (use the provided address)\n");
1064 fprintf ( fp, "Contact us if you need an extra method to be added [%s]\n", EMAIL);
1067 fprintf ( fp, "\n****** Pairwise Sequence Alignment Methods:\n");
1068 fprintf ( fp, "--------------------------------------------\n");
1072 if ( strm (l2[a][2], "pairwise") && !strstr (l2[a][3], "P"))
1073 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]:"");
1077 fprintf ( fp, "\n****** Pairwise Structural Alignment Methods:\n");
1078 fprintf ( fp, "--------------------------------------------\n");
1082 if ( strm (l2[a][2], "pairwise") && strstr (l2[a][3], "P"))
1083 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]:"");
1086 fprintf ( fp, "\n****** Multiple Sequence Alignment Methods:\n");
1087 fprintf ( fp, "--------------------------------------------\n");
1091 if ( strm (l2[a][2], "multiple"))
1092 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]:"");
1095 fprintf ( fp, "\n####### Prediction Methods available to generate Templates\n");
1096 fprintf ( fp, "-------------------------------------------------------------\n");
1100 if ( strm (l2[a][2], "predict"))
1101 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]:"");
1104 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");
1105 fprintf ( fp, "\nThese methods were selected because they are freeware opensource, easy to install and well supported");
1106 fprintf ( fp, "\nContact us if you need an extra method to be added [%s]\n", EMAIL);
1111 char* method_name2method_file (char *method)
1119 if ( check_file_exists (method) || (toupper(method[0])==method[0] && check_file_exists (method+1)))return NULL;
1121 if ( (p=strstr (method, "@"))!=NULL && !strstr (method, "em@"))p[0]='\0';
1122 mlist=produce_method_file (method);
1129 if ( lstrstr (method,mlist[a][0])){fname=mlist[a][1];break;}
1133 if ( fname==NULL) return NULL;
1136 sprintf (address, "%s", method_file_tag2value (fname,"ADDRESS"));
1137 sprintf (program, "%s", method_file_tag2value (fname,"PROGRAM"));
1138 check_program_is_installed (program,NULL,NULL,address,INSTALL_OR_DIE);
1139 if ( (method=strstr (method, "EP@"))!=NULL)
1144 list=string2list2 ( method, "@");
1145 fp=vfopen (fname, "a");
1146 for ( a=2; a<atoi (list[0]); a+=2)
1148 fprintf (fp, "%s %s\n", list[a], list[a+1]);
1153 free_char (list, -1);
1158 char *method_file_tag2value (char *method, char *tag)
1162 static char *buf, *line;
1163 if (!buf) buf=vcalloc ( 1000, sizeof (char));
1168 line=vcalloc (LONG_STRING+1, sizeof ( char));
1171 fp=vfopen (method, "r");
1172 while ( (c=fgetc (fp))!=EOF)
1175 fgets ( line,LONG_STRING, fp);
1177 if ( (line && (line[0]=='*' || line[0]=='#' || line[0] == '$'|| line[0]==' ' || line[0]=='\0' )));
1178 else if ( (p=strstr (line, tag )))
1181 sscanf (p+strlen (tag), " %s" , buf);
1189 struct TC_method * method_file2TC_method( char *method)
1192 static char *subcommand;
1197 //<EXECUTABLE><PARAM1><IN_FLAG><seq_file><PARAM2><OUT_FLAG><outname><PARAM>
1200 line=vcalloc (LONG_STRING+1, sizeof ( char));
1201 subcommand=vcalloc ( LONG_STRING, sizeof (char));
1204 m=vcalloc ( 1, sizeof (TC_method));
1206 /*set default parameter values*/
1207 m->gop=m->gep=UNDEFINED;
1208 sprintf (m->seq_type, "S");
1209 sprintf (m->weight, "sim");
1213 fp=vfopen (method, "r");
1214 while ( (c=fgetc (fp))!=EOF)
1217 fgets ( line,LONG_STRING, fp);
1220 line=substitute (line, "\n", " ");
1221 line=substitute (line, "%s", " ");
1222 line=substitute (line, "%e", "=");
1223 line=substitute (line, "%m", "-");
1225 if ( (line && (line[0]=='*' || line[0]=='#' || line[0] == '$'|| line[0]==' ' || line[0]=='\0' )))subcommand[0]='\0';
1226 //Parse PARAM, PARM1 and PARAM2 first because they may contain keywords
1227 else if ( (p=strstr (line, "PARAM1" )))
1229 sprintf (subcommand, " %s ", p+6);
1230 strcat ( m->param1, subcommand);
1232 else if ( (p=strstr (line, "PARAM2" )))
1234 sprintf (subcommand, " %s ", p+6);
1235 strcat ( m->param2, subcommand);
1237 else if ( (p=strstr (line, "PARAM" )))
1239 sprintf (subcommand, " %s ", p+5);
1240 strcat ( m->param, subcommand);
1241 }else if ( (p=strstr (line, "EXECUTABLE2" )))
1243 sscanf (p, "EXECUTABLE2 %s", m->executable2);
1245 else if ( (p=strstr (line, "EXECUTABLE" )))
1247 sscanf (p, "EXECUTABLE %s", m->executable);
1249 else if ( (p=strstr (line, "IN_FLAG2" ))) sscanf (p, "IN_FLAG2 %s" , m->in_flag2);
1250 else if ( (p=strstr (line, "IN_FLAG" ))) sscanf (p, "IN_FLAG %s" , m->in_flag);
1251 else if ( (p=strstr (line, "OUT_FLAG" ))) sscanf (p, "OUT_FLAG %s" , m->out_flag);
1252 else if ( (p=strstr (line, "OUT_MODE" ))) sscanf (p, "OUT_MODE %s" , m->out_mode);
1253 else if ( (p=strstr (line, "ALN_MODE" ))) sscanf (p, "ALN_MODE %s" , m->aln_mode);
1254 else if ( (p=strstr (line, "SEQ_TYPE" ))) sscanf (p, "SEQ_TYPE %s" , m->seq_type);
1255 else if ( (p=strstr (line, "WEIGHT" ))) sscanf (p, "WEIGHT %s" , m->weight);
1256 else if ( (p=strstr (line, "MATRIX" ))){ sscanf (p, "MATRIX %s" , m->matrix);}
1257 else if ( (p=strstr (line, "GOP" ))) sscanf (p, "GOP %d" , &m->gop);
1258 else if ( (p=strstr (line, "GEP" ))) sscanf (p, "GEP %d" , &m->gep);
1259 else if ( (p=strstr (line, "MAXID" ))) sscanf (p, "MAXID %d" , &m->maxid);
1260 else if ( (p=strstr (line, "MINID" ))) sscanf (p, "MINID %d" , &m->minid);
1261 else if ( (p=strstr (line, "EXTEND_SEQ" ))) sscanf (p, "EXTEND_SEQ %d" , &m->extend_seq);
1262 else if ( (p=strstr (line, "REVERSE_SEQ" ))) sscanf (p, "REVERSE_SEQ %d" , &m->reverse_seq);
1273 int TC_method2method_file( struct TC_method*m,char *fname )
1277 fp=vfopen ( fname, "w");
1278 if ( m->executable[0])fprintf (fp, "EXECUTABLE %s\n", m->executable);
1279 if (m->in_flag[0])fprintf (fp, "IN_FLAG %s\n", m->in_flag);
1280 if (m->out_flag[0])fprintf (fp, "OUT_FLAG %s\n", m->out_flag);
1281 if (m->out_mode[0])fprintf (fp, "OUT_MODE %s\n", m->out_mode);
1282 if (m->aln_mode[0])fprintf (fp, "ALN_MODE %s\n", m->aln_mode);
1283 if (m->seq_type)fprintf (fp, "SEQ_TYPE %s\n", m->seq_type);
1284 if (m->weight[0])fprintf (fp, "WEIGHT %s\n", m->weight);
1285 if (m->matrix[0])fprintf (fp, "MATRIX %s\n", m->matrix);
1286 if (m->gop!=UNDEFINED)fprintf (fp, "GOP %d\n", m->gop);
1287 if (m->gep!=UNDEFINED)fprintf (fp, "GEP %d\n", m->gep);
1288 if (m->minid!=0 )fprintf (fp, "MINID %d\n", m->minid);
1289 if (m->maxid!=100)fprintf (fp, "MAXID %d\n", m->maxid);
1290 if (m->param[0])fprintf (fp, "PARAM %s\n", m->param);
1291 if (m->param1[0])fprintf (fp, "PARAM1 %s\n", m->param1);
1292 if (m->param2[0])fprintf (fp, "PARAM1 %s\n", m->param2);
1293 if (m->in_flag2[0])fprintf (fp, "IN_FLAG2 %s\n", m->in_flag2);
1299 char *make_aln_command(TC_method *m, char *seq, char *aln)
1304 // 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);
1306 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);
1307 command=vcalloc ( strlen (buf)+100, sizeof (char));
1308 sprintf ( command, "%s", buf);
1309 //HERE ("%s", command); exit (0);
1311 command=substitute (command, "&bnsp", " ");
1312 command=substitute (command, "no_name", "");
1321 /*********************************************************************/
1326 /*********************************************************************/
1327 Constraint_list * unfreeze_constraint_list (Constraint_list *CL)
1329 free_int (CL->freeze, -1);
1332 Constraint_list * freeze_constraint_list (Constraint_list *CL)
1336 int **freeze=declare_int2 (S->nseq, S->len, 1);
1338 for ( a=0; a<S->nseq; a++)
1341 while (CL->residue_index[a][b])
1343 d+=CL->residue_index[a][b][0];
1344 freeze[a][b]=CL->residue_index[a][b][0];
1351 Constraint_list * empty_constraint_list (Constraint_list *CL)
1353 //reset all the indexes
1356 if ( !CL || ! CL->residue_index) return CL;
1357 for (a=0; a<(CL->S)->nseq; a++)
1360 while (CL->residue_index[a][b])
1362 CL->residue_index[a][b][0]=1;
1370 Constraint_list * undump_constraint_list (Constraint_list *CL, char *file)
1376 if (!CL || !CL->residue_index)return CL;
1377 entry=vcalloc ( CL->entry_len+1, sizeof (int));
1378 fp=vfopen (file, "r");
1380 while ((fscanf (fp, "%d ", &e))!=EOF)
1383 if (b==CL->entry_len)
1387 CL=add_entry2list2 (entry, CL);
1388 //dump does not make the entries symetrical
1389 //It reads in EXACTLY what was dumped
1398 int safe_dump_constraint_list (Constraint_list *CL,char *file, char *mode, Sequence *RS)
1403 // static int *entry;
1404 int *entry = vcalloc (CL->entry_len+1, sizeof (int));
1405 int b,c,s1, r1, s2, r2;
1407 if (!CL || !CL->S || !CL->residue_index || CL->ne==0)return;
1409 if (RS)cache=fix_seq_seq (S, RS);
1412 // entry=vcalloc (CL->entry_len+1, sizeof (int));
1415 fp=vfopen (file, mode);
1416 for (s1=0; s1<S->nseq; s1++)
1418 if (cache && cache[s1][0]==-1)continue;
1419 for (r1=1; r1<=S->len[s1]; r1++)
1421 entry[SEQ1]=(cache)?cache[s1][0]:s1;
1422 entry[R1]=(cache)?cache[s1][r1]:r1;
1423 if (entry[R1]<=0)continue;
1425 b=(CL->freeze)?CL->freeze[s1][r1]:1;
1426 for (;b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
1428 s2=CL->residue_index[s1][r1][b+SEQ2];
1429 r2=CL->residue_index[s1][r1][b+R2];
1431 entry[SEQ2]=(cache)?cache[s2][0]:s2;
1432 if ( entry[SEQ2]==-1)continue;
1435 entry[R2]=(cache)?cache[s2][r2]:r2;
1436 if (entry[R2]<=0)continue;
1440 entry[WE]=CL->residue_index[s1][r1][b+WE];
1441 entry[CONS]=CL->residue_index[s1][r1][b+CONS];
1442 entry[MISC]=CL->residue_index[s1][r1][b+MISC];
1444 for (c=0; c<CL->entry_len; c++)fprintf ( fp, "%d ", entry[c]);
1452 free_int (cache, -1);
1457 int dump_constraint_list (Constraint_list *CL, char *file, char *mode)
1459 return safe_dump_constraint_list (CL, file, mode, NULL);
1463 FILE* display_constraint_list (Constraint_list *CL, FILE *fp, char *tag)
1466 int b,c,l,s1,r1,s2,r2,w2,n;
1469 for (s1=0; s1<S->nseq; s1++)
1471 fprintf (fp, "SEQUENCE %d\n", s1);
1474 while (CL->residue_index[s1][r1])
1476 for (b=1; b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
1478 s2=CL->residue_index[s1][r1][b+SEQ2];
1479 r2=CL->residue_index[s1][r1][b+R2];
1480 w2=CL->residue_index[s1][r1][b+WE];
1481 fprintf ( fp, "\t%sS1:%5d - R1:%5d S2:%5d R2:%5d W:%5d\n", tag,s1,r1, s2, r2,w2);
1492 /*********************************************************************/
1494 /* LIST EXTENTION */
1497 /*********************************************************************/
1503 Constraint_list * evaluate_constraint_list_reference ( Constraint_list *CL)
1505 static CLIST_TYPE *entry;
1506 int a, b, c, s1, s2, r1, r2;
1511 CL->max_value=CL->max_ext_value=20;
1519 CL->max_value=CL->max_ext_value=0;
1520 max_res=vcalloc ( (CL->S)->nseq, sizeof (int**));
1522 for ( a=0; a< (CL->S)->nseq; a++)
1524 max_res[a]=vcalloc ( strlen ((CL->S)->seq[a])+1, sizeof (int*));
1525 for ( b=0; b<=(CL->S)->len[a]; b++)
1527 max_res[a][b]=vcalloc ( (CL->S)->nseq+1, sizeof (int));
1532 for (s1=0; s1<S->nseq; s1++)
1534 for ( r1=1; r1<=S->len[s1]; r1++)
1537 for (a=1; a<CL->residue_index[s1][r1][0]; a+=ICHUNK)
1539 int s2=CL->residue_index[s1][r1][a+SEQ2];
1540 int r2=CL->residue_index[s1][r1][a+R2];
1541 int w2=CL->residue_index[s1][r1][a+WE];
1542 if ( w2==UNDEFINED || ( (CL->moca) && (CL->moca)->forbiden_residues && ((CL->moca)->forbiden_residues[s1][r1]==UNDEFINED || (CL->moca)->forbiden_residues[s2][r2]==UNDEFINED)));
1545 max_res[s1][r1][s2]+=w2;
1546 max_res[s2][r2][s1]+=w2;
1547 CL->max_value=MAX(w2, CL->max_value);
1553 for ( a=0; a< (CL->S)->nseq; a++)
1554 for ( b=1; b<=(CL->S)->len[a]; b++)
1556 for ( c=0; c< (CL->S)->nseq; c++)
1558 max_res[a][b][(CL->S)->nseq]+= max_res[a][b][c];
1560 CL->max_ext_value=MAX(max_res[a][b][c],CL->max_ext_value);
1563 for ( a=0; a< (CL->S)->nseq; a++)
1565 for ( b=0; b<=(CL->S)->len[a]; b++)
1566 vfree ( max_res[a][b]);
1569 CL->max_ext_value=MAX(1,CL->max_ext_value);
1576 CL->nomatch=(CL->nomatch*CL->normalise)/CL->max_ext_value;
1582 /*********************************************************************/
1584 /* ENTRY MANIPULATION */
1587 /*********************************************************************/
1588 Constraint_list * add_list_entry2list (Constraint_list *CL, int n_para, ...)
1595 if (n_para>LIST_N_FIELDS)
1597 myexit (fprintf_error ( stderr, "Too Many Fields in List"));
1600 va_start (ap,n_para);
1601 entry=vcalloc (CL->entry_len+1, sizeof (int));
1603 for ( a=0; a<n_para; a++)
1605 field=va_arg(ap, int);
1606 val =va_arg(ap, CLIST_TYPE);
1610 add_entry2list(entry, CL);
1615 int *extract_entry (Constraint_list *CL)
1623 if (!entry)entry=vcalloc (100, sizeof (int));
1624 if (!CL){s=0;r=1;l=1; return NULL;}
1627 for (; s<(CL->S)->nseq; s++)
1629 while ((CL->residue_index[s][r]))
1631 for (; l<CL->residue_index[s][r][0];)
1636 entry[SEQ2]=CL->residue_index[s][r][l+SEQ2];
1637 entry[R2]= CL->residue_index[s][r][l+R2];
1638 entry[WE]= CL->residue_index[s][r][l+WE];
1639 entry[CONS]=CL->residue_index[s][r][l+CONS];
1640 entry[MISC]=CL->residue_index[s][r][l+MISC];
1657 int next_entry (Constraint_list *CL, int *s, int*r, int *l);
1658 int *extract_entry (Constraint_list *CL)
1666 if (!entry)entry=vcalloc (100, sizeof (int));
1667 if (!CL){s=0;r=1;l=1; return NULL;}
1670 while ((v=next_entry (CL, &s, &r, &l)))
1678 entry[SEQ2]=CL->residue_index[s][r][l-ICHUNK+SEQ2];
1679 entry[R2]= CL->residue_index[s][r][l-ICHUNK+R2];
1680 entry[WE]= CL->residue_index[s][r][l-ICHUNK+WE];
1681 entry[CONS]=CL->residue_index[s][r][l-ICHUNK+CONS];
1682 entry[MISC]=CL->residue_index[s][r][l-ICHUNK+MISC];
1683 entry[INDEX]=l-ICHUNK;
1690 int next_entry (Constraint_list *CL, int *s, int*r,int *l)
1694 if (s[0]>=S->nseq)return 0;
1695 else if (!CL->residue_index[s[0]][r[0]])
1702 else if ( l[0]>=CL->residue_index[s[0]][r[0]][0])
1717 int CLisCompacted (Constraint_list *CL, char *t)
1719 int s1, r1, s2, r2,ps2,pr2,b,c;
1722 for (s1=0; s1<S->nseq; s1++)
1723 for (r1=1; r1<=S->len[s1]; r1++)
1725 for (b=1; b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
1727 s2=CL->residue_index[s1][r1][b+SEQ2];
1728 r2=CL->residue_index[s1][r1][b+R2];
1732 if (s2==ps2 && r2==pr2)
1735 HERE ("%s -- NOT COMPACTED",t);
1738 else if ( s2<=ps2 && r2<pr2)
1740 HERE ("%s -- NOT SORTED",t);
1741 fprintf ( stderr, "\n");
1742 for (c=1; c<CL->residue_index[s1][r1][0]; c++)
1744 fprintf (stderr, "%5d ",CL->residue_index[s1][r1][c]);
1757 int checkCL (Constraint_list *CL, char *t)
1762 for (a=0; a<(CL->S)->nseq; a++)
1763 for (b=1; b<=(CL->S)->len[a]; b++)
1765 HERE ("%s %4d ==> %d",t,CL->residue_index[a][b][0], CL->residue_index[a][b][0]%ICHUNK);
1769 if (!CL){HERE ("CL is Not declared");fail=1;}
1770 else if ( !CL->S){HERE ("S is not declared in CL");fail=1;}
1771 else if ( !CL->residue_index){HERE ("residue index is not declared");fail=1;}
1772 else if (read_array_size_new (CL->residue_index)!=(CL->S)->nseq){HERE ("CL not well declared (S)");fail=1;}
1775 for (a=0; a<(CL->S)->nseq; a++)
1777 int s=(CL->S)->len[a]+1;
1778 int j=read_array_size_new (CL->residue_index[a]);
1784 for (a=0; a<(CL->S)->nseq; a++)
1786 int s=(CL->S)->len[a]+1;
1787 int j=read_array_size_new (CL->residue_index[a]);
1789 HERE ("\t %s %d %d",(CL->S)->name[a], s-1,j);
1795 HERE ("******** CHECKED CL: %s ******", t);
1802 Constraint_list *add_entry2list( CLIST_TYPE *entry, Constraint_list *CL)
1804 //adds an entry and its mirror to the list
1805 //if INDEX is set the entry replaces the entry with a similar index
1806 //otherwise the entry (and its mirror) are added
1812 if (entry[INDEX])return add_entry2list2(entry, CL);
1818 add_entry2list2 (entry, CL);
1824 add_entry2list2 (entry, CL);
1829 int get_entry_index (int *entry, Constraint_list *CL);
1830 Constraint_list *insert_entry (CLIST_TYPE *entry, Constraint_list *CL, int i);
1831 Constraint_list *update_entry (CLIST_TYPE *entry, Constraint_list *CL, int i);
1832 Constraint_list *reset_entry (CLIST_TYPE *entry, Constraint_list *CL, int i);
1833 Constraint_list *remove_entry (CLIST_TYPE *entry, Constraint_list *CL, int i);
1834 Constraint_list *add_entry2list2 (CLIST_TYPE *entry, Constraint_list *CL)
1836 //adds an entry to the list
1840 int i=CL->residue_index[entry[SEQ1]][entry[R1]][0];
1841 if (entry[INDEX]){return reset_entry (entry, CL, entry[INDEX]); }
1842 else if (i==1){insert_entry (entry, CL,1);}
1845 i=get_entry_index(entry,CL);
1846 if (i<0)insert_entry (entry,CL,-i);
1847 else update_entry (entry, CL, i);
1854 static Constraint_list *sCL;
1855 int get_entry_index_serial (int *entry, Constraint_list *CL);
1856 int get_entry_index_dico (int *entry, Constraint_list *CL);
1857 int get_entry_index (int *entry, Constraint_list *CL)
1861 int *r= CL->residue_index[s1][r1];
1864 return get_entry_index_dico (entry, CL);
1866 int get_entry_index_serial (int *entry, Constraint_list *CL)
1868 //return the index of an entry
1869 //positive value: the entry exists on position i
1870 //negative value: the entry must be created on poistion -i
1876 int *r= CL->residue_index[s1][r1];
1880 if (r[0]==1)return -1;//corresponding entry undeclared->must be inserted
1883 for (a=1; a<r[0]; a+=ICHUNK)
1887 if (r[a+SEQ2]==s2 && r[a+R2]==r2)return a;
1888 else if (r[a+SEQ2]==s2 && r[a+R2]>r2)return -a;
1889 else if (r[a+SEQ2]>s2)return -a;
1895 int get_entry_index_dico (int *entry, Constraint_list *CL)
1897 //return the index of an entry
1898 //positive value: the entry exists on position i
1899 //negative value: the entry must be created on poistion -i
1907 int *r= CL->residue_index[s1][r1];
1908 int ps2, pr2, ns2,nr2,p,n;
1912 if (r[0]==1)return -1;//corresponding entry undeclared->must be inserted
1915 delta=((r[0]-1)/ICHUNK);
1916 delta=MAX(1,(delta/2));
1922 i+=(delta*dir*ICHUNK);
1925 if (i<r[0] && s2==r[i+SEQ2] && r2==r[i+R2])return i;
1931 ps2=r[i-ICHUNK+SEQ2];
1933 p=(s2>ps2 || (s2==ps2 && r2>pr2))?1:0;
1939 n=(s2<ns2 || (s2==ns2 && r2<nr2))?1:0;
1942 if ( p && n) return -i;
1945 if (dir==-1)delta=MAX(1,(delta/2));
1950 if ( dir==1)delta=MAX(1,(delta/2));
1958 Constraint_list *remove_entry (CLIST_TYPE *entry, Constraint_list *CL, int i)
1960 //insert entry right after i;
1964 int *r=CL->residue_index[entry[SEQ1]][entry[R1]];
1969 if (bsize<s){vfree(buf); bsize=s;buf=vcalloc (bsize,sizeof (int));}
1970 memcpy(buf,r+i, s*sizeof (int));
1971 memcpy(r+i-ICHUNK, buf, s*sizeof (int));
1973 CL->residue_index[entry[SEQ1]][entry[R1]]=vrealloc(r,r[0]*sizeof (int));
1978 Constraint_list *insert_entry (CLIST_TYPE *entry, Constraint_list *CL, int i)
1980 //insert entry right after i;
1984 int *r=CL->residue_index[entry[SEQ1]][entry[R1]];
1986 //inserts a new entry between i-1 and i
1988 r=vrealloc (r, (r[0]+ICHUNK)*sizeof (int));
1989 CL->residue_index[entry[SEQ1]][entry[R1]]=r;
1993 if (bsize<s){vfree(buf); bsize=s;buf=vcalloc (bsize,sizeof (int));}
1994 if (s)memcpy(buf,r+i, s*sizeof (int));
1995 if (s)memcpy(r+i+ICHUNK, buf, s*sizeof (int));
1996 memcpy (r+i, entry, ICHUNK*sizeof (int));
2001 Constraint_list *reset_entry (CLIST_TYPE *entry, Constraint_list *CL, int i)
2003 int *r=CL->residue_index[entry[SEQ1]][entry[R1]];
2004 memcpy (r+i, entry, ICHUNK*sizeof (int));
2007 Constraint_list *update_entry (CLIST_TYPE *entry, Constraint_list *CL, int i)
2014 CL->residue_index[s1][r1][i+SEQ2]=entry[SEQ2];
2015 CL->residue_index[s1][r1][i+R2] =entry[R2];
2016 CL->residue_index[s1][r1][i+WE] =MAX(entry[WE],CL->residue_index[s1][r1][i+WE]);
2017 CL->residue_index[s1][r1][i+CONS]+=entry[CONS];
2018 CL->residue_index[s1][r1][i+MISC]=entry[MISC];
2022 /*********************************************************************/
2024 /* SEARCH IN LIST (ARRAY AND FILE) */
2027 /*********************************************************************/
2031 CLIST_TYPE *main_search_in_list_constraint ( int *key,int *p,int k_len,Constraint_list *CL)
2035 static CLIST_TYPE *l=NULL;
2036 int a, s1, s2, r1, r2, ni;
2038 if (!l)l=vcalloc (CL->entry_len+1, sizeof (int));
2039 for (a=0; a<CL->entry_len; a++)l[a]=key[a];
2047 ni=CL->residue_index[s1][r1][0];
2048 for (a=1; a<ni; a+=ICHUNK)
2050 if (CL->residue_index[s1][r1][a+SEQ2]==s2 && CL->residue_index[s1][r1][a+R2]==r2)
2056 l[WE]=CL->residue_index[s1][r1][a+WE];
2064 CLIST_TYPE return_max_constraint_list ( Constraint_list *CL, int field)
2066 return constraint_list2max (CL);
2070 /*********************************************************************/
2077 /*********************************************************************/
2078 Constraint_list *sort_constraint_list_inv (Constraint_list *CL, int start, int len)
2080 return sort_constraint_list (CL, start, len);
2084 Constraint_list *invert_constraint_list (Constraint_list *CL, int start,int len)
2092 Constraint_list * sort_constraint_list(Constraint_list *CL, int start, int len)
2097 int b,l,s1,r1,s2,r2,w2;
2098 for (s1=0; s1<S->nseq; s1++)
2100 for (r1=1; r1<=S->len[s1]; r1++)
2102 int nE=(CL->residue_index[s1][r1][0]-1)/ICHUNK;
2103 int sizE=sizeof(int)*ICHUNK;
2104 int *start=CL->residue_index[s1][r1]+1;
2105 qsort ((void*)start,nE,sizE,compare_constraint_list_entry);
2112 int compare_constraint_list_entry4bsearch ( const void*vx, const void*vy)
2115 const int *x=vx, *y=vy;
2118 if (x[a]<y[a])return -1;
2119 else if (x[a]>y[a]) return 1;
2123 int compare_constraint_list_entry ( const void*vx, const void*vy)
2126 const int *x=vx, *y=vy;
2127 for (a=0; a<ICHUNK; a++)
2129 if (x[a]<y[a])return -1;
2130 else if (x[a]>y[a]) return 1;
2134 /*********************************************************************/
2139 /*********************************************************************/
2140 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);
2141 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);
2143 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)
2146 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);
2147 else if ( strstr (CL->multi_thread, "methods"))
2148 return fork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode,type,local_stderr, CL, seq_source);
2150 return nfork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode,type,local_stderr, CL, seq_source);
2152 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)
2162 proclist=vcalloc (MAX_N_PID, sizeof (int));
2163 tmp_list=vcalloc (n_list+1, sizeof (char*));
2164 for (a=0; a<n_list; a++)tmp_list[a]=vtmpnam(NULL);
2166 if (!(CL->S) && (S=read_seq_in_n_list (fname, n_list,type,seq_source))==NULL)
2168 myexit (fprintf_error ( stderr, "NO SEQUENCE WAS SPECIFIED"));
2170 else if (CL->S==NULL)
2175 /*CHECK IF THERE IS A MATRIX AND GET RID OF OTHER METHODS*/
2176 for (b=0, a=0; a< n_list; a++)if (is_matrix(fname[a]) ||is_matrix(fname[a]+1) )b=a+1;
2181 else sprintf ( fname[0], "%s", fname[b-1]);
2183 return nfork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode, type,local_stderr, CL, seq_source);
2186 if (!CL)CL=declare_constraint_list ( S,NULL, NULL, 0,(strm(mem_mode, "disk"))?tmpfile():NULL, NULL);
2190 dump_constraint_list(CL,tmp_list[n_list], "w");
2194 CL->local_stderr=local_stderr;
2195 fprintf ( local_stderr, "\n\tMulti Core Mode: %d processors:\n", nproc);
2196 for (ns=0,a=0; a< n_list; a++)
2204 initiate_vtmpnam (NULL);
2205 CL->local_stderr=vfopen("/dev/null", "w");
2207 CL=read_constraint_list (CL, fname[a], in_mode, mem_mode,weight_mode);
2208 if (CL->ne>in)dump_constraint_list(CL,tmp_list[a], "w");
2209 myexit (EXIT_SUCCESS);
2215 fprintf ( local_stderr, "\n\t--- Process Method/Library/Aln %s", fname[a], ns);
2219 b=proclist[vwait(NULL)];
2220 fprintf (local_stderr, "\n\txxx Retrieved %s",fname[a]);
2221 if (tmp_list[b] && check_file_exists (tmp_list[b]))
2223 CL=undump_constraint_list(CL,tmp_list[b]);
2235 fprintf (local_stderr, "\n\txxx Retrieved %s",fname[a]);
2236 if (tmp_list[a] && check_file_exists (tmp_list[a]))
2238 CL=undump_constraint_list (CL,tmp_list[a]);
2242 fprintf ( local_stderr, "\n\n\tAll Methods Retrieved\n");
2244 if (tmp_list[n_list] && check_file_exists (tmp_list[n_list]))
2246 CL=undump_constraint_list(CL,tmp_list[n_list]);
2249 CL->local_stderr=local_stderr;
2255 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)
2261 if (!(CL->S) && (S=read_seq_in_n_list (fname, n_list,type,seq_source))==NULL)
2263 fprintf ( stderr, "\nNO SEQUENCE WAS SPECIFIED[FATAL]\n");
2264 myexit(EXIT_FAILURE);
2266 else if (CL->S==NULL)
2271 /*CHECK IF THERE IS A MATRIX AND GET RID OF OTHER METHODS*/
2272 for (b=0, a=0; a< n_list; a++)if (is_matrix(fname[a]) ||is_matrix(fname[a]+1) )b=a+1;
2277 else sprintf ( fname[0], "%s", fname[b-1]);
2282 if (!CL)CL=declare_constraint_list ( S,NULL, NULL, 0,(strm(mem_mode, "disk"))?tmpfile():NULL, NULL);
2283 CL->local_stderr=local_stderr;
2284 fprintf ( CL->local_stderr,"\nREAD/MAKE LIBRARIES:[%d]\n",n_list );
2286 CL=read_constraint_list (CL, fname[0], in_mode, mem_mode,weight_mode);
2287 for ( a=1; a< n_list; a++)
2289 CL=read_constraint_list (CL, fname[a], in_mode, mem_mode,weight_mode);
2291 CL->local_stderr=local_stderr;
2295 Constraint_list* read_constraint_list(Constraint_list *CL,char *in_fname,char *in_mode, char *mem_mode,char *weight_mode)
2297 Sequence *SL=NULL, *TS=NULL;
2299 Constraint_list *SUBCL=NULL;
2300 static char *read_mode;
2304 if ( !read_mode)read_mode=vcalloc ( STRING, sizeof (char));
2306 if ( is_lib_list (in_fname))sprintf ( read_mode, "lib_list");
2307 else if ( in_mode)sprintf (read_mode, "%s", in_mode);
2308 else if ( fname[0]=='A'){sprintf ( read_mode, "aln");fname++;}
2309 else if ( fname[0]=='L'){sprintf ( read_mode, "lib");fname++;}
2310 else if ( fname[0]=='M'){sprintf ( read_mode, "method");fname++;}
2311 else if ( fname[0]=='S'){sprintf ( read_mode, "sequence");return CL;}
2312 else if ( fname[0]=='P'){sprintf ( read_mode, "pdb") ;return CL;}
2313 else if ( fname[0]=='R'){sprintf ( read_mode, "profile") ;return CL;}
2314 else if ( fname[0]=='X'){sprintf ( read_mode, "matrix");++fname;}
2315 else if ( fname[0]=='W'){sprintf ( read_mode, "structure");fname++;}
2318 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);
2319 myexit (EXIT_SUCCESS);
2322 fprintf (CL->local_stderr, "\n\t%s [%s]\n", fname, read_mode);
2325 if ( strm (read_mode, "lib_list"))
2329 l=read_lib_list (fname, &n);
2330 for ( a=0; a<n; a++)
2331 CL=read_constraint_list (CL,l[a],in_mode, mem_mode,weight_mode);
2334 else if (strm(read_mode, "binary"))
2336 fprintf ( stderr, "\nERROR: Library %s: binary mode is not any more supported [FATAL:%s]\n", fname,PROGRAM);
2337 myexit (EXIT_FAILURE);
2339 else if ( strm (fname, "make_test_lib"))
2341 CL=make_test_lib (CL);
2343 else if ( strm2 (read_mode,"ascii","lib"))
2346 SUBCL=read_constraint_list_file(NULL, fname);
2349 else if (strm(read_mode, "method"))
2351 CL=produce_list ( CL, CL->S, fname,weight_mode,mem_mode);
2353 else if (strm(read_mode, "matrix"))
2355 CL->residue_index=NULL;
2357 CL->M=read_matrice ( fname);
2359 else if ( strm ( read_mode, "structure"))
2363 fprintf ( stderr, "\nERROR: Wstructure must come before Mmethod or Aaln [FATAL:%s]",PROGRAM);
2364 myexit (EXIT_FAILURE);
2367 if ( !(CL->STRUC_LIST))
2369 CL->STRUC_LIST=declare_sequence (1,1,10000);
2370 (CL->STRUC_LIST)->nseq=0;
2374 if ( check_file_exists(fname))
2376 TS=main_read_seq ( fname);
2377 for (a=0; a<TS->nseq; a++)sprintf (SL->name[SL->nseq++], "%s", TS->name[a]);
2378 free_sequence (TS, TS->nseq);
2382 sprintf (SL->name[SL->nseq++], "%s", fname);
2385 else if (strm (read_mode, "aln"))
2387 CL=aln_file2constraint_list ( fname,CL,weight_mode);
2391 SUBCL=read_constraint_list_file(SUBCL, fname);
2397 CL=merge_constraint_list (SUBCL, CL, "default");
2398 free_constraint_list_full (SUBCL);
2404 #define is_seq_source(Symbol,Mode,SeqMode) (Symbol==Mode && (SeqMode==NULL || strm (SeqMode, "ANY") || (SeqMode[0]!='_' && strchr (SeqMode,Symbol)) || (SeqMode[0]=='_' && !strchr (SeqMode,Symbol))))
2405 Sequence * read_seq_in_n_list(char **fname, int n, char *type, char *SeqMode)
2410 char **sequences=NULL;
2411 char **seq_name=NULL;
2418 /*THE TYPE OF EACH FILE MUST BE INDICATED*/
2419 /*SeqMode indicates the type of file that can be used as sequence sources*/
2422 SL: only sequences from Libraries and Sequences
2423 _A: anything BUT sequences from A(lignments)
2428 myexit (fprintf_error ( stderr, "NO in FILE"));
2432 for ( a=0; a< n ; a++)
2436 if (buf)vfree (buf);
2439 buf=name2type_name(fname[a]);mode=buf[0];lname=buf+1;
2441 if (is_seq_source ('A', mode, SeqMode))
2445 A=main_read_aln (lname,NULL);
2448 S1=seq2unique_name_seq (S1);
2449 if ((S=merge_seq ( S1, S))==NULL){fprintf ( stderr, "\nERROR: Sequence Error in %s [FATAL:%s]\n",lname, PROGRAM); myexit(EXIT_FAILURE);}
2451 free_sequence (S1, S1->nseq);
2453 else if ( is_seq_source ('R', mode, SeqMode))
2455 S=add_prf2seq (lname, S);
2458 else if (is_seq_source ('P', mode, SeqMode))
2462 S1=get_pdb_sequence (lname);
2465 add_warning ( stderr, "\nWarning: Could not use PDB: %s", lname);
2469 if ((S=merge_seq ( S1, S))==NULL){fprintf ( stderr, "\nERROR: Sequence Error in %s [FATAL:%s]\n",lname, PROGRAM); myexit(EXIT_FAILURE);}
2470 i=name_is_in_list (S1->name[0], S->name, S->nseq, 100);
2471 (S->T[i])->P=fill_P_template (S->name[i], lname, S);
2473 free_sequence (S1, S1->nseq);
2475 else if ( mode=='M');
2476 else if ( mode=='X');
2477 else if ( mode=='W');
2479 else if (is_seq_source ('S', mode, SeqMode))
2481 /*1 Try with my routines (read t_coffee and MSF)*/
2482 if ( (A=main_read_aln ( lname, NULL))!=NULL)
2490 S1=main_read_seq (lname);
2493 for ( b=0; b< S1->nseq; b++)ungap(S1->seq[b]);
2494 S1=seq2unique_name_seq (S1);
2497 if ((S=merge_seq ( S1, S))==NULL){fprintf ( stderr, "\nSequence Error in %s [FATAL:%s]\n",lname,PROGRAM); myexit(EXIT_FAILURE);}
2499 free_sequence (S1,S1->nseq);
2502 else if (is_seq_source ('L', mode, SeqMode))
2505 read_seq_in_list (lname,&nseq,&sequences,&seq_name);
2506 S1=fill_sequence_struc ( nseq, sequences, seq_name);
2508 for ( b=0; b< S1->nseq; b++)sprintf ( S1->file[b], "%s", lname);
2509 nseq=0;free_char (sequences, -1); free_char ( seq_name, -1);
2512 S1=seq2unique_name_seq (S1);
2514 if ((S=merge_seq( S1, S))==NULL){fprintf ( stderr, "\nSequence Error in %s [FATAL:%s]\n",lname,PROGRAM); myexit(EXIT_FAILURE);}
2515 free_sequence(S1, S1->nseq);
2518 else if ( !strchr ( "ALSMXPRWG", mode))
2520 myexit (fprintf_error ( stderr, "%s is neither a file nor a method [FATAL:%s]\n", lname));
2524 S=remove_empty_sequence (S);
2527 if ( type && type[0] )sprintf ( S->type, "%s", type);
2528 else S=get_sequence_type (S);
2530 if ( strm (S->type, "PROTEIN_DNA"))
2532 for ( a=0; a< S->nseq; a++)
2534 if (strm ( get_string_type ( S->seq[a]), "DNA") ||strm ( get_string_type ( S->seq[a]), "RNA") );
2535 else if ( strm ( get_string_type ( S->seq[a]), "PROTEIN"))
2537 S->seq[a]=thread_aa_seq_on_dna_seq (S->seq[a]);
2538 S->len[a]=strlen (S->seq[a]);
2539 S->max_len=MAX(S->max_len, S->len[a]);
2554 int read_cpu_in_list ( char *fname)
2560 fp=vfopen ( fname, "r");
2561 while ( (c=fgetc(fp))!='#');
2562 while ( (c=fgetc(fp))!='C' && c!=EOF);
2563 if ( c=='C')fscanf( fp, "PU %d\n", &cpu);
2567 char * expand_constraint_list_file ( char *file)
2575 if (!token_is_in_file (file,"+BLOCK+"))return file;
2577 new_file=vtmpnam (NULL);
2578 IN=vfopen ( file,"r");
2579 OUT=vfopen (new_file, "w");
2581 while ( (c=fgetc (IN))!=EOF)
2584 buf=vfgets (buf, IN);
2585 if ( !strstr (buf, "+BLOCK+"))
2586 fprintf (OUT, "%s", buf);
2589 list=string2list (buf);
2592 for (a=0; a< n; a++)
2594 fprintf ( OUT, "%5d %5d ",atoi(list[3])+a, atoi(list[4])+a);
2595 for (b=5; b<atoi(list[0]); b++) fprintf ( OUT, "%s ", list[b]);
2596 fprintf (OUT, "\n");
2598 free_char (list, -1);
2601 vfclose (IN); vfclose (OUT);
2606 Constraint_list * make_test_lib(Constraint_list *CL)
2612 entry=vcalloc (CL->entry_len+1, sizeof (int));
2613 HERE ("cncn: making artificial lib");//Keep this warning alive
2616 fprintf ( stderr, "\n");
2617 for (a=0; a< S->nseq-1; a++)
2619 fprintf ( stderr, "[%d-%d]", a, CL->ne);
2620 for ( b=a+1; b< S->nseq; b++)
2623 l1=MIN(S->len[a], S->len[b]);
2625 for (c=0; c<l1; c++)
2632 add_entry2list (entry, CL);
2639 Constraint_list * read_constraint_list_file(Constraint_list *CL, char *in_fname)
2642 int **index, *entry;
2643 int c,line=0,s1, s2, r1, r2, misc, cons,x,we;
2650 fname=expand_constraint_list_file (in_fname);
2651 NS=read_seq_in_n_list (&fname, 1,NULL, NULL);
2654 CL=declare_constraint_list_simple(NS);
2657 index=fix_seq_seq (NS, CL->S);
2658 entry=vcalloc ( CL->entry_len+1, sizeof (int));
2660 fp=vfopen(fname,"r");
2661 while ((c=fgetc(fp))!='#' && c!=EOF){line+=(c=='\n')?1:0;}
2664 while ((buf=vfgets ( buf, fp))!=NULL)
2667 if (buf[0]=='!')continue;
2668 else if (buf[0]=='#')
2670 sscanf ( buf, "#%d %d", &s1, &s2);
2672 if (s1>NS->nseq || s2>NS->nseq)error=1;
2676 cons=misc=r1=r2=we=0;
2677 x=sscanf (buf, "%d %d %d %d %d",&r1,&r2,&we,&cons,&misc);
2679 if (r1>NS->len[s1] || r2>NS->len[s2] || x<3)error=1;
2683 entry[SEQ1]=index[s1][0];
2684 entry[SEQ2]=index[s2][0];
2685 entry[R1]=index[s1][r1];
2686 entry[R2]=index[s2][r2];
2690 if (entry[SEQ1]>-1 && entry[SEQ2]>-1 && entry[R1]>0 && entry[R2]>0 && entry[WE]>0)
2691 add_entry2list (entry, CL);
2694 if (error)printf_exit (EXIT_FAILURE,stderr,"Parsing Error [L:%d F:%s S:%s]",line,in_fname,buf);
2698 if (!keepNS)free_sequence (NS,-1);
2701 free_int (index, -1);
2705 int read_seq_in_list ( char *fname, int *nseq, char ***sequences, char ***seq_name)
2713 static int max_nseq;
2714 static int *sn_list;
2718 fp=vfopen (fname, "r");
2719 fp=skip_commentary_line_in_file ('!', fp);
2720 fscanf (fp, "%d\n", &max_nseq);
2721 for ( lline=0,a=0; a<max_nseq; a++)
2724 fscanf (fp, "%*s %d %*s\n", &l);
2725 lline=MAX(lline, l);
2728 sequence=vcalloc (lline+1, sizeof (char));
2730 if ( seq_name[0]==NULL)
2732 seq_name[0]= declare_char (max_nseq,0);
2733 sequences[0]=declare_char (max_nseq,0);
2735 if ( sn_list==NULL)sn_list=vcalloc ( max_nseq, sizeof (int));
2736 else sn_list=vrealloc (sn_list, max_nseq*sizeof (int));
2738 fp=vfopen (fname,"r");
2739 fp=skip_commentary_line_in_file ('!', fp);
2740 if (fscanf ( fp, "%d\n", &list_nseq)!=1)return 0;
2741 for ( a=0; a<max_nseq; a++)
2743 fp=skip_commentary_line_in_file ('!', fp);
2744 fscanf ( fp, "%s %d %s\n", name, &seq_len, sequence);
2745 lower_string (sequence);
2746 if ((sn=name_is_in_list (name, seq_name[0], nseq[0], 100))==-1)
2748 seq_name[0][nseq[0]]=vcalloc (strlen (name)+1, sizeof (char));
2749 sprintf (seq_name[0][nseq[0]], "%s", name);
2750 sequences[0][nseq[0]]=vcalloc (strlen (sequence)+1, sizeof (char));
2751 sprintf (sequences[0][nseq[0]], "%s", sequence);
2766 /*********************************************************************/
2768 /* EXTENDED LIST OUTPUT */
2771 /*********************************************************************/
2773 FILE * save_extended_constraint_list ( Constraint_list *CL, char *mode, FILE *fp)
2776 if (!CL || !CL->S || CL->residue_index)return fp;
2780 fp=save_list_header (fp,CL);
2783 for ( a=0; a< (CL->S)->nseq; a++)
2785 for ( b=a; b<(CL->S)->nseq; b++)
2788 if ( a==b && !CL->do_self)continue;
2789 fp=save_extended_constraint_list_pair(CL, mode, (CL->S)->name[a], (CL->S)->name[b], fp);
2792 fprintf (fp, "! SEQ_1_TO_N\n");
2797 FILE * save_extended_constraint_list_pair ( Constraint_list *CL, char *mode, char* seq1, char * seq2,FILE *fp)
2804 if ((p=strstr (mode, "THR"))!=NULL)t=atoi(p+3);
2807 s1=name_is_in_list (seq1,(CL->S)->name, (CL->S)->nseq, 100);
2808 s2=name_is_in_list (seq2,(CL->S)->name, (CL->S)->nseq, 100);
2812 fprintf ( stderr, "Output Error: %s is not a sequence [FATAL:%s]\n", seq1, PROGRAM);
2817 fprintf ( stderr, "Output Error: %s is not a sequence [FATAL:%s]\n", seq2, PROGRAM);
2821 if ( strstr (mode, "pair"))fprintf (fp, "# 1 2\n");
2822 else if ( strstr (mode, "lib"))fprintf (fp, "# %d %d\n", s1+1, s2+1);
2824 for ( a=0; a<(CL->S)->len[s1]; a++)
2826 for ( b=0; b<(CL->S)->len[s2]; b++)
2828 if ( a>=b && s1==s2)continue;
2829 if ( strstr (mode, "pc"))score=residue_pair_extended_list_pc (CL, s1,a+1, s2, b+1);
2830 else if ( strstr (mode, "raw"))score=residue_pair_extended_list_raw (CL, s1,a+1, s2, b+1);
2832 score=CL->evaluate_residue_pair (CL, s1,a+1, s2, b+1);
2834 if (score<=t) continue;
2835 fprintf (fp, "%5d %5d %5d \n", a+1, b+1, score);
2843 /*********************************************************************/
2848 /*********************************************************************/
2850 FILE *save_extended_constraint_list ( Constraint_list *CL,Sequence *S, char *fname)
2859 fp=vfopen (fname, "w");
2860 fp=save_sub_list_header(fp, S->nseq, S->name, CL);
2862 tr=vcalloc (S->nseq+1, sizeof (int));
2863 for ( b=0,a=0; a< S->nseq; a++)
2866 if ( (i=name_is_in_list(S->name[a],(CL->S)->name,(CL->S)->nseq, 100))==-1)
2868 printf_exit (EXIT_FAILURE, stderr, "\nERROR: Sequence %s is not part of the sequence dataset [FATAL:%s]", S->name[a], PROGRAM);
2878 pos0=vcalloc ( S->nseq, sizeof (int*));
2879 for (a=0; a<S->nseq; a++)
2882 l=strlen (S->seq[a]);
2883 A->seq_al[a]=S->seq[a];
2884 pos0[a]=vcalloc (l+1, sizeof (int));
2885 for (b=0; b<l; b++)pos[a][b]=b+1;
2887 l_s=declare_int (2,2);
2888 ns=vcalloc ( 2, sizeof (int));
2891 for ( a=0; a< S->nseq-1; a++)
2892 for ( b=a+1; b<S->nseq; b++)
2894 int pos_i, pos_j, s;
2895 l_s[0]=tr[a];l_s[1]=tr[b];
2896 for ( pos_i=0; pos_i< S->len[a]; pos_i++)
2897 for (pos_j=0; pos_j<S->len[b]; pos_j++)
2899 s=(CL->get_dp_cost) ( A, pos0, ns[0], l_s[0], i-1, pos0, ns[1], l_s[1],pos_j-1, CL);
2900 if (s>epsilon)fprintf (fp, "%d %d %d", i, j, s);
2907 FILE * save_constraint_list ( Constraint_list *CL,int start, int len, char *fname, FILE *fp,char *mode, Sequence *S)
2910 static int* translation;
2915 if ( translation!=NULL)vfree(translation);
2916 translation=vcalloc ( (CL->S)->nseq+1, sizeof (int));
2917 for ( b=0,a=0; a< (CL->S)->nseq; a++)
2919 if ( name_is_in_list((CL->S)->name[a],S->name,S->nseq, 100)==-1)
2931 if (strm2(mode, "lib","ascii"))
2933 if ( fp==NULL)fp=vfopen ( fname, "w");
2934 fp=save_list_header (fp,CL);
2935 fp=save_constraint_list_ascii(fp, CL, 0, CL->ne, translation);
2941 myexit(fprintf (stderr,"\nUNKOWN MODE FOR OUTPUT: %s", mode));
2946 FILE * save_sub_list_header ( FILE *OUT, int n, char **name, Constraint_list *CL)
2953 for ( a=0; a<(CL->S)->nseq; a++)
2954 for ( b=0; b<n; b++)
2955 if (strm (name[b] , (CL->S)->name[a]))
2956 nseq+=((CL->S)->len[a]!=-1);
2958 fprintf ( OUT, "! TC_LIB_FORMAT_01\n%d\n",nseq);
2959 for ( a=0; a<n; a++)
2960 for ( b=0; b<(CL->S)->nseq; b++)
2961 if (strm (name[a] , (CL->S)->name[b]))
2962 if ((CL->S)->len[b]!=-1) fprintf ( OUT, "%s %d %s\n", (CL->S)->name[b], (CL->S)->len[b],(CL->S)->seq[b]);
2966 FILE * save_list_header ( FILE *OUT,Constraint_list *CL)
2971 for ( a=0; a<(CL->S)->nseq; a++)nseq+=((CL->S)->len[a]!=-1);
2974 fprintf ( OUT, "! TC_LIB_FORMAT_01\n%d\n",nseq);
2975 for ( a=0; a<(CL->S)->nseq; a++)
2976 if ((CL->S)->len[a]!=-1)
2978 fprintf ( OUT, "%s %d %s\n", (CL->S)->name[a], (CL->S)->len[a],(CL->S)->seq[a]);
2984 FILE *save_list_footer (FILE *OUT,Constraint_list *CL)
2986 if ( CL->cpu)fprintf (OUT, "! CPU %d\n",get_time());
2987 fprintf (OUT, "! SEQ_1_TO_N\n");
2991 FILE * save_constraint_list_ascii ( FILE *OUT,Constraint_list *CL, int start,int len, int *translation)
2993 int a, b, s1, s2, r1, r2, w2,x1, x2;
2995 if (len==start && CL->cpu!=-1)
2997 fprintf (OUT, "! CPU %d\n",get_time());
3003 int ***cacheI=vcalloc (S->nseq, sizeof (int**));
3004 int **cacheR=vcalloc (S->nseq, sizeof (int*));
3005 int *tot=vcalloc ( S->nseq, sizeof (int));
3006 int *max=vcalloc ( S->nseq, sizeof (int));
3007 for (a=0;a<S->nseq; a++)
3009 cacheI[a]=vcalloc (S->len[a], sizeof (int*));
3010 cacheR[a]=vcalloc (S->len[a], sizeof (int));
3012 for (a=0; a<S->nseq; a++)max[a]=S->len[a];
3014 for (s1=0; s1<S->nseq; s1++)
3016 for (r1=1; r1<=S->len[s1]; r1++)
3018 for (b=1; b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
3021 s2=CL->residue_index[s1][r1][b+SEQ2];
3022 if (tot[s2]>=max[s2])
3025 cacheI[s2]=vrealloc (cacheI[s2], max[s2]*sizeof (int*));
3026 cacheR[s2]=vrealloc (cacheR[s2], max[s2]*sizeof (int*));
3029 cacheI[s2][tot[s2]]=CL->residue_index[s1][r1]+b;
3030 cacheR[s2][tot[s2]]=r1;
3035 for (s2=0;s2<S->nseq; s2++)
3037 int x1=translation[s1];
3038 int x2=translation[s2];
3039 if (tot[s2] && x1!=-1 && x2!=-1 && x1<x2)
3041 fprintf ( OUT, "#%d %d\n", x1+1, x2+1);
3042 for ( r2=0; r2<tot[s2];r2++)
3044 int *v=cacheI[s2][r2];
3045 fprintf (OUT, "%5d %5d %5d %5d %5d\n",cacheR[s2][r2], v[R2], v[WE], v[CONS], v[MISC]);
3051 for (a=0; a<S->nseq; a++)
3056 vfree (cacheI); vfree (cacheR);
3061 return save_list_footer (OUT, CL);
3066 /*********************************************************************/
3068 /* LIST CONVERTION */
3071 /*********************************************************************/
3075 Constraint_list * extend_constraint_list ( Constraint_list *CL)
3083 int s1, r1, s2, r2,w2, s3, r3, w3;
3086 if (!CL || !CL->residue_index || !CL->S)return CL;
3090 fp=vfopen (tmp, "w");
3091 cache=declare_int (S->nseq, S->max_len+1);
3092 if (!entry)entry=vcalloc ( CL->entry_len+1, sizeof (int));
3093 for (s1=0; s1< S->nseq; s1++)
3095 for ( r1=1; r1<=S->len[s1]; r1++)
3101 for ( a=1; a<CL->residue_index[s1][r1][0]; a+=ICHUNK)
3104 s2=CL->residue_index[s1][r1][a+SEQ2];
3105 r2=CL->residue_index[s1][r1][a+R2];
3106 w2=CL->residue_index[s1][r1][a+WE];
3110 for ( a=1; a<CL->residue_index[s1][r1][0]; a+=ICHUNK)
3112 s2=CL->residue_index[s1][r1][a+SEQ2];
3113 r2=CL->residue_index[s1][r1][a+R2];
3114 w2=CL->residue_index[s1][r1][a+WE];
3116 for (b=1; b<CL->residue_index[s2][r2][0]; b+=ICHUNK)
3118 s3=CL->residue_index[s2][r2][b+SEQ2];
3119 r3=CL->residue_index[s2][r2][b+R2];
3120 w3=CL->residue_index[s2][r2][b+WE];
3122 if (!cache[s3][r3] && s3>s1)
3130 entry[WE]=MIN(w2, w3);
3133 for (e=0; e<CL->entry_len; e++)fprintf ( fp, "%d ", entry[e]);
3139 for (e=0; e<CL->entry_len; e++)fprintf ( fp, "%d ", entry[e]);
3144 for ( a=1; a<CL->residue_index[s1][r1][0]; a+=ICHUNK)
3146 s2=CL->residue_index[s1][r1][a+SEQ2];
3147 r2=CL->residue_index[s1][r1][a+R2];
3153 CL=undump_constraint_list(CL, tmp);
3154 free_int (cache, -1);
3158 Constraint_list * nfork_relax_constraint_list (Constraint_list *CL);
3159 Constraint_list * fork_relax_constraint_list (Constraint_list *CL);
3160 Constraint_list * relax_constraint_list (Constraint_list *CL)
3163 if (!CL || !CL->S || !CL->residue_index) return CL;
3166 if ( get_nproc()==1)return nfork_relax_constraint_list (CL);
3167 else if (strstr ( CL->multi_thread, "relax"))return fork_relax_constraint_list (CL);
3168 else return nfork_relax_constraint_list (CL);
3172 Constraint_list * fork_relax_constraint_list (Constraint_list *CL)
3174 int a, s1, s2, r1, r2,j;
3187 int t_s1, t_s2, t_r1, t_r2,x;
3193 if (!CL || !CL->residue_index)return CL;
3194 fprintf ( CL->local_stderr, "\nLibrary Relaxation: Multi_proc [%d]\n ", get_nproc());
3196 if ( !hasch || max_len!=(CL->S)->max_len)
3198 max_len=(CL->S)->max_len;
3199 if ( hasch) free_int ( hasch, -1);
3200 hasch=declare_int ( (CL->S)->nseq, (CL->S)->max_len+1);
3206 sl=n2splits (njobs, (CL->S)->nseq);
3207 pid_tmpfile=vcalloc (njobs, sizeof (char*));
3209 for (sjobs=0,j=0;j<njobs; j++)
3211 pid_tmpfile[j]=vtmpnam(NULL);
3212 if (vvfork (NULL)==0)
3214 initiate_vtmpnam(NULL);
3215 fp=vfopen (pid_tmpfile[j], "w");
3216 for (s1=sl[j][0]; s1<sl[j][1]; s1++)
3218 if (j==0)output_completion (CL->local_stderr,s1,sl[0][1],1, "Relax Library");
3219 for (r1=1; r1<S->len[s1]; r1++)
3223 for (x=1; x< CL->residue_index[s1][r1][0]; x+=ICHUNK)
3225 t_s1=CL->residue_index[s1][r1][x+SEQ2];
3226 t_r1=CL->residue_index[s1][r1][x+R2];
3227 hasch[t_s1][t_r1]=CL->residue_index[s1][r1][x+WE];
3230 for ( a=1; a<CL->residue_index[s1][r1][0]; a+=ICHUNK)
3234 s2=CL->residue_index[s1][r1][a+SEQ2];
3235 r2=CL->residue_index[s1][r1][a+R2];
3236 for (x=1; x< CL->residue_index[s2][r2][0]; x+=ICHUNK)
3238 t_s2=CL->residue_index[s2][r2][x+SEQ2];
3239 t_r2=CL->residue_index[s2][r2][x+R2];
3242 if (t_s2==s1 && t_r2==r1)score+=CL->residue_index[s2][r2][x+WE];
3243 else if (hasch[t_s2][t_r2])
3245 score+=MIN((((float)hasch[t_s2][t_r2])),(((float)CL->residue_index[s2][r2][x+WE])));
3248 norm2=MIN(norm1,norm2);
3249 score=((norm2)?score/norm2:0);
3250 fprintf (fp, "%d ",(int)(score));
3252 for (x=1; x< CL->residue_index[s1][r1][0]; x+=ICHUNK)
3254 t_s1=CL->residue_index[s1][r1][x+SEQ2];
3255 t_r1=CL->residue_index[s1][r1][x+R2];
3256 hasch[t_s1][t_r1]=0;
3261 myexit (EXIT_SUCCESS);
3269 while (sjobs>=0){vwait(NULL); sjobs--;}//wait for all jobs to complete
3270 for (j=0; j<njobs; j++)
3272 fp=vfopen (pid_tmpfile[j], "r");
3273 for (s1=sl[j][0]; s1<sl[j][1]; s1++)
3274 for (r1=1; r1<S->len[s1]; r1++)
3275 for ( a=1; a<CL->residue_index[s1][r1][0]; a+=ICHUNK)
3277 if (!(fscanf ( fp, "%d ", &CL->residue_index[s1][r1][a+WE])))
3279 printf_exit (EXIT_FAILURE,stderr, "Could not complete relaxation cycle");
3283 remove (pid_tmpfile[j]);
3286 CL=filter_constraint_list (CL,WE,thr);
3287 fprintf ( CL->local_stderr, "\nRelaxation Summary: [%d]--->[%d]\n", in,CL->ne);
3288 vfree (pid_tmpfile);
3294 Constraint_list * nfork_relax_constraint_list (Constraint_list *CL)
3296 int s1, r1, s2, r2, a;
3305 int t_s1, t_s2, t_r1, t_r2,x;
3309 if (!CL || !CL->residue_index)return CL;
3311 fprintf ( CL->local_stderr, "\nLibrary Relaxation:[%d] ", CL->ne);
3314 fp=vfopen (tmp, "w");
3316 if ( !hasch || max_len!=(CL->S)->max_len)
3318 max_len=(CL->S)->max_len;
3319 if ( hasch) free_int ( hasch, -1);
3320 hasch=declare_int ( (CL->S)->nseq, (CL->S)->max_len+1);
3324 for (s1=0; s1< S->nseq; s1++)
3326 output_completion (CL->local_stderr,s1,S->nseq,1, "Relax Library");
3327 for ( r1=1; r1<=S->len[s1]; r1++)
3331 for (x=1; x< CL->residue_index[s1][r1][0]; x+=ICHUNK)
3333 t_s1=CL->residue_index[s1][r1][x+SEQ2];
3334 t_r1=CL->residue_index[s1][r1][x+R2];
3335 hasch[t_s1][t_r1]=CL->residue_index[s1][r1][x+WE];
3339 for ( a=1; a<CL->residue_index[s1][r1][0]; a+=ICHUNK)
3343 s2=CL->residue_index[s1][r1][a+SEQ2];
3344 r2=CL->residue_index[s1][r1][a+R2];
3346 for (x=1; x< CL->residue_index[s2][r2][0]; x+=ICHUNK)
3348 t_s2=CL->residue_index[s2][r2][x+SEQ2];
3349 t_r2=CL->residue_index[s2][r2][x+R2];
3352 if (t_s2==s1 && t_r2==r1)score+=CL->residue_index[s2][r2][x+WE];
3353 else if (hasch[t_s2][t_r2])
3355 score+=MIN((((float)hasch[t_s2][t_r2])),(((float)CL->residue_index[s2][r2][x+WE])));
3358 norm2=MIN(norm1,norm2);
3359 score=((norm2)?score/norm2:0);
3360 fprintf (fp, "%d ",(int)(score));
3363 for (x=1; x< CL->residue_index[s1][r1][0]; x+=ICHUNK)
3365 t_s1=CL->residue_index[s1][r1][x+SEQ2];
3366 t_r1=CL->residue_index[s1][r1][x+R2];
3367 hasch[t_s1][t_r1]=0;
3372 fp=vfopen (tmp, "r");
3374 for (s1=0; s1< S->nseq; s1++)
3376 for ( r1=1; r1<=S->len[s1]; r1++)
3379 for ( a=1; a<CL->residue_index[s1][r1][0]; a+=ICHUNK)
3382 fscanf (fp, "%d ", &CL->residue_index[s1][r1][a+WE]);
3387 filter_constraint_list (CL,WE,thr);
3388 fprintf ( CL->local_stderr, "--->[%d]\n", CL->ne);
3393 // relax constraint list for gene prediction
3394 Constraint_list * expand_constraint_list_4gp (Constraint_list *CL, int T)
3400 int s1, s2, r1, r2,a,b,c,d,w;
3404 entry=vcalloc (CL->entry_len+1, sizeof (int));
3407 for (a=0; a<S->nseq; a++)//loop sequences
3409 for (b=1; b<=S->len[a];b++)
3411 for (c=1; c<CL->residue_index[a][b][0];c+=ICHUNK)
3417 s1=CL->residue_index[a][b][c+SEQ2];;
3418 r1=CL->residue_index[a][b][c+R2];
3419 w=residue_pair_extended_list_4gp (CL,s1, r1,s2, r2);
3427 add_entry2list (entry, CL);
3429 for (d=c+3; d<CL->residue_index[a][b][0]; d+=ICHUNK)
3431 s2=CL->residue_index[a][b][d];
3432 r2=CL->residue_index[a][b][d+1];
3433 w=residue_pair_extended_list_4gp (CL,s1, r1,s2, r2);
3451 Constraint_list * nfork_relax_constraint_list_4gp (Constraint_list *CL);
3452 Constraint_list * fork_relax_constraint_list_4gp (Constraint_list *CL);
3453 Constraint_list * relax_constraint_list_4gp (Constraint_list *CL)
3455 if ( get_nproc()==1)return nfork_relax_constraint_list_4gp (CL);
3456 else if (strstr ( CL->multi_thread, "relax"))return fork_relax_constraint_list_4gp (CL);
3457 else return nfork_relax_constraint_list_4gp (CL);
3460 Constraint_list * fork_relax_constraint_list_4gp (Constraint_list *CL)
3462 int a, s1, s2, r1, r2,n;
3465 int chunk, npid, job,pid;
3471 return nfork_relax_constraint_list_4gp(CL);
3476 if (!CL || !CL->L)return CL;
3480 if ((chunk=CL->ne/get_nproc())==0)chunk=get_nproc();
3483 pid_tmpfile=vcalloc ((CL->ne/chunk)+1, sizeof (char*));
3484 pid_list =vcalloc (MAX_N_PID, sizeof (int *));
3486 for (npid=0,job=0; job<CL->ne; job+=chunk)
3488 pid_tmpfile[npid]=vtmpnam(NULL);
3494 initiate_vtmpnam (NULL);
3496 e=MIN((s+chunk),CL->ne);
3497 fp=vfopen (pid_tmpfile[npid], "w");
3501 s1=CL->L[a*CL->entry_len+SEQ1];
3502 s2=CL->L[a*CL->entry_len+SEQ2];
3504 r1=CL->L[a*CL->entry_len+R1];
3505 r2=CL->L[a*CL->entry_len+R2];
3506 score=residue_pair_extended_list_4gp (CL,s1, r1,s2, r2);
3507 CL->L[a*CL->entry_len+WE]=score;
3508 fprintf (fp, "%d %d ", a, score);
3511 myexit (EXIT_SUCCESS);
3521 for (a=0; a<npid; a++)
3527 fp=vfopen (pid_tmpfile[pid_list[pid]], "r");
3528 while (fscanf (fp, "%d %d ",&i, &score)==2){CL->L[i*CL->entry_len+WE]=score;j++;}
3530 remove(pid_tmpfile[pid_list[pid]]);
3534 vfree (pid_tmpfile);
3538 for (n=0,a=0; a< CL->ne; a++)
3540 score=CL->L[a*CL->entry_len+WE];
3545 CL->L[n*CL->entry_len+SEQ1]=CL->L[a*CL->entry_len+SEQ1];
3546 CL->L[n*CL->entry_len+SEQ2]=CL->L[a*CL->entry_len+SEQ2];
3547 CL->L[n*CL->entry_len+R1]=CL->L[a*CL->entry_len+R1];
3548 CL->L[n*CL->entry_len+R2]=CL->L[a*CL->entry_len+R2];
3549 CL->L[n*CL->entry_len+WE]=score;
3555 CL->L=vrealloc (CL->L, n*CL->entry_len*sizeof (int));
3560 Constraint_list * nfork_relax_constraint_list_4gp (Constraint_list *CL)
3563 int s,r,a,t_s,t_r,l;
3571 entry=vcalloc (CL->entry_len, sizeof (int));
3573 if (!CL || !CL->residue_index)return CL;
3575 fp=vfopen (tmp, "w");
3576 for (s=0; s< S->nseq; s++)
3578 for ( r=1; r<=S->len[s]; r++)
3583 for ( a=1; a<CL->residue_index[s][r][0]; a+=ICHUNK)
3586 t_s=CL->residue_index[s][r][a+SEQ2];
3587 t_r=CL->residue_index[s][r][a+WE];
3588 fprintf (fp, "%d ",residue_pair_extended_list_pc (CL,s, r,t_s, t_r));
3593 fp=vfopen (tmp, "r");
3595 for (s=0; s< S->nseq; s++)
3597 for ( r=1; r<=S->len[s]; r++)
3602 for ( a=1; a<CL->residue_index[s][r][0]; a+=ICHUNK)
3604 fscanf (fp, "%d ", &CL->residue_index[s][r][a+WE]);
3610 return filter_constraint_list (CL,WE,th);
3613 int constraint_list2max ( Constraint_list *CL)
3617 int b,l,s1,r1,s2,r2,w2;
3618 for (s1=0; s1<S->nseq; s1++)
3620 for (r1=1; r1<=S->len[s1]; r1++)
3622 for (b=1; b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
3624 s2=CL->residue_index[s1][r1][b+SEQ2];
3625 r2=CL->residue_index[s1][r1][b+R2];
3626 w2=CL->residue_index[s1][r1][b+WE];
3633 int constraint_list2ne ( Constraint_list *CL)
3637 int b,l,s1,r1,s2,r2,w2;
3638 if (!CL || !CL->residue_index || !CL->S)return 0;
3641 for (s1=0; s1<S->nseq; s1++)
3643 for (r1=1; r1<=S->len[s1]; r1++)
3645 max+=CL->residue_index[s1][r1][0]-1;
3650 float constraint_list2connectivity (Constraint_list *CL)
3658 mat=declare_float (S->nseq, S->nseq);
3659 for (s1=0; s1<S->nseq; s1++)
3660 for ( r1=1;r1<=S->len[s1]; r1++)
3662 for (b=1; b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
3664 mat[s1][CL->residue_index[s1][r1][b+SEQ2]]++;
3667 for (s1=0; s1<S->nseq; s1++)
3668 for ( s2=0; s2<S->nseq; s2++)
3670 if ( s1==s2)continue;
3671 mat[s1][s2]*=(float)2;
3672 mat[s1][s2]/=(float)(S->len[s1]+S->len[s2]);
3676 free_float (mat, -1);
3677 tot=(float)tot/(float)(ntot);
3680 int constraint_list2avg ( Constraint_list *CL)
3685 int b,l,s1,r1,s2,r2,w2;
3686 for (s1=0; s1<S->nseq; s1++)
3688 for (r1=1; r1<=S->len[s1]; r1++)
3690 for (b=1; b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
3692 s2=CL->residue_index[s1][r1][b+SEQ2];
3693 r2=CL->residue_index[s1][r1][b+R2];
3694 w2=CL->residue_index[s1][r1][b+WE];
3700 return (n==0)?0:max/n;
3704 Constraint_list * filter_constraint_list (Constraint_list *CL,int field, int T)
3711 if (!CL || !CL->residue_index || !CL->S)return CL;
3714 for (s1=0; s1<S->nseq; s1++)
3716 for ( r1=1; r1<=S->len[s1]; r1++)
3718 int *r=CL->residue_index[s1][r1];
3719 for (d=1,b=1; b<r[0]; b+=ICHUNK)
3723 if (d!=b)for (c=0; c<ICHUNK; c++){r[d+c]=r[b+c];}
3729 CL->residue_index[s1][r1]=vrealloc (r, d*sizeof(int));;
3737 Constraint_list * shrink_constraint_list (Constraint_list *CL)
3740 Constraint_list *CL2;
3744 if (!CL || !CL->S || !CL->residue_index) return CL;
3746 ns=vcalloc (2, sizeof (int));
3747 ls=declare_int ((CL->S)->nseq, 2);
3749 A=seq2aln (CL->S,NULL, RM_GAP);
3750 B=seq2aln (CL->S,NULL, RM_GAP);
3751 CL2=declare_constraint_list (CL->S,NULL, NULL, 0,NULL, NULL);
3754 fprintf ( CL->local_stderr, "\n\n\tSHRINK Constraint List [%d element(s)]", CL->ne);
3755 for (n=0,a=0; a<(CL->S)->nseq-1; a++)
3756 for (b=a+1; b<(CL->S)->nseq; b++, n++)
3758 output_completion (CL->local_stderr,n, tot, 100, "slow_pair");
3762 ungap (A->seq_al[a]);
3763 ungap (A->seq_al[b]);
3764 linked_pair_wise (A, ns, ls, CL);
3765 B->seq_al[0]=A->seq_al[a];
3766 B->seq_al[1]=A->seq_al[b];
3767 sprintf (B->name[0], "%s", A->name[a]);
3768 sprintf (B->name[1], "%s", A->name[b]);
3770 B->len_aln=strlen (B->seq_al[0]);
3771 CL2=aln2constraint_list (B, CL2, "sim");
3778 Constraint_list *aln_file2constraint_list (char *alname, Constraint_list *CL,char *weight_mode)
3781 A=main_read_aln ( alname, NULL);
3782 CL=aln2constraint_list (A, CL, weight_mode);
3787 int *seqpair2weight (int s1, int s2, Alignment *A,Constraint_list *CL, char *weight_mode, int *weight)
3790 int a,c, ref_weight;
3793 if ( !weight)weight=vcalloc (MAX(2,A->len_aln), sizeof (int));
3796 if ( weight_mode==NULL || strcmp (weight_mode, "no")==0 || is_number (weight_mode))
3799 if (is_number (weight_mode))ref_weight=atoi(weight_mode);
3801 weight[1]=ref_weight;
3804 else if ( strstr ( weight_mode, "cons"))
3806 ref_weight=weight[1]=1000;
3808 else if ( strstr ( weight_mode, "OW"))
3811 sscanf ( weight_mode, "OW%d", &ow);
3812 weight[1]=ow*get_seq_sim ( A->seq_al[s1], A->seq_al[s2], "-", NULL);
3815 else if ( strstr ( weight_mode, "len"))
3817 weight[1]=A->len_aln;
3819 else if ( strstr (weight_mode, "winsim"))
3821 weight=get_seq_winsim ( A->seq_al[s1], A->seq_al[s2], "-", weight_mode+6, weight);
3823 else if ( strstr ( weight_mode, "sim") || strstr (weight_mode, "default"))
3826 if ( strstr(weight_mode, "sim"))sim_mode=strstr(weight_mode, "sim")+3;
3828 ref_weight=get_seq_sim ( A->seq_al[s1], A->seq_al[s2], "-", sim_mode);
3829 if (ref_weight == 0)
3831 weight[1]=ref_weight;
3834 else if ( strstr ( weight_mode, "subset"))
3836 ref_weight=get_seq_sim ( A->seq_al[s1], A->seq_al[s2], "-",NULL);
3837 weight[1]=ref_weight;
3839 else if ( strstr ( weight_mode, "cdna"))
3841 ref_weight=get_seq_sim ( A->seq_al[s1], A->seq_al[s2], "-", weight_mode+4);
3842 col=vcalloc ( A->len_aln+1, sizeof (int));
3844 for ( a=0; a<=A->len_aln; a++)col[a]=A->cdna_cache[0][a];
3846 for ( a=0; a<=A->len_aln; a++)col[a]=1;
3847 for ( c=0; c< A->len_aln; c++)weight[c]=ref_weight*col[c];
3851 else if ( strstr (weight_mode, "overaln"))
3853 ref_weight=get_seq_sim ( A->seq_al[s1], A->seq_al[s2], "-","idmat");
3854 //weight=pw_aln2clean_aln_weight (A->seq_al[s1], A->seq_al[s2], ref_weight,0, 0, 0, 0, NULL);
3855 printf_exit (EXIT_FAILURE, stderr,"ERROR: mode overaln not currently supported [FATAL:%s]", PROGRAM);
3859 fprintf ( stderr, "\nERROR: Weight Mode %s is unknown [FATAL:%s]", weight_mode, PROGRAM);
3866 Constraint_list *aln2constraint_list (Alignment *A, Constraint_list *CL,char *in_weight_mode)
3871 int fixed_nres1, fixed_nres2;
3877 char weight_mode [100];
3882 entry=vcalloc (CL->entry_len+1, sizeof (int));
3885 //MSA are now read as one to all (+ extra bits if needed) libraries
3886 //if ( atoigetenv ("TOP4TC")){HERE ("TOP=1");top=1;}
3888 sprintf ( weight_mode , "%s", (!in_weight_mode || strm (in_weight_mode, "default"))?"sim":in_weight_mode);
3891 if (strstr (weight_mode, "extend"))
3893 extend_seqaln(NULL, A);
3894 extend_seqaln(CL->S,NULL);
3895 if (CL->S!=A->S)extend_seqaln(A->S,NULL);
3898 fixed=fix_aln_seq_new (A, (CL->S));
3904 CL=declare_constraint_list (S,NULL, NULL, 0,NULL, NULL);
3908 cache=vcalloc (A->len_aln, sizeof (int));
3910 if ( (p=strstr (weight_mode, "_subset_")))
3912 alp=strchr (weight_mode, '_')+1;
3916 for ( a=0; a<A->nseq-1; a++)
3918 if ((s1=fixed[a][0])==-1)continue;
3920 for (set_misc=0,b=a+1; b< A->nseq; b++)
3927 if ((s2=fixed[b][0])==-1)continue;
3929 weight=seqpair2weight (a, b, A, CL, weight_mode, weight);
3930 for (c=0; c< A->len_aln; c++)
3933 isgap1=is_gap(A->seq_al[a][c]);
3934 isgap2=is_gap(A->seq_al[b][c]);
3938 if (cache[c]==-1 && top)continue;
3939 if (!isgap1)cache[c]=1;
3940 if (cache[c] && b==A->nseq-1)cache[c]=-1;
3943 use_pair=use_pair && !is_gap(A->seq_al[a][c]);
3944 use_pair=use_pair && !is_gap(A->seq_al[b][c]);
3945 use_pair=use_pair && A->seq_al[b][c]!=UNDEFINED_RESIDUE;
3946 use_pair=use_pair && A->seq_al[a][c]!=UNDEFINED_RESIDUE;
3947 use_pair=use_pair && !(do_pdb && pdb_weight==0);
3948 use_pair=use_pair && ((weight[0]==FORBIDEN)?weight[1]:weight[c]);
3950 if (alp)use_pair=use_pair && is_in_set (A->seq_al[b][c], alp) && is_in_set (A->seq_al[a][c], alp);
3955 if ((fixed_nres1=fixed[a][nres1])<0)continue;
3956 if ((fixed_nres2=fixed[b][nres2])<0)continue;
3960 entry[R1]=fixed_nres1;
3961 entry[R2]=fixed_nres2;
3963 if (do_pdb)entry[WE]=(NORM_F/MAXID)*pdb_weight;
3964 else entry[WE]=(NORM_F/MAXID)*((weight[0]==FORBIDEN)?weight[1]:weight[c]);
3965 add_entry2list (entry, CL);
3973 free_int (fixed, -1);
3975 if (strstr (weight_mode, "extend"))
3977 unextend_seqaln(NULL, A);
3978 unextend_seqaln(CL->S,NULL);
3979 if (A->S!=CL->S)unextend_seqaln(A->S,NULL);
3986 return aln2constraint_list (A->A, CL, weight_mode);
3999 int **list2residue_total_weight ( Constraint_list *CL)
4002 tot_weight[nseq][maxlen]
4003 where each residue is associated with the total of its weights in CL
4006 -the numbering of the residues goes from 1 to L:
4007 -the numbering of the sequences goes from 0 to N-1:
4014 int a,b,s1,r1,s2,r2,w2;
4017 if ( !CL || !CL->S || (CL->S)->nseq==0)return NULL;
4019 tot_weight=declare_int2 (S->nseq, S->len, 1);
4020 for (s1=0; s1<S->nseq; s1++)
4022 for (r1=1; r1<=S->len[s1]; r1++)
4024 for (b=1; b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
4026 s2=CL->residue_index[s1][r1][b+SEQ2];
4027 r2=CL->residue_index[s1][r1][b+R2];
4028 w2=CL->residue_index[s1][r1][b+WE];
4029 tot_weight[s1][r1]+=w2;
4030 tot_weight[s2][r2]+=w2;
4034 for (a=0; a<(CL->S)->nseq; a++)
4035 for (b=0; b<(CL->S)->len[a]; b++)
4036 tot_weight[a][b]/=(CL->S)->nseq;
4044 /*********************************************************************/
4046 /* LIST FUNCTIONS */
4049 /*********************************************************************/
4051 Constraint_list *merge_constraint_list ( Constraint_list *SL, Constraint_list *ML, char *mode)
4055 int s1,r1,s2,r2,a,b;
4058 entry=vcalloc (ICHUNK+10, sizeof (int));
4060 for (a=0;a<ICHUNK+10; a++)entry[a]=0;
4061 if (SL->S!= ML->S)cache=fix_seq_seq((SL->S),(ML->S));
4063 if (!ML || !SL)return ML;
4064 for (s1=0; s1<(SL->S)->nseq; s1++)
4066 if (cache && cache[s1][0]==-1)continue;
4067 for (r1=1; r1<=((SL)->S)->len[s1]; r1++)
4069 entry[SEQ1]=(cache)?cache[s1][0]:s1;
4070 entry[R1]=(cache)?cache[s1][r1]:r1;
4071 if (entry[R1]<=0)continue;
4072 b=(SL->freeze)?SL->freeze[s1][r1]:1;
4073 for (;b<SL->residue_index[s1][r1][0]; b+=ICHUNK)
4075 s2=SL->residue_index[s1][r1][b+SEQ2];
4076 r2=SL->residue_index[s1][r1][b+R2];
4077 entry[SEQ2]=(cache)?cache[s2][0]:s2;
4078 if ( entry[SEQ2]==-1)continue;
4081 entry[R2]=(cache)?cache[s2][r2]:r2;
4082 if (entry[R2]<=0)continue;
4085 entry[WE]=SL->residue_index[s1][r1][b+WE];
4086 entry[CONS]=SL->residue_index[s1][r1][b+CONS];
4087 entry[MISC]=SL->residue_index[s1][r1][b+MISC];
4089 add_entry2list2(entry, ML);
4095 if ( cache)free_int (cache, -1);
4102 int ** seq2defined_residues ( Sequence *S, Constraint_list *CL)
4105 int s1,r1,s2,r2,l,a,b;
4107 seq_count=declare_int (S->nseq, S->max_len+1);
4108 for (s1=0; s1<S->nseq; s1++)
4110 for ( r1=1; r1<=S->len[s1]; r1++)
4112 for (a=1; a<CL->residue_index[s1][r1][0]; a+=ICHUNK)
4114 int s2=CL->residue_index[s1][r1][a+SEQ2];
4115 int r2=CL->residue_index[s1][r1][a+R2];
4116 seq_count[s1][r1]++;
4117 seq_count[s2][r2]++;
4124 int ** aln2defined_residues ( Alignment *A, Constraint_list *CL)
4132 pos=aln2pos_simple(A, A->nseq);
4133 seq_count=seq2defined_residues(CL->S, CL);
4134 aln_count=declare_int (A->nseq, A->len_aln);
4135 for (a=0; a< A->nseq; a++)
4137 ra=name_is_in_list(A->name[a], (CL->S)->name, (CL->S)->nseq, 100);
4138 if ( ra==-1) continue;
4139 for ( b=0; b<A->len_aln; b++)
4140 if (pos[a][b]>0 && seq_count[ra][pos[a][b]]>0)aln_count[a][b]=1;
4143 free_int (seq_count, -1);
4148 /*********************************************************************/
4150 /* DEBUG CONSTRAINT_LIST */
4153 /*********************************************************************/
4156 /*********************************************************************/
4158 /* PRUNE CONSTRAINT_LIST */
4161 /*********************************************************************/
4164 char * list2prune_list ( Sequence *S, int **sm)
4167 int **mat, *used, *keep;
4175 if (get_string_variable("prune_lib_mode"))
4176 ns=atoi(get_string_variable("prune_lib_mode"));
4180 else if (ns<0)ns=-(n*ns)/100;
4181 else if (ns>=n)ns=n;
4187 keep=vcalloc (n, sizeof (int));
4188 used=vcalloc (n, sizeof (int));
4189 mat=declare_int (n, n);
4190 file=vtmpnam (NULL);
4192 //1-Identify the seed sequence: the one on average the further away from the rest
4198 mat[a][1]+=sm[a][b];
4200 sort_int_inv (mat, 2, 1, 0, n-1);
4203 keep[nk++]=mat[0][0];
4206 for (a=1; a<ns; a++)
4211 if (used[c]){mat[c][1]=n*1000;continue;}
4212 for (b=0; b<nk; b++)
4214 mat[c][1]+=sm[c][keep[b]];
4217 sort_int (mat, 2, 1, 0,n-1);
4218 keep[nk++]=mat[0][0];
4222 fp=vfopen (file, "w");
4223 for ( a=0; a<nk; a++)
4225 for (b=0; b<S->nseq; b++)
4228 fprintf ( fp, "\n2 %d %d", keep[a], b);
4232 vfree (keep); vfree (used);free_int (mat, -1);
4240 /*********************************************************************/
4242 /* WEIGHT CONSTRAINT_LIST */
4245 /*********************************************************************/
4247 Constraint_list *weight_constraint_list(Constraint_list * CL, char *seq_weight)
4254 if ( CL->ne==0){return CL;}
4255 else if ( strm(seq_weight, "t_coffee")) {W=compute_t_coffee_weight(CL);}
4256 else if (check_file_exists (seq_weight))
4258 W=read_seq_weight ((CL->S)->name, (CL->S)->nseq, seq_weight);
4263 W=declare_weights((CL->S)->nseq);
4264 sprintf ( W->mode, "no_seq_weight");
4265 for ( a=0; a<(CL->S)->nseq; a++)
4267 sprintf ( W->seq_name[a], "%s", (CL->S)->name[a]);
4273 CL=re_weight_constraint_list (CL,W);
4285 Weights* compute_t_coffee_weight(Constraint_list * CL)
4293 W=declare_weights(nseq);
4294 sprintf ( W->mode, "t_coffee");
4295 for ( a=0; a< nseq; a++)
4297 sprintf ( W->seq_name[a], "%s", (CL->S)->name[a]);
4301 for (a=0; a< (CL->S)->nseq-1; a++)
4302 for ( b=a+1; b< (CL->S)->nseq; b++)
4305 else if ( !(CL->S)->len[b] || !(CL->S)->len[a])d=1;
4308 d=((float)(CL->DM)->similarity_matrix[a][b]/MAXID)*10;
4317 for ( p=0,b=0; b< (CL->S)->nseq; b++)
4319 if ((CL->S)->len[b]==0)W->SEQ_W[b]=0;
4320 else W->SEQ_W[b]=2/W->SEQ_W[b];
4323 for ( b=0; b< (CL->S)->nseq; b++)
4325 W->SEQ_W[b]=W->SEQ_W[b]*((float)W->nseq/p);
4332 Constraint_list *set_weight4constraint_list(Constraint_list * CL,int w)
4337 if ( !CL || !CL->S || !CL->residue_index)return CL;
4339 for (s=0; s<S->nseq; s++)
4341 for ( r=1; r<=S->len[s]; r++)
4343 for (a=1; a<CL->residue_index[s][r][0]; a+=ICHUNK)
4345 CL->residue_index[s][r][a+WE]*=w;
4349 CL=evaluate_constraint_list_reference (CL);
4352 Constraint_list *re_weight_constraint_list(Constraint_list * CL,Weights *W)
4364 for (s=0; s<S->nseq; s++)
4366 for ( r=1; r<=S->len[s]; r++)
4368 for (a=1; a<CL->residue_index[s][r][0]; a+=ICHUNK)
4370 int t_s=CL->residue_index[s][r][a];
4371 CL->residue_index[s][r][a+WE]*=MIN(weight[s], weight[t_s]);
4375 CL=evaluate_constraint_list_reference (CL);
4379 Distance_matrix* cl2distance_matrix (Constraint_list *CL, Alignment *A, char *in_mode, char *in_sim_mode, int print)
4383 char sim_mode [100];
4387 if ( !CL)return NULL;
4388 sprintf ( mode, "%s", (CL && in_mode==NULL)?CL->distance_matrix_mode:in_mode);
4389 sprintf ( sim_mode, "%s", (CL && in_sim_mode==NULL)?CL->distance_matrix_sim_mode:in_sim_mode);
4391 if ( !CL->DM ||!strm ((CL->DM)->mode, mode) || !strm ((CL->DM)->sim_mode, sim_mode) || A )
4393 return seq2distance_matrix (CL, A, mode, sim_mode, print);
4403 Distance_matrix *seq2distance_matrix (Constraint_list *CL, Alignment *A,char *mode, char *sim_mode, int print)
4405 /*Compute the distance matrix associated with the Constraint List and the sequences*/
4406 /*Computation only occurs if the similiraty matrix is undefined : CL->similarity_matrix*/
4407 /*Undefine CL->similarity_matrix to force computation*/
4411 Constraint_list *NCL;
4418 static float **g_matrix;
4421 Distance_matrix *DM;
4422 int **sim_table=NULL;
4424 //mode: computation mode
4425 //sim_mode: mode for computing the similarity
4429 if (strm (mode, "ktup2"))
4431 B=seq2aln ( CL->S, NULL, 1);
4432 B=very_fast_aln (B, B->nseq,NULL);
4433 sprintf ( CL->distance_matrix_mode, "aln");
4434 DM=cl2distance_matrix (CL, B, NULL, NULL, 1);
4435 sprintf ( CL->distance_matrix_mode, "ktup2");
4436 sprintf ( DM->mode, "%s", mode);
4437 sprintf ( DM->sim_mode, "%s", sim_mode);
4442 if ( !CL) return NULL;
4445 for ( max_name=0,a=0; a< (CL->S)->nseq; a++)max_name=MAX(strlen ((CL->S)->name[a]), max_name);
4448 if ( CL->DM)DM=CL->DM;
4451 DM=vcalloc ( 1, sizeof (Distance_matrix));
4452 DM->nseq=(CL->S)->nseq;
4453 DM->similarity_matrix=declare_int ( (CL->S)->nseq, (CL->S)->nseq);
4454 DM->distance_matrix =declare_int ( (CL->S)->nseq, (CL->S)->nseq);
4455 DM->score_similarity_matrix=declare_int ( (CL->S)->nseq, (CL->S)->nseq);
4458 sprintf ( DM->mode, "%s", mode);
4459 sprintf ( DM->sim_mode, "%s", sim_mode);
4461 NCL=duplicate_constraint_list_soft (CL);
4462 NCL->pw_parameters_set=1;
4466 if ( CL->tree_aln)B=CL->tree_aln;
4467 else B=seq2aln ( NCL->S, NULL, 1);
4471 B=copy_aln (A, NULL);
4472 B=reorder_aln (B, (CL->S)->name, (CL->S)->nseq);
4475 if ( strm (mode, "very_fast"))
4477 sprintf ( NCL->dp_mode, "very_fast_pair_wise");
4478 NCL->evaluate_residue_pair=evaluate_matrix_score;
4479 if ( strm ((CL->S)->type, "DNA") ||strm ((CL->S)->type, "RNA") )
4481 NCL->M=read_matrice ("idmat");
4488 NCL->M=read_matrice ("blosum62mt");
4489 NCL->gop=get_avg_matrix_mm (NCL->M, AA_ALPHABET)*10;
4493 NCL->use_fragments=1;
4494 CL->diagonal_threshold=6;
4497 else if ( strm (mode, "ktup"))
4501 sim_table=ktup_dist_mat((CL->S)->seq,(CL->S)->nseq,NCL->ktup, (CL->S)->type);
4505 else if (strm (mode, "aln"))
4508 sim_table=aln2sim_mat (A, sim_mode);
4510 else if ( strm (mode, "fast") || strm ("idscore", mode))
4512 sprintf ( NCL->dp_mode, "myers_miller_pair_wise");
4513 NCL->evaluate_residue_pair=evaluate_matrix_score;
4514 if ( strm ((CL->S)->type, "DNA") || strm ((CL->S)->type, "RNA"))
4516 NCL->M=read_matrice ("idmat");
4522 NCL->M=read_matrice ("blosum62mt");
4523 NCL->gop=get_avg_matrix_mm (NCL->M, AA_ALPHABET)*10;
4527 else if ( strm (mode, "cscore"))
4529 if (!CL || !CL->residue_index || CL->ne==0)
4530 return seq2distance_matrix (CL, A,"idscore",sim_mode, print);
4532 else if ( strm (mode, "geometric") );
4533 else if (strm (mode, "slow"));
4534 else if (strm (mode, "clustalw"));
4535 else if (strm (mode, "no"))
4537 else if (strm (mode, "random"))
4541 fprintf ( stderr, "\nError: %s is an unknown distance_matrix_mode [FATAL:%s]", mode,PROGRAM);
4545 //Special Geometric Mode
4546 if ( strm (NCL->distance_matrix_mode, "geometric"))
4548 free_arrayN(g_matrix, 2);
4549 g_matrix=declare_float ((CL->S)->nseq, 3);
4550 n_coor=MIN(3,((CL->S)->nseq));
4552 for ( a=0; a<(CL->S)->nseq; a++)
4554 for (b=0; b<n_coor; b++)
4556 B=align_two_sequences ((CL->S)->seq[a], (CL->S)->seq[b], "pam250mt", -10, -1, "fasta_pair_wise");
4557 g_matrix[a][b]=get_seq_sim ( B->seq_al[0], B->seq_al[1], "-", NULL);
4561 ref=(float)sqrt((double)(10000*n_coor));
4565 ns=vcalloc ( 2, sizeof(int));
4566 l_s=declare_int ( 2, 1);
4571 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);
4573 for (a=0; a< (CL->S)->nseq; a++)
4575 if (CL->local_stderr && print>0)fprintf ( (CL->local_stderr), "\n\tSeq: %s", (CL->S)->name[a]);
4576 for ( b=a; b< (CL->S)->nseq; b++)
4578 if ( b==a){DM->similarity_matrix[a][b]=MAXID;}
4583 if ( !strm(mode, "ktup2") && ! strm (mode, "geometric"))
4585 ungap ( B->seq_al[a]);
4586 ungap ( B->seq_al[b]);
4589 if ( strm (mode, "slow"))
4592 B->score_aln=pair_wise (B, ns, l_s,NCL);
4594 id=get_seq_sim ( B->seq_al[a], B->seq_al[b], "-", sim_mode);
4595 if ( CL->residue_index)
4597 score=(int)(((float)B->score_aln)/(B->len_aln*SCORE_K));
4598 score=(int)(CL->normalise)?((score*MAXID)/(CL->normalise)):(score);
4600 else if ( CL->M)score=id;
4603 if ( score>MAXID)score=(CL->residue_index)?sub_aln2sub_aln_score (B, CL, CL->evaluate_mode, ns, l_s):id;
4606 else if ( strm2 (mode,"fast", "very_fast"))
4608 B->score_aln=pair_wise (B, ns, l_s,NCL);
4609 id=get_seq_sim ( B->seq_al[a], B->seq_al[b], "-", sim_mode);
4610 score=(int)(id)*SCORE_K;
4612 else if ( strm (mode, "cscore"))
4614 ungap ( B->seq_al[a]);
4615 ungap ( B->seq_al[b]);
4616 score=(int)linked_pair_wise (B, ns, l_s, NCL);
4619 score/=(B->len_aln*SCORE_K);
4622 else if ( strm (mode, "idscore"))
4624 score=id=idscore_pairseq (B->seq_al[a], B->seq_al[b], NCL->gop, NCL->gep, NCL->M, sim_mode);
4625 //HERE ("%s %d %d ->%d", sim_mode, a, b, (int)id);
4627 else if (strm (mode, "ktup"))
4633 else if (strm (mode, "aln"))
4635 score=id=sim_table[a][b];
4639 else if ( strm (mode, "geometric"))
4641 id=get_geometric_distance (g_matrix,n_coor, a, b, "euclidian");
4642 id=MAXID*(1-((id/ref)));
4643 score=(int)(id)*SCORE_K;
4645 else if ( strm (mode, "no"))
4650 else if ( strm (mode, "random"))
4657 id=B->score_aln=pair_wise (B, ns, l_s,NCL);
4661 DM->similarity_matrix[a][b]=DM->similarity_matrix[b][a]=(int)(id);
4663 DM->distance_matrix[a][b]=DM->distance_matrix[b][a]=MAXID-(int)(id);
4667 DM->score_similarity_matrix[a][b]=DM->score_similarity_matrix[b][a]=(int)score;
4669 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);
4679 if (CL->local_stderr) fprintf (CL->local_stderr, "\n");
4680 free_constraint_list (NCL);
4689 free_int (sim_table, -1);
4695 /*********************************************************************/
4700 /*********************************************************************/
4701 char * seq2rna_lib ( Sequence *S, char *name)
4707 if (!name)name=vtmpnam (NULL);
4708 fp=vfopen (name, "w");
4709 for ( a=0; a<S->nseq; a++)
4712 fprintf (fp, "%s\n", rna_struc2rna_lib(S->name[a], S->seq[a], NULL));
4719 Constraint_list *read_rna_lib ( Sequence *S, char *fname)
4726 if (check_file_exists (fname))
4729 list=read_lib_list ( fname, &n);
4735 list=vcalloc (S->nseq, sizeof (char*));
4736 for ( a=0; a<S->nseq; a++)
4738 if ((F=seq_has_template (S, a, "_F_")))
4740 list[n++]=F->template_file;
4745 R=declare_constraint_list ( S,NULL, NULL, 0,NULL, NULL);
4747 for (a=0; a< n; a++)
4750 if (list[a])R=read_constraint_list_file (R, list[a]);
4757 Constraint_list * rna_lib_extension ( Constraint_list *CL, Constraint_list *R)
4759 CLIST_TYPE *entry=NULL;
4760 int a,b,c,d,e,n1,n2, ne,s1,r1,s2,r2,w2;
4767 list1=vcalloc ( 100, sizeof (int));
4768 list2=vcalloc ( 100, sizeof (int));
4770 if (!tmp) tmp=vtmpnam (NULL);
4771 fp=vfopen (tmp, "w");
4772 entry=vcalloc ( 100, sizeof (int));
4773 for (s1=0; s1<S->nseq; s1++)
4775 for (r1=1; r1<=S->len[s1]; r1++)
4778 for (c=1; c<CL->residue_index[s1][r1][0]; c+=ICHUNK)
4780 s2=CL->residue_index[s1][r1][c+SEQ2];
4781 r2=CL->residue_index[s1][r1][c+R2];
4782 w2=CL->residue_index[s1][r1][c+WE];
4788 for (b=1; b<R->residue_index[s1][r1][0]; b+=ICHUNK)
4790 list1[n1++]=R->residue_index[s1][r1][b+R2];
4794 for (b=1; b<R->residue_index[s2][r2][0]; b+=ICHUNK)
4796 list2[n2++]=R->residue_index[s2][r2][b+R2];
4799 for (b=1; b<n1; b++)
4800 for (d=1; d<n2; d++)
4804 for (e=0; e<CL->entry_len; e++) fprintf (fp, "%d ", entry[e]);
4811 return undump_constraint_list (CL,tmp);
4814 char *** produce_method_file ( char *method)
4816 static char ***list;
4820 if (!list)list=declare_arrayN(3, sizeof (char),1000,2, 100);
4824 sprintf (list[n][0], "t_coffee");
4825 sprintf (list[n][1], "%s", vtmpnam(NULL));
4826 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
4827 fprintf ( fp, "EXECUTABLE t_coffee\n");
4828 fprintf ( fp, "ADDRESS built_in");
4829 fprintf ( fp, "ALN_MODE any\n");
4830 fprintf ( fp, "OUT_MODE L\n");
4831 fprintf ( fp, "IN_FLAG no_name\n");
4832 fprintf ( fp, "OUT_FLAG no_name\n");
4833 fprintf ( fp, "SEQ_TYPE S\n");
4834 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
4835 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
4839 /*Space holder method to analyze very large dATASETS*/
4840 sprintf (list[n][0], "test_pair");
4841 sprintf (list[n][1], "%s", vtmpnam(NULL));
4842 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
4843 fprintf ( fp, "EXECUTABLE test_pair\n");
4844 fprintf ( fp, "DOC Fast alignmnents on the best diagonals\n");
4845 fprintf ( fp, "ALN_MODE pairwise\n");
4846 fprintf ( fp, "OUT_MODE fL\n");
4847 fprintf ( fp, "IN_FLAG no_name\n");
4848 fprintf ( fp, "OUT_FLAG no_name\n");
4849 fprintf ( fp, "SEQ_TYPE S\n");
4850 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
4851 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
4854 sprintf (list[n][0], "fast_pair");
4855 sprintf (list[n][1], "%s", vtmpnam(NULL));
4856 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
4857 fprintf ( fp, "EXECUTABLE fast_pair\n");
4858 fprintf ( fp, "DOC Fast alignmnents on the best diagonals\n");
4859 fprintf ( fp, "ALN_MODE pairwise\n");
4860 fprintf ( fp, "OUT_MODE fL\n");
4861 fprintf ( fp, "IN_FLAG no_name\n");
4862 fprintf ( fp, "OUT_FLAG no_name\n");
4863 fprintf ( fp, "SEQ_TYPE S\n");
4864 if (strm (retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
4866 fprintf ( fp, "MATRIX dna_idmat\n");
4867 fprintf ( fp, "GOP -50\n");
4868 fprintf ( fp, "GEP -1\n");
4870 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
4871 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
4874 sprintf (list[n][0], "exon3_pair");
4875 sprintf (list[n][1], "%s", vtmpnam(NULL));
4876 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
4877 fprintf ( fp, "EXECUTABLE exon3_pair\n");
4878 fprintf ( fp, "ALN_MODE pairwise\n");
4879 fprintf ( fp, "OUT_MODE fL\n");
4880 fprintf ( fp, "IN_FLAG no_name\n");
4881 fprintf ( fp, "OUT_FLAG no_name\n");
4882 fprintf ( fp, "SEQ_TYPE G\n");
4883 fprintf ( fp, "MATRIX exon2mt\n");
4884 fprintf ( fp, "GOP 0\n");
4885 fprintf ( fp, "GEP -1\n");
4886 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
4887 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
4890 sprintf (list[n][0], "exon2_pair");
4891 sprintf (list[n][1], "%s", vtmpnam(NULL));
4892 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
4893 fprintf ( fp, "EXECUTABLE exon2_pair\n");
4894 fprintf ( fp, "ALN_MODE pairwise\n");
4895 fprintf ( fp, "OUT_MODE fL\n");
4896 fprintf ( fp, "IN_FLAG no_name\n");
4897 fprintf ( fp, "OUT_FLAG no_name\n");
4898 fprintf ( fp, "SEQ_TYPE G\n");
4899 fprintf ( fp, "MATRIX exon2mt\n");
4900 fprintf ( fp, "GOP -10\n");
4901 fprintf ( fp, "GEP -1\n");
4902 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
4903 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
4906 sprintf (list[n][0], "exon_pair");
4907 sprintf (list[n][1], "%s", vtmpnam(NULL));
4908 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
4909 fprintf ( fp, "EXECUTABLE exon_pair\n");
4910 fprintf ( fp, "ALN_MODE pairwise\n");
4911 fprintf ( fp, "OUT_MODE fL\n");
4912 fprintf ( fp, "IN_FLAG no_name\n");
4913 fprintf ( fp, "OUT_FLAG no_name\n");
4914 fprintf ( fp, "SEQ_TYPE G\n");
4915 fprintf ( fp, "MATRIX exon2mt\n");
4916 fprintf ( fp, "GOP -10\n");
4917 fprintf ( fp, "GEP -1\n");
4918 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
4919 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
4923 sprintf (list[n][0], "blastr_pair");
4924 sprintf (list[n][1], "%s", vtmpnam(NULL));
4925 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
4926 fprintf ( fp, "EXECUTABLE slow_pair\n");
4927 fprintf ( fp, "ALN_MODE pairwise\n");
4928 fprintf ( fp, "OUT_MODE fL\n");
4929 fprintf ( fp, "IN_FLAG no_name\n");
4930 fprintf ( fp, "OUT_FLAG no_name\n");
4931 fprintf ( fp, "SEQ_TYPE S\n");
4932 fprintf ( fp, "EXTEND_SEQ 1\n");
4933 fprintf ( fp, "MATRIX blosumR\n");
4934 fprintf ( fp, "GOP -20\n");
4935 fprintf ( fp, "GEP 0\n");
4936 fprintf ( fp, "WEIGHT extend_sim\n");
4938 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
4939 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
4942 sprintf (list[n][0], "promo_pair");
4943 sprintf (list[n][1], "%s", vtmpnam(NULL));
4944 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
4945 fprintf ( fp, "EXECUTABLE slow_pair\n");
4946 fprintf ( fp, "ALN_MODE pairwise\n");
4947 fprintf ( fp, "OUT_MODE fL\n");
4948 fprintf ( fp, "IN_FLAG no_name\n");
4949 fprintf ( fp, "OUT_FLAG no_name\n");
4950 fprintf ( fp, "SEQ_TYPE S\n");
4951 fprintf ( fp, "EXTEND_SEQ 1\n");
4952 fprintf ( fp, "MATRIX promoter_tf1\n");
4953 fprintf ( fp, "GOP -40\n");
4954 fprintf ( fp, "GEP 0\n");
4955 fprintf ( fp, "WEIGHT extend_sim\n");
4957 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
4958 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
4961 sprintf (list[n][0], "clean_slow_pair");
4962 sprintf (list[n][1], "%s", vtmpnam(NULL));
4963 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
4964 fprintf ( fp, "DOC regular dynamic Programming\n");
4965 fprintf ( fp, "EXECUTABLE slow_pair\n");
4966 fprintf ( fp, "ALN_MODE pairwise\n");
4967 fprintf ( fp, "OUT_MODE fL\n");
4968 fprintf ( fp, "IN_FLAG no_name\n");
4969 fprintf ( fp, "OUT_FLAG no_name\n");
4970 fprintf ( fp, "SEQ_TYPE S\n");
4971 fprintf ( fp, "WEIGHT clean\n");
4972 if ( strm ( retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
4974 fprintf ( fp, "MATRIX dna_idmat\n");
4975 fprintf ( fp, "GOP -10\n");
4976 fprintf ( fp, "GEP -1\n");
4978 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
4979 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
4982 sprintf (list[n][0], "slow_pair");
4983 sprintf (list[n][1], "%s", vtmpnam(NULL));
4984 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
4985 fprintf ( fp, "DOC regular dynamic Programming\n");
4986 fprintf ( fp, "EXECUTABLE slow_pair\n");
4987 fprintf ( fp, "ALN_MODE pairwise\n");
4988 fprintf ( fp, "OUT_MODE fL\n");
4989 fprintf ( fp, "IN_FLAG no_name\n");
4990 fprintf ( fp, "OUT_FLAG no_name\n");
4991 fprintf ( fp, "SEQ_TYPE S\n");
4992 if ( strm ( retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
4994 fprintf ( fp, "MATRIX dna_idmat\n");
4995 fprintf ( fp, "GOP -10\n");
4996 fprintf ( fp, "GEP -1\n");
4998 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
4999 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5002 sprintf (list[n][0], "biphasic_pair");
5003 sprintf (list[n][1], "%s", vtmpnam(NULL));
5004 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5005 fprintf ( fp, "DOC bi-phasic dynamic Programming\n");
5006 fprintf ( fp, "EXECUTABLE biphasic_pair\n");
5007 fprintf ( fp, "ALN_MODE pairwise\n");
5008 fprintf ( fp, "OUT_MODE fL\n");
5009 fprintf ( fp, "IN_FLAG no_name\n");
5010 fprintf ( fp, "OUT_FLAG no_name\n");
5011 fprintf ( fp, "SEQ_TYPE S\n");
5012 if ( strm ( retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5014 fprintf ( fp, "MATRIX dna_idmat\n");
5015 fprintf ( fp, "GOP -10\n");
5016 fprintf ( fp, "GEP -1\n");
5018 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5019 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5022 sprintf (list[n][0], "proba_pair");
5023 sprintf (list[n][1], "%s", vtmpnam(NULL));
5024 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5025 fprintf ( fp, "DOC Probabilistic pairwise alignment\n");
5026 fprintf ( fp, "EXECUTABLE proba_pair\n");
5027 fprintf ( fp, "ALN_MODE pairwise\n");
5028 fprintf ( fp, "OUT_MODE fL\n");
5029 fprintf ( fp, "IN_FLAG no_name\n");
5030 fprintf ( fp, "OUT_FLAG no_name\n");
5031 fprintf ( fp, "SEQ_TYPE S\n");
5032 if ( strm ( retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5034 fprintf ( fp, "GOP %d\n",CODE4DNA);//code for DNA
5038 fprintf ( fp, "GOP %d\n",CODE4PROTEINS);//Code for Proteins
5040 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5041 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5045 sprintf (list[n][0], "best_pair4prot");
5046 sprintf (list[n][1], "%s", vtmpnam(NULL));
5047 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5048 fprintf ( fp, "DOC Combination of the best template methods\n");
5049 fprintf ( fp, "EXECUTABLE best_pair4prot\n");
5050 fprintf ( fp, "ALN_MODE pairwise\n");
5051 fprintf ( fp, "OUT_MODE fL\n");
5052 fprintf ( fp, "IN_FLAG no_name\n");
5053 fprintf ( fp, "OUT_FLAG no_name\n");
5054 fprintf ( fp, "SEQ_TYPE S\n");
5055 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5056 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5057 if (strm (retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5059 printf_exit (EXIT_FAILURE, stderr, "\nERROR: The mode best_pair4prot is only suited for Proteins [FATAL:%s]\n", PROGRAM);
5064 sprintf (list[n][0], "best_pair4rna");
5065 sprintf (list[n][1], "%s", vtmpnam(NULL));
5066 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5067 fprintf ( fp, "DOC Combination of the best template methods\n");
5068 fprintf ( fp, "EXECUTABLE best_pair4rna\n");
5069 fprintf ( fp, "ALN_MODE pairwise\n");
5070 fprintf ( fp, "OUT_MODE fL\n");
5071 fprintf ( fp, "IN_FLAG no_name\n");
5072 fprintf ( fp, "OUT_FLAG no_name\n");
5073 fprintf ( fp, "SEQ_TYPE S\n");
5074 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5075 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5076 // if (strm(retrieve_seq_type(), "RNA"))
5078 // printf_exit (EXIT_FAILURE, stderr, "\nERROR: The mode best_pair4rna is only suited for RNA [FATAL:%s]\n", PROGRAM);
5084 sprintf (list[n][0], "lalign_id_pair");
5085 sprintf (list[n][1], "%s", vtmpnam(NULL));
5086 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5087 fprintf ( fp, "DOC local alignment reporting the N best pairwise local alignments\n");
5088 fprintf ( fp, "EXECUTABLE lalign_id_pair\n");
5089 fprintf ( fp, "ALN_MODE pairwise\n");
5090 fprintf ( fp, "OUT_MODE fL\n");
5091 fprintf ( fp, "IN_FLAG no_name\n");
5092 fprintf ( fp, "OUT_FLAG no_name\n");
5093 if ( strm (retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))
5095 fprintf ( fp, "MATRIX dna_idmat\n");
5096 fprintf ( fp, "GOP -10\n");
5097 fprintf ( fp, "GEP -1\n");
5101 fprintf ( fp, "MATRIX blosum50mt\n");
5102 fprintf ( fp, "GOP -10\n");
5103 fprintf ( fp, "GEP -4\n");
5105 fprintf ( fp, "MAXID 100\n");
5106 fprintf ( fp, "SEQ_TYPE S\n");
5107 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5108 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5111 sprintf (list[n][0], "align_pdbpair");
5112 sprintf (list[n][1], "%s", vtmpnam(NULL));
5113 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5114 fprintf ( fp, "EXECUTABLE align_pdb_pair\n");
5115 fprintf ( fp, "ALN_MODE pairwise\n");
5116 fprintf ( fp, "OUT_MODE fL\n");
5117 fprintf ( fp, "IN_FLAG no_name\n");
5118 fprintf ( fp, "OUT_FLAG no_name\n");
5119 fprintf ( fp, "SEQ_TYPE P\n");
5120 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5121 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5124 sprintf (list[n][0], "lalign_pdbpair");
5125 sprintf (list[n][1], "%s", vtmpnam(NULL));
5126 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5127 fprintf ( fp, "EXECUTABLE lalign_pdb_pair\n");
5128 fprintf ( fp, "ALN_MODE pairwise\n");
5129 fprintf ( fp, "OUT_MODE fL\n");
5130 fprintf ( fp, "IN_FLAG no_name\n");
5131 fprintf ( fp, "OUT_FLAG no_name\n");
5132 fprintf ( fp, "SEQ_TYPE P\n");
5133 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5134 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5137 sprintf (list[n][0], "ktup_msa");
5138 sprintf (list[n][1], "%s", vtmpnam(NULL));
5139 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5140 fprintf ( fp, "EXECUTABLE ktup_msa\n");
5141 fprintf ( fp, "ALN_MODE multiple\n");
5142 fprintf ( fp, "OUT_MODE fL\n");
5143 fprintf ( fp, "IN_FLAG no_name\n");
5144 fprintf ( fp, "OUT_FLAG no_name\n");
5145 fprintf ( fp, "SEQ_TYPE s\n");
5146 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5147 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5150 sprintf (list[n][0], "seq_pair");
5151 sprintf (list[n][1], "%s", vtmpnam(NULL));
5152 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5153 fprintf ( fp, "EXECUTABLE seq_pair\n");
5154 fprintf ( fp, "ALN_MODE pairwise\n");
5155 fprintf ( fp, "OUT_MODE fL\n");
5156 fprintf ( fp, "IN_FLAG no_name\n");
5157 fprintf ( fp, "OUT_FLAG no_name\n");
5158 fprintf ( fp, "SEQ_TYPE s\n");
5159 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5160 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5163 sprintf (list[n][0], "extern_pdbpair");
5164 sprintf (list[n][1], "%s", vtmpnam(NULL));
5165 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5166 fprintf ( fp, "EXECUTABLE tc_P_generic_method.pl\n");
5167 fprintf ( fp, "ALN_MODE pairwise\n");
5168 fprintf ( fp, "OUT_MODE A\n");
5169 fprintf ( fp, "IN_FLAG no_name\n");
5170 fprintf ( fp, "OUT_FLAG no_name\n");
5171 fprintf ( fp, "SEQ_TYPE P\n");
5172 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5173 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5176 sprintf (list[n][0], "externprofile_pair");
5177 sprintf (list[n][1], "%s", vtmpnam(NULL));
5178 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5179 fprintf ( fp, "EXECUTABLE tc_R_generic_method\n");
5180 fprintf ( fp, "ALN_MODE pairwise\n");
5181 fprintf ( fp, "OUT_MODE A\n");
5182 fprintf ( fp, "IN_FLAG no_name\n");
5183 fprintf ( fp, "OUT_FLAG no_name\n");
5184 fprintf ( fp, "SEQ_TYPE R\n");
5185 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5186 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5189 sprintf (list[n][0], "thread_pair");
5190 sprintf (list[n][1], "%s", vtmpnam(NULL));
5191 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5192 /*This runs thread_pair@EP@EXECUTABLE2@threpg*/
5193 fprintf ( fp, "EXECUTABLE thread_pair\n");
5194 fprintf ( fp, "EXECUTABLE2 t_coffee\n");
5195 fprintf ( fp, "ALN_MODE pairwise\n");
5196 fprintf ( fp, "OUT_MODE fL\n");
5197 fprintf ( fp, "IN_FLAG -infile=\n");
5198 fprintf ( fp, "IN_FLAG2 -pdbfile1=\n");
5199 fprintf ( fp, "OUT_FLAG -outfile=\n");
5200 fprintf ( fp, "SEQ_TYPE Ps\n");
5201 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5202 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5205 sprintf (list[n][0], "fugue_pair");
5206 sprintf (list[n][1], "%s", vtmpnam(NULL));
5207 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5208 /*This runs thread_pair@EP@EXECUTABLE2@threpg*/
5209 fprintf ( fp, "EXECUTABLE thread_pair\n");
5210 fprintf ( fp, "EXECUTABLE2 fugueali\n");
5211 fprintf ( fp, "ALN_MODE pairwise\n");
5212 fprintf ( fp, "OUT_MODE fL\n");
5213 fprintf ( fp, "IN_FLAG -infile=\n");
5214 fprintf ( fp, "IN_FLAG2 -pdbfile1=\n");
5215 fprintf ( fp, "OUT_FLAG -outfile=\n");
5216 fprintf ( fp, "SEQ_TYPE Ps\n");
5217 fprintf ( fp, "ADDRESS %s\n", FUGUE_ADDRESS);
5218 fprintf ( fp, "PROGRAM %s\n", FUGUE_4_TCOFFEE);
5221 sprintf (list[n][0], "pdb_pair");
5222 sprintf (list[n][1], "%s", vtmpnam(NULL));
5223 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5224 fprintf ( fp, "EXECUTABLE pdb_pair\n");
5225 fprintf ( fp, "EXECUTABLE2 t_coffee\n");
5226 fprintf ( fp, "ALN_MODE pairwise\n");
5227 fprintf ( fp, "OUT_MODE fL\n");
5228 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5229 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5230 fprintf ( fp, "OUT_FLAG -outfile=\n");
5231 fprintf ( fp, "SEQ_TYPE P\n");
5232 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5233 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5236 sprintf (list[n][0], "hh_pair");
5237 sprintf (list[n][1], "%s", vtmpnam(NULL));
5238 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5239 fprintf ( fp, "EXECUTABLE profile_pair\n");
5240 fprintf ( fp, "EXECUTABLE2 hhalign\n");
5241 fprintf ( fp, "ALN_MODE pairwise\n");
5242 fprintf ( fp, "OUT_MODE fL\n");
5243 fprintf ( fp, "IN_FLAG -profile1=\n");
5244 fprintf ( fp, "IN_FLAG2 -profile2=\n");
5245 fprintf ( fp, "OUT_FLAG -outfile=\n");
5246 fprintf ( fp, "SEQ_TYPE R\n");
5247 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5248 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5249 fprintf ( fp, "SUPPORTED NO");
5252 sprintf (list[n][0], "profile_pair");
5253 sprintf (list[n][1], "%s", vtmpnam(NULL));
5254 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5255 fprintf ( fp, "EXECUTABLE profile_pair\n");
5256 fprintf ( fp, "EXECUTABLE2 clustalw\n");
5257 fprintf ( fp, "ALN_MODE pairwise\n");
5258 fprintf ( fp, "OUT_MODE fL\n");
5259 fprintf ( fp, "IN_FLAG -profile1=\n");
5260 fprintf ( fp, "IN_FLAG2 -profile2=\n");
5261 fprintf ( fp, "OUT_FLAG -outfile=\n");
5262 fprintf ( fp, "SEQ_TYPE R\n");
5263 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5264 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5265 fprintf ( fp, "SUPPORTED NO");
5269 //Switch to TM_align if SAP is not installed
5271 if (method && strm (method, "sap_pair") && !check_program_is_installed (SAP_4_TCOFFEE,NULL,NULL,SAP_ADDRESS,INSTALL))
5276 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");
5280 sprintf (list[n][0], "sap_pair");
5281 sprintf (list[n][1], "%s", vtmpnam(NULL));
5284 fp=vfopen (list[n-1][1], "w");
5285 fprintf ( fp, "DOC: TM-Align: pairwise structural aligner [%s]\n", TMALIGN_ADDRESS);
5286 fprintf ( fp, "EXECUTABLE pdb_pair\n");
5287 fprintf ( fp, "EXECUTABLE2 TMalign\n" );
5288 fprintf ( fp, "ALN_MODE pairwise\n");
5289 fprintf ( fp, "OUT_MODE fL\n");
5290 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5291 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5292 fprintf ( fp, "OUT_FLAG -outfile=\n");
5293 fprintf ( fp, "ADDRESS %s\n", TMALIGN_ADDRESS);
5294 fprintf ( fp, "PROGRAM %s\n", TMALIGN_4_TCOFFEE);
5295 fprintf ( fp, "SEQ_TYPE P\n");
5301 sprintf (list[n][0], "sap_pair");
5302 sprintf (list[n][1], "%s", vtmpnam(NULL));
5304 if (method==NULL || strm (method, list[n-1][0]))
5306 fp=vfopen (list[n-1][1], "w");
5307 fprintf ( fp, "DOC: sap: pairwise structural aligner [%s]\n", SAP_ADDRESS);
5308 fprintf ( fp, "EXECUTABLE sap_pair\n");
5309 fprintf ( fp, "ALN_MODE pairwise\n");
5310 fprintf ( fp, "OUT_MODE fL\n");
5311 fprintf ( fp, "IN_FLAG no_name\n");
5312 fprintf ( fp, "OUT_FLAG no_name\n");
5313 fprintf ( fp, "WEIGHT 100\n");
5314 fprintf ( fp, "SEQ_TYPE P\n");
5315 fprintf ( fp, "ADDRESS %s\n", SAP_ADDRESS);
5316 fprintf ( fp, "PROGRAM %s\n", SAP_4_TCOFFEE);
5320 sprintf (list[n][0], "sara_pair");
5321 sprintf (list[n][1], "%s", vtmpnam(NULL));
5323 if (method==NULL || strm (method, list[n-1][0])){
5324 fp=vfopen (list[n-1][1], "w");
5325 fprintf ( fp, "DOC: SARA: pairwise structural RNA aligner [%s]\n", ADDRESS_BUILT_IN);
5326 fprintf ( fp, "EXECUTABLE rna_pair\n");
5327 fprintf ( fp, "EXECUTABLE2 runsara.py\n" );
5328 fprintf ( fp, "ALN_MODE pairwise\n");
5329 fprintf ( fp, "OUT_MODE fL\n");
5330 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5331 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5332 fprintf ( fp, "OUT_FLAG -outfile=\n");
5333 fprintf ( fp, "SEQ_TYPE P\n");
5334 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5335 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5339 sprintf (list[n][0], "daliweb_pair");
5340 sprintf (list[n][1], "%s", vtmpnam(NULL));
5341 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5342 fprintf ( fp, "DOC: Dalilite: pairwise structural aligner [%s]\n", DALILITEc_ADDRESS);
5343 fprintf ( fp, "EXECUTABLE pdbid_pair\n");
5344 fprintf ( fp, "EXECUTABLE2 daliweb\n" );
5345 fprintf ( fp, "ALN_MODE pairwise\n");
5346 fprintf ( fp, "OUT_MODE fL\n");
5347 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5348 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5349 fprintf ( fp, "OUT_FLAG -outfile=\n");
5350 fprintf ( fp, "SEQ_TYPE P\n");
5351 fprintf ( fp, "ADDRESS %s\n", DALILITEc_ADDRESS);
5352 fprintf ( fp, "PROGRAM %s\n", DALILITEc_4_TCOFFEE);
5355 sprintf (list[n][0], "dali_pair");
5356 sprintf (list[n][1], "%s", vtmpnam(NULL));
5357 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5358 fprintf ( fp, "DOC: Dalilite: pairwise structural aligner [%s]\n", DALILITEc_ADDRESS);
5359 fprintf ( fp, "EXECUTABLE pdb_pair\n");
5360 fprintf ( fp, "EXECUTABLE2 DaliLite\n" );
5361 fprintf ( fp, "ALN_MODE pairwise\n");
5362 fprintf ( fp, "OUT_MODE fL\n");
5363 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5364 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5365 fprintf ( fp, "OUT_FLAG -outfile=\n");
5366 fprintf ( fp, "SEQ_TYPE P\n");
5367 fprintf ( fp, "ADDRESS %s\n", DALILITEc_ADDRESS);
5368 fprintf ( fp, "PROGRAM %s\n", DALILITEc_4_TCOFFEE);
5372 sprintf (list[n][0], "mustang_pair");
5373 sprintf (list[n][1], "%s", vtmpnam(NULL));
5374 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5375 fprintf ( fp, "DOC: Mustang: pairwise structural aligner [%s]\n", MUSTANG_ADDRESS);
5376 fprintf ( fp, "EXECUTABLE pdb_pair\n");
5377 fprintf ( fp, "EXECUTABLE2 mustang\n" );
5378 fprintf ( fp, "ALN_MODE pairwise\n");
5379 fprintf ( fp, "OUT_MODE fL\n");
5380 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5381 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5382 fprintf ( fp, "OUT_FLAG -outfile=\n");
5383 fprintf ( fp, "SEQ_TYPE P\n");
5384 fprintf ( fp, "ADDRESS %s\n", MUSTANG_ADDRESS);
5385 fprintf ( fp, "PROGRAM %s\n", MUSTANG_4_TCOFFEE);
5388 sprintf (list[n][0], "TMalign_pair");
5389 sprintf (list[n][1], "%s", vtmpnam(NULL));
5390 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5391 fprintf ( fp, "DOC: TM-Align: pairwise structural aligner [%s]\n", TMALIGN_ADDRESS);
5392 fprintf ( fp, "EXECUTABLE pdb_pair\n");
5393 fprintf ( fp, "EXECUTABLE2 TMalign\n" );
5394 fprintf ( fp, "ALN_MODE pairwise\n");
5395 fprintf ( fp, "OUT_MODE fL\n");
5396 fprintf ( fp, "IN_FLAG -pdbfile1=\n");
5397 fprintf ( fp, "IN_FLAG2 -pdbfile2=\n");
5398 fprintf ( fp, "OUT_FLAG -outfile=\n");
5399 fprintf ( fp, "ADDRESS %s\n", TMALIGN_ADDRESS);
5400 fprintf ( fp, "PROGRAM %s\n", TMALIGN_4_TCOFFEE);
5401 fprintf ( fp, "SEQ_TYPE P\n");
5404 sprintf (list[n][0], "cdna_fast_pair");
5405 sprintf (list[n][1], "%s", vtmpnam(NULL));
5406 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5407 fprintf ( fp, "EXECUTABLE cdna_fast_pair\n");
5408 fprintf ( fp, "ALN_MODE pairwise\n");
5409 fprintf ( fp, "OUT_MODE fL\n");
5410 fprintf ( fp, "IN_FLAG no_name\n");
5411 fprintf ( fp, "OUT_FLAG no_name\n");
5412 fprintf ( fp, "SEQ_TYPE S\n");
5413 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5414 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5417 sprintf (list[n][0], "cdna_cfast_pair");
5418 sprintf (list[n][1], "%s", vtmpnam(NULL));
5419 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5420 fprintf ( fp, "EXECUTABLE cdna_cfast_pair\n");
5421 fprintf ( fp, "ALN_MODE pairwise\n");
5422 fprintf ( fp, "OUT_MODE fL\n");
5423 fprintf ( fp, "IN_FLAG no_name\n");
5424 fprintf ( fp, "OUT_FLAG no_name\n");
5425 fprintf ( fp, "SEQ_TYPE S\n");
5426 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
5427 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
5430 sprintf (list[n][0], "blastp_msa");
5431 sprintf (list[n][1], "%s", vtmpnam(NULL));
5432 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5433 fprintf ( fp, "DOC: BLAST multiple Aligner [%s]\n", NCBIBLAST_ADDRESS);
5434 fprintf ( fp, "EXECUTABLE seq_msa\n");
5435 fprintf ( fp, "EXECUTABLE2 blastp\n" );
5436 fprintf ( fp, "ALN_MODE multiple\n");
5437 fprintf ( fp, "OUT_MODE fL\n");
5438 fprintf ( fp, "IN_FLAG -infile=\n");
5439 fprintf ( fp, "OUT_FLAG -outfile=\n");
5440 fprintf ( fp, "SEQ_TYPE S\n");
5441 fprintf ( fp, "ADDRESS %s\n", NCBIBLAST_ADDRESS);
5442 fprintf ( fp, "PROGRAM %s\n", NCBIBLAST_4_TCOFFEE);
5445 sprintf (list[n][0], "blastp_o2a");
5446 sprintf (list[n][1], "%s", vtmpnam(NULL));
5447 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5448 fprintf ( fp, "DOC: BLAST multiple Aligner [%s]\n", NCBIBLAST_ADDRESS);
5449 fprintf ( fp, "EXECUTABLE seq_msa\n");
5450 fprintf ( fp, "EXECUTABLE2 blastp\n" );
5451 fprintf ( fp, "ALN_MODE o2a\n");
5452 fprintf ( fp, "OUT_MODE fL\n");
5453 fprintf ( fp, "IN_FLAG -infile=\n");
5454 fprintf ( fp, "OUT_FLAG -outfile=\n");
5455 fprintf ( fp, "SEQ_TYPE S\n");
5456 fprintf ( fp, "ADDRESS %s\n", NCBIBLAST_ADDRESS);
5457 fprintf ( fp, "PROGRAM %s\n", NCBIBLAST_4_TCOFFEE);
5460 sprintf (list[n][0], "clustalw2_pair");
5461 sprintf (list[n][1], "%s", vtmpnam(NULL));
5462 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5463 fprintf ( fp, "DOC: clustalw [%s]\n", CLUSTALW2_ADDRESS);
5464 fprintf ( fp, "EXECUTABLE clustalw\n");
5465 fprintf ( fp, "ALN_MODE pairwise\n");
5466 fprintf ( fp, "OUT_MODE aln\n");
5467 fprintf ( fp, "IN_FLAG %sINFILE=\n",CWF);
5468 fprintf ( fp, "OUT_FLAG %sOUTFILE=\n",CWF);
5469 fprintf ( fp, "PARAM %sOUTORDER=INPUT %sNEWTREE=SCRATCH_FILE %salign\n",CWF,CWF,CWF);
5470 fprintf ( fp, "SEQ_TYPE S\n");
5471 fprintf ( fp, "ADDRESS %s\n", CLUSTALW2_ADDRESS);
5472 fprintf ( fp, "PROGRAM %s\n", CLUSTALW2_4_TCOFFEE);
5475 sprintf (list[n][0], "clustalw2_msa");
5476 sprintf (list[n][1], "%s", vtmpnam(NULL));
5477 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5478 fprintf ( fp, "DOC clustalw[%s]\n", CLUSTALW2_ADDRESS);
5479 fprintf ( fp, "EXECUTABLE clustalw2\n");
5480 fprintf ( fp, "ALN_MODE multiple\n");
5481 fprintf ( fp, "OUT_MODE aln\n");
5482 fprintf ( fp, "IN_FLAG %sINFILE=\n",CWF);
5483 fprintf ( fp, "OUT_FLAG %sOUTFILE=\n", CWF);
5484 fprintf ( fp, "PARAM %sOUTORDER=INPUT %sNEWTREE=SCRATCH_FILE %salign\n",CWF,CWF,CWF);
5485 fprintf ( fp, "SEQ_TYPE S\n");
5486 fprintf ( fp, "ADDRESS %s\n", CLUSTALW2_ADDRESS);
5487 fprintf ( fp, "PROGRAM %s\n", CLUSTALW2_4_TCOFFEE);
5490 sprintf (list[n][0], "clustalw_pair");
5491 sprintf (list[n][1], "%s", vtmpnam(NULL));
5492 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5493 fprintf ( fp, "DOC: clustalw [%s]\n", CLUSTALW_ADDRESS);
5494 fprintf ( fp, "EXECUTABLE clustalw\n");
5495 fprintf ( fp, "ALN_MODE pairwise\n");
5496 fprintf ( fp, "OUT_MODE aln\n");
5497 fprintf ( fp, "IN_FLAG %sINFILE=\n", CWF);
5498 fprintf ( fp, "OUT_FLAG %sOUTFILE=\n",CWF);
5499 fprintf ( fp, "PARAM %sOUTORDER=INPUT %sNEWTREE=SCRATCH_FILE %salign\n",CWF,CWF,CWF);
5500 fprintf ( fp, "SEQ_TYPE S\n");
5501 fprintf ( fp, "ADDRESS %s\n", CLUSTALW_ADDRESS);
5502 fprintf ( fp, "PROGRAM %s\n", CLUSTALW_4_TCOFFEE);
5505 sprintf (list[n][0], "clustalw_msa");
5506 sprintf (list[n][1], "%s", vtmpnam(NULL));
5507 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5508 fprintf ( fp, "DOC clustalw[%s]\n", CLUSTALW_ADDRESS);
5509 fprintf ( fp, "EXECUTABLE clustalw\n");
5510 fprintf ( fp, "ALN_MODE multiple\n");
5511 fprintf ( fp, "OUT_MODE aln\n");
5512 fprintf ( fp, "IN_FLAG %sINFILE=\n", CWF);
5513 fprintf ( fp, "OUT_FLAG %sOUTFILE=\n", CWF);
5514 fprintf ( fp, "PARAM %sOUTORDER=INPUT %sNEWTREE=SCRATCH_FILE %salign\n",CWF,CWF,CWF);
5515 fprintf ( fp, "SEQ_TYPE S\n");
5516 fprintf ( fp, "ADDRESS %s\n", CLUSTALW_ADDRESS);
5517 fprintf ( fp, "PROGRAM %s\n", CLUSTALW_4_TCOFFEE);
5520 sprintf (list[n][0], "mafftdef_pair");
5521 sprintf (list[n][1], "%s", vtmpnam(NULL));
5522 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5523 fprintf ( fp, "EXECUTABLE mafft\n");
5524 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
5525 fprintf ( fp, "ALN_MODE pairwise\n");
5526 fprintf ( fp, "OUT_MODE aln\n");
5527 fprintf ( fp, "PARAM1 \n");
5528 fprintf ( fp, "IN_FLAG &bnsp\n");
5529 fprintf ( fp, "OUT_FLAG >\n");
5530 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5531 fprintf ( fp, "SEQ_TYPE S\n");
5532 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
5533 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
5537 sprintf (list[n][0], "mafftdef_msa");
5538 sprintf (list[n][1], "%s", vtmpnam(NULL));
5539 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5540 fprintf ( fp, "EXECUTABLE mafft\n");
5541 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
5542 fprintf ( fp, "ALN_MODE multiple\n");
5543 fprintf ( fp, "OUT_MODE aln\n");
5544 fprintf ( fp, " \n");
5545 fprintf ( fp, "IN_FLAG &bnsp\n");
5546 fprintf ( fp, "OUT_FLAG >\n");
5547 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5548 fprintf ( fp, "SEQ_TYPE S\n");
5549 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
5550 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
5553 sprintf (list[n][0], "mafft_pair");
5554 sprintf (list[n][1], "%s", vtmpnam(NULL));
5555 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5556 fprintf ( fp, "EXECUTABLE mafft\n");
5557 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
5558 fprintf ( fp, "ALN_MODE pairwise\n");
5559 fprintf ( fp, "OUT_MODE aln\n");
5560 fprintf ( fp, "PARAM1 --localpair --maxiterate 1000 \n");
5561 fprintf ( fp, "IN_FLAG &bnsp\n");
5562 fprintf ( fp, "OUT_FLAG >\n");
5563 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5564 fprintf ( fp, "SEQ_TYPE S\n");
5565 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
5566 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
5569 sprintf (list[n][0], "mafft_msa");
5570 sprintf (list[n][1], "%s", vtmpnam(NULL));
5571 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5572 fprintf ( fp, "EXECUTABLE mafft\n");
5573 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
5574 fprintf ( fp, "ALN_MODE multiple\n");
5575 fprintf ( fp, "OUT_MODE aln\n");
5576 fprintf ( fp, "PARAM1 --localpair --maxiterate 1000 \n");
5577 fprintf ( fp, "IN_FLAG &bnsp\n");
5578 fprintf ( fp, "OUT_FLAG >\n");
5579 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5580 fprintf ( fp, "PARAM \n");
5581 fprintf ( fp, "SEQ_TYPE S\n");
5582 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
5583 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
5586 sprintf (list[n][0], "mafftjtt_pair");
5587 sprintf (list[n][1], "%s", vtmpnam(NULL));
5588 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5589 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
5590 fprintf ( fp, "EXECUTABLE mafft \n");
5591 fprintf ( fp, "ALN_MODE pairwise\n");
5592 fprintf ( fp, "OUT_MODE aln\n");
5593 fprintf ( fp, "IN_FLAG &bnsp\n");
5594 fprintf ( fp, "OUT_FLAG >\n");
5595 fprintf ( fp, "PARAM1 --jtt 250 --localpair --maxiterate 1000 \n");
5596 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5597 fprintf ( fp, "SEQ_TYPE S\n");
5598 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
5599 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
5602 sprintf (list[n][0], "mafftjtt_msa");
5603 sprintf (list[n][1], "%s", vtmpnam(NULL));
5604 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5605 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
5606 fprintf ( fp, "EXECUTABLE mafft \n");
5608 fprintf ( fp, "ALN_MODE multiple\n");
5609 fprintf ( fp, "OUT_MODE aln\n");
5610 fprintf ( fp, "IN_FLAG &bnsp\n");
5611 fprintf ( fp, "OUT_FLAG >\n");
5612 fprintf ( fp, "PARAM1 --jtt 250 --localpair --maxiterate 1000 \n");
5613 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5614 fprintf ( fp, "SEQ_TYPE S\n");
5615 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
5616 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
5619 sprintf (list[n][0], "mafftgins_pair");
5620 sprintf (list[n][1], "%s", vtmpnam(NULL));
5621 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5622 fprintf ( fp, "EXECUTABLE mafft\n");
5623 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
5624 fprintf ( fp, "ALN_MODE pairwise\n");
5625 fprintf ( fp, "OUT_MODE aln\n");
5626 fprintf ( fp, "PARAM1 --globalpair --maxiterate 1000 \n");
5627 fprintf ( fp, "IN_FLAG &bnsp\n");
5628 fprintf ( fp, "OUT_FLAG >\n");
5629 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5630 fprintf ( fp, "SEQ_TYPE S\n");
5631 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
5632 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
5635 sprintf (list[n][0], "mafftgins_msa");
5636 sprintf (list[n][1], "%s", vtmpnam(NULL));
5637 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5638 fprintf ( fp, "EXECUTABLE mafft\n");
5639 fprintf ( fp, "DOC Mafft [%s]\n", MAFFT_ADDRESS);
5640 fprintf ( fp, "ALN_MODE multiple\n");
5641 fprintf ( fp, "OUT_MODE aln\n");
5642 fprintf ( fp, "PARAM1 --globalpair --maxiterate 1000 \n");
5643 fprintf ( fp, "IN_FLAG &bnsp\n");
5644 fprintf ( fp, "OUT_FLAG >\n");
5645 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5646 fprintf ( fp, "SEQ_TYPE S\n");
5647 fprintf ( fp, "ADDRESS %s\n", MAFFT_ADDRESS);
5648 fprintf ( fp, "PROGRAM %s\n", MAFFT_4_TCOFFEE);
5651 sprintf (list[n][0], "dialigntx_pair");
5652 sprintf (list[n][1], "%s", vtmpnam(NULL));
5653 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5654 fprintf ( fp, "DOC dialign-tx [%s]\n", DIALIGNTX_ADDRESS);
5655 fprintf ( fp, "EXECUTABLE dialign-tx\n");
5656 fprintf ( fp, "ALN_MODE pairwise\n");
5657 fprintf ( fp, "OUT_MODE aln\n");
5658 if ( isdir (DIALIGNTX_DIR))
5659 fprintf ( fp, "PARAM1 %s \n", DIALIGNTX_DIR);
5661 fprintf ( fp, "PARAM1 %s \n", get_mcoffee_4_tcoffee());
5662 fprintf ( fp, "IN_FLAG &bnsp\n");
5663 fprintf ( fp, "OUT_FLAG &bnsp\n");
5664 fprintf ( fp, "PARAM >/dev/null&bnsp2>/dev/null\n");
5665 fprintf ( fp, "SEQ_TYPE S\n");
5666 fprintf ( fp, "ADDRESS %s\n", DIALIGNTX_ADDRESS);
5667 fprintf ( fp, "PROGRAM %s\n", DIALIGNTX_4_TCOFFEE);
5670 sprintf (list[n][0], "dialigntx_msa");
5671 sprintf (list[n][1], "%s", vtmpnam(NULL));
5672 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5673 fprintf ( fp, "DOC dialign-tx [%s]\n", DIALIGNTX_ADDRESS);
5674 fprintf ( fp, "EXECUTABLE dialign-tx\n");
5675 fprintf ( fp, "ALN_MODE multiple\n");
5676 fprintf ( fp, "OUT_MODE aln\n");
5677 if ( isdir (DIALIGNTX_DIR))
5678 fprintf ( fp, "PARAM1 %s \n", DIALIGNTX_DIR);
5680 fprintf ( fp, "PARAM1 %s \n", get_mcoffee_4_tcoffee());
5681 fprintf ( fp, "IN_FLAG &bnsp\n");
5682 fprintf ( fp, "OUT_FLAG &bnsp\n");
5683 fprintf ( fp, "PARAM >/dev/null&bnsp2>/dev/null\n");
5684 fprintf ( fp, "SEQ_TYPE S\n");
5685 fprintf ( fp, "ADDRESS %s\n", DIALIGNTX_ADDRESS);
5686 fprintf ( fp, "PROGRAM %s\n", DIALIGNTX_4_TCOFFEE);
5689 sprintf (list[n][0], "dialignt_pair");
5690 sprintf (list[n][1], "%s", vtmpnam(NULL));
5691 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5692 fprintf ( fp, "DOC dialign-tx [%s]\n", DIALIGNT_ADDRESS);
5693 fprintf ( fp, "EXECUTABLE dialign-tx\n");
5694 fprintf ( fp, "ALN_MODE pairwise\n");
5695 fprintf ( fp, "OUT_MODE aln\n");
5696 if ( isdir (DIALIGNT_DIR))
5697 fprintf ( fp, "PARAM1 %s \n", DIALIGNT_DIR);
5699 fprintf ( fp, "PARAM1 %s \n", get_mcoffee_4_tcoffee());
5700 fprintf ( fp, "IN_FLAG &bnsp\n");
5701 fprintf ( fp, "OUT_FLAG &bnsp\n");
5702 fprintf ( fp, "PARAM >/dev/null&bnsp2>/dev/null\n");
5703 fprintf ( fp, "SEQ_TYPE S\n");
5704 fprintf ( fp, "ADDRESS %s\n", DIALIGNT_ADDRESS);
5705 fprintf ( fp, "PROGRAM %s\n", DIALIGNT_4_TCOFFEE);
5709 sprintf (list[n][0], "dialignt_msa");
5710 sprintf (list[n][1], "%s", vtmpnam(NULL));
5711 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5712 fprintf ( fp, "DOC dialign-tx [%s]\n", DIALIGNT_ADDRESS);
5713 fprintf ( fp, "EXECUTABLE dialign-tx\n");
5714 fprintf ( fp, "ALN_MODE multiple\n");
5715 fprintf ( fp, "OUT_MODE aln\n");
5716 if ( isdir (DIALIGNT_DIR))
5717 fprintf ( fp, "PARAM1 %s \n", DIALIGNT_DIR);
5719 fprintf ( fp, "PARAM1 %s \n", get_mcoffee_4_tcoffee());
5720 fprintf ( fp, "IN_FLAG &bnsp\n");
5721 fprintf ( fp, "OUT_FLAG &bnsp\n");
5722 fprintf ( fp, "PARAM >/dev/null&bnsp2>/dev/null\n");
5723 fprintf ( fp, "SEQ_TYPE S\n");
5724 fprintf ( fp, "ADDRESS %s\n", DIALIGNT_ADDRESS);
5725 fprintf ( fp, "PROGRAM %s\n", DIALIGNT_4_TCOFFEE);
5729 sprintf (list[n][0], "poa_pair");
5730 sprintf (list[n][1], "%s", vtmpnam(NULL));
5731 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5732 fprintf ( fp, "DOC Partial Order Graph Alignment [%s]\n", POA_ADDRESS);
5733 fprintf ( fp, "EXECUTABLE poa\n");
5734 fprintf ( fp, "ALN_MODE pairwise\n");
5735 fprintf ( fp, "OUT_MODE aln\n");
5736 fprintf ( fp, "PARAM1 -toupper \n");
5737 fprintf ( fp, "IN_FLAG -read_fasta&bnsp\n");
5738 fprintf ( fp, "OUT_FLAG -clustal&bnsp\n");
5739 if (file_exists (POA_DIR, POA_FILE1))
5740 fprintf ( fp, "PARAM %s/%s&bnsp2>/dev/null\n",POA_DIR,POA_FILE1);
5742 fprintf ( fp, "PARAM %s/%s&bnsp2>/dev/null\n", get_mcoffee_4_tcoffee(), POA_FILE1);
5743 fprintf ( fp, "SEQ_TYPE S\n");
5744 fprintf ( fp, "ADDRESS %s\n", POA_ADDRESS);
5745 fprintf ( fp, "PROGRAM %s\n",POA_4_TCOFFEE);
5749 sprintf (list[n][0], "poa_msa");
5750 sprintf (list[n][1], "%s", vtmpnam(NULL));
5751 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5752 fprintf ( fp, "DOC Partial Order Graph Alignment [%s]\n", POA_ADDRESS);
5753 fprintf ( fp, "EXECUTABLE poa\n");
5754 fprintf ( fp, "ALN_MODE multiple\n");
5755 fprintf ( fp, "OUT_MODE aln\n");
5756 fprintf ( fp, "PARAM1 -toupper \n");
5757 fprintf ( fp, "IN_FLAG -read_fasta&bnsp\n");
5758 fprintf ( fp, "OUT_FLAG -clustal&bnsp\n");
5759 if (file_exists (POA_DIR, POA_FILE1))
5760 fprintf ( fp, "PARAM %s/%s&bnsp2>/dev/null\n",POA_DIR,POA_FILE1);
5762 fprintf ( fp, "PARAM %s/%s&bnsp2>/dev/null\n", get_mcoffee_4_tcoffee(), POA_FILE1);
5763 fprintf ( fp, "SEQ_TYPE S\n");
5764 fprintf ( fp, "ADDRESS %s\n", POA_ADDRESS);
5765 fprintf ( fp, "PROGRAM %s\n",POA_4_TCOFFEE);
5768 sprintf (list[n][0], "probcons_pair");
5769 sprintf (list[n][1], "%s", vtmpnam(NULL));
5770 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5771 fprintf ( fp, "DOC probcons [%s]\n", PROBCONS_ADDRESS);
5772 fprintf ( fp, "ALN_MODE pairwise\n");
5773 fprintf ( fp, "OUT_MODE aln\n");
5774 fprintf ( fp, "IN_FLAG &bnsp\n");
5775 fprintf ( fp, "OUT_FLAG >\n");
5776 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5777 fprintf ( fp, "SEQ_TYPE S\n");
5778 if ( strm (retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))fprintf ( fp, "EXECUTABLE probconsRNA\n");
5779 else fprintf ( fp, "EXECUTABLE probcons\n");
5780 fprintf ( fp, "ADDRESS %s\n", PROBCONS_ADDRESS);
5781 fprintf ( fp, "PROGRAM %s\n",PROBCONS_4_TCOFFEE);
5784 sprintf (list[n][0], "probcons_msa");
5785 sprintf (list[n][1], "%s", vtmpnam(NULL));
5786 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5787 fprintf ( fp, "DOC probcons [%s]\n", PROBCONS_ADDRESS);
5788 fprintf ( fp, "ALN_MODE multiple\n");
5789 fprintf ( fp, "OUT_MODE aln\n");
5790 fprintf ( fp, "IN_FLAG &bnsp\n");
5791 fprintf ( fp, "OUT_FLAG >\n");
5792 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5793 fprintf ( fp, "SEQ_TYPE S\n");
5794 if ( strm (retrieve_seq_type(), "DNA") || strm (retrieve_seq_type(), "RNA"))fprintf ( fp, "EXECUTABLE probconsRNA\n");
5795 else fprintf ( fp, "EXECUTABLE probcons\n");
5796 fprintf ( fp, "ADDRESS %s\n", PROBCONS_ADDRESS);
5797 fprintf ( fp, "PROGRAM %s\n",PROBCONS_4_TCOFFEE);
5800 sprintf (list[n][0], "probconsRNA_pair");
5801 sprintf (list[n][1], "%s", vtmpnam(NULL));
5802 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5803 fprintf ( fp, "DOC probcons [%s]\n", PROBCONSRNA_ADDRESS);
5804 fprintf ( fp, "ALN_MODE pairwise\n");
5805 fprintf ( fp, "OUT_MODE aln\n");
5806 fprintf ( fp, "IN_FLAG &bnsp\n");
5807 fprintf ( fp, "OUT_FLAG >\n");
5808 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5809 fprintf ( fp, "SEQ_TYPE S\n");
5810 fprintf ( fp, "EXECUTABLE probconsRNA\n");
5811 fprintf ( fp, "ADDRESS %s\n", PROBCONSRNA_ADDRESS);
5812 fprintf ( fp, "PROGRAM %s\n",PROBCONSRNA_4_TCOFFEE);
5815 sprintf (list[n][0], "probconsRNA_msa");
5816 sprintf (list[n][1], "%s", vtmpnam(NULL));
5817 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5818 fprintf ( fp, "DOC probcons [%s]\n", PROBCONSRNA_ADDRESS);
5819 fprintf ( fp, "ALN_MODE multiple\n");
5820 fprintf ( fp, "OUT_MODE aln\n");
5821 fprintf ( fp, "IN_FLAG &bnsp\n");
5822 fprintf ( fp, "OUT_FLAG >\n");
5823 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5824 fprintf ( fp, "SEQ_TYPE S\n");
5825 fprintf ( fp, "EXECUTABLE probconsRNA\n");
5826 fprintf ( fp, "ADDRESS %s\n", PROBCONSRNA_ADDRESS);
5827 fprintf ( fp, "PROGRAM %s\n",PROBCONSRNA_4_TCOFFEE);
5830 sprintf (list[n][0], "muscle_pair");
5831 sprintf (list[n][1], "%s", vtmpnam(NULL));
5832 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5833 fprintf ( fp, "DOC Muscle [%s]\n", MUSCLE_ADDRESS);
5834 fprintf ( fp, "EXECUTABLE muscle\n");
5835 fprintf ( fp, "ALN_MODE pairwise\n");
5836 fprintf ( fp, "OUT_MODE aln\n");
5837 fprintf ( fp, "IN_FLAG -in&bnsp\n");
5838 fprintf ( fp, "OUT_FLAG -out&bnsp\n");
5839 fprintf ( fp, "PARAM -quiet&bnsp-maxmb&bnsp0&bnsp>/dev/null\n");
5840 fprintf ( fp, "SEQ_TYPE S\n");
5841 fprintf ( fp, "ADDRESS %s\n", MUSCLE_ADDRESS);
5842 fprintf ( fp, "PROGRAM %s\n", MUSCLE_4_TCOFFEE);
5845 sprintf (list[n][0], "muscle_msa");
5846 sprintf (list[n][1], "%s", vtmpnam(NULL));
5847 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5848 fprintf ( fp, "DOC Muscle [%s]\n", MUSCLE_ADDRESS);
5849 fprintf ( fp, "EXECUTABLE muscle\n");
5850 fprintf ( fp, "ALN_MODE multiple\n");
5851 fprintf ( fp, "OUT_MODE aln\n");
5852 fprintf ( fp, "IN_FLAG -in&bnsp\n");
5853 fprintf ( fp, "OUT_FLAG -out&bnsp\n");
5854 fprintf ( fp, "PARAM -quiet&bnsp-maxmb&bnsp0&bnsp>/dev/null\n");
5855 fprintf ( fp, "SEQ_TYPE S\n");
5856 fprintf ( fp, "ADDRESS %s\n", MUSCLE_ADDRESS);
5857 fprintf ( fp, "PROGRAM %s\n", MUSCLE_4_TCOFFEE);
5862 sprintf (list[n][0], "mus4_msa");
5863 sprintf (list[n][1], "%s", vtmpnam(NULL));
5864 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5865 fprintf ( fp, "DOC Muscle [%s]\n", MUS4_ADDRESS);
5866 fprintf ( fp, "EXECUTABLE mus4\n");
5867 fprintf ( fp, "ALN_MODE multiple\n");
5868 fprintf ( fp, "OUT_MODE aln\n");
5869 fprintf ( fp, "IN_FLAG --input&bnsp\n");
5870 fprintf ( fp, "OUT_FLAG --output&bnsp\n");
5871 fprintf ( fp, "SEQ_TYPE S\n");
5872 fprintf ( fp, "ADDRESS %s\n", MUS4_ADDRESS);
5873 fprintf ( fp, "PROGRAM %s\n", MUS4_4_TCOFFEE);
5876 sprintf (list[n][0], "mus4_pair");
5877 sprintf (list[n][1], "%s", vtmpnam(NULL));
5878 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5879 fprintf ( fp, "DOC Mus4 [%s]\n", MUS4_ADDRESS);
5880 fprintf ( fp, "EXECUTABLE mus4\n");
5881 fprintf ( fp, "ALN_MODE pairwise\n");
5882 fprintf ( fp, "OUT_MODE aln\n");
5883 fprintf ( fp, "IN_FLAG --input&bnsp\n");
5884 fprintf ( fp, "OUT_FLAG --output&bnsp\n");
5885 fprintf ( fp, "SEQ_TYPE S\n");
5886 fprintf ( fp, "ADDRESS %s\n", MUS4_ADDRESS);
5887 fprintf ( fp, "PROGRAM %s\n", MUS4_4_TCOFFEE);
5892 sprintf (list[n][0], "t_coffee_pair");
5893 sprintf (list[n][1], "%s", vtmpnam(NULL));
5894 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5895 fprintf ( fp, "EXECUTABLE t_coffee\n");
5896 fprintf ( fp, "DOC T-Coffee [%s]\n", TCOFFEE_ADDRESS);
5897 fprintf ( fp, "ALN_MODE pairwise\n");
5898 fprintf ( fp, "OUT_MODE aln\n");
5899 fprintf ( fp, "IN_FLAG -infile&bnsp\n");
5900 fprintf ( fp, "OUT_FLAG -outfile&bnsp\n");
5901 fprintf ( fp, "SEQ_TYPE S\n");
5902 fprintf ( fp, "ADDRESS %s\n", TCOFFEE_ADDRESS);
5903 fprintf ( fp, "PROGRAM %s\n", TCOFFEE_4_TCOFFEE);
5906 sprintf (list[n][0], "t_coffee_msa");
5907 sprintf (list[n][1], "%s", vtmpnam(NULL));
5908 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5909 fprintf ( fp, "EXECUTABLE t_coffee\n");
5910 fprintf ( fp, "DOC T-Coffee [%s]\n", TCOFFEE_ADDRESS);
5911 fprintf ( fp, "ALN_MODE multiple\n");
5912 fprintf ( fp, "OUT_MODE aln\n");
5913 fprintf ( fp, "IN_FLAG -infile&bnsp\n");
5914 fprintf ( fp, "OUT_FLAG -outfile&bnsp\n");
5915 fprintf ( fp, "SEQ_TYPE S\n");
5916 fprintf ( fp, "ADDRESS %s\n", TCOFFEE_ADDRESS);
5917 fprintf ( fp, "PROGRAM %s\n", TCOFFEE_4_TCOFFEE);
5920 sprintf (list[n][0], "pcma_pair");
5921 sprintf (list[n][1], "%s", vtmpnam(NULL));
5922 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5923 fprintf ( fp, "DOC PCMA [%s]\n", PCMA_ADDRESS);
5924 fprintf ( fp, "EXECUTABLE pcma\n");
5925 fprintf ( fp, "ALN_MODE pairwise\n");
5926 fprintf ( fp, "OUT_MODE aln\n");
5927 fprintf ( fp, "IN_FLAG -infile=\n");
5928 fprintf ( fp, "OUT_FLAG -outfile=\n");
5929 fprintf ( fp, "SEQ_TYPE S\n");
5930 fprintf ( fp, "ADDRESS %s\n", PCMA_ADDRESS);
5931 fprintf ( fp, "PROGRAM %s\n", PCMA_4_TCOFFEE);
5934 sprintf (list[n][0], "pcma_msa");
5935 sprintf (list[n][1], "%s", vtmpnam(NULL));
5936 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5937 fprintf ( fp, "DOC PCMA [%s]\n", PCMA_ADDRESS);
5938 fprintf ( fp, "EXECUTABLE pcma\n");
5939 fprintf ( fp, "ALN_MODE multiple\n");
5940 fprintf ( fp, "OUT_MODE aln\n");
5941 fprintf ( fp, "IN_FLAG -infile=\n");
5942 fprintf ( fp, "OUT_FLAG -outfile=\n");
5943 fprintf ( fp, "SEQ_TYPE S\n");
5944 fprintf ( fp, "ADDRESS %s\n", PCMA_ADDRESS);
5945 fprintf ( fp, "PROGRAM %s\n", PCMA_4_TCOFFEE);
5948 sprintf (list[n][0], "kalign_pair");
5949 sprintf (list[n][1], "%s", vtmpnam(NULL));
5950 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5951 fprintf ( fp, "EXECUTABLE kalign\n");
5952 fprintf ( fp, "DOC kalign [%s]\n", KALIGN_ADDRESS);
5953 fprintf ( fp, "ALN_MODE pairwise\n");
5954 fprintf ( fp, "OUT_MODE aln\n");
5955 fprintf ( fp, "IN_FLAG -i&bnsp\n");
5956 fprintf ( fp, "OUT_FLAG -o&bnsp\n");
5957 fprintf ( fp, "SEQ_TYPE S\n");
5958 fprintf ( fp, "ADDRESS %s\n", KALIGN_ADDRESS);
5959 fprintf ( fp, "PROGRAM %s\n", KALIGN_4_TCOFFEE);
5962 sprintf (list[n][0], "kalign_msa");
5963 sprintf (list[n][1], "%s", vtmpnam(NULL));
5964 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5965 fprintf ( fp, "EXECUTABLE kalign\n");
5966 fprintf ( fp, "DOC kalign [%s]\n", KALIGN_ADDRESS);
5967 fprintf ( fp, "ALN_MODE multiple\n");
5968 fprintf ( fp, "OUT_MODE aln\n");
5969 fprintf ( fp, "IN_FLAG -i&bnsp\n");
5970 fprintf ( fp, "OUT_FLAG -o&bnsp\n");
5971 fprintf ( fp, "SEQ_TYPE S\n");
5972 fprintf ( fp, "ADDRESS %s\n", KALIGN_ADDRESS);
5973 fprintf ( fp, "PROGRAM %s\n", KALIGN_4_TCOFFEE);
5976 sprintf (list[n][0], "amap_pair");
5977 sprintf (list[n][1], "%s", vtmpnam(NULL));
5978 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5979 fprintf ( fp, "EXECUTABLE amap\n");
5980 fprintf ( fp, "DOC amap [%s]\n", AMAP_ADDRESS);
5981 fprintf ( fp, "ALN_MODE pairwise\n");
5982 fprintf ( fp, "OUT_MODE aln\n");
5983 fprintf ( fp, "IN_FLAG &bnsp\n");
5984 fprintf ( fp, "OUT_FLAG >\n");
5985 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
5986 fprintf ( fp, "SEQ_TYPE S\n");
5987 fprintf ( fp, "ADDRESS %s\n", AMAP_ADDRESS);
5988 fprintf ( fp, "PROGRAM %s\n", AMAP_4_TCOFFEE);
5991 sprintf (list[n][0], "amap_msa");
5992 sprintf (list[n][1], "%s", vtmpnam(NULL));
5993 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
5994 fprintf ( fp, "EXECUTABLE amap\n");
5995 fprintf ( fp, "DOC amap [%s]\n", AMAP_ADDRESS);
5996 fprintf ( fp, "ALN_MODE multiple\n");
5997 fprintf ( fp, "OUT_MODE aln\n");
5998 fprintf ( fp, "IN_FLAG &bnsp\n");
5999 fprintf ( fp, "OUT_FLAG >\n");
6000 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6001 fprintf ( fp, "SEQ_TYPE S\n");
6002 fprintf ( fp, "ADDRESS %s\n", AMAP_ADDRESS);
6003 fprintf ( fp, "PROGRAM %s\n", AMAP_4_TCOFFEE);
6006 sprintf (list[n][0], "proda_pair");
6007 sprintf (list[n][1], "%s", vtmpnam(NULL));
6008 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6009 fprintf ( fp, "DOC proda [%s]\n", PRODA_ADDRESS);
6010 fprintf ( fp, "EXECUTABLE proda\n");
6011 fprintf ( fp, "ALN_MODE pairwise\n");
6012 fprintf ( fp, "OUT_MODE aln\n");
6013 fprintf ( fp, "IN_FLAG &bnsp\n");
6014 fprintf ( fp, "OUT_FLAG >\n");
6015 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6016 fprintf ( fp, "SEQ_TYPE S\n");
6017 fprintf ( fp, "ADDRESS %s\n", PRODA_ADDRESS);
6018 fprintf ( fp, "PROGRAM %s\n", PRODA_4_TCOFFEE);
6021 sprintf (list[n][0], "proda_msa");
6022 sprintf (list[n][1], "%s", vtmpnam(NULL));
6023 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6024 fprintf ( fp, "DOC proda [%s]\n", PRODA_ADDRESS);
6025 fprintf ( fp, "EXECUTABLE proda\n");
6026 fprintf ( fp, "ALN_MODE multiple\n");
6027 fprintf ( fp, "OUT_MODE aln\n");
6028 fprintf ( fp, "IN_FLAG &bnsp\n");
6029 fprintf ( fp, "OUT_FLAG >\n");
6030 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6031 fprintf ( fp, "SEQ_TYPE S\n");
6032 fprintf ( fp, "ADDRESS %s\n", PRODA_ADDRESS);
6033 fprintf ( fp, "PROGRAM %s\n", PRODA_4_TCOFFEE);
6036 sprintf (list[n][0], "prank_pair");
6037 sprintf (list[n][1], "%s", vtmpnam(NULL));
6038 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6039 fprintf ( fp, "DOC prank [%s]\n", PRANK_ADDRESS);
6040 fprintf ( fp, "EXECUTABLE tc_generic_method.pl\n");
6041 fprintf ( fp, "ALN_MODE pairwise\n");
6042 fprintf ( fp, "OUT_MODE aln\n");
6043 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());
6044 fprintf ( fp, "IN_FLAG -infile=\n");
6045 fprintf ( fp, "OUT_FLAG -outfile=\n");
6046 fprintf ( fp, "SEQ_TYPE S\n");
6047 fprintf ( fp, "ADDRESS %s\n", PRANK_ADDRESS);
6048 fprintf ( fp, "PROGRAM %s\n", PRANK_4_TCOFFEE);
6051 sprintf (list[n][0], "prank_msa");
6052 sprintf (list[n][1], "%s", vtmpnam(NULL));
6053 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6054 fprintf ( fp, "DOC prank [%s]\n", PRANK_ADDRESS);
6055 fprintf ( fp, "EXECUTABLE tc_generic_method.pl\n");
6056 fprintf ( fp, "ALN_MODE multiple\n");
6057 fprintf ( fp, "OUT_MODE aln\n");
6058 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());
6059 fprintf ( fp, "IN_FLAG -infile=\n");
6060 fprintf ( fp, "OUT_FLAG -outfile=\n");
6061 fprintf ( fp, "SEQ_TYPE S\n");
6062 fprintf ( fp, "ADDRESS %s\n", PRANK_ADDRESS);
6063 fprintf ( fp, "PROGRAM %s\n", PRANK_4_TCOFFEE);
6066 sprintf (list[n][0], "fsa_pair");
6067 sprintf (list[n][1], "%s", vtmpnam(NULL));
6068 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6069 fprintf ( fp, "DOC fsa [%s]\n", FSA_ADDRESS);
6070 fprintf ( fp, "EXECUTABLE fsa\n");
6071 fprintf ( fp, "ALN_MODE pairwise\n");
6072 fprintf ( fp, "OUT_MODE aln\n");
6073 fprintf ( fp, "IN_FLAG &bnsp\n");
6074 fprintf ( fp, "OUT_FLAG >\n");
6075 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6076 fprintf ( fp, "SEQ_TYPE S\n");
6077 fprintf ( fp, "ADDRESS %s\n", FSA_ADDRESS);
6078 fprintf ( fp, "PROGRAM %s\n", FSA_4_TCOFFEE);
6081 sprintf (list[n][0], "fsa_msa");
6082 sprintf (list[n][1], "%s", vtmpnam(NULL));
6083 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6084 fprintf ( fp, "DOC fsa [%s]\n", FSA_ADDRESS);
6085 fprintf ( fp, "EXECUTABLE fsa\n");
6086 fprintf ( fp, "ALN_MODE multiple\n");
6087 fprintf ( fp, "OUT_MODE aln\n");
6088 fprintf ( fp, "IN_FLAG &bnsp\n");
6089 fprintf ( fp, "OUT_FLAG >\n");
6090 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6091 fprintf ( fp, "SEQ_TYPE S\n");
6092 fprintf ( fp, "ADDRESS %s\n", FSA_ADDRESS);
6093 fprintf ( fp, "PROGRAM %s\n", FSA_4_TCOFFEE);
6096 sprintf (list[n][0], "tblastx_msa");
6097 sprintf (list[n][1], "%s", vtmpnam(NULL));
6098 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6099 fprintf ( fp, "DOC tblastx [%s]\n", NCBIBLAST_ADDRESS);
6100 fprintf ( fp, "EXECUTABLE tc_generic_method.pl\n");
6101 fprintf ( fp, "ALN_MODE multiple\n");
6102 fprintf ( fp, "PARAM -mode=tblastx_msa\n");
6103 fprintf ( fp, "OUT_MODE L\n");
6104 fprintf ( fp, "IN_FLAG -infile=\n");
6105 fprintf ( fp, "OUT_FLAG -outfile=\n");
6106 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6107 fprintf ( fp, "SEQ_TYPE S\n");
6108 fprintf ( fp, "ADDRESS %s\n", NCBIBLAST_ADDRESS);
6109 fprintf ( fp, "PROGRAM %s\n", NCBIBLAST_4_TCOFFEE);
6112 sprintf (list[n][0], "tblastpx_msa");
6113 sprintf (list[n][1], "%s", vtmpnam(NULL));
6114 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6115 fprintf ( fp, "DOC tblastpx [%s]\n", NCBIBLAST_ADDRESS);
6116 fprintf ( fp, "EXECUTABLE tc_generic_method.pl\n");
6117 fprintf ( fp, "ALN_MODE multiple\n");
6118 fprintf ( fp, "PARAM -mode=tblastpx_msa\n");
6119 fprintf ( fp, "OUT_MODE L\n");
6120 fprintf ( fp, "IN_FLAG -infile=\n");
6121 fprintf ( fp, "OUT_FLAG -outfile=\n");
6122 fprintf ( fp, "PARAM &bnsp2>/dev/null\n");
6123 fprintf ( fp, "SEQ_TYPE S\n");
6124 fprintf ( fp, "ADDRESS %s\n", NCBIBLAST_ADDRESS);
6125 fprintf ( fp, "PROGRAM %s\n", NCBIBLAST_4_TCOFFEE);
6131 sprintf (list[n][0], "em");
6132 sprintf (list[n][1], "%s", vtmpnam(NULL));
6134 if (method==NULL || lstrstr (method,"em@"))
6137 fp=vfopen (list[n-1][1], "w");
6141 l2=string2list2 ( method, "@");
6142 fprintf ( fp, "PARAM -method=%s -mode=seq_msa -tmpdir=%s\n",l2[2], get_tmp_4_tcoffee());
6143 fprintf ( fp, "ALN_MODE %s\n", l2[3]);
6146 fprintf ( fp, "EXECUTABLE tc_generic_method.pl\n");
6147 fprintf ( fp, "OUT_MODE aln\n");
6148 fprintf ( fp, "IN_FLAG -infile=\n");
6149 fprintf ( fp, "OUT_FLAG -outfile=\n");
6150 fprintf ( fp, "SEQ_TYPE S\n");
6151 fprintf ( fp, "ADDRESS %s\n", ADDRESS_BUILT_IN);
6152 fprintf ( fp, "PROGRAM %s\n", PROGRAM_BUILT_IN);
6156 sprintf (list[n][0], "consan_pair");
6157 sprintf (list[n][1], "%s", vtmpnam(NULL));
6158 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6159 fprintf ( fp, "DOC consan (sfold) RNA pairwise sequence aligner [%s]\n", CONSAN_ADDRESS);
6160 fprintf ( fp, "EXECUTABLE fasta_seq2consan_aln.pl \n");
6161 fprintf ( fp, "ALN_MODE pairwise\n");
6162 fprintf ( fp, "OUT_MODE aln\n");
6163 fprintf ( fp, "IN_FLAG -i&bnsp\n");
6164 fprintf ( fp, "OUT_FLAG -o&bnsp\n");
6165 fprintf ( fp, "PARAM -d&bnsp%s&bnsp2>/dev/null\n",get_mcoffee_4_tcoffee());
6166 fprintf ( fp, "SEQ_TYPE S\n");
6167 fprintf ( fp, "ADDRESS %s\n", CONSAN_ADDRESS);
6168 fprintf ( fp, "PROGRAM %s\n", CONSAN_4_TCOFFEE);
6171 sprintf (list[n][0], "RNAplfold");
6172 sprintf (list[n][1], "%s", vtmpnam(NULL));
6173 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6174 fprintf ( fp, "EXECUTABLE RNAplfold \n");
6175 fprintf ( fp, "ALN_MODE predict\n");
6176 fprintf ( fp, "SEQ_TYPE RNA\n");
6177 fprintf ( fp, "ADDRESS %s\n", RNAPLFOLD_ADDRESS);
6178 fprintf ( fp, "PROGRAM %s\n", RNAPLFOLD_4_TCOFFEE);
6181 sprintf (list[n][0], "HMMtop");
6182 sprintf (list[n][1], "%s", vtmpnam(NULL));
6183 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6184 fprintf ( fp, "EXECUTABLE HMMtop \n");
6185 fprintf ( fp, "ALN_MODE predict\n");
6186 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6187 fprintf ( fp, "ADDRESS %s\n", HMMTOP_ADDRESS);
6188 fprintf ( fp, "PROGRAM %s\n", HMMTOP_4_TCOFFEE);
6191 sprintf (list[n][0], "GOR4");
6192 sprintf (list[n][1], "%s", vtmpnam(NULL));
6193 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6194 fprintf ( fp, "EXECUTABLE GORIV \n");
6195 fprintf ( fp, "ALN_MODE predict\n");
6196 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6197 fprintf ( fp, "ADDRESS %s\n", GOR4_ADDRESS);
6198 fprintf ( fp, "PROGRAM %s\n", GOR4_4_TCOFFEE);
6201 sprintf (list[n][0], "wublast_client");
6202 sprintf (list[n][1], "%s", vtmpnam(NULL));
6203 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6204 fprintf ( fp, "EXECUTABLE wublast.pl \n");
6205 fprintf ( fp, "ALN_MODE predict\n");
6206 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6207 fprintf ( fp, "ADDRESS %s\n", EBIWUBLASTc_ADDRESS);
6208 fprintf ( fp, "PROGRAM %s\n", EBIWUBLASTc_4_TCOFFEE);
6211 sprintf (list[n][0], "blastpgp_client");
6212 sprintf (list[n][1], "%s", vtmpnam(NULL));
6213 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6214 fprintf ( fp, "EXECUTABLE blastpgp.pl \n");
6215 fprintf ( fp, "ALN_MODE predict\n");
6216 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6218 fprintf ( fp, "ADDRESS %s\n", EBIBLASTPGPc_ADDRESS);
6219 fprintf ( fp, "PROGRAM %s\n", EBIBLASTPGPc_4_TCOFFEE);
6222 sprintf (list[n][0], "ncbi_netblast");
6223 sprintf (list[n][1], "%s", vtmpnam(NULL));
6224 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6225 fprintf ( fp, "EXECUTABLE blastcl3 \n");
6226 fprintf ( fp, "ALN_MODE predict\n");
6227 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6229 fprintf ( fp, "ADDRESS %s\n", NCBIWEBBLAST_ADDRESS);
6230 fprintf ( fp, "PROGRAM %s\n", NCBIWEBBLAST_4_TCOFFEE);
6233 sprintf (list[n][0], "local_ncbiblast");
6234 sprintf (list[n][1], "%s", vtmpnam(NULL));
6235 n++;if (method==NULL || strm (method, list[n-1][0])){fp=vfopen (list[n-1][1], "w");
6236 fprintf ( fp, "EXECUTABLE blastall \n");
6237 fprintf ( fp, "ALN_MODE predict\n");
6238 fprintf ( fp, "SEQ_TYPE PROTEIN\n");
6240 fprintf ( fp, "ADDRESS %s\n", NCBIBLAST_ADDRESS);
6241 fprintf ( fp, "PROGRAM %s\n", NCBIBLAST_4_TCOFFEE);
6249 /******************************COPYRIGHT NOTICE*******************************/
6250 /*© Centro de Regulacio Genomica */
6252 /*Cedric Notredame */
6253 /*Fri Feb 18 08:27:45 CET 2011 - Revision 596. */
6254 /*All rights reserved.*/
6255 /*This file is part of T-COFFEE.*/
6257 /* T-COFFEE is free software; you can redistribute it and/or modify*/
6258 /* it under the terms of the GNU General Public License as published by*/
6259 /* the Free Software Foundation; either version 2 of the License, or*/
6260 /* (at your option) any later version.*/
6262 /* T-COFFEE is distributed in the hope that it will be useful,*/
6263 /* but WITHOUT ANY WARRANTY; without even the implied warranty of*/
6264 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the*/
6265 /* GNU General Public License for more details.*/
6267 /* You should have received a copy of the GNU General Public License*/
6268 /* along with Foobar; if not, write to the Free Software*/
6269 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
6270 /*............................................... |*/
6271 /* If you need some more information*/
6272 /* cedric.notredame@europe.com*/
6273 /*............................................... |*/
6277 /******************************COPYRIGHT NOTICE*******************************/