Exemple #1
0
main ()
{
  t_sassy  sassy; 			/* sample sequence segments table */
  int      segments;			/* sequence reaction pairs */
  short    sequence  [ MAX_COSMID + 1 ];/* cosmid DNA bases sequenced */
  int      steps     [ MAX_PAIRS + 1 ];	/* number of walking steps */
  float    ave_seq1  [ MAX_PAIRS + 1 ];	/* average times a base sequenced 1 */
  float    ave_seq2  [ MAX_PAIRS + 1 ];	/* average times a base sequenced 2 */
  float    coverage1 [ MAX_PAIRS + 1 ];	/* cosmid coverage 1 */
  float    coverage2 [ MAX_PAIRS + 1 ];	/* cosmid coverage 2 */
  int      groups1   [ MAX_PAIRS + 1 ];	/* ordered groups 1 */
  int      groups2   [ MAX_PAIRS + 1 ];	/* ordered groups 2 */
  int      islands1  [ MAX_PAIRS + 1 ];	/* sequence islands 1 */
  int      islands2  [ MAX_PAIRS + 1 ];	/* sequence islands 2 */

  long  count = 0;
  long  max_rand = 0;  /* temporary code */
  long  last_rand; 

  /* Compute the maximum random number. */
  for ( segments = 1; count < 50000; segments++ )
  {
    last_rand = rand ();
    count++;
    if ( last_rand > max_rand )
    {
      max_rand = last_rand;
      count = 0;
    }  /* if */
  }  /* for */
  printf ( "Maximum random number = %d\n", max_rand );
  return;

  /* Test series on increasing number of segments. */
  for ( segments = 1; segments <= MAX_PAIRS; segments++ )
  {
    /* Randomly select segments. */
    new_segments ( segments, COSMID_SIZE, &sassy );

    /* Count the number of ordered groups. */
    count_groups ( &sassy, &(groups1 [ segments ]) );

    /* Compute the cosmid coverage. */
    coverage ( &sassy, &(islands1 [ segments ]), &(coverage1 [ segments ]),
        &(ave_seq1 [ segments ]), sequence );

    /* Perform walk into all unknown regions. */
    walk_once ( &sassy, sequence, &(steps [ segments ]) );

    /* Count the number of ordered groups after walk. */
    count_groups ( &sassy, &(groups2 [ segments ]) );

    /* Compute the cosmid coverage after walk. */
    coverage ( &sassy, &(islands2 [ segments ]), &(coverage2 [ segments ]),
        &(ave_seq2 [ segments ]), sequence );
  }  /* for */

  /* Print out the results. */

}  /* main */
Exemple #2
0
// Returns true if rect fully overlaps n
bool buildQuery(const Node& n, const Rect rect, const int32_t count, Point* out_points, bool x)
{
  if (n.isLeaf()) {
    return true;
  } else {
    bool leftFullyOverlaps = false, rightFullyOverlaps = false;
    if (x) {
      if (rect.lx < n.split)
        leftFullyOverlaps = buildQuery(*n.left, rect, count, out_points, false);
      if (rect.hx >= n.split)
        rightFullyOverlaps = buildQuery(*n.right, rect, count, out_points, false);
    } else {
      if (rect.ly < n.split)
        leftFullyOverlaps = buildQuery(*n.left, rect, count, out_points, true);
      if (rect.hy >= n.split)
        rightFullyOverlaps = buildQuery(*n.right, rect, count, out_points, true);
    }

    if (leftFullyOverlaps && rightFullyOverlaps) {
      if (n.points.empty()) {
        s_nodes.emplace_back(coverage(n.left->rect, rect), n.left.get());
        s_nodes.emplace_back(coverage(n.right->rect, rect), n.right.get());
        return false;
      }
      return true;
    } else if (leftFullyOverlaps) {
      s_nodes.emplace_back(coverage(n.left->rect, rect), n.left.get());
    } else if (rightFullyOverlaps) {
      s_nodes.emplace_back(coverage(n.right->rect, rect), n.right.get());
    }
    return false;
  }
}
Exemple #3
0
Model::Model(shared_ptr<RInside>& ri, const std::string& net_var) :
		R(ri), net(false), trans_runner(create_transmission_runner()), cd4_calculator(create_CD4Calculator()), viral_load_calculator(
				create_ViralLoadCalculator()), popsize(), max_id(0), stage_map(), stats() {

	List rnet = as<List>((*R)[net_var]);
	PersonCreator person_creator(trans_runner);
	initialize_network(rnet, net, person_creator);
	init_stage_map(stage_map);

	popsize.push_back(net.vertexCount());
	max_id = net.vertexCount();

	// get initial stats
	stats.incrementCurrentEdgeCount(net.edgeCount());
	stats.incrementCurrentSize(net.vertexCount());
	for (auto iter = net.verticesBegin(); iter != net.verticesEnd(); ++iter) {
		if ((*iter)->isInfected()) {
			stats.incrementCurrentTotalInfectedCount(1);
		}
	}
	stats.resetForNextTimeStep();

	float art_coverage_rate = Parameters::instance()->getDoubleParameter(ART_COVERAGE_RATE);
	BinomialGen coverage(repast::Random::instance()->engine(),
			boost::random::binomial_distribution<>(1, art_coverage_rate));
	Random::instance()->putGenerator(ART_COVERAGE_BINOMIAL, new DefaultNumberGenerator<BinomialGen>(coverage));

}
Exemple #4
0
    ///////////////////////////////////////////////////////////////////////////
    // argument = [angle, radius1, radius2]
    ///////////////////////////////////////////////////////////////////////////
    vec3_t
    operator()( vec3_t const& argument ) const
    {
      vec3_t coverage(0, 0, 0); // [first gradient, second gradient, both gradients]
      classify_sample_by_signed_gradient<point<value_type,2> > insidetest;

      typename std::vector<value_type>::const_iterator w = _weights.begin();
      for ( typename std::vector<vec2_t>::const_iterator  s = _samples.begin(); s != _samples.end(); ++s, ++w)
      {
        // compute both gradients: since pixel is circularly approximated first gradient has angle of 0, the second relatively
        vec2_t fst_gradient(0,            argument[1]);
        vec2_t snd_gradient(argument[0],  argument[2]);

        // sample covered by object?
        bool covered_fst = insidetest(fst_gradient, *s);
        bool covered_snd = insidetest(snd_gradient, *s);

        // sum up weighted samples
        coverage[0] += (*w) * value_type( covered_fst && !covered_snd);
        coverage[1] += (*w) * value_type(!covered_fst && covered_snd);
        coverage[2] += (*w) * value_type( covered_fst && covered_snd);
      }

      // normalize coverage
      coverage /= _maxintegral;

      // return coverage
      return coverage;
    }
int menu_countCoverage(int argc, char **argv) {

    /* ------------------------------- */
    /*        countCoverage            */
    /* -i bamsFile                     */
    /* -p paramFile                    */
    /* ------------------------------- */

    if (argc == 1) {
        printf("/*-----------------------------------*/\n");
        printf("/*            extractFeature         */\n");
        printf("/* -i bams file list                 */\n");
        printf("/* -p parameter setting file         */\n");
        printf("/*-----------------------------------*/\n");
        exit(EXIT_SUCCESS);
    }

    char *bamsFile = (char *)calloc(MAX_DIR_LEN, sizeof(char));
    char *paramFile = (char *)calloc(MAX_DIR_LEN, sizeof(char));
    int ni;
    int iOK = 0, pOK = 0;

    ni = 1;
    while (ni < argc) {
        if (strcmp(argv[ni], "-i") == 0) {
            ni++;
            strcpy(bamsFile, argv[ni]);
            iOK = 1;
        }
        else if (strcmp(argv[ni], "-p") == 0) {
            ni++;
            strcpy(paramFile, argv[ni]);
            pOK = 1;
        }
        else {
            printf("Error: unkown parameters!\n");
            exit(EXIT_FAILURE);
        }
        ni++;
    }

    /* check args */
    if ((iOK + pOK) < 2) {
        printf("Error: input arguments not correct!\n");
        exit(EXIT_FAILURE);
    }
    else {
        coverage(bamsFile, paramFile);
    }

    /* free pointers */
    free(bamsFile);
    free(paramFile);

    return 0;
}
    void SoftwareRendererImp::rasterize_triangle(float x0, float y0, float x1,
            float y1, float x2, float y2, Color color) {
        // Task 2:
        // Implement triangle rasterization
        int x, y;
        Vector2D A = Vector2D(x0, y0);
        Vector2D B = Vector2D(x1, y1);
        Vector2D C = Vector2D(x2, y2);

        if (E(A, B, C) > 0) {
            Vector2D temp = A;
            A = B;
            B = temp;
        }

        for (x = MIN3(x0, x1, x2); x <= MAX3(x0, x1, x2); x++) {
            for (y = MIN3(y0, y1, y2); y <= MAX3(y0, y1, y2); y++) {
                Vector2D test = Vector2D(x, y);
                Vector2D test1 = Vector2D(x - 0.25, y - 0.25);
                Vector2D test2 = Vector2D(x - 0.75, y + 0.25);
                Vector2D test3 = Vector2D(x + 0.25, y - 0.75);
                Vector2D test4 = Vector2D(x + 0.75, y + 0.75);

                if (coverage(A, B, C, test)) {
                    sample_mark[y * target_w + x] = 1;
                }
                if (coverage(A, B, C, test1)) {
                    super_sample_plot(2 * x - 0.5, 2 * y - 0.5, color);
                }
                if (coverage(A, B, C, test2)) {
                    super_sample_plot(2 * x - 0.5, 2 * y + 0.5, color);
                }
                if (coverage(A, B, C, test3)) {
                    super_sample_plot(2 * x + 0.5, 2 * y - 0.5, color);
                }
                if (coverage(A, B, C, test4)) {
                    super_sample_plot(2 * x + 0.5, 2 * y + 0.5, color);
                }

            }
        }

    }
Exemple #7
0
int main(int argc, char **argv)
{
	if (argc == 1) {
		coverage();
		return 0;
	}
	if (argc == 2 && strcmp(argv[1], "err")==0) {
		errorTest();
		return 0;
	}
	testFile(argv[1]);
	return 0;
}
void their_statistics(string filename, vector<Trajectory>& trajs, vector<Segment> &segs, vector<vector<int>> &clusters, int a){
	//coverages

	ofstream out;
	out.open(filename);
	out<<"clusters coverages"<<endl;
	int num = 0; 
	for(auto &seg : segs){
		num+=seg.numpoints;
	}
	out<<"n = "<<num<<endl;
	vector<int> converages;
	for(auto &c: clusters){
		converages.push_back(coverage(segs, c));
	}
	sort(converages.begin(), converages.end());
	for(int i = 0; i<clusters.size(); i++){
		out<<converages[converages.size()-i-1]<<endl;
	}

	//compression
	vector<double> compressions;
	vector<double> gaps;
	for(auto &t: trajs){
		int num=0;
		int numgaps=0;
		for(int j = t.start_index; j<t.start_index+t.fragments_size; j++){
			if (clusters[segs[j].myclus].size()>a){
				num+=1;
			}
			else{
				numgaps+=clusters[segs[j].myclus].size();
			}
		}
		compressions.push_back(((double)(num))/((double)(t.points.size())));
		gaps.push_back(((double)(numgaps))/((double)(t.points.size())));
	}
	sort(compressions.begin(), compressions.end());
	sort(gaps.begin(), gaps.end());
	out<<"compressions"<<endl;
	for(auto val: compressions){
		out<<val<<endl;
	}
	out<<"gaps"<<endl;
	for(auto val: gaps){
		out<<val<<endl;
	}
	out.close();
}
Exemple #9
0
    virtual void HandleSplit(EdgeId old_edge, EdgeId new_edge1, EdgeId new_edge2) {
//		size_t length1 = this->g().length(newEdge1);
//		size_t length = this->g().length(oldEdge);
//		size_t coverage = KPlusOneMerCoverage(oldEdge);
//		size_t coverage1 = coverage * length1 / length;
//		if (coverage1 == 0)
//			coverage1 = 1;
//		size_t coverage2 = coverage - coverage1;
//		if (coverage2 == 0)
//			coverage2 = 1;
//		SetCoverage(newEdge1, coverage1);
//		SetCoverage(newEdge2, coverage2);
        double avg_cov = coverage(old_edge);
        SetRawCoverage(new_edge1, max(1, (int) math::round(avg_cov * (double) this->g().length(new_edge1))));
        SetRawCoverage(new_edge2, max(1, (int) math::round(avg_cov * (double) this->g().length(new_edge2))));
    }
Exemple #10
0
int Domain::computeCoverage()
{
    QBitArray coverage(myExamples->getAllExamples()->size(), false);
    int i = 0;
    for(QList<QBitArray>::iterator iexample = termOccurences4Examples.begin(); iexample != termOccurences4Examples.end(); ++iexample)
    {
        if((*iexample).count(true) > 0)
            coverage.setBit(i, true);
        i++;
    }

    //compute coverage
    coverage &= myExamples->getSignClass();
    int numofcoverage = coverage.count(true);

    return numofcoverage;
}
Exemple #11
0
  void path_trace(DeviceTask &task, RenderTile &tile, KernelGlobals *kg)
  {
    const bool use_coverage = kernel_data.film.cryptomatte_passes & CRYPT_ACCURATE;

    scoped_timer timer(&tile.buffers->render_time);

    Coverage coverage(kg, tile);
    if (use_coverage) {
      coverage.init_path_trace();
    }

    float *render_buffer = (float *)tile.buffer;
    int start_sample = tile.start_sample;
    int end_sample = tile.start_sample + tile.num_samples;

    /* Needed for Embree. */
    SIMD_SET_FLUSH_TO_ZERO;

    for (int sample = start_sample; sample < end_sample; sample++) {
      if (task.get_cancel() || task_pool.canceled()) {
        if (task.need_finish_queue == false)
          break;
      }

      for (int y = tile.y; y < tile.y + tile.h; y++) {
        for (int x = tile.x; x < tile.x + tile.w; x++) {
          if (use_coverage) {
            coverage.init_pixel(x, y);
          }
          path_trace_kernel()(kg, render_buffer, sample, x, y, tile.offset, tile.stride);
        }
      }

      tile.sample = sample + 1;

      task.update_progress(&tile, tile.w * tile.h);
    }
    if (use_coverage) {
      coverage.finalize();
    }
  }
Exemple #12
0
sprite make_circle_quadrant(int radius)
{
    std::vector<float> coverage(radius*radius);
    compute_circle_quadrant_coverage(coverage.data(), radius);

    const int width = radius+2;
    auto memory = reinterpret_cast<uint8_t *>(std::malloc(width*width));
    if(!memory) throw std::bad_alloc();
    std::shared_ptr<uint8_t> pixels(memory, std::free);
    auto out = pixels.get(); auto in = coverage.data();
    *out++ = 255;
    for(int i=0; i<radius; ++i) *out++ = 255;
    *out++ = 0;
    for(int i=0; i<radius; ++i)
    {
        *out++ = 255;
        for(int i=0; i<radius; ++i) *out++ = static_cast<uint8_t>(*in++ * 255);
        *out++ = 0;
    }
    for(int i=0; i<width; ++i) *out++ = 0;

    return {pixels, {width,width}, true};
}
Exemple #13
0
	void coalesce () {
		if (!_dirty) {
			return;
		}

	restart:		
		for (typename List::iterator i = _list.begin(); i != _list.end(); ++i) {
			for (typename List::iterator j = _list.begin(); j != _list.end(); ++j) {

				if (i == j) {
					continue;
				}

				if (coverage (i->from, i->to, j->from, j->to) != OverlapNone) {
					i->from = std::min (i->from, j->from);
					i->to = std::max (i->to, j->to);
					_list.erase (j);
					goto restart;
				}
			}
		}

		_dirty = false;
	}
Exemple #14
0
int main ( int argc, char * argv[]) {

    Options options;
    Protein protein;
    Alignment * alignment = NULL;
    int retval;
    int almtctr1, almtctr2;
    double **score = NULL, corr,  pctg_gaps;
    double **clustering_score = NULL;
    double *area, *distance;
    int **rank_order= NULL,**res_rank=NULL,**int_cvg=NULL ;
    int ** correlated = NULL, **almt2prot = NULL, **prot2almt = NULL;
    /* command file is required */
    if ( argc < 2 ) {
	fprintf ( stderr, "Usage: %s <command file>.\n", argv[0]);
	exit (0);
    }
    retval = read_cmd_file ( argv[1], &options);
    if (retval) exit(retval);
    retval = logger (&options, INTRO, "");
    if (retval) exit(retval);
   

    /*******************************************/
    /*                                         */
    /*  PDB input                              */
    /*                                         */
    /*******************************************/
    if ( ! options.pdbname[0]) {
	fprintf (stderr, "%s cannot work without structure (cmd file was %s).\n",
		 argv[0], argv[1]);
	exit (1);
	
    } else {

	/* warn if no chain given */
	if ( !options.chain) {
	    retval = logger (&options, WARN, "No chain specified. Using the first one.");
	    if ( retval) exit (1);
	}
	if (retval) exit(retval);
	/* read in the structure */
	retval = read_pdb (options.pdbname, &protein, options.chain);
	if (retval) exit(retval);

   }

    
    /*******************************************/
    /*                                         */
    /*  alignment scoring                      */
    /*                                         */
    /*******************************************/
    if ( ! ( alignment = emalloc ( options.no_of_alignments*sizeof(Alignment)) )) return 1;
    if ( ! ( score = emalloc ( options.no_of_alignments*sizeof(double*)) )) return 1;
    if ( ! ( rank_order = emalloc ( options.no_of_alignments*sizeof(int*)) )) return 1;
    if ( ! ( clustering_score = emalloc ( options.no_of_alignments*sizeof(double*)) )) return 1;
    if ( ! ( res_rank = emalloc ( options.no_of_alignments*sizeof(int*)) )) return 1;
    if ( ! ( int_cvg = emalloc ( options.no_of_alignments*sizeof(int*)) )) return 1;
    if ( ! ( almt2prot = emalloc ( options.no_of_alignments*sizeof(int*)) )) return 1;
    if ( ! ( prot2almt = emalloc ( options.no_of_alignments*sizeof(int*)) )) return 1;
    if ( ! ( area = emalloc ( options.no_of_alignments*sizeof(double)) )) return 1;
    if ( ! ( distance = emalloc ( options.no_of_alignments*sizeof(double)) )) return 1;

    printf ( "\t%8s   %20s  %8s  %8s  %8s  \n", "almt#", "name        ",  "<dist to qry>", "%gaps", "area");
    
    for ( almtctr1 = 0; almtctr1 < options.no_of_alignments; almtctr1++) {

	/* read in the alignment */
	retval = read_clustalw (options.almtname[almtctr1], alignment + almtctr1);
	if (retval) exit(retval);
	/* pairwise distances btw the seqs */
	retval   = seq_pw_dist (alignment+almtctr1);
	if ( retval) return retval;
	/* average dist to the query in this alignment: */ 
	distance[almtctr1] = avg_dist_to_special (&options, alignment + almtctr1);
	/* percentage of gaps in the alignment: */
	pctg_gaps = (double) alignment->total_gaps/ ( (alignment+almtctr1)->length*(alignment+almtctr1)->number_of_seqs);
	/* make the residue scoring array */
	score[almtctr1] = emalloc ( alignment[almtctr1].length*sizeof(double));
	/* fill in the score array */ 
	scoring (&options,  alignment+almtctr1, score[almtctr1]);
	
	/* translate the scoring into rank order */
	rank_order[almtctr1] = emalloc ( alignment[almtctr1].length*sizeof(int));
	score2rank (score[almtctr1], rank_order[almtctr1], alignment[almtctr1].length);
	
	/* mapping between the protein and the alignment almtctr1 */
	if ( ! (almt2prot[almtctr1] = (int *) emalloc (alignment[almtctr1].length*sizeof(int))) )exit (1);
	if ( ! (prot2almt[almtctr1] = (int *) emalloc (protein.length*sizeof(int))) )exit (1);
	retval    = struct_almt_mapping (&protein, alignment+almtctr1, options.query,  prot2almt[almtctr1], almt2prot[almtctr1]);
	if (retval) exit(retval);
	
	/* find coverage info implied by the scoring array */
	if ( ! (res_rank[almtctr1] = (int*) emalloc (protein.length*sizeof(int))) ) exit (1);
	if ( ! (int_cvg[almtctr1] =  (int*) emalloc (protein.length*sizeof(int))) ) exit (1);
	coverage ( &protein, almt2prot[almtctr1], score[almtctr1], alignment[almtctr1].length,
		   res_rank[almtctr1], int_cvg[almtctr1] );
	/*clustering score*/
	clustering_score[almtctr1]  =  (double*) emalloc (protein.length*sizeof(double));
	if (!clustering_score[almtctr1]) exit(retval);
	clustering ( &protein,  res_rank[almtctr1], int_cvg[almtctr1], clustering_score[almtctr1]);
	/* cumulative clustering score*/
	area[almtctr1]  = area_over_coverage (int_cvg[almtctr1], clustering_score[almtctr1], protein.length);
					     
	printf ( "\t   %4d   %20s   %8.3lf     %8.3lf  %8.3lf \n",
		 almtctr1, options.almtname[almtctr1], distance[almtctr1], pctg_gaps, area[almtctr1]);
    }

    /* find the table of correlations */
    if ( ! (correlated = intmatrix ( options.no_of_alignments, options.no_of_alignments) ) ) return 1;
    for ( almtctr1 = 0; almtctr1 < options.no_of_alignments -1; almtctr1++) {
	correlated[almtctr1][almtctr1] = 1;
	for ( almtctr2 = almtctr1+1; almtctr2 < options.no_of_alignments; almtctr2++) {
	    if ( alignment[almtctr1].length != alignment[almtctr2].length  ) {
		fprintf ( stderr, "Error alignments in the files %s and %s ",
			  options.almtname[almtctr1], options.almtname[almtctr2]);
		fprintf ( stderr, "seem to be of unequal length: %d and %d.\n",
			  alignment[almtctr1].length ,  alignment[almtctr2].length);
		return 1;
	    }
	    corr = spearman ( rank_order[almtctr1], rank_order[almtctr2], alignment[almtctr1].length );
	    printf ( " %3d  %3d  %8.4lf\n", almtctr1, almtctr2, corr);
	    correlated[almtctr1][almtctr2] = ( corr > 0.9 );
	}
    }

    
    /* find corelated clusters (of sequence selections)*/
    {
	int  *cluster_count_per_size;
	int  no_of_clusters;
	int  max_size, secnd_max_size , ** cluster;
	int size = options.no_of_alignments;
	int i,j;
	double dist, ar, max_area, dist_at_max_area;
	double min_dist_at_max_area, min_dist, max_area_at_min_dist;
	int almt_no, min_dist_almt;
	int cluster_counter (int  no_of_things,  int *neighbors[],
			      int cluster_count_per_size[], int * no_of_clusters,
			      int * max_size, int * secnd_max_size , int * cluster[]);
	
	
	if ( ! ( cluster_count_per_size = emalloc (size*sizeof(int)))) return 1; 
	if ( ! (cluster = intmatrix ( size+1, size+1) ) ) return 1;
	retval = cluster_counter (size,  correlated,  cluster_count_per_size,  &no_of_clusters,
			 & max_size,  &secnd_max_size , cluster);
	if ( retval ) return 1;

	printf ( "number of clusters: %d \n", no_of_clusters);
	for (i=0; i<=size; i++ ) {
	    if ( ! cluster[i][0] ) continue;
	    if ( !i ) {
		printf ( "\t isolated:\n");
	    } else {
		printf ("\t cluster size: %3d \n", cluster[i][0]); 
	    }
	    for (j=1; j <= cluster[i][0]; j++ ) {
		printf ( "%3d ", cluster[i][j] );
	    }
	    printf ( "\n");
	}

	
	/* which cluster is the closest to the singled out sequence ("special") */
	min_dist_at_max_area = dist_at_max_area = 10;
	max_area_at_min_dist = min_dist = -10;
	min_dist_almt = -1;
	for (i=0; i<=size; i++ ) {
	    if ( ! cluster[i][0] ) continue;
	    
	    max_area = -100;
	    almt_no =  dist_at_max_area = -1;
	    
	    for (j=1; j <= cluster[i][0]; j++ ) {
		dist = distance[cluster[i][j]] ;
		ar =  area[cluster[i][j]] ;
		if ( max_area < ar ) {
		    max_area = ar;
		    dist_at_max_area = dist;
		    almt_no = cluster[i][j];
		}
	    }
	    if ( almt_no < 0 ) {
		fprintf ( stderr, "Error selecting the alignment (1)\n");
		exit (1);
	    }
	    
	    if ( min_dist_at_max_area > dist_at_max_area ) {
		min_dist = dist_at_max_area;
		max_area_at_min_dist = max_area;
		min_dist_almt = almt_no;
	    }
	}
	if ( min_dist_almt < 0 ) {
	    fprintf ( stderr, "Error selecting the alignment (2)\n");
	    exit (1);
	}
	
	printf ( "choosing alignment %d %s (distance: %5.3f  area: %6.3f)\n",
		min_dist_almt, options.almtname[min_dist_almt],  min_dist, max_area_at_min_dist);
	
	
	free (cluster_count_per_size);
	free_matrix ( (void **) cluster);
    }
    free (score);

    logger ( &options, NOTE, "");
    return 0;
}
Exemple #15
0
Fichier : stb.c Projet : cran/STB
void getCoverage(double *mat, double *lower, double *upper, int *nCol, int *nRow, int *nCpu, double *cov)
{
    cov[0] = coverage(mat, lower, upper, *nCol, *nRow, *nCpu);
    return;
}
Exemple #16
0
Fichier : stb.c Projet : cran/STB
void getSTB(double *mat, int *nCol, int *nRow, double *alpha, double *tol, int *max_iter, int *nCpu, double *Q, double *cov)
{
    int check=1, iter=0, i, j;
    double include, alpha_old, tmp, best_cov; // best_alpha;
    double *tmp_col, *lower, *upper, *best_Q;

    lower = calloc(*nCol, sizeof(double));
    upper = calloc(*nCol, sizeof(double));
    best_Q = calloc(2*(*nCol), sizeof(double));

    include = 1-(*alpha);											/* requested simultaneous tolerance limit, i.e. coverage */
    alpha_old = *alpha;
    *alpha = (*alpha)/2;
    best_cov=1.0;

#ifdef _OPENMP
    omp_set_num_threads(*nCpu);										/* set number of cores */
#endif

    while(check==1)
    {
        iter += 1;

        #pragma omp parallel for\
        shared(mat, lower, upper, Q)\
        private(i,j,tmp_col)
        for(i=0; i<*nCol; i++)																/* pont-wise tolerance limits */
        {
            tmp_col = calloc(*nRow, sizeof(double));

            for(j=0; j<(*nRow); j++)
            {
                tmp_col[j] = mat[i*(*nRow)+j];										/* copy i-th col of the matrix 'mat'*/
            }
            Q[i*2]=SASquantile(tmp_col, *alpha, *nRow, EPS);					/* 1st row */
            lower[i]=Q[i*2];
            Q[i*2+1]=SASquantile(tmp_col, 1-(*alpha), *nRow, EPS);		/* 2nd row */
            upper[i]=Q[i*2+1];

            free(tmp_col);
        }
        *cov=coverage(mat, lower, upper, *nCol, *nRow, *nCpu);				/* compute coverage of current STB */
        if(*cov >= include)																		/* at least 100(1-alpha)% coverage */
        {
            if(*cov < best_cov)																	/* coverage better than former result */
            {
                //best_alpha = *alpha;
                best_Q = Q;
                best_cov = *cov;
            }
        }
        if( abs_double((*alpha) - alpha_old)/2 == 0 )					/* terminate if alpha cannot become smaller */
        {
            check = 0;
        }
        if( iter == *max_iter ) 															/* terminate if max number of iterations reached */
        {
            check = 0;
        }

        if( abs_double(*cov - include) <= *tol &&  (*cov - include) >= 0 )
        {
            check = 0;																					/* convergence tolerance reached */
        }
        else																									/* bisection step */
        {
            if( (*cov - include) < 0)
            {
                tmp = *alpha;
                *alpha = *alpha - abs_double(alpha_old-(*alpha))/2;
                alpha_old = tmp;
            }
            else
            {
                tmp = *alpha;
                *alpha = *alpha +  abs_double(alpha_old-(*alpha))/2;
                alpha_old = tmp;
            }
        }
    }
    *cov = best_cov;			/* Use best values from iteration history */
    Q = best_Q;
}
Exemple #17
0
RangeList<T> subtract (Range<T> range, RangeList<T> sub)
{
	/* Start with the input range */
	RangeList<T> result;
	result.add (range);

	if (sub.empty () || range.empty()) {
		return result;
	}

	typename RangeList<T>::List s = sub.get ();

	/* The basic idea here is to keep a list of the result ranges, and subtract
	   the bits of `sub' from them one by one.
	*/
	
	for (typename RangeList<T>::List::const_iterator i = s.begin(); i != s.end(); ++i) {

		/* Here's where we'll put the new current result after subtracting *i from it */
		RangeList<T> new_result;

		typename RangeList<T>::List r = result.get ();

		/* Work on all parts of the current result using this range *i */
		for (typename RangeList<T>::List::const_iterator j = r.begin(); j != r.end(); ++j) {

			switch (coverage (j->from, j->to, i->from, i->to)) {
			case OverlapNone:
				/* The thing we're subtracting (*i) does not overlap this bit of the result (*j),
				   so pass it through.
				*/
				new_result.add (*j);
				break;
			case OverlapInternal:
				/* Internal overlap of the thing we're subtracting (*i) from this bit of the result,
				   so we should end up with two bits of (*j) left over, from the start of (*j) to
				   the start of (*i), and from the end of (*i) to the end of (*j).
				*/
				assert (j->from < i->from);
				assert (j->to > i->to);
				new_result.add (Range<T> (j->from, i->from - 1));
				new_result.add (Range<T> (i->to + 1, j->to));
				break;
			case OverlapStart:
				/* The bit we're subtracting (*i) overlaps the start of the bit of the result (*j),
				 * so we keep only the part of of (*j) from after the end of (*i)
				 */
				assert (i->to < j->to);
				new_result.add (Range<T> (i->to + 1, j->to));
				break;
			case OverlapEnd:
				/* The bit we're subtracting (*i) overlaps the end of the bit of the result (*j),
				 * so we keep only the part of of (*j) from before the start of (*i)
				 */
				assert (j->from < i->from);
				new_result.add (Range<T> (j->from, i->from - 1));
				break;
			case OverlapExternal:
				/* total overlap of the bit we're subtracting with the result bit, so the
				   result bit is completely removed; do nothing */
				break;
			}
		}

		new_result.coalesce ();
		result = new_result;
	}

	return result;
}
Exemple #18
0
int  score_output (Alignment *alignment, Protein *protein, int *almt2prot, 
		   double ** score, double *** in_group_score, double ** spec_score){

    int almt_pos, score_ctr;
    int  pos, unsunk_pos, g, s;

    char filename[BUFFLEN];
    char aa = '\0', pdbid[PDB_ATOM_RES_NO_LEN+1] = {'\0'};
    double cvg;
    double ** cons_cvg = NULL;
    double ** spec_cvg = NULL;
    FILE  * fptr = NULL;
    Group * group;
    int nongap_pos_ctr[alignment->no_groups];
    int nongap_not_all_pos_ctr[alignment->no_groups];
   
    
    sprintf (filename, "%s.score", options.outname);

    fptr = efopen (filename, "w");
    if ( !fptr) return 1;

    /* find residue ranks (coverage)*/
    if ( !(cons_cvg = dmatrix(1+alignment->no_groups, alignment->length) )) return 1;
    if ( !(spec_cvg = dmatrix(1+alignment->no_groups, alignment->length) )) return 1;
	
    /* entropy */
    coverage (alignment, score[1], cons_cvg[0], -1);
    /* rvet */
    /* coverage (alignment, score[0], cons_cvg[0], -1); */
    
    /* conservation in the individual groups */
    for  (g=0; g < alignment->no_groups; g++) {
	coverage (alignment, in_group_score[0][g], cons_cvg[g+1], g+1); /* conservation */
	coverage (alignment, spec_score[g+1], spec_cvg[g+1], -(100+g)); /* discriminants */
    }
    /* spec score */
    g = 0;
    coverage (alignment, spec_score[g], spec_cvg[g], 0); /* determinants */
    


    /******** header **************************/
    fprintf (fptr, "%%%6s %8s", "almt", "gaps(%)");

    fprintf (fptr, " %8s ", "entropy");
    
    for  (g=0; g < alignment->no_groups; g++) {
	fprintf (fptr, " %s ", alignment->group[g].group_name);
    }
    
    fprintf (fptr, " %8s ", "discr");
    for (g=0; g<alignment->no_groups; g++) {
	fprintf (fptr, " dets_in_%s ", alignment->group[g].group_name);
    }
    
    for (g=0; g<alignment->no_groups; g++) {
	group = alignment->group+g;
	s  = group->group_member[0];
	fprintf ( fptr, " %s ", alignment->name[s]);
	fprintf ( fptr, " pos_in_%s ", alignment->name[s]);
    }
    
    
    if ( almt2prot ) {
	fprintf (fptr, " %8s ", "pdb_aa");
	fprintf (fptr, " %8s ", "pdb_id");
    }
    
    if ( options.dssp_name[0] ) {
      fprintf (fptr, "%6s", "surf");
    }

    fprintf (fptr, "\n");
   
    for (g=0; g<alignment->no_groups; g++) {
	nongap_pos_ctr[g] = -1;
	nongap_not_all_pos_ctr[g]  = -1;
    }
    pos = -1;
    unsunk_pos = -1;
    for (almt_pos = 0; almt_pos < alignment->length; almt_pos++) {

	if ( spec_score[0][almt_pos] != ALL_GAPS )  pos++;
	
	for  (g=0; g < alignment->no_groups; g++) {
	    group = alignment->group+g;
	    s  = group->group_member[0];
	    if (alignment->sequence[s][almt_pos] != '.' ) {
		nongap_pos_ctr[g]++;
		if ( spec_score[0][almt_pos] != ALL_GAPS) {
		    nongap_not_all_pos_ctr[g]++;
		}
	    }
	}

	fprintf (fptr, "%6d %8d", almt_pos+1, 
		 (int)(100*(double)alignment->column_gaps[almt_pos]/alignment->number_of_seqs));

	/************************/
	/* conservation scores  */
	/* overall conservation */
	score_ctr = 0; 
	if (alignment->sunk[almt_pos]) {
	    cvg = 1;
	} else {
	    unsunk_pos ++;
	    cvg = cons_cvg[score_ctr][unsunk_pos];
	}
	fprintf (fptr, " %8.2lf ", cvg);
	
	
	/*****************************/
	/* within-group conservation */
	for ( score_ctr=0; score_ctr<alignment->no_groups; score_ctr++) {
	    
	    group = alignment->group+score_ctr;
	    s  = group->group_member[0];
	    if (alignment->sequence[s][almt_pos] == '.' ) {//<========
		cvg = 1;
	    } else {
		cvg = cons_cvg[score_ctr+1][nongap_pos_ctr[score_ctr]];
	    }
	    fprintf (fptr, " %8.2lf ", cvg);
	    
	}
	/***********************/
	/* specificity  scores */
	score_ctr = 0;
	if ( spec_score[0][almt_pos] == ALL_GAPS  ||  alignment->sunk[almt_pos] ) {
	    cvg = 0.5;
	} else {
	    cvg = spec_cvg[score_ctr][ nongap_not_all_pos_ctr[score_ctr] ];
	}
	fprintf (fptr, " %8.2lf ", cvg);

	for (score_ctr = 1; score_ctr <= alignment->no_groups; score_ctr++) {

	    group = alignment->group+score_ctr-1;
	    s  = group->group_member[0];
	    if ( spec_score[0][almt_pos] == ALL_GAPS  ||  alignment->sequence[s][almt_pos] == '.' ) {
		cvg = 0.5;
	    } else {
		cvg = spec_cvg[score_ctr][ nongap_not_all_pos_ctr[score_ctr-1] ];
	    }
	    fprintf (fptr, " %8.2lf ", cvg);
	}

	
	
	/************************/
	/*  representative seqs */
	for (g=0; g<alignment->no_groups; g++) {
	    group = alignment->group+g;
	    s  = group->group_member[0];
	    aa = alignment->sequence[s][almt_pos];
	    fprintf (fptr, "%6c", aa);
	    if ( aa == '.' ) {
		fprintf (fptr, "%5s", ".");
	    } else {
		fprintf (fptr, "%5d", nongap_pos_ctr[g]+1);
	    }
	}
	if ( almt2prot) {
	     if ( almt2prot[almt_pos] >= 0 ) {
		  sprintf (pdbid, "%s", protein->sequence[ almt2prot[almt_pos] ].pdb_id );
		  aa = protein->sequence[ almt2prot[almt_pos] ].res_type_short;
		  fprintf (fptr, "%6c%5s", aa, pdbid);
	     } else {
		  fprintf (fptr, "%6s%5s", ".", ".");
	     }
	}
	
	/* surface accessibility */
	if ( options.dssp_name[0] ) {
	  int acc =  ( almt2prot[almt_pos] < 0 ) ?  
	    -1: protein->sequence[almt2prot[almt_pos]].solvent_accessible;
	    fprintf ( fptr," %6d",  acc);
	}
	
	fprintf (fptr, "\n");
    }

    fclose (fptr);
    free_dmatrix (cons_cvg);
    free_dmatrix (spec_cvg);
    
    return 0;

}
Exemple #19
0
int main(int argc, const char * argv[]) {
    const double pi = std::abs(std::atan2(0,-1));
    Floorplan flp;

    double wall_loss = 2.0;                      // layered drywall
    double angle_loss = 5.0 / (pi/2);            // 5.0dB for 90 degrees
    double exterior_wall_loss = 15.0;            // thick concrete

    int size_x = 15;
    int size_y = 15;

    unsigned seed = 0;
    unsigned st_seed = 0;
    int office = 0;
    double office_x = 3.0;
    double office_y = 4.0;
    double hall_width = 2.0;

    const char *save = 0;
    const char *load = 0;
    const char *saveimage = 0;
    std::vector<int> pathset;

    bool display_paths = 1;
    bool label_floorplan = 1;
    double grid_measurements = 5.0;
    double step = 0.5;

    bool truncate_dijkstra = true;

    // quick hack for various computations
    // mode 0 == s-t breakpoint path computation
    // mode 1 == all destinations
    // mode 2 == approx all dest
    // mode 3 == heatmap
    // mode 4 == random s-t pair breakpoint evaluation
    // mode 5 == coverage
    // mode 6 == ratio_all_measurement
    int mode = 0;

    int num_experiments = 100;

    double p = 20.0/std::log(10.0);

    // This program finds the paths from pts[0] to pts[1]
    Point pts[3];
    pts[0].x = 2.5;
    pts[0].y = 1.5;
    pts[1].x = 9.3;
    pts[1].y = 12.3;
    pts[2].x = 7.9;
    pts[2].y = 11.1;

    int limit = 50;

    int argi = 1;
    while (argi < argc - 1) {
        if (strcmp(argv[argi], "-sx") == 0) size_x = atoi(argv[++argi]);
        else if (strcmp(argv[argi], "-sy") == 0) size_y = atoi(argv[++argi]);
        else if (strcmp(argv[argi], "-wl") == 0) wall_loss = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-al") == 0) angle_loss = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-el") == 0) exterior_wall_loss = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-sd") == 0) seed = atoi(argv[++argi]);
        else if (strcmp(argv[argi], "-st") == 0) st_seed = atoi(argv[++argi]);
        else if (strcmp(argv[argi], "-s") == 0) save = argv[++argi];
        else if (strcmp(argv[argi], "-l") == 0) load = argv[++argi];
        else if (strcmp(argv[argi], "-w") == 0) saveimage = argv[++argi];
        else if (strcmp(argv[argi], "-p0x") == 0) pts[0].x = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-p0y") == 0) pts[0].y = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-p1x") == 0) pts[1].x = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-p1y") == 0) pts[1].y = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-dp") == 0) display_paths = atoi(argv[++argi]);
        else if (strcmp(argv[argi], "-gm") == 0) grid_measurements = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-step") == 0) step = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-mode") == 0) mode = atoi(argv[++argi]);
        else if (strcmp(argv[argi], "-p") == 0) p = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-office") == 0) office = atoi(argv[++argi]);
        else if (strcmp(argv[argi], "-office_x") == 0) office_x = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-office_y") == 0) office_y = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-hall_width") == 0) hall_width = atof(argv[++argi]);
        else if (strcmp(argv[argi], "-n") == 0) num_experiments = atoi(argv[++argi]);
        else if (strcmp(argv[argi], "-path") == 0) pathset.push_back(atoi(argv[++argi]));
        else if (strcmp(argv[argi], "-truncate") == 0) truncate_dijkstra = atoi(argv[++argi]);
        else if (strcmp(argv[argi], "-label") == 0) label_floorplan = atoi(argv[++argi]);

        argi++;
    }

    if (load) {
        double start_time = util::cpu_timer();
        flp.load(load);
        std::cerr << "Floorplan loaded in " << (util::cpu_timer() - start_time)
                  << " cpu seconds." << std::endl;
    } else {
        double start_time = util::cpu_timer();
        if (office == 1) {
            flp.genOffice1(size_x, size_y, office_x, office_y, hall_width,
                           wall_loss, angle_loss, exterior_wall_loss);
        } else if (office == 2) {
            flp.genOffice2(size_x, size_y, office_x, office_y, hall_width,
                           wall_loss, angle_loss, exterior_wall_loss);
        } else if (office == 3) {
            flp.genOffice3(size_x, size_y, office_x, office_y, hall_width,
                           wall_loss, angle_loss, exterior_wall_loss);
        } else if (office == 4) {
            flp.genOffice4(size_x, size_y, office_x, office_y, hall_width,
                           wall_loss, angle_loss, exterior_wall_loss);
        } else {
            flp.genRandomFloorplan(size_x, size_y, wall_loss, angle_loss,
                                   exterior_wall_loss, seed);
        }
        std::cerr << "Floorplan generated in " << (util::cpu_timer() - start_time)
                  << " cpu seconds." << std::endl;
    }

    std::cerr << "Floorplan contains " << flp.getNumCorners() << " corners and "
              << flp.getNumWalls() << " walls." << std::endl;

    if (save) {
        double start_time = util::cpu_timer();
        flp.save(save);
        std::cerr << "Floorplan saved in " << (util::cpu_timer() - start_time)
                  << " cpu seconds." << std::endl;
    }

    int npts = 2;
    if (mode == 1 || mode == 2) npts = 3;

    if (mode == 3) label_floorplan = false;
    DominantPath dmp(&flp, npts, pts, label_floorplan);

    if (mode != 3 && mode != 4 && mode != 6) {
        double geng2_start = util::cpu_timer();
        dmp.generateG2();
        std::cerr << "G2 generated " << dmp.numG2Points() << " points, "
                  << dmp.numG2Links() << " links in "
                  << (util::cpu_timer() - geng2_start) << " cpu seconds."
                  << std::endl;
    }

    Path *paths = new Path[limit];
    int npaths = 2;
    if (mode == 0) {
        double break_start = util::cpu_timer();
        int count = dmp.BreakPoints(0, 1, limit, paths, npaths);
        std::cerr << count << " relaxations performed in "
                  << (util::cpu_timer() - break_start) << " cpu seconds."
                  << std::endl;
        if (display_paths) {
            dmp.printPaths(npaths, paths, p, saveimage, pathset);
        }
        for (int i = 0; i < npaths; i++) {
            printf("%f\n", (paths[i].L+p*std::log(paths[i].D)));
        }
    } else if (mode == 1) {
        double break_start = util::cpu_timer();
        dmp.Dijkstra_all_dest(100, paths);
        std::cerr << "Dijkstra_all_dest finished in "
                  << (util::cpu_timer() - break_start) << " cpu seconds."
                  << std::endl;
    } else if (mode == 2) {
        double break_start = util::cpu_timer();
        dmp.Approx_all_dest(p, step, paths, truncate_dijkstra);
        std::cerr << "Approx_all_dest finished in "
                  << (util::cpu_timer() - break_start) << " cpu seconds."
                  << std::endl;
    } else if (mode == 3) {
        dmp.heatmap(p, step, pts[0].x, pts[0].y,
                    flp.getWidth(), flp.getHeight(),
                    grid_measurements, saveimage, truncate_dijkstra);
    } else if (mode == 4) { // for testing
        Random_st_pairs rsp(&flp, p);
        rsp.size_x = flp.getWidth();
        rsp.size_y = flp.getHeight();
        rsp.test(num_experiments, st_seed);
    } else if (mode == 5) {
        double break_start = util::cpu_timer();
        coverage(dmp);
        std::cerr << "coverage finished in "
        << (util::cpu_timer() - break_start) << " cpu seconds."
        << std::endl;
    } else if (mode == 6) {
        dmp.ratio_all_measurement(step, pts[0].x, pts[0].y,
                                  flp.getWidth(), flp.getHeight(),
                                  grid_measurements, false, false, true);
    }
    
    delete [] paths;

    return 0;
}
Exemple #20
0
 void Save(EdgeId e, ostream& out) const {
     out << (boost::format("%.6f") % coverage(e)).str();
 }
 const vector<double>& coverage(const TowerPosition& tp) const {
     return coverage(tp.position, tp.tower);
 }