/// <summary> /// Generates alignment functions for alignment between features in each separation dimension. /// Warps the elution value for each feature based on the alignment function. /// </summary> /// <param name="aligneeFeatures">The features to warp.</param> /// <param name="baselineFeatures">The features to warp to.</param> /// <param name="includeMassInMatchScore"> /// Should mass be considered when scoring a match between an alignee feature and baseline feature? /// </param> /// <returns>The list of alignment results for each separation dimension.</returns> public NewAlignmentData WarpNet(List <UMCLight> aligneeFeatures, List <UMCLight> baselineFeatures, bool includeMassInMatchScore) { // Generate candidate matches: Match alignee features -> baseline features by mass only var featureMatcher = new LcmsWarpFeatureMatcher(this.options); featureMatcher.GenerateCandidateMatches(aligneeFeatures, baselineFeatures); var warpedFeatures = new List <UMCLight>(aligneeFeatures); var results = new Dictionary <FeatureLight.SeparationTypes, LcmsWarpResults>(); // Perform warp on each separation dimension. foreach (var separationType in this.options.SeparationTypes) { // Get matches for given separation dimension var matches = featureMatcher.GetMatchesAs(separationType); // Calculate two dimensional statistics for mass and the current separation dimension. var statistics = LcmsWarpStatistics.CalculateAndGetStatistics(matches); // Calculate alignee sections var aligneeSections = new LcmsWarpSectionInfo(this.options.NumTimeSections); aligneeSections.InitSections(aligneeFeatures); // Calculate baseline sections var baselineSections = new LcmsWarpSectionInfo(this.options.NumTimeSections * this.options.ContractionFactor); baselineSections.InitSections(baselineFeatures); // Generate alignment function, only score sections based on NET. var alignmentScorer = new LcmsWarpAlignmentScorer(this.options, includeMassInMatchScore, statistics); var alignmentFunction = alignmentScorer.GetAlignment(aligneeSections, baselineSections, matches); alignmentFunction.SeparationType = separationType; // Create alignment score heatmap var alignmentScoreHeatMap = LcmsWarpPlotDataCreator.GetAlignmentHeatMap( alignmentScorer.AlignmentScoreMatrix, true, this.options.NumTimeSections, this.options.NumBaselineSections, this.options.MaxExpansionWidth); // Warp the values in the features for this separation type warpedFeatures = alignmentFunction.GetWarpedFeatures(warpedFeatures).ToList(); var dimensionResults = new LcmsWarpResults { AlignmentFunction = alignmentFunction, Statistics = statistics, AlignmentScoreHeatMap = alignmentScoreHeatMap }; results.Add(separationType, dimensionResults); } return(new NewAlignmentData { SeparationAlignments = results, AlignedFeatures = warpedFeatures, }); }
/// <summary> /// Calculates the Standard deviations of the matches. /// Note: method requires more than 6 matches to produce meaningful results. /// </summary> public static LcmsWarpStatistics CalculateAndGetStatistics(List <LcmsWarpFeatureMatch> matches) { if (matches.Count <= RequiredMatches) { throw new ArgumentException(string.Format("This requires at least {0} matches to produce meaningful results", RequiredMatches)); } // Calculate NET delta (difference between alignee and baseline NET). var massDeltas = new List <double>(matches.Count); var netDeltas = new List <double>(matches.Count); foreach (var match in matches) { var baselineFeature = match.BaselineFeature; massDeltas.Add(((baselineFeature.MassMonoisotopic - match.AligneeFeature.MassMonoisotopic) * 1000000) / match.AligneeFeature.MassMonoisotopic); netDeltas.Add(match.BaselineNet - match.Net); } // Two dimensional expectation maximization double normalProbability, falseHitProbDensity, muMass, muNet, massStdDev, netStdDev; MathUtilities.TwoDem( massDeltas, netDeltas, out normalProbability, out falseHitProbDensity, out muMass, out muNet, out massStdDev, out netStdDev); var statistics = new LcmsWarpStatistics { MassStdDev = massStdDev, NetStdDev = netStdDev, FalseHitProbDensity = falseHitProbDensity, NormalProbability = normalProbability }; return(statistics); }