Exemple #1
0
        public static PrecursorMassCollection PrecursorMasses(IRawDataPlus rawFile, PrecursorScanCollection precursorScans, TrailerExtraCollection trailerExtras, ScanIndex index)
        {
            rawFile.SelectInstrument(Device.MS, 1);
            Log.Information("Extracting precursor masses");

            PrecursorMassCollection precursorMasses = new PrecursorMassCollection();
            var scans = index.ScanEnumerators[MSOrderType.Any];

            ProgressIndicator progress = new ProgressIndicator(scans.Count(), "Extracting precursor masses");

            foreach (int scan in scans)
            {
                if (index.allScans[scan].MSOrder == MSOrderType.Ms2)
                {
                    double parent_mass = rawFile.GetScanEventForScanNumber(scan).GetReaction(0).PrecursorMass;
                    precursorMasses[scan] = new PrecursorMassData(trailerExtras[scan].MonoisotopicMZ, parent_mass);
                }
                if (index.allScans[scan].MSOrder == MSOrderType.Ms3)
                {
                    int    ms2scan     = precursorScans[scan].MS2Scan;
                    double parent_mass = rawFile.GetScanEventForScanNumber(scan).GetReaction(0).PrecursorMass;
                    precursorMasses[scan] = new PrecursorMassData(trailerExtras[ms2scan].MonoisotopicMZ, parent_mass);
                }

                progress.Update();
            }
            progress.Done();

            return(precursorMasses);
        }
Exemple #2
0
        public static void WriteSearchMGF(WorkflowParameters parameters, CentroidStreamCollection centroids, SegmentScanCollection segments, RetentionTimeCollection retentionTimes,
                                          PrecursorMassCollection precursorMasses, PrecursorScanCollection precursorScans, TrailerExtraCollection trailerExtras, MethodDataContainer methodData,
                                          ScanIndex index, string rawFileName, bool fixedScans = false)
        {
            var pars = parameters.QcParams.SearchParameters;

            int[] scans = AdditionalMath.SelectRandomScans(scans: index.ScanEnumerators[MSOrderType.Ms2],
                                                           num: parameters.QcParams.NumberSpectra, fixedScans: parameters.QcParams.FixedScans);

            string mgfFile = ReadWrite.GetPathToFile(parameters.QcParams.QcSearchDataDirectory, rawFileName, ".mgf");

            MgfWriter.WriteMGF(rawFileName, centroids, segments, parameters, retentionTimes, precursorMasses, precursorScans,
                               trailerExtras, methodData, index, outputFile: mgfFile, scans: scans);
        }
Exemple #3
0
        public static ScanMetaDataCollectionDDA AggregateMetaDataDDA(CentroidStreamCollection centroidStreams, SegmentScanCollection segmentScans, MethodDataContainer methodData,
                                                                     PrecursorScanCollection precursorScans, TrailerExtraCollection trailerExtras, PrecursorMassCollection precursorMasses,
                                                                     RetentionTimeCollection retentionTimes, ScanDependentsCollections scanDependents, ScanEventReactionCollection reactions, ScanIndex index)
        {
            //ProgressIndicator progress = new ProgressIndicator(index.ScanEnumerators[MSOrderType.Any].Count(),
            //   "Formatting scan meta data");

            ScanMetaDataCollectionDDA metaData = new ScanMetaDataCollectionDDA();

            int[] scans = index.ScanEnumerators[MSOrderType.Any];

            double isoWindow = MetaDataCalculations.Ms1IsoWindow(methodData);

            Console.WriteLine("Calculating meta data");

            Console.WriteLine("  MS1 isolation interference");
            metaData.Ms1IsolationInterference = MetaDataCalculations.Ms1Interference(centroidStreams, precursorMasses, trailerExtras,
                                                                                     precursorScans, reactions, index);

            Console.WriteLine("  MS2 scan cycle density");
            metaData.MS2ScansPerCycle = MetaDataCalculations.MS2ScansPerCycle(scanDependents, index);

            Console.WriteLine("  Ion injection time");
            metaData.FillTime = MetaDataCalculations.FillTimes(trailerExtras, index);

            Console.WriteLine("  Duty cycle");
            metaData.DutyCycle = MetaDataCalculations.DutyCycle(retentionTimes, index);

            Console.WriteLine("  Intensity distribution");
            metaData.IntensityDistribution = MetaDataCalculations.IntensityDistributions(centroidStreams, segmentScans, index);

            Console.WriteLine("  Summed intensities");
            metaData.SummedIntensity = MetaDataCalculations.SummedIntensities(centroidStreams, segmentScans, index);

            metaData.FractionConsumingTop80PercentTotalIntensity = MetaDataCalculations.Top80Frac(centroidStreams, segmentScans, index);

            //Task.WaitAll();

            return(metaData);
        }
Exemple #4
0
        public static Dictionary <int, double> Ms1Interference(CentroidStreamCollection centroidStreams, PrecursorMassCollection precursorMasses,
                                                               TrailerExtraCollection trailerExtras, PrecursorScanCollection precursorScans, ScanEventReactionCollection reactions, ScanIndex index)
        {
            ConcurrentDictionary <int, double> interference = new ConcurrentDictionary <int, double>();

            int chunkSize = Constants.MultiThreading.ChunkSize(index.ScanEnumerators[index.AnalysisOrder].Count());

            var batches = index.ScanEnumerators[index.AnalysisOrder].Chunk(chunkSize);

            Parallel.ForEach(batches, Constants.MultiThreading.Options(), batch =>
            {
                foreach (int scan in batch)
                {
                    int preScan = precursorScans[scan].MasterScan;
                    interference.AddOrUpdate(scan, Algorithms.Ms1Interference.CalculateForOneScan(centroidStreams[preScan], reactions[scan],
                                                                                                  precursorMasses[scan].MonoisotopicMZ, trailerExtras[scan].ChargeState), (a, b) => b);
                }
            });

            var interferenceOut = new Dictionary <int, double>();

            foreach (var item in interference)
            {
                interferenceOut.Add(item.Key, item.Value);
            }

            return(interferenceOut);
        }
Exemple #5
0
        public static PrecursorPeakCollection AnalyzeAllPeaks(CentroidStreamCollection centroids, RetentionTimeCollection retentionTimes,
                                                              PrecursorMassCollection precursorMasses, PrecursorScanCollection precursorScans, ScanIndex index, int MaxProcesses)
        {
            ConcurrentDictionary <int, PrecursorPeakData> peaks = new ConcurrentDictionary <int, PrecursorPeakData>();

            DistributionMultiple allPeaksAsymmetry = new DistributionMultiple();
            DistributionMultiple allPeaksWidths    = new DistributionMultiple();
            var lockTarget = new object(); // this is so we can keep track of progress in the parallel loop

            int chunkSize = Constants.MultiThreading.ChunkSize(index.ScanEnumerators[MSOrderType.Ms2].Count());

            var batches = index.ScanEnumerators[MSOrderType.Ms2].Chunk(chunkSize);

            ProgressIndicator P = new ProgressIndicator(total: index.ScanEnumerators[MSOrderType.Ms2].Length, message: "Analyzing precursor peaks");

            P.Start();

            Parallel.ForEach(batches, Constants.MultiThreading.Options(MaxProcesses), batch =>
            {
                PrecursorPeakData peak;
                foreach (int scan in batch)
                {
                    // [2018-12-04] changing to use picked mass and not monoisomass. The monoisomass might be low in intensity and would not represent the whole elution profile
                    peak = OnePeak(centroids, retentionTimes, precursorMasses[scan].ParentMZ, precursorScans[scan].MasterScan, ddScan: scan, index: index);

                    if (peak.NScans < 5 | peak.PeakFound == false |
                        peak.ContainsFirstMS1Scan | peak.ContainsLastMS1Scan)
                    {
                        peak.PeakShape = null;
                    }
                    else
                    {
                        var newShape   = GetPeakShape(peak);
                        peak.PeakShape = newShape;
                        allPeaksAsymmetry.Add(newShape.Asymmetry);
                        allPeaksWidths.Add(newShape.Width);
                    }

                    peak.Area = CalculatePeakArea(peak);

                    peaks.AddOrUpdate(scan, peak, (a, b) => b);

                    lock (lockTarget)
                    {
                        P.Update();
                    }
                }
            });
            P.Done();

            var peaksOut = new PrecursorPeakCollection();

            foreach (var item in peaks)
            {
                peaksOut.Add(item.Key, item.Value);
            }

            if (allPeaksWidths.P50.Count() == 0)
            {
                peaksOut.PeakShapeMedians = new Data.Containers.PeakShape(width: new Width(), asymmetry: new Asymmetry(), peakMax: 0);
            }
            else
            {
                peaksOut.PeakShapeMedians = new Data.Containers.PeakShape(width: allPeaksWidths.GetMedians(), asymmetry: allPeaksAsymmetry.GetMedians(), peakMax: 0);
            }

            return(peaksOut);
        }
Exemple #6
0
        public static void RefineMonoIsoMassChargeValues(WorkFlows.WorkflowParameters parameters, CentroidStreamCollection centroids, PrecursorMassCollection precursorMasses, TrailerExtraCollection trailerExtras, PrecursorPeakCollection precursorPeaks, PrecursorScanCollection precursorScans)
        {
            int    ms2Scan, ms1Scan, refinedCharge;
            double refinedMass;

            ProgressIndicator P = new ProgressIndicator(precursorPeaks.Count(), "Refining precursor charge and monoisotopic mass");

            P.Start();

            foreach (var peak in precursorPeaks)
            {
                ms2Scan = peak.Value.Ms2Scan;

                if (peak.Value.PeakFound)
                {
                    ms1Scan = peak.Value.MaxScan;
                }
                else
                {
                    ms1Scan = precursorScans[ms2Scan].MasterScan;
                }

                (refinedCharge, refinedMass) = GetMonoIsotopicMassCharge(centroids[ms1Scan], precursorMasses[ms2Scan].ParentMZ,
                                                                         trailerExtras[ms2Scan].ChargeState, parameters.ConsideredChargeStates.Min, parameters.ConsideredChargeStates.Max);

                precursorMasses[ms2Scan].MonoisotopicMZ = refinedMass;
                trailerExtras[ms2Scan].MonoisotopicMZ   = refinedMass;
                trailerExtras[ms2Scan].ChargeState      = refinedCharge;

                P.Update();
            }
            P.Done();
        }