Пример #1
0
        private static List <UMCLight> FilterFeaturesByAbundance(List <UMCLight> features,
                                                                 LcmsWarpAlignmentOptions alignmentOptions)
        {
            // Sort by abundance to ease filtering process. Options look at the percentage of abundance
            // so threshhold needs to be converted to what the abundance sum would be.
            features.Sort((x, y) => x.AbundanceSum.CompareTo(y.AbundanceSum));

            if (alignmentOptions.TopFeatureAbundancePercent <= 0)
            {
                return(features);
            }

            var percent   = 1 - (alignmentOptions.TopFeatureAbundancePercent / 100);
            var total     = features.Count - Convert.ToInt32(features.Count * percent);
            var threshold = features[Math.Min(features.Count - 1, Math.Max(0, total))].AbundanceSum;

            // Re-sort with regards to monoisotopic mass for accurate application of NET-Mass function
            // to the dataset we need to align.
            features.Sort((x, y) => x.MassMonoisotopic.CompareTo(y.MassMonoisotopic));

            if (threshold <= 0)
            {
                return(features);
            }

            // Filters features below a certain threshold.
            var filteredFeatures = features.Where(feature => feature.AbundanceSum >= threshold);

            return(filteredFeatures.ToList());
        }
Пример #2
0
        /// <summary>
        /// Public constructor for the LCMS Alignment Processor
        /// Initializes a new LCMSWarp object using the LCMS Alignment options
        /// that are passed into the Processor
        /// </summary>
        /// <remarks>
        /// Store data using SetReferenceDatasetFeatures and SetAligneeDatasets,
        /// then call PerformAlignmentToMsFeatures, which calls either PerformNetWarp or PerformNetMassWarp</remarks>
        public LcmsWarpAlignmentProcessor(LcmsWarpAlignmentOptions options)
        {
            _options  = options;
            _lcmsWarp = new LcmsWarp(_options);

            _lcmsWarp.Progress += lcmsWarp_Progress;

            _currentTaskPercentCompleteAtStart = new Dictionary <CurrentLcmsWarpTask, double>
            {
                { CurrentLcmsWarpTask.Unstarted, 0 },
                { CurrentLcmsWarpTask.GenerateCandidateMatches, 0 },
                { CurrentLcmsWarpTask.GetMatchProbabilities, 10 },
                { CurrentLcmsWarpTask.CalculateAlignmentMatrix, 90 },
                { CurrentLcmsWarpTask.CalculateAlignmentFunction, 93 },
                { CurrentLcmsWarpTask.GetTransformedNets, 96 },
                { CurrentLcmsWarpTask.CalculateAlignmentMatches, 98 },
                { CurrentLcmsWarpTask.Complete, 100 }
            };

            _percentCompleteAtStartOfTask = 0;
            _percentCompleteAtEndOfTask   = 100;

            _aligningToMassTagDb = false;
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NewLcmsWarp"/> class.
 /// </summary>
 /// <param name="options">The alignment configuration options.</param>
 public NewLcmsWarp(LcmsWarpAlignmentOptions options)
 {
     this.options = options;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LcmsWarpFeatureMatcher" /> class.
 /// </summary>
 /// <param name="options">Options for the LCMSWarp alignment algorithm.</param>
 public LcmsWarpFeatureMatcher(LcmsWarpAlignmentOptions options)
 {
     this.options = options;
     this.Matches = new List <LcmsWarpFeatureMatch>();
 }
Пример #5
0
 public LcmsWarpFeatureAligner(LcmsWarpAlignmentOptions options)
 {
     _options = options;
 }
Пример #6
0
        /// <summary>
        /// Aligns the dataset to the data stored in the alignment processor.
        /// </summary>
        /// <param name="alignmentProcessor">Aligner</param>
        /// <param name="features">LC-MS Features to align to the baseline</param>
        /// <param name="alignmentOptions">Options</param>
        /// <param name="progress"></param>
        /// <returns></returns>
        private AlignmentData AlignFeatures(LcmsWarpAlignmentProcessor alignmentProcessor,
                                            IEnumerable <UMCLight> features,
                                            LcmsWarpAlignmentOptions alignmentOptions,
                                            IProgress <ProgressData> progress = null)
        {
            var progData      = new ProgressData(progress);
            var localProgress = new Progress <ProgressData>(p => progData.Report(p.Percent, p.Status));
            var alignmentData = new AlignmentData();

            OnStatus("Starting alignment of features.");

            // Set minMtdbnet and maxMtdbnet to 0
            alignmentData.MinMTDBNET = 0;
            alignmentData.MaxMTDBNET = 0;

            var umcLights = features as List <UMCLight> ?? features.ToList();

            progData.StepRange(5, "Starting alignment of features.");
            var filteredFeatures = FilterFeaturesByAbundance(umcLights, alignmentOptions);

            // Convert the features, and make a map, so that we can re-adjust the aligned values later.
            var map = FeatureDataConverters.MapFeature(umcLights);

            progData.StepRange(10, "Setting alignee features.");
            // Set features
            OnStatus("Setting alignee features.");
            alignmentProcessor.SetAligneeDatasetFeatures(filteredFeatures);

            progData.StepRange(90, "Performing alignment warping.");
            // Find alignment
            OnStatus("Performing alignment warping.");
            alignmentProcessor.PerformAlignmentToMsFeatures(localProgress);

            progData.StepRange(95);
            // Extract alignment function
            alignmentData.AlignmentFunction = alignmentProcessor.GetAlignmentFunction();

            progData.StepRange(100);
            // Extract the NET value for every scan
            _scanToNETMap = alignmentProcessor.GetScanToNETMapping();

            // Correct the features (updates NetAligned and MassMonoisotopicAligned)
            OnStatus("Applying alignment function to all features.");
            progData.Status = "Applying alignment function to all features.";
            umcLights       = alignmentProcessor.ApplyNetMassFunctionToAligneeDatasetFeatures(umcLights);
            progData.Report(100);

            // Find min/max scan for meta-data
            var minScanBaseline = int.MaxValue;
            var maxScanBaseline = int.MinValue;

            foreach (var feature in umcLights)
            {
                maxScanBaseline = Math.Max(maxScanBaseline, feature.Scan);
                minScanBaseline = Math.Min(minScanBaseline, feature.Scan);
            }

            // Update the scan and NET ranges
            alignmentData.MinScanBaseline = minScanBaseline;
            alignmentData.MaxScanBaseline = maxScanBaseline;
            alignmentData.MinMTDBNET      = (float)alignmentProcessor.MinReferenceNet;
            alignmentData.MaxMTDBNET      = (float)alignmentProcessor.MaxReferenceNet;

            // Cache the matching features
            alignmentData.FeatureMatches = alignmentProcessor.FeatureMatches;

            // Pull out the heat maps...
            OnStatus("Retrieving alignment data.");
            progData.Status          = "Retrieving alignment data.";
            alignmentData.HeatScores = alignmentProcessor.GetAlignmentHeatMap(alignmentOptions.StandardizeHeatScores);

            // Mass and net error histograms!
            alignmentData.MassErrorHistogram  = alignmentProcessor.GetMassErrorHistogram(alignmentOptions.MassBinSize);
            alignmentData.NetErrorHistogram   = alignmentProcessor.GetNetErrorHistogram(alignmentOptions.NetBinSize);
            alignmentData.DriftErrorHistogram = alignmentProcessor.GetDriftErrorHistogram(alignmentOptions.DriftTimeBinSize);

            // Get the residual data from the warp.
            alignmentData.ResidualData = alignmentProcessor.GetResidualData();

            alignmentData.NETIntercept          = alignmentProcessor.NetIntercept;
            alignmentData.NETRsquared           = alignmentProcessor.NetRsquared;
            alignmentData.NETSlope              = alignmentProcessor.NetSlope;
            alignmentData.MassMean              = alignmentProcessor.MassMu;
            alignmentData.MassStandardDeviation = alignmentProcessor.MassStd;
            alignmentData.NETMean = alignmentProcessor.NetMu;
            alignmentData.NETStandardDeviation = alignmentProcessor.NetStd;
            alignmentData.BaselineIsAmtDB      = _options.AlignToMassTagDatabase;

            return(alignmentData);
        }