예제 #1
0
        /// <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,
            });
        }
예제 #2
0
        /// <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>
        /// <returns>The features with all NET values warped.</returns>
        public NewAlignmentData WarpNetMass(List <UMCLight> aligneeFeatures, List <UMCLight> baselineFeatures)
        {
            // First pass NET warp: Perform warp by only scoring matches in NET
            var netWarpedFirstPass = this.WarpNet(aligneeFeatures, baselineFeatures, false);

            // Generate matches from features by matching in both mass and NET
            var featureMatcher = new LcmsWarpFeatureMatcher(this.options);

            featureMatcher.GenerateCandidateMatches(
                netWarpedFirstPass.AlignedFeatures,
                baselineFeatures,
                this.options.SeparationTypes);
            var matches = featureMatcher.Matches;

            // Calculate mass alignment
            var massCalibrator   = MassCalibrationFactory.GetCalibrator(this.options);
            var massCalibrations = massCalibrator.CalculateCalibration(matches);

            // Warp features.
            var warpedFeatures = massCalibrations.GetWarpedFeatures(aligneeFeatures).ToList();

            // Calculate histograms/plots for mass alignment
            var massErrorHistogram = LcmsWarpPlotDataCreator.GetMassErrorHistogram(matches, 10);

            // Create results object
            var massAlignmentResult = new LcmsWarpResults
            {
                AlignmentFunction = massCalibrations,
                ErrorHistogram    = massErrorHistogram,
            };

            // Second pass NET warp: Perform warp that scores matches in mass AND NET
            var netMassWarpedSecondPass = this.WarpNet(warpedFeatures, baselineFeatures, true);

            // Add mass alignment results to existing alignment results from the NET alignment.
            netMassWarpedSecondPass.MassAlignment = massAlignmentResult;
            return(netMassWarpedSecondPass);
        }