Ejemplo n.º 1
0
void
vec4_gs_visitor::set_stream_control_data_bits(unsigned stream_id)
{
   /* control_data_bits |= stream_id << ((2 * (vertex_count - 1)) % 32) */

   /* Note: we are calling this *before* increasing vertex_count, so
    * this->vertex_count == vertex_count - 1 in the formula above.
    */

   /* Stream mode uses 2 bits per vertex */
   assert(c->control_data_bits_per_vertex == 2);

   /* Must be a valid stream */
   assert(stream_id >= 0 && stream_id < MAX_VERTEX_STREAMS);

   /* Control data bits are initialized to 0 so we don't have to set any
    * bits when sending vertices to stream 0.
    */
   if (stream_id == 0)
      return;

   /* reg::sid = stream_id */
   src_reg sid(this, glsl_type::uint_type);
   emit(MOV(dst_reg(sid), stream_id));

   /* reg:shift_count = 2 * (vertex_count - 1) */
   src_reg shift_count(this, glsl_type::uint_type);
   emit(SHL(dst_reg(shift_count), this->vertex_count, 1u));

   /* Note: we're relying on the fact that the GEN SHL instruction only pays
    * attention to the lower 5 bits of its second source argument, so on this
    * architecture, stream_id << 2 * (vertex_count - 1) is equivalent to
    * stream_id << ((2 * (vertex_count - 1)) % 32).
    */
   src_reg mask(this, glsl_type::uint_type);
   emit(SHL(dst_reg(mask), sid, shift_count));
   emit(OR(dst_reg(this->control_data_bits), this->control_data_bits, mask));
}
Ejemplo n.º 2
0
	size_t EnvelopFinder::extendPeak(PeakSet& pk_set, RichPeakListByMZ& pks_mz,RichPeakListByMZ::iterator iter_mz, unsigned int charge, int direction)
	{
		//int dist = direction > 0 ? std::distance(iter_mz, pks_mz.end())-1 : std::distance(pks_mz.begin(), iter_mz);
		
		unsigned int shift = 1;
		//int prev_dist = 0;

		// Experimental candidate base peak.
		RichPeakPtr expr_base_pk = *iter_mz;

		int mode = param.getParameter<int>("mode").first;
		// For confidence estimation, using internal_accuracy.
		double internal_accuracy = param.getParameter<double>("internal_accuracy").first;

		// For peak finding and lambda estimation, using external_accuracy.
		double external_accuracy = param.getParameter<double>("external_accuracy").first;

		// Calculate the mass of the candidate base peak.
		// Notice that there will be mechanism where there is electron capture.
		double mass = calculateMass(expr_base_pk->mz, charge * mode);

		// Create theoretical boundary. The boundary has been adjusted to fit the charge.
		//EnvelopBoundary env_bound = this->createBoundary(mass, charge);
		EnvelopBoundary& env_bound = pk_set.getBoundary();

		//std::cout << "Up Boundary: " << std::endl;
		//env_bound.first.printPeakList<peak_mz>();
		//std::cout << "Down Boundary: " << std::endl;
		//env_bound.second.printPeakList<peak_mz>();

		// Get a copy of the base peak iterator for further move operation.
		//RichPeakListByMZ::iterator iter = iter_mz;
		int stop_flag = 1;

		// Dynamically convert pk_set into vector of envelops.
		std::pair<unsigned int, size_t> shift_count(0,1);
		size_t max_env = 0;

		//std::advance(iter_mz, direction);
		if(direction < 0 && iter_mz == pks_mz.begin())
			return 0;
		std::advance(iter_mz, direction);
		if(direction > 0 && iter_mz == pks_mz.end())
			return 0;

		// TBD: the program should efficiently location the position of most likely peak. instead of sequentially search for it.
		while(1)
		{


			std::cout << "Shift: " << shift << std::endl;

			// Get the boundary peaks at current shift.
			PeakPtr theo_pk1 = env_bound.getUpperBound().getPeakByShift<peak_intensity>(direction * shift);
			PeakPtr theo_pk2 = env_bound.getLowerBound().getPeakByShift<peak_intensity>(direction * shift);

			// No extension any more.
			if(theo_pk1->mz == 0.0 && theo_pk2->mz == 0.0)
				break;

			RichPeakPtr current_pk = *iter_mz;
			std::cout << "Examine peak: " << current_pk->mz << std::endl;

			// Experimental distance from current peak to base peak.
			// Notice that the value might be negative.
			double expr_dist = abs(current_pk->mz - expr_base_pk->mz);

			// Theoretical distance from current peak to base peak. Adjusted for charged peak.
			double theo_dist1 = abs(env_bound.getUpperBound().getMassDifferenceByShift<peak_intensity>(0, shift));
			double theo_dist2 = abs(env_bound.getLowerBound().getMassDifferenceByShift<peak_intensity>(0, shift));

			double max_dist = theo_dist1;
			double min_dist = theo_dist2;

			if(max_dist < min_dist) {
				swap(min_dist, max_dist);
			}

			double error1 = 1e6 * (expr_dist - min_dist)/expr_base_pk->mz;
			double error2 = 1e6 * (expr_dist - max_dist)/expr_base_pk->mz;
			
			if(error1 < -1 * external_accuracy) {
				// Before the shift region: keep moving the iterator.
				// std::advance(iter_mz, direction); continue;
			} else if(error2 > external_accuracy) { 
				// Beyond the shift region: update shift.
				if(stop_flag == 0) {
					shift++; stop_flag = 1; continue;
				} else {
					// break means no missing peak is allowed in the middle. This might be controlled by some parameter.
					stop_flag = 1;
					break;
				}
			} else {
				// A matching peak. Notice the effect of charge state.
				std::cout << "A matching peak!" << std::endl;
				
				if(shift == shift_count.first) {
					shift_count.second++;
				} else {
					// Reset shift_count.
					shift_count = std::make_pair(shift, 1);
				}

				// Update maximum number of envelops.
				if(shift_count.second > max_env)
					max_env = shift_count.second;

				stop_flag = 0;
				// Estimate the confidence of the mz in terms of estimating lambda.
				double diff = max_dist - min_dist;

				// Error window is used for confidence estimation.
				double err_win = internal_accuracy * expr_base_pk->mz * 1e-6;
				double prob = diff/(diff + 2*err_win);

				// Indicate the sign of the error window.
				int err_sign = (theo_dist1 < theo_dist2 ? -1 : 1);

				//: lambda_mz should always be in (0, 1). If lambda is closed to 1, the pattern is closed to no-sulfate boundary, and 0 for high-sulfate boundary.
				double lambda_mz = (expr_dist - theo_dist2+err_sign*err_win)/(theo_dist1 - theo_dist2 + 2*err_sign*err_win);

				// Round the abnormal lambda_mz to the boundary.
				if(lambda_mz > 1) {
					lambda_mz = 1.0;
					prob = 1.0;
				} else if(lambda_mz < 0) {
					lambda_mz = 0.0;
					prob = 1.0;
				}

				// TBD: estimate lambda_abd (within 5%) and delta_lambda.
				// Notice: lambda_abd can be < 0 or > 1.
				double lambda_abd = (current_pk->resolution/expr_base_pk->resolution - theo_pk2->intensity)/(theo_pk1->intensity - theo_pk2->intensity);

				InfoPeakPtr pk_infor = boost::make_shared<InfoPeak>(current_pk->resolution, lambda_mz, lambda_abd, prob);
				// Notice: The abundance information should be initialized during the establish of global lambda value.
				//pk_infor.adjusted_abundance = env_bound.getTheoreticalPeak(lambda_abd, shift).intensity;
				
				pk_set.addPeak(shift, current_pk, pk_infor);
				
			}
			if(direction < 0 && iter_mz == pks_mz.begin())
				break;
			std::advance(iter_mz, direction);
			if(direction > 0 && iter_mz == pks_mz.end())
				break;
		}
		return max_env;
	}
int main(int argc, char *argv[])
{
  FILE *in, *out;
  char outFileName[255];
  int size = -1;
  int val;
  
  char * fileData;
  char * fileDataTemp;
  int round = 0;
  int count;
  int forcount = 0;
  int running_max_count = 0;


  if (argc != 2 && argc != 3) {
    printf("Usage: xoranal inputfile [outfile]\n");
    return -1;
  }

  if ((in = fopen(argv[1], "rb")) == NULL) {
    printf("Cant't open file name %s\n", argv[1]);
    return -1;
  }

  // generate output name from input name if no output name given
  if (argc == 2) {
  	snprintf(outFileName, 200, "%s.xoranal.txt", argv[1]);
  } else {
  	strcpy(outFileName, argv[2]);
  }
  if ((out = fopen(outFileName, "wb")) == NULL) {
    printf("Cant't open file name %s\n", outFileName);
    fclose(in);
    return -1;
  }
  
  // read file
  fseek(in, 0, SEEK_END);
  size = ftell(in);
  printf("filesize %i bytes\n", size);
  fileData = (char *) calloc(size, sizeof(char));
  fileDataTemp = (char *) calloc(size, sizeof(char));
  
  rewind(in);
  forcount = 0;
  while((val = fgetc(in)) != EOF) {
	fileData[forcount++] = val;
  }
  fclose(in);

  while(++round <= KEYSIZE_MAX) {
	count = shift_count(fileData, fileDataTemp, size, round);
	fprintf(out, "%10i %10i %f%%\n", round, count, 100 * (float)count / (float)size);

  if(count > running_max_count) {
    printf("new max @ %10i %10i %f%%\n", round, count, 100 * (float)count / (float)size);
    running_max_count = count;
  }
	
	if(round % 10 == 0)
		printf("round %4i / %4i finished\n", round, KEYSIZE_MAX);
  }
  
  fclose(out);
  
  printf("finished, see %s for results\n", outFileName);
  
  return 0;
}