/* BEGIN DEFUNCT */ obreak() { struct a { char *nsiz; }; register size_t n, d, ds; /* * set n to new data size */ n = btoc(((struct a *)u.u_ap)->nsiz) - ctos(u.u_tsize) * stoc(1); if (n < 0) n = 0; /* * since we can't pass a -ve argument for the difference to chksize, * if d is negative, make ds equal to the final value and clear d. * keep the real difference in n for later use in expand. */ ds = u.u_dsize; if ((n = d = clrnd(n - u.u_dsize)) < 0) { ds += d; d = 0; } if (ctob(ds + d) > u.u_rlimit[RLIMIT_DATA].rlim_cur) { u.u_error = ENOMEM; return; } if (chksize((u_int)u.u_tsize, (u_int)ds, (u_int)d, (u_int)u.u_ssize)) return; if (swpexpand(ds + d, u.u_ssize, &u.u_dmap, &u.u_smap) == 0) return; expand((int)n, 0); }
MStringS::MStringS(const char* string){ if(!string){ data=0; sz=0; return ; } int size=strlen(string); if (!size) {data=0; return ;} data=(short*)new char[size*2+2]; //MString ret; ret.Reserv(size); for(int i=0; i<size; i++) data[i]=ctos(string[i]); sz=size; data[sz]=0; }
void squareImageLabel::removeHashSquare(const pixel& p) { // (pixels identify on coordinates, not colors) if (hashSquares_.removeOne(p)) { hashSquaresToBeRemoved_.push_back(p); --lastHashDrawn_; } else { qWarning() << "Pixel not found on remove" << hashSquares_.size() << p.x() << p.y() << ctos(p.color()); } }
/* Affichage des constantes d'un L-System donne */ String dispConstants(String constants) { int i=0; String strLsystem = (String)malloc(50*sizeof(char)); strcpy (strLsystem,""); strcat(strLsystem,"Constants: {"); for(i=0;i<(int)strlen(constants);i++){ strcat(strLsystem,ctos(constants[i])); if (i!=(int)strlen(constants)-1) strcat(strLsystem,","); } strcat(strLsystem,"}\n"); return strLsystem; }
/* Affichage des variables de l'alphabet d'un L-System donne */ String dispVariables(String variables) { int i = 0; String strLsystem = (String)malloc(50*sizeof(char)); strcpy (strLsystem,""); strcat(strLsystem,"Variables: {"); for(i=0;i<(int)strlen(variables);i++){ strcat(strLsystem,ctos(variables[i])); if (i!=(int)strlen(variables)-1) strcat(strLsystem,","); } strcat(strLsystem,"}\n"); return strLsystem; }
/* Affichage des regles correspondantes a chacune des variables d'un L-System donne */ String dispRules (Rules* teteliste, String variables) { String str = (String)malloc(200*sizeof(char)); strcpy (str,""); Rules* l = teteliste; double i=0; while (l!=NULL) { str = strcat(str,"( "); str = strcat(str,ctos(variables[(int)i])); str = strcat(str," -> "); str = strcat(str,l->rule); str = strcat(str," ) "); i = i+1; l = l->next; } return str; }
/* Renvoi de la generation suivante d'une generation donnee pour un L-System donne */ String nextGen(String generation, Lsystem lsystem) { String generation2=(String)malloc((double)strlen(generation)*sizeof(char)); strcpy (generation2,""); double i = 0; double lenghtTot = (double)strlen(generation); while (i<(double)strlen(generation)){ int nbVar = isVariable(generation[(int)i],lsystem); if (nbVar==-1) strcat(generation2,ctos(generation[(int)i])); else { int j; Rules* l = lsystem.rules; for (j=0;j<nbVar;j++){ l = l->next; } lenghtTot = lenghtTot+(double)strlen(l->rule); generation2 = (String)realloc(generation2,lenghtTot*sizeof(char)); strcat(generation2,l->rule); } i = i+1; } return generation2; }
double maxlike(int nbseq, char** seq, char** seqname, char* c_tree, options opt, char* ctree1, char* ctree2){ int i, j, k, l, ii, nbseq2, lgseq, lgsite, *drapeau, *drapeau2, cont=0, tree_is_rooted, nbparam, nbvrai, nbcompute, bl; char **orderedseq, racine, *site; double *lgbi, *lgbp, *weight, lkh, maxlkh=-1.e100, prov, rem_titv, rem_root, *freq; static int nbtree=0; FILE* outfile; /* printmemory("deb maxlike"); */ gamma_nbcl=opt->init->GAMMA_NCL; /* READ TREE, GET NB OF TAXA */ s_tree=(tree*)check_alloc(1, sizeof(tree)); lgseq=(int)strlen(seq[0]); s_tree->alivebr=(int*)check_alloc(2*nbseq, sizeof(int)); s_tree->node=ctos(c_tree, &nbseq2, &tree_is_rooted); if(strchr(c_tree, ':')) bl=1; else bl=0; if (nbseq2>nbseq) { printf("More taxa in tree file than in sequence file\n"); exit(EXIT_FAILURE); } /* ALLOCATE AND INIT S_TREE */ s_tree->nbseq=nbseq=nbseq2; s_tree->seq=seq; s_tree->names=seqname; s_tree->listgc=(double*)check_alloc(2*nbseq, sizeof(double)); s_tree->listbr=(branche*)check_alloc(2*nbseq, sizeof(branche)); s_tree->lgbr_init=(double*)check_alloc(2*nbseq-3, sizeof(double)); for(i=0;i<2*nbseq-2;i++){ s_tree->listbr[i]=(struct branche*)check_alloc(1, sizeof(struct branche)); } makelistbr_unrooted(NULL, s_tree->node[0], s_tree->listbr, s_tree->alivebr, 2*nbseq-3); for(i=0;i<2*nbseq-3;i++) s_tree->lgbr_init[i]=s_tree->listbr[i]->length; for(ii=0;ii<2*nbseq-3;ii++) s_tree->alivebr[ii]=1; s_tree->nbalivebr=0; for(i=0;i<2*nbseq-3;i++) s_tree->nbalivebr+=s_tree->alivebr[i]; set_var_param(s_tree, opt->compute); nbparam=s_tree->nb_var_param; s_tree->classlike_s=(double**)check_alloc(gamma_nbcl, sizeof(double)); for(i=0;i<gamma_nbcl;i++) s_tree->classlike_s[i]=(double*)check_alloc(lgseq, sizeof(double)); s_tree->like_s=(double*)check_alloc(lgseq, sizeof(double)); s_tree->likeasrv_s=(double*)check_alloc(lgseq, sizeof(double)); s_tree->dlike_s=(double**)check_alloc(nbparam, sizeof(double*)); s_tree->dlikeasrv_s=(double**)check_alloc(nbparam, sizeof(double*)); for(i=0;i<nbparam;i++){ s_tree->dlike_s[i]=(double*)check_alloc(lgseq, sizeof(double)); s_tree->dlikeasrv_s[i]=(double*)check_alloc(lgseq, sizeof(double)); } s_tree->d2like_s=(double**)check_alloc(nbparam, sizeof(double*)); s_tree->d2likeasrv_s=(double**)check_alloc(nbparam, sizeof(double*)); for(i=0;i<nbparam;i++){ s_tree->d2like_s[i]=(double*)check_alloc(lgseq, sizeof(double)); s_tree->d2likeasrv_s[i]=(double*)check_alloc(lgseq, sizeof(double)); } s_tree->classdlike_s=(double***)check_alloc(gamma_nbcl, sizeof(double**)); s_tree->classd2like_s=(double***)check_alloc(gamma_nbcl, sizeof(double**)); for(i=0;i<gamma_nbcl;i++){ s_tree->classdlike_s[i]=(double**)check_alloc(nbparam, sizeof(double*)); s_tree->classd2like_s[i]=(double**)check_alloc(nbparam, sizeof(double*)); for(j=0;j<nbparam;j++){ s_tree->classdlike_s[i][j]=(double*)check_alloc(lgseq, sizeof(double)); s_tree->classd2like_s[i][j]=(double*)check_alloc(lgseq, sizeof(double)); } } s_tree->deriv=(double*)check_alloc(nbparam, sizeof(double)); s_tree->deriv2=(double*)check_alloc(nbparam, sizeof(double)); /* printmemory("fin tree alloc"); */ for(i=0;i<2*nbseq-2;i++) alloc_node(s_tree->node[i], lgseq, nbparam, nbseq, (i<nbseq), 0, gamma_nbcl); alloc_node(root, lgseq, nbparam, nbseq, 0, 0, gamma_nbcl); /* printmemory("fin node alloc"); */ /* INIT LIKELIHOOD AT TIPS */ for(i=0;i<nbseq;i++){ for(j=0;j<4;j++){ /* 4 patterns for tip nodes */ for(k=0;k<4;k++){ /* 4 possible states */ for(l=0;l<gamma_nbcl;l++){ if(j==k) s_tree->node[i]->x[l][j][k]=1.; else s_tree->node[i]->x[l][j][k]=0.; } } } } /* CHECK SEQUENCE FILE */ for(i=nbseq2;i<2*nbseq2-2;i++) sprintf(s_tree->node[i]->nom, "int%d", i-nbseq2+1); drapeau=(int*)check_alloc(nbseq, sizeof(int)); drapeau2=(int*)check_alloc(nbseq, sizeof(double)); for(i=0;i<nbseq2;i++) drapeau2[i]=0; orderedseq=check_alloc(MAXNSP, sizeof(char*)); for(i=0;i<nbseq2;i++){ for(j=0;j<nbseq;j++){ if(!drapeau[j] && strncmp(s_tree->node[i]->nom, seqname[j], MAXLNAME)==0){ drapeau[j]=drapeau2[i]=1; orderedseq[i]=seq[j]; break; } } if(drapeau2[i]==0){ printf("Taxon %s not found in sequence file.\n", s_tree->node[i]->nom); exit(EXIT_FAILURE); } } s_tree->nbseq=nbseq=nbseq2; /* SET "PATTERNS" (relationships between sites) */ s_tree->sitetopatt=check_alloc(lgseq, sizeof(int)); weight=(double*)check_alloc(lgseq, sizeof(double)); for(i=0;i<lgseq;i++) weight[i]=0.; site=(char*)check_alloc(nbseq, sizeof(char)); lgsite=0; for(i=0;i<lgseq;i++){ cont=0; for(j=0;j<nbseq;j++) site[j]=orderedseq[j][i]; for(k=0;k<lgsite;k++){ if(samesite(site, s_tree, k)){ weight[k]++; cont=1; break; } } if(cont){ s_tree->sitetopatt[i]=k; continue; } for(j=0;j<nbseq;j++) s_tree->node[j]->seq[lgsite]=site[j]; weight[lgsite]=1.; s_tree->sitetopatt[i]=lgsite; lgsite++; } free(drapeau); free(drapeau2); free(site); s_tree->lgseq=lgsite; s_tree->weight=weight; s_tree->weightsum=lgseq; /* printf("%d species, %d sites, %d patterns\n", nbseq, lgseq, lgsite);*/ /* AMMEND INPUT */ /* ts/tv */ rem_titv=opt->init->INIT_TITV; if(opt->init->INIT_TITV<=0.){ freq=(double*)check_alloc(16, sizeof(double)); opt->init->INIT_TITV=0.; nbvrai=nbseq*(nbseq-1)/2; for(i=0;i<nbseq;i++){ for(j=i+1;j<nbseq;j++){ prov=alsurbet_kim(seq[i], seq[j], freq); if(prov<-0.5) nbvrai--; else opt->init->INIT_TITV+=prov; } } free(freq); opt->init->INIT_TITV/=nbvrai; } /* root */ rem_root=opt->init->INIT_ROOT; if(opt->init->INIT_ROOT<=0.){ opt->init->INIT_ROOT=root->l1/(root->l1+root->l2); if(!bl) opt->init->INIT_ROOT=0.5; } /* branch lengths */ s_tree->dist=(double**)check_alloc(nbseq, sizeof(double*)); for(i=0;i<nbseq;i++) s_tree->dist[i]=(double*)check_alloc(nbseq, sizeof(double)); if(strcmp(opt->init->INIT_LENGTH, "REDO")==0){ for(i=0;i<nbseq;i++){ for(j=i;j<nbseq;j++){ if(i==j) s_tree->dist[i][j]=0.; else s_tree->dist[i][j]=s_tree->dist[j][i]=gg95(seq[i], seq[j], opt->init->INIT_TITV); } } } /* ROOT TREE AND ORGANIZE */ organize_tree(NULL, root); organize_listbr(s_tree); setpattern(s_tree); for(ii=0;ii<2*nbseq-3;ii++) setunderlyingbr(root, s_tree->listbr[ii], ii); setunderlyinggc(root, s_tree->nbseq); set_numerobr(root, s_tree->listbr, 2*nbseq-3); for(i=0;i<nbseq;i++){ s_tree->node[i]->alive1=0; s_tree->node[i]->alive2=0; s_tree->node[i]->alive3=1; } for(i=nbseq;i<2*nbseq-2;i++){ s_tree->node[i]->alive1=1; s_tree->node[i]->alive2=1; s_tree->node[i]->alive3=1; } root->alive1=root->alive2=1; root->alive3=-1; for(ii=0;ii<2*nbseq-3;ii++) s_tree->alivebr[ii]=1; /* CALL COMPUTE */ if(opt->init->NBRANDOM>0) nbcompute=opt->init->NBRANDOM; else nbcompute=1; for(l=0;l<nbcompute;l++){ lkh=compute(s_tree, opt->init, opt->compute, opt->converge, opt->print); if(lkh>maxlkh) maxlkh=lkh; if(!opt->print->PRINT1 && !opt->print->PRINT2) printf("%f\n", lkh); } if(ctree1) stoc(s_tree->node, nbseq, 1, ctree1, 0); if(ctree2) stoc(s_tree->node, nbseq, 1, ctree2, 1); if(opt->print->EVAL_OUT){ outfile=fopen("detailed_out", "a"); nbtree++; fprintf(outfile, "%d\t%s\t%f\t%f\t%f\t%f\t%f\t%f\n", nbtree, ctree1, maxlkh, s_tree->titv, s_tree->GCanc, s_tree->gamma_shp, s_tree->covar, s_tree->pi); fclose(outfile); } opt->init->INIT_TITV=rem_titv; opt->init->INIT_ROOT=rem_root; /* FREE */ free_tree(s_tree, gamma_nbcl); free(s_tree); free_node(root, lgseq, nbparam, 0, gamma_nbcl); free(orderedseq); return maxlkh; }