public override void GetFitScores(IEnumerable <IsosResult> isosResults) { foreach (var result in isosResults) { //create a temporary mass tag, as a data object for storing relevant info, and using the CalculateMassesForIsotopicProfile() method. var mt = new PeptideTarget { ChargeState = (short)result.IsotopicProfile.ChargeState, MonoIsotopicMass = result.IsotopicProfile.MonoIsotopicMass }; mt.MZ = (mt.MonoIsotopicMass / mt.ChargeState) + Globals.PROTON_MASS; //TODO: use Josh's isotopicDistribution calculator after confirming averagine formula mt.EmpiricalFormula = _tomIsotopicPatternGenerator.GetClosestAvnFormula(result.IsotopicProfile.MonoIsotopicMass, false); mt.IsotopicProfile = _tomIsotopicPatternGenerator.GetIsotopePattern(mt.EmpiricalFormula, _tomIsotopicPatternGenerator.aafIsos); TheorIsotopicProfile = mt.IsotopicProfile; mt.CalculateMassesForIsotopicProfile(mt.ChargeState); var theorXYData = mt.IsotopicProfile.GetTheoreticalIsotopicProfileXYData(result.IsotopicProfile.GetFWHM()); offsetDistribution(theorXYData, mt.IsotopicProfile, result.IsotopicProfile); // Obsolete Class-wide variable: MercuryDistributionCreator distributionCreator; // //double resolution = result.IsotopicProfile.GetMZofMostAbundantPeak() / result.IsotopicProfile.GetFWHM(); //distributionCreator.CreateDistribution(result.IsotopicProfile.MonoIsotopicMass, result.IsotopicProfile.ChargeState, resolution); //distributionCreator.OffsetDistribution(result.IsotopicProfile); //XYData theorXYData = distributionCreator.Data; var areaFitter = new AreaFitter(); var fitVal = areaFitter.GetFit(theorXYData, result.Run.XYData, 0.1, out _); if (double.IsNaN(fitVal) || fitVal > 1) { result.IsotopicProfile.Score = 1; } else { result.IsotopicProfile.Score = fitVal; } } }
public double CalculateFitScore(IsotopicProfile theorProfile, IsotopicProfile observedProfile, XYData massSpecXYData) { if (observedProfile == null || observedProfile.Peaklist == null || observedProfile.Peaklist.Count == 0) { return(1.0); // this is the worst possible fit score. ( 0.000 is the best possible fit score); Maybe we want to return a '-1' to indicate a failure... } var indexOfMostAbundantTheorPeak = theorProfile.GetIndexOfMostIntensePeak(); var indexOfCorrespondingObservedPeak = PeakUtilities.getIndexOfClosestValue(observedProfile.Peaklist, theorProfile.getMostIntensePeak().XValue, 0, observedProfile.Peaklist.Count - 1, 0.1); if (indexOfCorrespondingObservedPeak < 0) // most abundant peak isn't present in the actual theoretical profile... problem! { return(1.0); } var mzOffset = observedProfile.Peaklist[indexOfCorrespondingObservedPeak].XValue - theorProfile.Peaklist[indexOfMostAbundantTheorPeak].XValue; var theorXYData = theorProfile.GetTheoreticalIsotopicProfileXYData(observedProfile.GetFWHM()); //theorXYData.Display(); theorXYData.OffSetXValues(mzOffset); //May want to avoid this offset if the masses have been aligned using LCMS Warp //theorXYData.Display(); var areafitter = new AreaFitter(); int ionCountUsed; var fitval = areafitter.GetFit(theorXYData, massSpecXYData, 0.1, out ionCountUsed); if (double.IsNaN(fitval) || fitval > 1) { fitval = 1; } return(fitval); }