Beispiel #1
0
int	 PeakList::findPeakWithMaxIntensity(mass_t expectedMass, mass_t tolerance) const
{
    PeakRange pr = findPeaksInRange(expectedMass-tolerance, expectedMass+tolerance);
    if (pr.num_peaks==0)
        return -1;

    if (pr.num_peaks ==1)
        return pr.low_idx;

    const float doubleTolerance = tolerance + tolerance;

    mass_t maxWeightedValue = (doubleTolerance - fabs(peaks_[pr.low_idx].mass - expectedMass)) *
                              peaks_[pr.low_idx].intensity;

    int maxPeakIdx=pr.low_idx;

    // find closest peak to exp_pos
    for (int i=1; i<pr.num_peaks; i++)
    {
        const int peakIdx = pr.low_idx + i;
        const mass_t weightedValue = (doubleTolerance - fabs(peaks_[peakIdx].mass -
                                      expectedMass)) * peaks_[peakIdx].intensity;

        if (weightedValue>maxWeightedValue)
        {
            maxWeightedValue=weightedValue;
            maxPeakIdx = peakIdx;
        }
        else
            break;
    }
    return maxPeakIdx;
}
Beispiel #2
0
// There are fixed magic numbers in this function that should not be changed
// (even though actual tolerances or values in config file might differ)
// changing these numbers without retraining all models might give unanticipated results
void PeakList::calculateLogRandomProbabilities(vector<float>& logIntensities,
        vector<float>& logRandomProbabilities) const
{
    if (numPeaks_<2)
        return;

    const float oneOverSqrt2pi = 1.0 / sqrt(2.0*3.1415927);
    const float logBias = log(1.2); // to fine tune the zero probabilites
    const mass_t peakWindowSize = 0.6; // this is fixed and independent of the tolerance!!!
    const mass_t margin      = 25.0;   // fixed and independent of values in config file
    const mass_t windowSize = 100.0;   // fixed and independent of values in config file
    const mass_t minPeakMass = peaks_[0].mass;
    const mass_t maxPeakMass = peaks_[numPeaks_-1].mass;
    const mass_t visibleRange = (maxPeakMass - minPeakMass);

    logRandomProbabilities.resize(numPeaks_);
    int i;
    for (i=0; i<numPeaks_; i++)
    {
        const mass_t peakMass = peaks_[i].mass;
        const mass_t relativePosition = (peakMass-minPeakMass)/visibleRange;
        const mass_t leftWindow  = margin + relativePosition * windowSize;
        const mass_t rightWindow = margin + windowSize - leftWindow;
        const PeakRange pr = findPeaksInRange(peakMass - leftWindow, peakMass + rightWindow);
        const float peakWindowProb = peakWindowSize /(leftWindow + rightWindow);

        // some freak cases have 0 peak counts (only in unix)
        const int numPeaksInRange = (pr.num_peaks>0 ? pr.num_peaks : 1);
        const float zeroProbability = pow((1.0 - peakWindowProb),numPeaksInRange);

        if (numPeaksInRange<5)
        {
            logRandomProbabilities[i] = log(1.0-zeroProbability) + logBias;
        }
        else // compute special probability based on peak densitiy model
        {
            vector<float> windowLogIntensities;
            int j;
            for (j=pr.low_idx; j<=pr.high_idx; j++)
                windowLogIntensities.push_back(logIntensities[j]);

            float mean=0,sd=1;
            calc_mean_sd(windowLogIntensities,&mean,&sd);
            const float e = (logIntensities[i] - mean)/sd;
            if (e<0)
            {
                logRandomProbabilities[i] = log(1 - zeroProbability) + logBias;
            }
            else
            {
                const float normalizedValue = (oneOverSqrt2pi/ sd) * exp(-0.5*e*e);
                const float normalizationConstant = (1.0 - zeroProbability) / (oneOverSqrt2pi / sd); //
                logRandomProbabilities[i] = log(normalizedValue*normalizationConstant);
            }
        }
    }
}
Beispiel #3
0
/***********************************************************************
calcs for each peak the probability of observing it at random (based on
 the neighbor's distribution. Assumes the log_intens are distributed
 according to a normal disribution.
************************************************************************/
void Spectrum::set_log_random_probs()
{
	if (numPeaks_<2)
		return;
	const float log_add = log(1.2);
	const float one_over_sqr_2pi = 1.0 / sqrt(2*3.1415927);
	const mass_t peak_window_size = 0.6; // this is fixed and independent of the tolerance!
	const mass_t margin      = 25.0;
	const mass_t window_size = 100.0;
	const mass_t min_mass = peaks_[0].mass;
	const mass_t max_mass = peaks_[numPeaks_-1].mass;
	const mass_t viz_range = (max_mass - min_mass);

	logRandomProbabilities_.resize(numPeaks_);	
	int i;
	for (i=0; i<numPeaks_; i++)
	{
		const mass_t peak_mass    = peaks_[i].mass;
		const mass_t rel_position = (peak_mass-min_mass)/viz_range;
		const mass_t left_window  = margin + rel_position * window_size;
		const mass_t right_window = margin + window_size - left_window;
		const PeakRange pr = findPeaksInRange(peak_mass-left_window,peak_mass+right_window);
		const float peak_window_prob = peak_window_size /(left_window + right_window);

		// some freak cases have 0 peak counts (only in unix)
		const int num_peaks_in_range = (pr.num_peaks>0 ? pr.num_peaks : 1);
		const float zero_prob = pow((1.0 - peak_window_prob),num_peaks_in_range); 

		if (pr.num_peaks<5)
		{
			logRandomProbabilities_[i] = log(1.0-zero_prob) + log_add;
		}
		else
		{
			vector<float> log_intens;
			int j;
			for (j=pr.low_idx; j<=pr.high_idx; j++)
				log_intens.push_back(logIntensities_[j]);
		
			float mean=0,sd=1;
			calc_mean_sd(log_intens,&mean,&sd);
			const float e = (logIntensities_[i] - mean)/sd;
			if (e<0)
			{
				logRandomProbabilities_[i] = log(1 - zero_prob) + log_add;
			}
			else
			{
				const float norm = (one_over_sqr_2pi/ sd) * exp(-0.5*e*e);
				const float norm_const = (1 - zero_prob) / (one_over_sqr_2pi/ sd); //
				logRandomProbabilities_[i] = log(norm*norm_const);
			}
		} 
	}
}
Beispiel #4
0
void PeakList::calculateLogLocalRanks(mass_t windowSize, vector<float>& logLocalRanks) const
{

    const mass_t halfWindowSize = windowSize * 0.5;
    logLocalRanks.resize(numPeaks_);

    int i;
    for (i=0; i<numPeaks_; i++)
    {
        const PeakRange pr= findPeaksInRange(peaks_[i].mass - halfWindowSize,
                                             peaks_[i].mass + halfWindowSize);
        int above=0;
        int j;
        for (j=pr.low_idx; j<=pr.high_idx && j<numPeaks_; j++)
            if (peaks_[j].intensity>peaks_[i].intensity)
                above++;

        logLocalRanks[i] = log(1.0 + static_cast<float>(above));
    }
}
Beispiel #5
0
/*********************************************************************
// gives each peak it log local rank
// good be done more effciently...
**********************************************************************/
void Spectrum::calc_log_local_ranks()
{
	const mass_t half_window_size = config_->get_local_window_size() * 0.5;
	
	logLocalRanks_.resize(numPeaks_);	
	
	int i;
	for (i=0; i<numPeaks_; i++)
	{
		
		const mass_t peak_mass = peaks_[i].mass;

		const PeakRange pr= findPeaksInRange(peak_mass - half_window_size,
											 peak_mass + half_window_size);
		int above=0;
		int j;
		for (j=pr.low_idx; j<=pr.high_idx && j<numPeaks_; j++)
			if (peaks_[j].intensity>peaks_[i].intensity)
				above++;

		logLocalRanks_[i] = log(1.0 + static_cast<float>(above));
	}	
}