Пример #1
0
static int
Sort_Array(netsnmp_container *c)
{
    binary_array_table *t = (binary_array_table*)c->container_data;
    netsnmp_assert(t!=NULL);
    netsnmp_assert(c->compare!=NULL);

    if (c->flags & CONTAINER_KEY_UNSORTED)
        return 0;

    if (t->dirty) {
        /*
         * Sort the table 
         */
        if (t->count > 1)
            array_qsort(t->data, 0, t->count - 1, c->compare);
        t->dirty = 0;

        /*
         * no way to know if it actually changed... just assume so.
         */
        ++c->sync;
    }

    return 1;
}
Пример #2
0
static void
array_qsort(void **data, int first, int last, netsnmp_container_compare *f)
{
    int i, j;
    void *mid, *tmp;
    
    i = first;
    j = last;
    mid = data[(first+last)/2];
    
    do {
        while (i < last && (*f)(data[i], mid) < 0)
            ++i;
        while (j > first && (*f)(mid, data[j]) < 0)
            --j;

        if(i < j) {
            tmp = data[i];
            data[i] = data[j];
            data[j] = tmp;
            ++i;
            --j;
        }
        else if (i == j) {
            ++i;
            --j;
            break;
        }
    } while(i <= j);

    if (j > first)
        array_qsort(data, first, j, f);
    
    if (i < last)
        array_qsort(data, i, last, f);
}
Пример #3
0
int align_backbone (Descr *descr1, Protein * protein1, Representation *rep1, 
		    Descr *descr2, Protein * protein2, Representation *rep2, 
		    List_of_maps *list){
    
     if ( list->best_array_used == 0) return 1;
     
     int best_ctr, map_ctr, retval;
     int * new_best;
     double *bb_score_array;
     Map *current_map;


     if ( !(bb_score_array = emalloc(list->best_array_used*sizeof(double))))  return 1;    
     if ( !(new_best = emalloc(list->best_array_used*sizeof(int))))  return 1;    
 
     
     for (best_ctr=0; best_ctr<list->best_array_used; best_ctr++) {

	 map_ctr = list->map_best[best_ctr];
	 if ( map_ctr >= list->best_array_allocated) {
	     printf ("%s:%d error assigning array size.\n", __FILE__, __LINE__ );
	     exit (1);
	 }
	 current_map = list->map+map_ctr;
	 retval = single_map_align_backbone (descr1, protein1, rep1, descr2, protein2, rep2, current_map);
	 if (retval) {
	     printf (" error doing bb alignment   db:%s  query:%s \n",
		     descr1->name, descr2->name);
	     exit (retval);
	 }
	 
	 new_best[best_ctr] = map_ctr;
	 /* the array_qsort sorts in the increasing order, so use negative aln score: */
	 bb_score_array[best_ctr] = -current_map->aln_score;
     }

     array_qsort ( new_best, bb_score_array, list->best_array_used);

     memcpy (list->map_best, new_best, list->best_array_used*sizeof(int));

     free (bb_score_array);
     free (new_best);
     
     return 0;
}
Пример #4
0
static int dealias_ipid32_bo(scamper_dealias_probe_t **probes, int probec)
{
  scamper_dealias_probe_t **s = NULL;
  uint32_t a, b, c = 1, max_bs = 0, max_nobs = 0, u32;
  int i, rc = 2;

  if((s = memdup(probes, sizeof(scamper_dealias_probe_t *) * probec)) == NULL)
    return -1;
  array_qsort((void **)s, probec, (array_cmp_t)dealias_probe_def_cmp);

  for(i=0; i<probec-1; i++)
    {
      if(s[i]->def != s[i+1]->def)
	{
	  if(c >= 3)
	    {
	      if(max_nobs < max_bs)
		rc = 0;
	      else if(max_nobs > max_bs)
		rc = 1;
	      if(rc == 0)
		goto done;
	    }
	  c = 1; max_nobs = 0; max_bs = 0;
	}
      else
	{
	  a = s[i]->replies[0]->ipid32; b = s[i+1]->replies[0]->ipid32;
	  u32 = dealias_ipid32_diff(a, b);
	  if(u32 > max_nobs || max_nobs == 0)
	    max_nobs = u32;
	  u32 = dealias_ipid32_diff(byteswap32(a), byteswap32(b));
	  if(u32 > max_bs || max_bs == 0)
	    max_bs = u32;
	  c++;
	}
    }

 done:
  if(s != NULL) free(s);
  return rc;
}
Пример #5
0
void scamper_dealias_probes_sort_def(scamper_dealias_t *dealias)
{
  array_qsort((void **)dealias->probes, dealias->probec,
	      (array_cmp_t)dealias_probe_def_cmp);
  return;
}
Пример #6
0
int coverage ( Alignment * alignment, double * score,  double * res_fract_rank, int gap_treatment) {

    int *sorted_res;
    int pos, ctr, ctr2;
    int first, cvg_ctr;
    int almt_pos, gaps;
    int new_length = alignment->length;
    int usable_position, ref_s = 0, g;
    int *int_cvg;
    double *protein_score, prev_score; /* "score" refers to alignment positions */
    Group  *group, *ref_group;

    if (gap_treatment > 0) {
     	group = alignment->group+gap_treatment-1;
    }
    
    sorted_res    =    (int *) emalloc ( alignment->length*sizeof (int) );
    if (!sorted_res) return 1;

    if ( ! (int_cvg = emalloc(alignment->length*sizeof(int) ) ) ) return 1;
 
    if ( gap_treatment  <= -100 ) {
	g = -(gap_treatment+100);
	ref_group = alignment->group+ g;
	ref_s     = ref_group->group_member[0];
	gaps = 0;
	for (almt_pos=0; almt_pos < alignment->length; almt_pos ++ ) {
	    if ( score[almt_pos] == ALL_GAPS
		 || alignment->sequence[ref_s][almt_pos] == '.') gaps++;
	}
	
	new_length = alignment->length - gaps;
	
    } else if ( gap_treatment  == -2 ) {
	new_length = alignment->length;
	
    } else if ( gap_treatment == -1 ) {
	new_length = alignment->length - alignment->number_of_sunk_positions;
	
    } else if ( gap_treatment == 0 ) {
	gaps = 0;
	for (almt_pos=0; almt_pos < alignment->length; almt_pos ++ ) {
	    if ( score[almt_pos] == ALL_GAPS ) gaps++;
	}
	new_length = alignment->length - gaps;
	
    } else {
	ref_group = alignment->group+ gap_treatment-1;
	ref_s     = ref_group->group_member[0];
	gaps = 0;
	for (almt_pos=0; almt_pos < alignment->length; almt_pos ++ ) {
	    if (alignment->sequence[ref_s][almt_pos] == '.') gaps++;
	}
	new_length = alignment->length - gaps;
   }
 
    /*allocate */
    protein_score = (double *) emalloc ( new_length*sizeof (double) );
    if (!protein_score ) return 1;

     /* remove gapped positions from the score array */
    pos = 0;
    for (almt_pos=0; almt_pos < alignment->length; almt_pos ++ ) {


	usable_position = 1;
	if (gap_treatment <= -100) {
	    if ( score[almt_pos] == ALL_GAPS ||
		 alignment->sequence[ref_s][almt_pos] == '.')
		usable_position = 0;
	    
	} else if ( gap_treatment == -1  ) {
	    if ( alignment->sunk[almt_pos] )  usable_position = 0;
	    
	} else if (gap_treatment == 0) {
	    if ( score[almt_pos] == ALL_GAPS) usable_position = 0;
	    
	} else if (gap_treatment > 0) {
	    if (alignment->sequence[ref_s][almt_pos] == '.') usable_position = 0;
	    
	}
	
	if ( ! usable_position) continue;

	if ( pos >= new_length ) {
	    fprintf (stderr, "Error: pos ctr (%d) >= allocated length (%d) \n", pos, new_length);
	    exit (1);
	}
	protein_score[pos] = score[almt_pos];
	pos ++;
   }

    
    /* sort protein residues according to the new array */
    for (pos=0; pos < new_length; pos++) sorted_res[pos] = pos;
    array_qsort ( sorted_res, protein_score, new_length);

    /* turn the sorted array to coverage info */
    
    /* the lowest score in the game */
    prev_score = protein_score[ sorted_res[0] ];

    
    first   = 0;
    cvg_ctr = 0;
    int_cvg[cvg_ctr] = 0;
   
    for (ctr=0; ctr < alignment->length; ctr++) {
	res_fract_rank[ctr] = 1.0;
    }
    for (ctr=0; ctr < new_length; ctr++) {
	
	if ( protein_score[ sorted_res[ctr] ] <= prev_score ) {
	    int_cvg[cvg_ctr] ++;
	} else {
	    prev_score  = protein_score[ sorted_res[ctr] ];
	    for (ctr2=first; ctr2 <ctr; ctr2++ ) {
		res_fract_rank[ sorted_res[ctr2] ] = (double) int_cvg[cvg_ctr]/new_length;
	    }
	    first = ctr;
	    cvg_ctr ++;
	    if ( cvg_ctr <  alignment->length) {
		int_cvg[cvg_ctr] =  int_cvg[cvg_ctr-1] + 1;
	    }
	}
    }
    for (ctr2=first; ctr2 <ctr; ctr2++ ) {
	res_fract_rank[ sorted_res[ctr2] ] =  (double) int_cvg[cvg_ctr]/new_length;
    }
    
 
    /* free */
    free (protein_score);
    free (sorted_res);
    free (int_cvg);
    
    return 0;
}