Skip to content

Commit

Permalink
fixed an issue with libraries order. It had to do with the freeze fun…
Browse files Browse the repository at this point in the history
…ction that was out of sync with the ordered inserzion of the CL->entries
  • Loading branch information
cnotred committed Mar 28, 2023
1 parent cd06c91 commit 70d88dd
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 51 deletions.
17 changes: 3 additions & 14 deletions lib/dp_lib/util_dp_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,26 +556,15 @@ Constraint_list *method2pw_cl (TC_method *M, Constraint_list *CL)
PW_CL->get_dp_cost=slow_get_dp_cost;
PW_CL->evaluate_residue_pair=evaluate_matrix_score;
PW_CL->extend_jit=0;


if (get_string_variable ("fs_matrix"))sprintf (PW_CL->method_matrix,"%s",get_string_variable ("fs_matrix"));
else sprintf (PW_CL->method_matrix,"idmat");



if (int_variable_isset ("fs_gop") && get_int_variable("fs_gop")<0)
PW_CL->gop=get_int_variable("fs_gop");
else
PW_CL->gop= get_avg_matrix_mm (PW_CL->M, AA_ALPHABET)*10;

if (int_variable_isset ("fs_gep") && get_int_variable("fs_gep")<0)
PW_CL->gep=get_int_variable("fs_gep");
else
PW_CL->gep= -1;


}
else if ( strm (mode, "proba_pair"))
{

PW_CL->maximise=1;
PW_CL->TG_MODE=1;
PW_CL->use_fragments=0;
Expand Down
27 changes: 19 additions & 8 deletions lib/dp_lib/util_dp_suboptimal_nw.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ int suboptimal_pair_wise ( Alignment *A, int *ns, int **ls, Constraint_list *CL,
entry[R1]=i;entry[R2]=j;
entry[WE]=id;
entry[CONS]=1;

add_entry2list (entry,A->CL);
}
}
Expand Down Expand Up @@ -628,14 +628,15 @@ int proba_pair_wise ( Alignment *A, int *ns, int **ls, Constraint_list *CL)
static int TinsProb_ml, TmatchProb_ml;
int i, j,I, J;
float *F, *B;

int l;
float thr=0.01;//ProbCons Default
char *alphabet;


int do_reset=0;
//HERE ("DO reset must be replaced by a higher order reset");

//Free all the memory
if (A==NULL)
if (A==NULL || do_reset)
{
free_float (transMat, -1);transMat=NULL;
free_float (insProb, -1);insProb=NULL;
Expand All @@ -653,7 +654,7 @@ int proba_pair_wise ( Alignment *A, int *ns, int **ls, Constraint_list *CL)
forward_proba_pair_wise (NULL, NULL, 0,0,NULL,NULL,NULL,NULL,NULL);
backward_proba_pair_wise (NULL, NULL, 0,0,NULL,NULL,NULL,NULL,NULL);
ProbaMatrix2CL(NULL, NULL, NULL, 0, 0, NULL, NULL, 0, NULL);
return 0;
if (!do_reset || !A)return 0;
}

if (!transMat && (strm (retrieve_seq_type(), "DNA")))
Expand Down Expand Up @@ -1447,6 +1448,8 @@ Constraint_list *ProbaMatrix2CL (Alignment *A, int *ns, int **ls, int NumMatrixT
return NULL;
}



I=strlen (A->seq_al[ls[0][0]]);
J=strlen (A->seq_al[ls[1][0]]);

Expand Down Expand Up @@ -1485,21 +1488,29 @@ Constraint_list *ProbaMatrix2CL (Alignment *A, int *ns, int **ls, int NumMatrixT
if (v>0.01)old_n++;
}
}

sort_int_inv (list, 3, 2, 0, list_n-1);
if (!entry)entry=(int*)vcalloc ( CL->entry_len+1, CL->el_size);

list_n=MIN(list_n,(F*MIN(I,J)));
//list_n=MIN(list_n,(F*MIN(I,J)));



for (i=0; i<list_n; i++)
{
int x, y;

entry[SEQ1]=s1;
entry[SEQ2]=s2;
entry[R1] =list[i][0];
entry[R2] =list[i][1];
entry[WE] =list[i][2];
entry[CONS]=1;

add_entry2list (entry,A->CL);

}

tot_new+=list_n;
tot_old+=old_n;
// HERE ("LIB_SIZE NEW: %d (new) %d (old) [%.2f]", list_n, old_n, (float)tot_new/(float)tot_old);
Expand Down
17 changes: 9 additions & 8 deletions lib/t_coffee_lib/t_coffee.c
Original file line number Diff line number Diff line change
Expand Up @@ -5137,8 +5137,6 @@ get_cl_param(\
if ((CL->S)->nseq>1 && !do_convert)
{
CL=read_n_constraint_list (list_file,n_list,NULL, mem_mode,weight,type, le, CL, seq_source);

//CL=post_process_constraint_list (CL); //needed when constraints are added, for instance the RNA modes
}
else if ( do_convert && out_lib[0])
{
Expand All @@ -5151,12 +5149,12 @@ get_cl_param(\
CL=read_n_constraint_list (list_file,n_list,NULL, mem_mode,weight,type, le, CL, seq_source);
}
}

//This very important step insures the CL is symetrical
//This is essential for the remaining computation
//It should not be done before because some methods may not be symetrical for specific reasons
//And the CL may be used in different contexts
CL=CL2simCL (CL);


if ( CL->M)clean_aln=0;

Expand Down Expand Up @@ -5276,13 +5274,14 @@ get_cl_param(\

if (CL->ne>0 && out_lib[0]!='\0' && !strm (out_lib, "no"))
{

if (strstr (out_lib_mode, "extended"))
{
char emode[1000];
//Do the processing before saving the extended lib*/
processed_lib=1;

if ( filter_lib) CL=filter_constraint_list (CL,CL->weight_field, filter_lib);

for (a=0; a<relax_lib; a++)CL=relax_constraint_list (CL);
for (a=0; a<shrink_lib; a++)CL=shrink_constraint_list (CL);
sprintf ( emode, "lib_%s", out_lib_mode);
Expand Down Expand Up @@ -5316,11 +5315,13 @@ get_cl_param(\

if (!processed_lib)
{
if ( filter_lib) CL=filter_constraint_list (CL,CL->weight_field, filter_lib);
if (atoigetenv ("EXTEND4TC")==1)CL=extend_constraint_list(CL);

for (a=0; a<relax_lib; a++)CL=relax_constraint_list (CL);
for (a=0; a<shrink_lib; a++)CL=shrink_constraint_list (CL);
if ( filter_lib) CL=filter_constraint_list (CL,CL->weight_field, filter_lib);

if (atoigetenv ("EXTEND4TC")==1)CL=extend_constraint_list(CL);

for (a=0; a<relax_lib; a++)CL=relax_constraint_list (CL);
for (a=0; a<shrink_lib; a++)CL=shrink_constraint_list (CL);
}

CL=evaluate_constraint_list_reference (CL);
Expand Down
81 changes: 60 additions & 21 deletions lib/util_lib/util_constraints_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "dp_lib_header.h"

static int entry_len;

int dump2ne (char*file, int entry_len);
/**
* \file util_constraints_list.c
* All utilities for the Constraint_list.
Expand Down Expand Up @@ -60,7 +60,7 @@ Constraint_list *produce_list ( Constraint_list *CL, Sequence *S, char * metho
njob=queue2n(job)+1;

nproc=get_nproc();

HERE ("CL->multi_thread=%s", CL->multi_thread);
if (strstr ( CL->multi_thread, "jobcells"))return fork_cell_produce_list (CL, S, method, weight, mem_mode,job,nproc,local_stderr);
else if (strstr ( CL->multi_thread, "joblines"))return fork_line_produce_list (CL, S, method, weight, mem_mode,job, nproc,local_stderr);
else if (strstr ( CL->multi_thread, "jobs"))return fork_subset_produce_list (CL, S, method, weight, mem_mode,job, nproc,local_stderr); //Recommended default
Expand Down Expand Up @@ -143,6 +143,7 @@ Constraint_list *fork_subset_produce_list ( Constraint_list *CL, Sequence *S,
done=0;
while (job!=end)
{
//empty_constraint_list (CL);
if (a==0)output_completion ( local_stderr,done,todo,1, "Submit Job");
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 );

Expand Down Expand Up @@ -1278,12 +1279,32 @@ char *make_aln_command(TC_method *m, char *seq, char *aln)
/* */
/* */
/*********************************************************************/
Constraint_list * unfreeze_constraint_list (Constraint_list *CL)
Constraint_list * unfreeze_constraint_list_old (Constraint_list *CL)
{
free_int (CL->freeze, -1);
CL->freeze=NULL;
}
Constraint_list * unfreeze_constraint_list (Constraint_list *CL)
{
int s1, r1, b;
Sequence *S=CL->S;
for (s1=0; s1<S->nseq; s1++)
for (r1=1; r1<=S->len[s1]; r1++)
for (b=1; b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
CL->residue_index[s1][r1][b+MISC]=0;
return CL;
}
Constraint_list * freeze_constraint_list (Constraint_list *CL)
{
int s1, r1, b;
Sequence *S=CL->S;
for (s1=0; s1<S->nseq; s1++)
for (r1=1; r1<=S->len[s1]; r1++)
for (b=1; b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
CL->residue_index[s1][r1][b+MISC]=CL->residue_index[s1][r1][b+WE];
return CL;
}
Constraint_list * freeze_constraint_list_old (Constraint_list *CL)
{
int a, b, d=0;
Sequence *S=CL->S;
Expand Down Expand Up @@ -1320,13 +1341,26 @@ Constraint_list * empty_constraint_list (Constraint_list *CL)
CL->ne=0;
return CL;
}

int dump2ne (char*file, int entry_len)
{
int *entry, b, c, e, tot;
FILE *fp;
int count=0;
if (!file) return 0;
entry=(int*)vcalloc ( entry_len+1, sizeof (int));
fp=vfopen (file, "rb");
if (!fp) return 0;
while ((b=fread (entry, sizeof(int), entry_len, fp))==entry_len)count++;
vfree(entry);
vfclose (fp);
return count;
}
Constraint_list * undump_constraint_list (Constraint_list *CL, char *file)
{

int *entry, b, c, e, tot;
FILE *fp;

if (!CL || !CL->residue_index)return CL;
entry=(int*)vcalloc ( CL->entry_len+1, sizeof (int));

Expand Down Expand Up @@ -1372,7 +1406,7 @@ int safe_dump_constraint_list (Constraint_list *CL,char *file, char *mode, Seque
if (entry[R1]<=0)continue;

b=(CL->freeze)?CL->freeze[s1][r1]:1;
for (;b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
for (b=1;b<CL->residue_index[s1][r1][0]; b+=ICHUNK)
{
s2=CL->residue_index[s1][r1][b+SEQ2];
r2=CL->residue_index[s1][r1][b+R2];
Expand All @@ -1389,7 +1423,8 @@ int safe_dump_constraint_list (Constraint_list *CL,char *file, char *mode, Seque
entry[WE]=CL->residue_index[s1][r1][b+WE];
entry[CONS]=CL->residue_index[s1][r1][b+CONS];
entry[MISC]=CL->residue_index[s1][r1][b+MISC];
fwrite(entry, sizeof (int),CL->entry_len,fp);
if (entry[MISC]!=entry[WE])
fwrite(entry, sizeof (int),CL->entry_len,fp);
}
}
}
Expand Down Expand Up @@ -1745,8 +1780,11 @@ Constraint_list *add_entry2list( CLIST_TYPE *entry, Constraint_list *CL)
int r1=entry[R1];
int r2=entry[R2];

if (entry[INDEX])return add_entry2list2(entry, CL);

if (entry[INDEX])
{
return add_entry2list2(entry, CL);
}

entry[SEQ1]=s2;
entry[SEQ2]=s1;
entry[R1]=r2;
Expand Down Expand Up @@ -2169,12 +2207,7 @@ Constraint_list*reload_constraint_list (Constraint_list *CL)

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)
{


if (1==1 && !strstr (CL->multi_thread, "methods"))//deprecated
return fork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode,type,local_stderr, CL, seq_source, 1);
else
return fork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode,type,local_stderr, CL, seq_source, get_nproc());
return fork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode,type,local_stderr, CL, seq_source, get_nproc());
}


Expand Down Expand Up @@ -2226,19 +2259,20 @@ Constraint_list* fork_read_n_constraint_list(char **fname,int n_list, char *in_m
n_list=1;

return read_constraint_list (CL, fname[0], in_mode, mem_mode,weight_mode);
// return fork_read_n_constraint_list(fname,n_list, in_mode,mem_mode,weight_mode, type,local_stderr, CL, seq_source,1);

}

if (!CL)CL=declare_constraint_list ( S,NULL, NULL, 0,(strm(mem_mode, "disk"))?tmpfile():NULL, NULL);

if (CL->ne)
{

dump_constraint_list(CL,tmp_list[n_list], "w");
CL->ne=0;
}

CL->local_stderr=local_stderr;

fprintf ( local_stderr, "\n\tMulti Core Mode (read): %d processor(s):\n", nproc);
for (ns=0,a=0; a< n_list; a++)
{
Expand All @@ -2251,7 +2285,9 @@ Constraint_list* fork_read_n_constraint_list(char **fname,int n_list, char *in_m
initiate_vtmpnam (NULL);
CL->local_stderr=vfopen("/dev/null", "w");
in=CL->ne;

CL=read_constraint_list (CL, fname[a], in_mode, mem_mode,weight_mode);

if (CL->ne>in)dump_constraint_list(CL,tmp_list[a], "w");
myexit (EXIT_SUCCESS);
}
Expand All @@ -2264,6 +2300,7 @@ Constraint_list* fork_read_n_constraint_list(char **fname,int n_list, char *in_m
{
b=proclist[vwait(NULL)];
fprintf (local_stderr, "\n\txxx Retrieved %s",fname[a]);

if (tmp_list[b] && check_file_exists (tmp_list[b]))
{
CL=undump_constraint_list(CL,tmp_list[b]);
Expand All @@ -2280,8 +2317,9 @@ Constraint_list* fork_read_n_constraint_list(char **fname,int n_list, char *in_m
a=proclist[pid2];
fprintf (local_stderr, "\n\txxx Retrieved %s",fname[a]);
if (tmp_list[a] && check_file_exists (tmp_list[a]))
{
CL=undump_constraint_list (CL,tmp_list[a]);
{

CL=undump_constraint_list (CL,tmp_list[a]);
}
ns--;
}
Expand All @@ -2291,7 +2329,7 @@ Constraint_list* fork_read_n_constraint_list(char **fname,int n_list, char *in_m
{
CL=undump_constraint_list(CL,tmp_list[n_list]);
}

CL->local_stderr=local_stderr;

vfree (proclist);
Expand Down Expand Up @@ -2367,6 +2405,7 @@ Constraint_list* read_constraint_list(Constraint_list *CL,char *in_fname,char *i
{

CL=produce_list ( CL, CL->S, fname,weight_mode,mem_mode);

}
else if (strm(read_mode, "matrix"))
{
Expand Down Expand Up @@ -4365,8 +4404,8 @@ Constraint_list *merge_constraint_list ( Constraint_list *SL, Constraint_list
entry[SEQ1]=(cache)?cache[s1][0]:s1;
entry[R1]=(cache)?cache[s1][r1]:r1;
if (entry[R1]<=0)continue;
b=(SL->freeze)?SL->freeze[s1][r1]:1;
for (;b<SL->residue_index[s1][r1][0]; b+=ICHUNK)

for (b=1;b<SL->residue_index[s1][r1][0]; b+=ICHUNK)
{
s2=SL->residue_index[s1][r1][b+SEQ2];
r2=SL->residue_index[s1][r1][b+R2];
Expand Down

0 comments on commit 70d88dd

Please sign in to comment.