Exemple #1
0
// functie care returneaza produsul cu pret minim dintr-o categorie din lista de categorii
produs* minim(categorii* c, char* nume)
{
	if (c->curenta != NULL && strcmp(c->curenta->nume, nume) == 0)
	{
		return minim(c->curenta);
	}
	if (c->urmatoarea != NULL)
	{
		return minim(c->urmatoarea, nume);
	}
	return NULL;
}
Exemple #2
0
void minimize_ipf(density_t *ndft){
  int optimization_algorithm;

  optimization_algorithm = 2; parse_int ("optimization_algorithm", &optimization_algorithm);
  gradient_free_mode = 1;     parse_int ("gradient_free_mode", &gradient_free_mode);
  epsilon_grad = 1.0e-3;      parse_double ("epsilon_grad", &epsilon_grad);
  epsilon_gvalue = 1.0e-8;    parse_double ("epsilon_gvalue", &epsilon_gvalue);
  minim_maxiter = 100;        parse_int ("minim_maxiter", &minim_maxiter);

 switch(optimization_algorithm){
  case GRADIENT_BASED :
    minim(ndft);
    break;
  case NLOPT :
#if defined(HAVE_NLOPT) || defined(HAVE_BAYES)
    minim_nlopt(ndft);
#else
    messages_basic("Compiled without nlopt support. Change optimization_algorithm");
    parallel_end(EXIT_FAILURE);
#endif
    break;
  case BAYES :
#if defined(HAVE_BAYES)
    minim_bayes(ndft);
#else
    messages_basic("Compiled without bayesopt support. Change optimization_algorithm");
    parallel_end(EXIT_FAILURE);
#endif
    break;
  default :
    minimd(ndft);
    break;
  }

}
Exemple #3
0
// functie care afla minimul global dintr-o categorie si site-ul in care se gaseste
produs* minim(siteuri* s, char* nume)
{
	if (s != NULL && s->curent != NULL)
	{
		if (s->urmatorul != NULL)
		{
			return minim(minim(s->curent->lista_categorii, nume), minim(s->urmatorul, nume), s->curent, s->urmatorul->curent);
		}
		else
		{
			siteul_cerut = s->curent;
			return minim(s->curent->lista_categorii, nume);
		}
	}
	else
	{
		return NULL;
	}
}
Exemple #4
0
//afisarea minimului
void afiseaza_minimul(siteuri* s, char* nume,char *pr_st)
{
	produs* p = minim(s, nume);
	if (p != NULL)
	{
		strcpy(pr_st, "Site: ");
		strcat(pr_st, siteul_cerut->nume);
		strcat(pr_st, "\r\nProdus: ");
		strcat(pr_st, p->nume);
	}
}
Exemple #5
0
int main()
{  
	 
	///lectura de imagen
	char carName[50];
	printf("\n Introduzca el nombre de la imagen extension *BMP (ej:lena.bmp) : \n");
	scanf("%s", carName);

	IMAGE *img;
	//el formato de entrada de la imagen es nombre.extención, para este caso solo lee imagenes BMP.
	loadBMP(carName, &img);//el formato de entrada de la imagen es nombre.extención, para este caso solo lee imagenes BMP.
	//variables de entrada a la funcion
	uint8_t Rpixel;
	uint8_t Bpixel;
	uint8_t Gpixel;
	uint8_t maxi;
	uint8_t mini;
	float filtro;
	float H;
	float sat;
	int i;
	float *x;
	

	//recorriendo la imagen
	for (i = 0; i < img->width*img->height; i++) {
		Rpixel=(uint8_t)img->data[i].r;
		Bpixel=(uint8_t)img->data[i].b;
		Gpixel=(uint8_t)img->data[i].g;

		// se definen las funciones max y min para el calculo de los canales hsv
		maxi = (uint8_t)maxim(Rpixel, Gpixel, Bpixel);
		mini = (uint8_t)minim(Rpixel, Gpixel, Bpixel);
		sat = Saturacion(maxi, mini);//calculo de la saturacion del pixel
		H =Color(maxi,mini,Rpixel, Gpixel, Bpixel);//calculando canal de color H
		filtro=FiltroExperimental(H,sat,(float)(maxi)/255);//definiendo filtro multiplicador de color

		//retornando de hsv a rgb
		x=ConvHsvRgb(filtro*H,sat,(float)(maxi)/(255));

		//salida a imagen 
		img->data[i].r = x[1];
		img->data[i].g = x[2];
		img->data[i].b = x[3];
		}
	

	writeBMP("img.bmp", img); //guardado de imagen
	freeBMP(img);// libera memoria de la imagen.
	free(img);
	return 0;
}
Exemple #6
0
tree *succ(tree *x) {
    tree *y;
    if (x->right != NULL)
        return minim(x->right);
    else {
        y = x->parent;
        while (y != NULL && (x == y->right)) {
            x = y;
            y = y->parent;
        }
    }
    return y;
}
Arb minim(Arb arb)
{
	if (arb==NULL)
		{
			printf("arborele e vid");
		}
	else
	{
		if ((*arb).st==NULL)
			return arb;
		else
			return minim((*arb).st);
	}
}
Arb sterge(Arb *arb,int x)
{
	Arb tmp;
	tmp=(Nod*)malloc(sizeof(Nod));
	if ((*arb)==NULL)
	{
		//printf("Nodul nu a fost gasit");
	}
	else
	{
		if ((**arb).val>x)
		{
			(**arb).st=sterge(&((**arb).st),x);
		}
		else
		{
			if ((**arb).val<x)
				{
					(**arb).dr=sterge(&((**arb).dr),x);
				}
			else
			{
				//am gasit elementul.o luam pe cele3 cazuri
				if (((**arb).st!=NULL)&&((**arb).dr!=NULL))
				{
					tmp=minim((**arb).dr);
					(**arb).val=(*tmp).val;
					(**arb).dr=sterge(&((**arb).dr),x);//la o recitire nu am inteles linia asta de cod..s-ar putea sa trebuiasca sa ramana doar ce e dupa egal.
					
				}
				else
				{
					tmp=(*arb);
					if ((**arb).st!=NULL)
						(*arb)=(**arb).st;
					else
						(*arb)=(**arb).dr;
				free(tmp);
				}
				
			}
		}
	}
return (*arb);
}
Exemple #9
0
tree * search_tree(tree *l, int x) {

    /*if (l->left == NULL)
     m = 0;
     else
     m = (l->left->count) + 1;
     if (x == (m + 1))
     return l;
     else
     if (x > (m + 1))
     return search_tree(l->right, x - m - 1);
     else
     return search_tree(l->left, x);
     */
    tree *y = minim(l);
    int counter = 0;
    while (counter != x) {
        y = succ(y);
        counter++;
    }
    return y;
}
Exemple #10
0
void CybOBB::buildOBB(CybVector3D<double>* covMatrix, cybMesh<cybSurfaceTriTraits>* mesh)
{
	//Calculating the eigen vectors and the eigen values of the covariance matrix.
	//The eigen vectors will be the OBB's orienting vectors.
	CybVector3D<double> eigenVectors[3];
	double eigenValues[3];
	calculateEigenSystem(covMatrix, eigenValues, eigenVectors);
	
	//Organizing the orientation matrix
	for(int j = 0; j < 3; ++j)
	{
		for(int i = 0; i < 3; ++i)
		{
			orientation[j][i] = covMatrix[i][j];
		}
		orientation[j].normalize();
	}

	//Calculating the maximum and minimum values on each axis, projecting onto the orientation vectors.
	CybVector3D<double> minim(1e10, 1e10, 1e10), maxim(-1e10, -1e10, -1e10);
	CybVector3D<double> p_prime(0,0,0);
	CybVector3D<double> aux(0,0,0);
	int qttPoints = mesh->getNumberOfVertices();
	sVertex* cPoint; //current point
	for(int i = 0; i < qttPoints; ++i)
	{
		cPoint = mesh->getVertex(i);
		aux(cPoint->getCoord(0), cPoint->getCoord(1), cPoint->getCoord(2));
		p_prime(orientation[0] ^ aux, orientation[1] ^ aux, orientation[2] ^ aux);
		minim = minim.min(p_prime);
		maxim = maxim.max(p_prime);
	}
	
	//Cálculo do centro (ponto médio dos eixos) e dos semi-eixos.
	CybVector3D<double> cAux = (maxim + minim) * 0.5;
	center(orientation[0] ^ cAux, orientation[1] ^ cAux, orientation[2] ^ cAux);
	sizes = (maxim - minim) * 0.5;
}
Exemple #11
0
int maxim(int ** maze,node state,int alpha,int beta, int depth,int* dir){
	if(gameover(state) || depth>DEP)
		return (gain(state)-DEEPCONST*2*depth);
	int bestmove=-INF;
	node temp;int direction;
	if(maze[state.x1+1][state.y1]!=-1){
		copy(&temp,&state);
		temp.x1++;
		if(maze[state.x1+1][state.y1]>0){
			temp.bonus[label[state.x1+1][state.y1]]=0;
			temp.s1+=labelvalue[label[state.x1+1][state.y1]];
		}
			
		int tmp=minim(maze,temp,alpha,beta,depth,&direction);
		//if(depth==0)
		//printf("%d %d %d \n",tmp,state.x1+1,state.y1);
		if(tmp>bestmove){
			bestmove=tmp;
			*dir=1;
			if(bestmove>alpha)
				alpha=bestmove;
		}
		if(alpha>beta)
			return bestmove;
	} 


	if(maze[state.x1][state.y1-1]!=-1){
		copy(&temp,&state);
		temp.y1--;
		if(maze[state.x1][state.y1-1]>0){
			temp.bonus[label[state.x1][state.y1-1]]=0;
			temp.s1+=labelvalue[label[state.x1][state.y1-1]];
		}
			
		int tmp=minim(maze,temp,alpha,beta,depth,&direction);
		//if(depth==0)
		//printf("%d %d %d \n",tmp,state.x1,state.y1-1);
		if(tmp>bestmove){
			bestmove=tmp;
			*dir=0;
			if(bestmove>alpha)
				alpha=bestmove;
		}
		if(alpha>beta)
			return bestmove;
	} 
	
	if(maze[state.x1][state.y1+1]!=-1){
		copy(&temp,&state);
		temp.y1++;
		if(maze[state.x1][state.y1+1]>0){
			temp.bonus[label[state.x1][state.y1+1]]=0;
			temp.s1+=labelvalue[label[state.x1][state.y1+1]];
		}
			
		int tmp=minim(maze,temp,alpha,beta,depth,&direction);
		//if(depth==0)
		//printf("%d %d %d \n",tmp,state.x1,state.y1+1);
		if(tmp>bestmove){
			bestmove=tmp;
			*dir=2;
			if(bestmove>alpha)
				alpha=bestmove;
		}
		if(alpha>beta)
			return bestmove;
	} 


	if(maze[state.x1-1][state.y1]!=-1){
		copy(&temp,&state);
		temp.x1--;
		if(maze[state.x1-1][state.y1]>0){
			temp.bonus[label[state.x1-1][state.y1]]=0;
			temp.s1+=labelvalue[label[state.x1-1][state.y1]];
		}
			
		int tmp=minim(maze,temp,alpha,beta,depth,&direction);
		//if(depth==0)		
		//printf("%d %d %d \n",tmp,state.x1-1,state.y1);
		if(tmp>bestmove){
			bestmove=tmp;
			*dir=3;
			if(bestmove>alpha)
				alpha=bestmove;
		}
		if(alpha>beta)
			return bestmove;
	} 

	return bestmove;
	
}
Exemple #12
0
int main(int argc, char *argv[])
{
  FILE *filelist;
  FILE *thisfile;
  FILE *outfile;
  gzFile reffile;
  char ss[4096],sss[4096],char_mask[256];
  long i;

  if(argc != 4)
  {
    printf("\n Usage %s genome_file annotation_file_list outfile\n",argv[0]);
    exit(1);
  }

  sprintf(ss,"%s",argv[3]);
  if((outfile=fopen(ss,"w"))==(FILE *)NULL)
  {
    printf("\n Can not open file %s\n",ss);
    exit(1);
  }

  long genome_size = (long)3500000000;
  char *genome_buffer;

  genome_buffer = (char *)malloc(sizeof(char)*(genome_size+1));
  if(!genome_buffer)
  {
    printf("\n Failed to allocate memory for the Genome Buffer \n");
    exit(1);
  }

  if((reffile=gzopen(argv[1],"r"))==(gzFile)NULL)
  {
  printf("\n Can not open file %s for reading\n",sss);
  exit(1);
  }

  printf("\n About to read genome \n\n");

  long g_temp = 0;
  if(genome_size < MAX_FILE_BUFFER)
    g_temp = gzread(reffile,(void *)genome_buffer,(unsigned int)sizeof(char)*genome_size);
  else
  {
    long count = 0;
    while(count < genome_size)
	{
	  int ttemp = minim((long)genome_size - count,MAX_FILE_BUFFER);
	  g_temp += gzread(reffile,(void *)&genome_buffer[count],ttemp);
	  count += ttemp;
	}
    }
  gzclose(reffile);
  genome_size = g_temp;
  printf("\n Genome Size is %ld \n",genome_size);

  // set all char's to the 4 or 'N' code except for ACTG or actg (see below)
  for(i=0;i<256;i++)
    char_mask[i] = 0;

  // set other characters to appropriate score
  char_mask['A'] = 1;
  char_mask['a'] = 1;
  char_mask['C'] = 2;
  char_mask['c'] = 2;
  char_mask['G'] = 3;
  char_mask['g'] = 3;
  char_mask['T'] = 4;
  char_mask['t'] = 4;

  // set genome buffer to appropriate code
  for(i=0;i<genome_size;i++)
    genome_buffer[i] = char_mask[(int)genome_buffer[i]];

  if( (filelist = fopen(argv[2],"r")) == (FILE *)NULL)
  {
    printf("\nCan't open %s for reading \n",argv[2]);
    exit(1);
  }
  else
  {
    printf("\nOpened %s for reading.\n", argv[2]);
  }

  fgets(sss,4095,filelist);
  int len = strlen(sss);

  /*
   * keep track of which codes have been used; zero out the range of acceptable
   * codes and just mark the ones that should be used as 1
   */
  int used[256];
  for(i=0;i<256;i++)
	 used[i]   = 0;

  /*
   * these are acceptable codes - recall powers of 2 allow bitwise or comparisons
   */
  used[8]   = 1;
  used[16]  = 1;
  used[32]  = 1;
  used[64]  = 1;
  used[128] = 1;

  while(len > 2)
  {
    char *token;
    token = strtok(sss," \n\t");
    if( (thisfile = fopen(token,"r")) == (FILE *)NULL)
    {
      printf("\nCan't open %s for reading.\n",token);
      exit(1);
    }
    else
    {
      printf("\nOpened %s for reading...", token);
    }
    fgets(sss,4095,thisfile);
    int this_add = (char)atoi(sss);
    char cadd;
    if( (this_add < 1) || (this_add > 255) )
    {
      printf("\n Found a mask of %d which is impossible [1...255 is possible range]. \n",this_add);
      exit(2);
    }
    if(used[this_add] != 1)
    {
  		printf("\n You gave a value of %d which is not a power of 2. \n",this_add);
    }
    
    // initially, I thought we'd only have one file per annotation type, but it
    // tunred out to make more sense that there are multiple files per site type
    // so turning off setting the 'used' flag.
    // used[this_add] = 0;
    cadd = (char) this_add;
    fgets(sss,4095,thisfile);
    int len2 = strlen(sss);
    while(len2 > 2)
    {
	    char *token2;
  	  long start, stop;
  	  token2 = strtok(sss," \n\t");
  	  start = atol(token2);
  	  if( (start < 0) || (start > genome_size))
  	  {
	      printf("\n ERROR: start: %ld is incompatable with genome size: %ld \n",
          start, genome_size);
	      exit(3);
	    }
  	  token2 = strtok(NULL," \n\n");
  	  stop = atol(token2);
      if( (stop < 0) || (stop > genome_size) )
      {
        printf("\n ERROR: start: %ld, stop: %ld incompatable with genome size: %ld \n",
          start, stop, genome_size);
        exit(3);
      }

      // transcripts coming from the negative strand need their start/stop flipped
      if ( stop < start )
      {
        long tmp = stop;
        stop = start;
        start = tmp;
      }
  	  for(i=start;i<=stop;i++)
  	    genome_buffer[i] = genome_buffer[i] | cadd;
  	  sss[0] = '\0';
  	  if(!feof(thisfile))
  	    fgets(sss,4095,thisfile);
  	  len2 = strlen(sss);
    }
    fclose(thisfile);
    printf(" done.\n");

    sss[0] = '\0';
    if(!feof(filelist))
      fgets(sss,4095,filelist);
    len = strlen(sss);
  }
  fwrite(genome_buffer,sizeof(char),genome_size,outfile);
  fclose(outfile);
  return 0;
}
Exemple #13
0
int main(int argc, char *argv[])
{ int    K=-1,KB=-1;
  char **Seqs;
  char **Names;
  char **SeqsB;
  char **NamesB;
  char *seqfilename=NULL,*dbfilename=NULL;
  int internalCompare=0; /* whether query and database sequences are the same */
  int *Profiles;
  int *ProfilesB=NULL;
  int ori;
  int first=1;
  FILE *seqfile=NULL, *dbfile=NULL;
  int *kmerCounts,*kmerIndex;
  int *len,*lenB;
  int *frontDiscount;
  int i,j;
  int maxlen=0;
  int minlen=40;
  int doTrimming=0;

  argc = AS_configure(argc, argv);

  { /* Parse the argument list using "man 3 getopt". */
    int ch,errflg=0;
    optarg = NULL;
    while (!errflg && ((ch = getopt(argc, argv, "fFg:hk:q:d:m:t")) != EOF))
      {
	switch(ch) {
	case 'f':
	  fullnames=1;
	  break;
	case 'F':
	  dbfullnames=1;
	  break;
	case 'g':
	  GRANULARITY = atoi(optarg);
	  assert(GRANULARITY>0&&GRANULARITY<500);
	  break;
	case 'h':
	  usage(argv[0]);
	  break;
	case 'q':
	  if(seqfile!=NULL)fclose(seqfile);
	  seqfile=fopen(optarg,"r");
	  assert(seqfile!=NULL);
	  seqfilename=optarg;
	  if(dbfile==NULL){
	    dbfile=fopen(optarg,"r");
	    assert(dbfile!=NULL);
	    dbfilename=optarg;
	  }
	  break;
	case 'd':
	  if(dbfile!=NULL){
	    fclose(dbfile);
	  }
	  dbfile=fopen(optarg,"r");
	  assert(dbfile!=NULL);
	  dbfilename=optarg;
	  break;
	case 'k':
	  ksize=atoi(optarg);
	  assert(ksize>0&&ksize<14);
	  break;
	case 'm':
	  minlen=atoi(optarg);
	  assert(minlen>=40&&minlen<1400);
	  break;
	case 't':
	  doTrimming=1;
	  fprintf(stderr,"Will trim to common range\n");
	  break;
	case '?':
	  errflg++;
	  usage(argv[0]);
	  break;
	default :
	  fprintf( stderr, "Unrecognized option -%c\n", optopt);
	  errflg++;
	  usage(argv[0]);
	}
      }
  }

  assert(seqfile!=NULL);
  assert(dbfile!=NULL);
  if(seqfilename==dbfilename || strcmp(seqfilename,dbfilename)==0){
    internalCompare=1;
  } else {
    internalCompare=0;
  }

  get_sequences(seqfile,&K,&Seqs,&Names);
  assert(K>=0);
  fprintf(stderr,"Read in %d query sequences\n",K+1);
  len = (int *)safe_malloc(sizeof(int)*(K+1));
  for(i=0;i<=K;i++){
    len[i]=strlen(Seqs[i]);
    if(maxlen<len[i]){
      maxlen=len[i];
    }
  }

  if(dbfullnames)fullnames=1;

  get_sequences(dbfile,&KB,&SeqsB,&NamesB);
  assert(KB>=0);
  fprintf(stderr,"Read in %d database sequences\n",KB+1);
  lenB = (int *)safe_malloc(sizeof(int)*(KB+1));
  frontDiscount = (int *)safe_malloc(sizeof(int)*(KB+1));
  for(i=0;i<=KB;i++){
    lenB[i]=strlen(SeqsB[i]);
    frontDiscount[i]=0;
  }

  for (i = 0; i < 128; i++){
    Map[i] = -1;
  }
  Map['a'] = Map['A'] = 0;
  Map['c'] = Map['C'] = 1;
  Map['g'] = Map['G'] = 2;
  Map['t'] = Map['T'] = 3;

  calc_kmer_members((const char **)SeqsB,ksize,&kmerCounts,&kmerIndex,KB+1);

  fprintf(stderr,"Built index\n");


  {
    int **hitCounts=NULL;

    hitCounts = (int **) safe_malloc(maxlen*sizeof(int*));

    for(j= 0; j<maxlen; j++){
      hitCounts[j] = (int *) safe_malloc((KB+1)*sizeof(int));
    }

    for (i = 0; i <= K; i++){
      int k;
      int kword = 0;
      int h = -ksize;
      int bestfront=-1, bestback=-1;
      int bestscore=-1,bestloc=-1;
      int bestsimple=-1,simplescore=-1;
      int ilen,ilenlessone;
      int startbestmatch=0;
      int endbestmatch = len[i]-1;

      ilen=len[i];
      ilenlessone=ilen-1;

      for(k=0;k<ksize;k++){
	for(j= 0; j<=KB; j++){
	  hitCounts[k][j] = 0;
	}
      }

      for(j=0;j<ksize-1;j++){
	int x = Map[(int) (Seqs[i][j])];
	if (x >= 0){
	  kword = (kword << 2) | x;
	}else{
	  kword <<= 2;
	  h = j-(ksize-1);
	}
      }


      while(Seqs[i][j]!='\0'){
	int x = Map[(int) (Seqs[i][j])];
	if (x >= 0){
	  kword = ((kword << 2) | x) & kmax;
	}else{
	  kword <<= 2;
	  h = j-(ksize-1);
	}
	for(k=0;k<=KB;k++){
	  hitCounts[j][k]=hitCounts[j-1][k];
	}
	if (j >= h+ksize){
	  for(k=kmerCounts[kword];k<kmerCounts[kword+1];k++){
	    if(internalCompare && kmerIndex[k]==i)continue;
	    if(k==kmerCounts[kword]||(kmerIndex[k]!=kmerIndex[k-1])){
	      hitCounts[j][kmerIndex[k]]++;
	    }
	  }
	}
	j++;
      }

      for( k=0;k<=KB;k++){
	if(hitCounts[ilenlessone][k]>simplescore){
	  simplescore = hitCounts[ilenlessone][k];
	  bestsimple=k;
	}
      }

      {
	ALNoverlap *ovl=NULL;
	double erate=0.02;
	// below, .9 fudge factor may be necessary to handle cases where some matching kmers are random out of order matches
	int minovl=simplescore *.9;
	while(erate<.4){
	  ovl = DP_Compare(Seqs[i], SeqsB[bestsimple],
                           -lenB[bestsimple]+minovl, len[i]-minovl,
                           strlen(Seqs[i]), strlen(SeqsB[bestsimple]),
                           0,
                           erate,
                           1e-6,
                           maxim(minlen,minovl),
                           AS_FIND_LOCAL_ALIGN_NO_TRACE);
	  if(ovl!=NULL)break;
	  erate*=2.;
	}
	if(ovl!=NULL){
	  if(ovl->begpos>0){
	    startbestmatch=ovl->begpos;
	  }
	  if(ovl->endpos<0){
	    endbestmatch=len[i]+ovl->endpos;
	    assert(endbestmatch>0);
	  }
	}
      }

      //      printf("startbestmatch init at %d\n",startbestmatch);
      //      printf("endbestmatch init at %d\n",endbestmatch);

      for(k=0;k<=KB;k++){
	frontDiscount[k]=hitCounts[startbestmatch+ksize-2][k];
      }


      for(j=startbestmatch+ksize-1;j<=endbestmatch;j+=GRANULARITY){
	int maxfront=-1;
	int maxback=-1;
	int whichfront=-1,whichback=-1;
	for(k=0;k<=KB;k++){
	  if(hitCounts[j][k]-frontDiscount[k]>maxfront){
	    maxfront=hitCounts[j][k]-frontDiscount[k];
	    whichfront=k;
	  }
	  if(hitCounts[endbestmatch][k]-hitCounts[j][k]>maxback){
	    maxback=hitCounts[endbestmatch][k]-hitCounts[j][k];
	    whichback=k;
	  }
	}
	if(maxfront+maxback>bestscore){
	  bestscore=maxfront+maxback;
	  bestfront=whichfront;
	  bestback=whichback;
	  bestloc=j;
#ifdef DEBUG_SEGMENTATION
	  fprintf(stderr,"New best %d: loc %d seqs %s / %s bestfront %d bestback %d\n",
		  bestscore,
		  bestloc,NamesB[bestfront],NamesB[bestback],bestfront,bestback);
#endif
	}
      }

      if(doTrimming){
	int frontstart=startbestmatch;
	int frontend=endbestmatch;

	int backstart=startbestmatch;
	int backend=endbestmatch;

	ALNoverlap *ovl=NULL;
	double erate=0.02;
	// below, .9 fudge factor may be necessary to handle cases where some matching kmers are random out of order matches
	int minovl=hitCounts[bestloc][bestfront]*.9;
	if(bestfront!=bestsimple){
	  while(erate<.4){
	    ovl = DP_Compare(Seqs[i], SeqsB[bestfront],
                             -lenB[bestfront]+minovl, len[i]-minovl,
                             strlen(Seqs[i]), strlen(SeqsB[bestfront]),
                             0,
                             erate,
                             1e-6,
                             maxim(minlen,minovl),
                             AS_FIND_LOCAL_ALIGN_NO_TRACE);
	    if(ovl!=NULL)break;
	    erate*=2.;
	  }
	  if(ovl!=NULL){
	    if( minim(frontend,len[i]+ovl->endpos) <= maxim(frontstart,ovl->begpos) ){
	      // complain
	      fprintf(stderr,
		      "trouble with overlap found at erate %f: ahang %d bhang %d => frontend %d <= frontstart %d\n"
		      ">Qseq\n%s\n>Dseq\n%s\n",
		      erate,
		      ovl->begpos, ovl->endpos, frontend, frontstart,Seqs[i],SeqsB[bestfront]);
	      // and do nothing!
	    } else {
	      // update
	      frontstart = maxim(frontstart,ovl->begpos);
	      frontend = minim(frontend,len[i]+ovl->endpos);
	    }
	  }
	}
	erate=0.02;
	// below, .9 fudge factor may be necessary to handle cases where some matching kmers are random out of order matches
	minovl=(hitCounts[ilenlessone][bestback]-hitCounts[bestloc][bestback])*.9;
	//	fprintf(stderr,"DEBUG: minovl = %d\n",hitCounts[ilenlessone][bestback]);
	ovl=NULL;
	if(bestback!=bestsimple){
	  //	  fprintf(stderr,"initial settings: backstart, backend to %d %d\n",backstart,backend);
	  while(erate<.4){
	    ovl = DP_Compare(Seqs[i], SeqsB[bestback],
                             -lenB[bestback], len[i],
                             strlen(Seqs[i]), strlen(SeqsB[bestback]),
                             0,
                             erate,
                             1e-6,
                             maxim(minlen,minovl),
                             AS_FIND_LOCAL_ALIGN_NO_TRACE);
	    //ovl = DP_Compare(Seqs[i],SeqsB[bestback],-lenB[bestback],len[i],0,erate,1e-6,40,AS_FIND_LOCAL_ALIGN_NO_TRACE);
	    if(ovl!=NULL)break;
	    erate*=2.;
	  }
	  if(ovl!=NULL){

	    if( minim(backend,len[i]+ovl->endpos) <= maxim(backstart,ovl->begpos) ){
	      // complain
	      fprintf(stderr,
		      "trouble with overlap found at erate %f: ahang %d bhang %d => backend %d <= backstart %d\n"
		      ">Qseq\n%s\n>Dseq\n%s\n",
		      erate,
		      ovl->begpos, ovl->endpos, backend, backstart,Seqs[i],SeqsB[bestback]);
	      // and do nothing
	    } else {
	      // update
	      backstart=maxim(backstart,ovl->begpos);
	      backend=minim(backend,len[i]+ovl->endpos);
	      //	      fprintf(stderr,"Updating backstart, backend to %d %d\n",backstart,backend);
	    }
	  }
	}

	// things are problematic if the overlap is to a region that doesn't come close to the implied breakpoint (bestloc);
	// however, partial sequence issues can make an absolute test fail, hence the constant 100 below:
	if(frontstart<bestloc+100&&frontend>bestloc-100){
	  startbestmatch= (startbestmatch > frontstart ? startbestmatch : frontstart);
	  endbestmatch= (endbestmatch < frontend ? endbestmatch : frontend);
	}
	if(backstart<bestloc+100&&backend>bestloc-100){
	  startbestmatch= (startbestmatch > backstart ? startbestmatch : backstart);
	  endbestmatch= (endbestmatch < backend ? endbestmatch : backend);
	}

	//	fprintf(stderr,"Final bestmatch start %d end %d\n",startbestmatch,endbestmatch);

	simplescore=hitCounts[endbestmatch][bestsimple]-hitCounts[startbestmatch+ksize-2][bestsimple];
	bestscore=
	  hitCounts[endbestmatch][bestback]-hitCounts[bestloc][bestback]+
	  hitCounts[bestloc][bestfront]-hitCounts[startbestmatch+ksize-2][bestfront];


      }

      //      printf("startbestmatch final at %d\n",startbestmatch);
      //      printf("endbestmatch final at %d\n",endbestmatch);

      assert(startbestmatch<=bestloc+100&&endbestmatch>bestloc-100);


      if(simplescore <= hitCounts[endbestmatch][bestfront]-hitCounts[startbestmatch+ksize-2][bestfront]){
	bestsimple=bestfront;
	simplescore=hitCounts[endbestmatch][bestfront]-hitCounts[startbestmatch+ksize-2][bestfront];
	//	fprintf(stderr,"Resetting best simple, presumably due to trimming (now bestfront)\n");
      }

      if( simplescore <= hitCounts[endbestmatch][bestback]-hitCounts[startbestmatch+ksize-2][bestback]){
	bestsimple=bestback;
	simplescore=hitCounts[endbestmatch][bestback]-hitCounts[startbestmatch+ksize-2][bestback];
	//	fprintf(stderr,"Resetting best simple, presumably due to trimming (now bestback)\n");
      }

      if(bestscore>simplescore){
	printf("%s (len=%d): best split = %d %s : %s (score = %d from %d to %d ; separately, scores = %d and %d; best single %s scores %d )\n",
	       Names[i],ilen,bestloc,NamesB[bestfront],NamesB[bestback],
	       bestscore,startbestmatch,endbestmatch,
	       hitCounts[endbestmatch][bestfront]-hitCounts[startbestmatch+ksize-2][bestfront],
	       hitCounts[endbestmatch][bestback]-hitCounts[startbestmatch+ksize-2][bestback],
	       NamesB[bestsimple],simplescore);
      } else {
	printf("%s (len=%d): best match = %s (from %d to %d, score = %d )\n",
	       Names[i],ilen,NamesB[bestsimple],startbestmatch,endbestmatch,simplescore);
      }

    }

  }

  return (0);
}
Exemple #14
0
template <class C, class I> C ABC<C, I>::minim(void) {
	return minim(&arrel);
}
Exemple #15
0
template <class C, class I> C ABC<C, I>::minim(Node **node) {
	if(*node == NULL) throw "minim: arbre buit";
	if((*node)->fesq != NULL) return minim(&(*node)->fesq);
	return (*node)->clau;
}
Exemple #16
0
// functie care returneaza produsul cu pret minim din categorie
produs* minim(categorie* c)
{
	return minim(c->produse);
}