Esempio n. 1
0
        public static RawMetricsDataDDA GetMetricsDataDDA(ScanMetaDataCollectionDDA metaData, MethodDataContainer methodData,
                                                          string rawFileName, RetentionTimeCollection retentionTimes, ScanIndex index, PrecursorPeakCollection peakData,
                                                          PrecursorScanCollection precursorScans, QuantDataCollection quantData = null)
        {
            RawMetricsDataDDA metricsData = new RawMetricsDataDDA();

            metricsData.DateAcquired = methodData.CreationDate;
            metricsData.Instrument   = methodData.Instrument;
            Console.WriteLine("Calculating metrics");

            metricsData.RawFileName = rawFileName;
            metricsData.Instrument  = methodData.Instrument;
            metricsData.MS1Analyzer = methodData.MassAnalyzers[MSOrderType.Ms];
            metricsData.MS2Analyzer = methodData.MassAnalyzers[MSOrderType.Ms2];

            metricsData.TotalAnalysisTime = retentionTimes[index.ScanEnumerators[MSOrderType.Any].Last()] -
                                            retentionTimes[index.ScanEnumerators[MSOrderType.Any].First()];

            metricsData.NumberOfEsiFlags = MetricsCalculations.NumberOfEsiFlags(metaData, index);

            metricsData.TotalScans = index.TotalScans;
            metricsData.MS1Scans   = index.ScanEnumerators[MSOrderType.Ms].Length;
            metricsData.MS2Scans   = index.ScanEnumerators[MSOrderType.Ms2].Length;

            if (methodData.AnalysisOrder == MSOrderType.Ms3)
            {
                metricsData.MS3Analyzer = methodData.MassAnalyzers[MSOrderType.Ms3];
                metricsData.MS3Scans    = index.ScanEnumerators[MSOrderType.Ms3].Length;
            }
            else
            {
                metricsData.MS3Analyzer = MassAnalyzerType.Any;
                metricsData.MS3Scans    = 0;
            }

            var pickedMs1 = new HashSet <int>((from x in index.ScanEnumerators[methodData.AnalysisOrder]
                                               select precursorScans[x].MasterScan)).ToList();

            metricsData.MSOrder = methodData.AnalysisOrder;

            metricsData.MedianSummedMS1Intensity = MetricsCalculations.GetMedianSummedMSIntensity(metaData.SummedIntensity, index, MSOrderType.Ms);
            metricsData.MedianSummedMS2Intensity = MetricsCalculations.GetMedianSummedMSIntensity(metaData.SummedIntensity, index, MSOrderType.Ms2);

            metricsData.MedianPrecursorIntensity = (from x in peakData.Keys select peakData[x].ParentIntensity).ToArray().Percentile(50);

            metricsData.MedianMS1FillTime = MetricsCalculations.GetMedianMSFillTime(metaData.FillTime, index, MSOrderType.Ms);
            metricsData.MedianMS2FillTime = MetricsCalculations.GetMedianMSFillTime(metaData.FillTime, index, MSOrderType.Ms2);

            if (methodData.AnalysisOrder == MSOrderType.Ms3)
            {
                metricsData.MedianMS3FillTime = MetricsCalculations.GetMedianMSFillTime(metaData.FillTime, index, MSOrderType.Ms3);
            }

            metricsData.MeanTopN = MetricsCalculations.GetMeanMs2ScansPerCycle(metaData.MS2ScansPerCycle);

            metricsData.MeanDutyCycle = MetricsCalculations.GetMedianDutyCycle(metaData.DutyCycle, index);

            metricsData.MedianMs2FractionConsumingTop80PercentTotalIntensity =
                MetricsCalculations.GetMedianMs2FractionConsumingTop80PercentTotalIntensity(
                    metaData.FractionConsumingTop80PercentTotalIntensity, index);


            metricsData.MS1ScanRate = metricsData.MS1Scans / metricsData.TotalAnalysisTime;
            metricsData.MS2ScanRate = metricsData.MS2Scans / metricsData.TotalAnalysisTime;
            if (methodData.AnalysisOrder == MSOrderType.Ms3)
            {
                metricsData.MS3ScanRate = metricsData.MS3Scans / metricsData.TotalAnalysisTime;
            }

            metricsData.MedianBaselinePeakWidth   = peakData.PeakShapeMedians.Width.P10;
            metricsData.MedianHalfHeightPeakWidth = peakData.PeakShapeMedians.Width.P50;

            // we can't access the instrument method in Linux, so we will assume the gradient length is the length of the MS acquisition
            metricsData.Gradient     = retentionTimes[index.allScans.Keys.Max()];
            metricsData.PeakCapacity = metricsData.Gradient / metricsData.MedianHalfHeightPeakWidth;

            metricsData.MedianAsymmetryFactor = peakData.PeakShapeMedians.Asymmetry.P10;

            // add isolation interference
            metricsData.MedianMs1IsolationInterference = (from scan in index.ScanEnumerators[methodData.AnalysisOrder]
                                                          select metaData.Ms1IsolationInterference[scan]).ToArray().Percentile(50);

            (double timeBefore, double timeAfter, double fracAbove)   = MetricsCalculations.ChromIntensityMetrics(metaData, retentionTimes, index);
            metricsData.TimeBeforeFirstScanToExceedPoint1MaxIntensity = timeBefore;
            metricsData.TimeAfterLastScanToExceedPoint1MaxIntensity   = timeAfter;
            metricsData.FractionOfRunAbovePoint1MaxIntensity          = fracAbove;

            metricsData.Ms1FillTimeDistribution = new Distribution((from x in index.ScanEnumerators[MSOrderType.Ms] select metaData.FillTime[x]).ToArray());
            metricsData.Ms2FillTimeDistribution = new Distribution((from x in index.ScanEnumerators[MSOrderType.Ms2] select metaData.FillTime[x]).ToArray());
            if (methodData.AnalysisOrder == MSOrderType.Ms3)
            {
                metricsData.Ms3FillTimeDistribution = new Distribution((from x in index.ScanEnumerators[MSOrderType.Ms3] select metaData.FillTime[x]).ToArray());
            }

            metricsData.PeakShape.Asymmetry.P10 = peakData.PeakShapeMedians.Asymmetry.P10;
            metricsData.PeakShape.Asymmetry.P50 = peakData.PeakShapeMedians.Asymmetry.P50;

            metricsData.PeakShape.Width.P10 = peakData.PeakShapeMedians.Width.P10;
            metricsData.PeakShape.Width.P50 = peakData.PeakShapeMedians.Width.P50;

            // now add the quant meta data, if quant was performed
            double        medianReporterIntensity = 0;
            QuantMetaData quantMetaData           = new QuantMetaData();
            SerializableDictionary <string, double> medianReporterIntensityByChannel = new SerializableDictionary <string, double>();

            if (quantData != null)
            {
                string        reagent     = quantData.LabelingReagents;
                string[]      allTags     = new LabelingReagents().Reagents[reagent].Labels;
                List <double> allChannels = new List <double>();
                Dictionary <string, List <double> > byChannel = new Dictionary <string, List <double> >();
                foreach (string tag in allTags)
                {
                    byChannel.Add(tag, new List <double>());
                }
                foreach (int scan in index.ScanEnumerators[methodData.AnalysisOrder])
                {
                    foreach (string tag in allTags)
                    {
                        byChannel[tag].Add(quantData[scan][tag].Intensity);
                        allChannels.Add(quantData[scan][tag].Intensity);
                    }
                }
                medianReporterIntensity = allChannels.ToArray().Percentile(50);

                foreach (string tag in allTags)
                {
                    medianReporterIntensityByChannel[tag] = byChannel[tag].ToArray().Percentile(50);
                }

                quantMetaData.medianReporterIntensity          = medianReporterIntensity;
                quantMetaData.medianReporterIntensityByChannel = medianReporterIntensityByChannel;
                quantMetaData.quantTags   = allTags;
                metricsData.QuantMeta     = quantMetaData;
                metricsData.IncludesQuant = true;
            }
            return(metricsData);
        }
Esempio n. 2
0
        public static void GetMetricsData(this MetricsData metricsData, ScanMetaDataCollection metaData, RawDataCollection rawData, IRawDataPlus rawFile, QuantDataCollection quantData = null)
        {
            List <Operations> operations = new List <Operations> {
                Operations.ScanIndex, Operations.RetentionTimes, Operations.MethodData, Operations.MetaData
            };

            if (!rawData.isBoxCar)
            {
                operations.Add(Operations.PeakRetAndInt);
                operations.Add(Operations.PeakShape);
            }

            rawData.Check(rawFile, operations);

            metricsData.RawFileName = rawData.rawFileName;
            metricsData.Instrument  = rawData.instrument;
            metricsData.MS1Analyzer = rawData.methodData.MassAnalyzers[MSOrderType.Ms];
            metricsData.MS2Analyzer = rawData.methodData.MassAnalyzers[MSOrderType.Ms2];

            metricsData.TotalAnalysisTime = rawData.retentionTimes[rawData.scanIndex.ScanEnumerators[MSOrderType.Any].Last()] -
                                            rawData.retentionTimes[rawData.scanIndex.ScanEnumerators[MSOrderType.Any].First()];

            metricsData.TotalScans = rawData.scanIndex.allScans.Count();
            metricsData.MS1Scans   = rawData.scanIndex.ScanEnumerators[MSOrderType.Ms].Length;
            metricsData.MS2Scans   = rawData.scanIndex.ScanEnumerators[MSOrderType.Ms2].Length;

            if (rawData.methodData.AnalysisOrder == MSOrderType.Ms3)
            {
                metricsData.MS3Analyzer = rawData.methodData.MassAnalyzers[MSOrderType.Ms3];
                metricsData.MS3Scans    = rawData.scanIndex.ScanEnumerators[MSOrderType.Ms3].Length;
            }
            else
            {
                metricsData.MS3Analyzer = MassAnalyzerType.Any;
                metricsData.MS3Scans    = 0;
            }

            metricsData.MSOrder = rawData.methodData.AnalysisOrder;

            List <double> ms2intensities       = new List <double>();
            List <double> precursorIntensities = new List <double>();
            List <double> ms1fillTimes         = new List <double>();
            List <double> ms2fillTimes         = new List <double>();
            List <double> ms3fillTimes         = new List <double>();
            List <double> ms2scansPerCycle     = new List <double>();
            List <double> dutyCycles           = new List <double>();
            List <double> fractionConsuming80  = new List <double>();

            foreach (int scan in rawData.scanIndex.ScanEnumerators[MSOrderType.Ms])
            {
                ms1fillTimes.Add(metaData[scan].FillTime);
                ms2scansPerCycle.Add(metaData[scan].MS2ScansPerCycle);
                dutyCycles.Add(metaData[scan].DutyCycle);
            }

            foreach (int scan in rawData.scanIndex.ScanEnumerators[MSOrderType.Ms2])
            {
                precursorIntensities.Add(rawData.peakData[scan].ParentIntensity);
                ms2intensities.Add(metaData[scan].SummedIntensity);
                ms2fillTimes.Add(metaData[scan].FillTime);
                fractionConsuming80.Add(metaData[scan].FractionConsumingTop80PercentTotalIntensity);
            }

            if (rawData.methodData.AnalysisOrder == MSOrderType.Ms3)
            {
                foreach (int scan in rawData.scanIndex.ScanEnumerators[MSOrderType.Ms3])
                {
                    ms3fillTimes.Add(metaData[scan].FillTime);
                }
            }

            metricsData.MedianPrecursorIntensity = precursorIntensities.ToArray().Percentile(50);
            metricsData.MedianMs2FractionConsumingTop80PercentTotalIntensity = fractionConsuming80.ToArray().Percentile(50);

            metricsData.MedianSummedMS2Intensity = ms2intensities.ToArray().Percentile(50);
            metricsData.MedianMS1FillTime        = ms1fillTimes.ToArray().Percentile(50);
            metricsData.MedianMS2FillTime        = ms2fillTimes.ToArray().Percentile(50);

            if (rawData.methodData.AnalysisOrder == MSOrderType.Ms3)
            {
                metricsData.MedianMS3FillTime = ms3fillTimes.ToArray().Percentile(50);
            }
            else
            {
                metricsData.MedianMS3FillTime = -1;
            }

            metricsData.MeanTopN      = ms2scansPerCycle.Average();
            metricsData.MeanDutyCycle = dutyCycles.Average();
            metricsData.MS1ScanRate   = metricsData.MS1Scans / metricsData.TotalAnalysisTime;
            metricsData.MS2ScanRate   = metricsData.MS2Scans / metricsData.TotalAnalysisTime;
            metricsData.MS3ScanRate   = metricsData.MS3Scans / metricsData.TotalAnalysisTime;

            // only do the following if it isn't a boxcar experiment
            if (!rawData.isBoxCar)
            {
                metricsData.MedianBaselinePeakWidth   = rawData.peakData.PeakShapeMedians.Width.P10;
                metricsData.MedianHalfHeightPeakWidth = rawData.peakData.PeakShapeMedians.Width.P50;

                // we can't access the instrument method in Linux, so we will assume the gradient length is the length of the MS acquisition
                metricsData.Gradient     = rawData.retentionTimes[rawData.scanIndex.allScans.Keys.Max()];
                metricsData.PeakCapacity = metricsData.Gradient / metricsData.MedianHalfHeightPeakWidth;

                metricsData.MedianAsymmetryFactor = rawData.peakData.PeakShapeMedians.Asymmetry.P10;
            }

            // add isolation interference
            metricsData.MedianMs1IsolationInterference = (from scan in rawData.scanIndex.ScanEnumerators[rawData.methodData.AnalysisOrder]
                                                          select rawData.metaData[scan].Ms1IsolationInterference).ToArray().Percentile(50);

            // now add the quant meta data, if quant was performed
            double        medianReporterIntensity = 0;
            QuantMetaData quantMetaData           = new QuantMetaData();
            SerializableDictionary <string, double> medianReporterIntensityByChannel = new SerializableDictionary <string, double>();

            if (quantData != null & rawData.Performed.Contains(Operations.Quantification))
            {
                string        reagent     = quantData.LabelingReagents;
                string[]      allTags     = new LabelingReagents().Reagents[reagent].Labels;
                List <double> allChannels = new List <double>();
                Dictionary <string, List <double> > byChannel = new Dictionary <string, List <double> >();
                foreach (string tag in allTags)
                {
                    byChannel.Add(tag, new List <double>());
                }
                foreach (int scan in rawData.scanIndex.ScanEnumerators[rawData.methodData.AnalysisOrder])
                {
                    foreach (string tag in allTags)
                    {
                        byChannel[tag].Add(quantData[scan][tag].Intensity);
                        allChannels.Add(quantData[scan][tag].Intensity);
                    }
                }
                medianReporterIntensity = allChannels.ToArray().Percentile(50);

                foreach (string tag in allTags)
                {
                    medianReporterIntensityByChannel[tag] = byChannel[tag].ToArray().Percentile(50);
                }

                quantMetaData.medianReporterIntensity          = medianReporterIntensity;
                quantMetaData.medianReporterIntensityByChannel = medianReporterIntensityByChannel;
                quantMetaData.quantTags   = allTags;
                metricsData.QuantMeta     = quantMetaData;
                metricsData.IncludesQuant = true;
            }
        }