Esempio n. 1
0
        public static void WriteMatrix(RawDataCollection rawData, MetricsData metrics, string outputDirectory = null)
        {
            string fileName = ReadWrite.GetPathToFile(outputDirectory, rawData.rawFileName, "_Metrics.txt");

            using (StreamWriter f = new StreamWriter(fileName)) //Open a new file
            {
                f.WriteLine("RawFile:\t" + metrics.RawFileName);
                f.WriteLine("Instrument:\t" + metrics.Instrument);
                f.WriteLine("ExperimentOrder:\t" + metrics.MSOrder);
                f.WriteLine("MS1Analyzer:\t" + metrics.MS1Analyzer);
                f.WriteLine("MS2Analyzer:\t" + metrics.MS2Analyzer);

                if (metrics.MSOrder == MSOrderType.Ms3)
                {
                    f.WriteLine("MS3Analyzer:\t" + metrics.MS3Analyzer);
                }
                else
                {
                    f.WriteLine("MS3Analyzer:\tNone");
                }

                f.WriteLine("TotalAnalysisTime(min):\t" + Math.Round(metrics.TotalAnalysisTime, 4));
                f.WriteLine("TotalScans:\t" + metrics.TotalScans);
                f.WriteLine("MS1Scans:\t" + metrics.MS1Scans);
                f.WriteLine("MS2Scans:\t" + metrics.MS2Scans);
                f.WriteLine("MS3Scans:\t" + metrics.MS3Scans);
                f.WriteLine("MeanTopN:\t" + Math.Round(metrics.MeanTopN, 4));
                f.WriteLine("MS1ScanRate(/sec):\t" + Math.Round(metrics.MS1ScanRate / 60, 4));
                f.WriteLine("MS2ScanRate(/sec):\t" + Math.Round(metrics.MS2ScanRate / 60, 4));
                f.WriteLine("MeanDutyCycle:\t" + Math.Round(metrics.MeanDutyCycle, 4));
                f.WriteLine("MedianMS1FillTime:\t" + Math.Round(metrics.MedianMS1FillTime, 4));
                f.WriteLine("MedianMS2FillTime:\t" + Math.Round(metrics.MedianMS2FillTime, 4));
                f.WriteLine("MedianMS3FillTime:\t" + Math.Round(metrics.MedianMS3FillTime, 4));
                f.WriteLine("MedianMS2Intensity:\t" + Math.Round(metrics.MedianSummedMS2Intensity, 4));
                f.WriteLine("MedianMS1IsolationInterference:\t" + Math.Round(metrics.MedianMs1IsolationInterference, 4));
                if (!rawData.isBoxCar)
                {
                    f.WriteLine("MedianPeakWidthAt10Percent(s):\t" + Math.Round(metrics.MedianBaselinePeakWidth * 60, 4));
                    f.WriteLine("MedianPeakWidthAtHalfMax(s):\t" + Math.Round(metrics.MedianHalfHeightPeakWidth * 60, 4));
                    f.WriteLine("MedianAsymmetryFactor:\t" + Math.Round(metrics.MedianAsymmetryFactor, 4));
                    f.WriteLine("ColumnCapacity:\t" + Math.Round(metrics.PeakCapacity, 4));
                }

                if (metrics.IncludesQuant == true)
                {
                    foreach (string tag in metrics.QuantMeta.quantTags)
                    {
                        f.WriteLine("{0}MedianReporterIonIntensity:\t{1}", tag, metrics.QuantMeta.medianReporterIntensityByChannel[tag]);
                    }
                    f.WriteLine("OverallMedianReporterIonIntensity:\t{0}", metrics.QuantMeta.medianReporterIntensity);
                }
            }
        }
Esempio n. 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);
        }
Esempio n. 3
0
        public static void ParseDIA(IRawFileThreadManager rawFile, WorkflowParameters parameters)
        {
            var staticRawFile = rawFile.CreateThreadAccessor();

            staticRawFile.SelectInstrument(Device.MS, 1);

            staticRawFile.CheckIfBoxcar();

            ScanIndex Index = Extract.ScanIndices(rawFile.CreateThreadAccessor());

            TrailerExtraCollection trailerExtras = Extract.TrailerExtras(rawFile.CreateThreadAccessor(), Index);

            MethodDataContainer methodData = Extract.MethodData(rawFile.CreateThreadAccessor(), Index);

            PrecursorScanCollection precursorScans = Extract.PrecursorScansByMasterScanMs2Only(rawFile.CreateThreadAccessor(), trailerExtras, Index);

            (CentroidStreamCollection centroidStreams, SegmentScanCollection segmentScans) =
                Extract.MsData(rawFile: rawFile.CreateThreadAccessor(), index: Index);

            RetentionTimeCollection retentionTimes = Extract.RetentionTimes(rawFile.CreateThreadAccessor(), Index);

            ScanMetaDataCollectionDIA metaData = MetaDataProcessingDIA.AggregateMetaDataDIA(centroidStreams, segmentScans, methodData,
                                                                                            trailerExtras, retentionTimes, Index);

            RawMetricsDataDIA metrics = null;

            if (parameters.ParseParams.Metrics)
            {
                metrics = MetaDataProcessingDIA.GetMetricsDataDIA(metaData, methodData, staticRawFile.FileName, retentionTimes, Index);
                MetricsWriter.WriteMatrix(metrics, staticRawFile.FileName, parameters.ParseParams.OutputDirectory);
            }

            if (parameters.ParseParams.Parse)
            {
                string matrixFileName = ReadWrite.GetPathToFile(parameters.ParseParams.OutputDirectory, staticRawFile.FileName, "._parse.txt");

                //MatrixWriter.ParseQuantDIA()

                //ParseWriter writerDIA = new ParseWriter(matrixFileName, centroidStreams, segmentScans, metaData,
                //    retentionTimes, trailerExtras, precursorScans, Index);
                //writerDIA.WriteMatrixDIA();
            }

            // I'm not sure what goes into a DIA mgf file, so we aren't making one yet
            //if (parameters.ParseParams.WriteMgf)
            //{
            //    ParseWriter writerMGF = new ParseWriter(centroidStreams, segmentScans, parameters, retentionTimes, precursorMasses, precursorScans, trailerExtras, methodData, Index);
            //    writerMGF.WriteMGF(staticRawFile.FileName);
            //}
        }
Esempio n. 4
0
        public static void UniversalDDA(IRawFileThreadManager rawFileThreadManager, WorkflowParameters parameters, QcDataCollection qcDataCollection)
        {
            MethodDataContainer         methodData;
            CentroidStreamCollection    centroidStreams;
            SegmentScanCollection       segmentScans;
            TrailerExtraCollection      trailerExtras;
            PrecursorMassCollection     precursorMasses;
            RetentionTimeCollection     retentionTimes;
            ScanEventReactionCollection reactions;
            ScanMetaDataCollectionDDA   metaData = null;
            PrecursorPeakCollection     peakData = null;
            int nScans;

            var staticRawFile = rawFileThreadManager.CreateThreadAccessor();

            staticRawFile.SelectInstrument(Device.MS, 1);

            var err = staticRawFile.FileError;

            if (err.HasError)
            {
                Console.WriteLine("ERROR: {0} reports error code: {1}. The associated message is: {2}",
                                  Path.GetFileName(staticRawFile.FileName), err.ErrorCode, err.ErrorMessage);
                Console.WriteLine("Skipping this file");

                Log.Error("{FILE} reports error code: {ERRORCODE}. The associated message is: {ERRORMESSAGE}",
                          Path.GetFileName(staticRawFile.FileName), err.ErrorCode, err.ErrorMessage);

                return;
            }

            //staticRawFile.CheckIfBoxcar();

            (ScanIndex Index, PrecursorScanCollection precursorScans, ScanDependentsCollections scanDependents) =
                Extract.ScanIndicesPrecursorsDependents(rawFileThreadManager, MaxProcesses: parameters.MaxProcesses);

            nScans = Index.ScanEnumerators[MSOrderType.Ms2].Length;

            using (var rawFile = rawFileThreadManager.CreateThreadAccessor())
            {
                reactions = Extract.ScanEvents(rawFile, Index);

                methodData = Extract.MethodData(rawFile, Index);

                (centroidStreams, segmentScans) = Extract.MsData(rawFile: rawFile, index: Index);

                trailerExtras = Extract.TrailerExtras(rawFile, Index);

                precursorMasses = Extract.PrecursorMasses(rawFile, precursorScans, trailerExtras, Index);

                retentionTimes = Extract.RetentionTimes(rawFile, Index);
            }

            if (parameters.ParseParams.Parse | parameters.ParseParams.Quant | parameters.ParseParams.Metrics | parameters.RefineMassCharge | parameters.QcParams.QcDirectory != null)
            {
                peakData = AnalyzePeaks.AnalyzeAllPeaks(centroidStreams, retentionTimes, precursorMasses, precursorScans, Index, parameters.MaxProcesses);

                if (parameters.RefineMassCharge)
                {
                    MonoIsoPredictor.RefineMonoIsoMassChargeValues(parameters, centroidStreams, precursorMasses, trailerExtras, peakData, precursorScans);
                }

                metaData = MetaDataProcessingDDA.AggregateMetaDataDDA(centroidStreams, segmentScans, methodData, precursorScans,
                                                                      trailerExtras, precursorMasses, retentionTimes, scanDependents, reactions, Index, parameters.MaxProcesses);
            }

            QuantDataCollection quantData = null;

            if (parameters.ParseParams.Quant)
            {
                quantData = Quantification.Quantify(centroidStreams, segmentScans, parameters, methodData, Index);
            }

            RawMetricsDataDDA rawMetrics = null;

            if (parameters.ParseParams.Metrics | parameters.QcParams.QcDirectory != null)
            {
                rawMetrics = MetaDataProcessingDDA.GetMetricsDataDDA(metaData, methodData, staticRawFile.FileName, retentionTimes, Index, peakData, precursorScans, quantData);
            }

            if (parameters.ParseParams.Metrics)
            {
                MetricsWriter.WriteMatrix(rawMetrics, null, staticRawFile.FileName, parameters.ParseParams.OutputDirectory);
            }

            if (parameters.ParseParams.Parse | parameters.ParseParams.Quant)
            {
                string matrixFileName = ReadWrite.GetPathToFile(parameters.ParseParams.OutputDirectory, staticRawFile.FileName, "_Matrix.txt");

                /*
                 * ParseWriter writerDDA = new ParseWriter(matrixFileName, centroidStreams, segmentScans, metaData, retentionTimes,
                 * precursorMasses, precursorScans, peakData, trailerExtras, Index, quantData);
                 * writerDDA.WriteMatrixDDA(methodData.AnalysisOrder);
                 */
                MatrixWriter.ParseQuantDDA(matrixFileName, centroidStreams, segmentScans, metaData, retentionTimes,
                                           precursorMasses, precursorScans, peakData, trailerExtras, Index, quantData);
            }

            if (parameters.ParseParams.WriteMgf)
            {
                //ParseWriter writerMGF = new ParseWriter(centroidStreams, segmentScans, parameters, retentionTimes, precursorMasses, precursorScans, trailerExtras, methodData, Index);
                //writerMGF.WriteMGF(staticRawFile.FileName);

                MgfWriter.WriteMGF(staticRawFile.FileName, centroidStreams, segmentScans, parameters, retentionTimes, precursorMasses, precursorScans, trailerExtras, methodData, Index);
            }

            if (parameters.ParseParams.Chromatogram != null)
            {
                ChromatogramWriter.WriteChromatogram(centroidStreams, segmentScans, retentionTimes, methodData, Index, parameters, staticRawFile.FileName);
            }

            if (parameters.QcParams.QcDirectory != null)
            {
                qcDataCollection = QC.QcWorkflow.LoadOrCreateQcCollection(parameters);

                SearchMetricsContainer searchMetrics = new SearchMetricsContainer(staticRawFile.FileName, staticRawFile.CreationDate, methodData);

                // check if the raw file already exists in the QC data with a different name
                if (QcWorkflow.CheckIfFilePresentInQcCollection(staticRawFile.FileName, qcDataCollection))
                {
                    Log.Information("A file with the same creation date and time as {File} already exists in the QC data", staticRawFile.FileName);

                    Console.WriteLine("A file with the same creation date and time as {File} already exists in the QC data. Skipping to next file.",
                                      staticRawFile.FileName);
                }
                else
                {
                    if (parameters.QcParams.PerformSearch)
                    {
                        Search.WriteSearchMGF(parameters, centroidStreams, segmentScans, retentionTimes, precursorMasses, precursorScans, trailerExtras, methodData,
                                              Index, staticRawFile.FileName, parameters.QcParams.FixedScans);

                        Search.RunSearch(parameters, methodData, staticRawFile.FileName);

                        searchMetrics = SearchQC.ParseSearchResults(searchMetrics, parameters, staticRawFile.FileName, nScans);
                    }

                    QcDataContainer qcData = new QcDataContainer();
                    qcData.DDA           = rawMetrics;
                    qcData.SearchMetrics = searchMetrics;

                    QC.QcWorkflow.UpdateQcCollection(qcDataCollection, qcData, methodData, staticRawFile.FileName);
                }
            }
        }
Esempio n. 5
0
        public static void ParseDDA(IRawFileThreadManager rawFileThreadManager, WorkflowParameters parameters)
        {
            MethodDataContainer         methodData;
            CentroidStreamCollection    centroidStreams;
            SegmentScanCollection       segmentScans;
            TrailerExtraCollection      trailerExtras;
            PrecursorMassCollection     precursorMasses;
            RetentionTimeCollection     retentionTimes;
            ScanEventReactionCollection reactions;
            ScanMetaDataCollectionDDA   metaData   = null;
            PrecursorPeakCollection     peakData   = null;
            RawMetricsDataDDA           rawMetrics = null;
            QuantDataCollection         quantData  = null;

            var staticRawFile = rawFileThreadManager.CreateThreadAccessor();

            staticRawFile.SelectInstrument(Device.MS, 1);

            //staticRawFile.CheckIfBoxcar();

            (ScanIndex Index, PrecursorScanCollection precursorScans, ScanDependentsCollections scanDependents) =
                Extract.ScanIndicesPrecursorsDependents(rawFileThreadManager);

            using (var rawFile = rawFileThreadManager.CreateThreadAccessor())
            {
                reactions = Extract.ScanEvents(rawFile, Index);

                methodData = Extract.MethodData(rawFile, Index);

                (centroidStreams, segmentScans) = Extract.MsData(rawFile: rawFile, index: Index);

                trailerExtras = Extract.TrailerExtras(rawFile, Index);

                precursorMasses = Extract.PrecursorMasses(rawFile, precursorScans, trailerExtras, Index);

                retentionTimes = Extract.RetentionTimes(rawFile, Index);
            }

            if (parameters.ParseParams.Parse | parameters.ParseParams.Quant | parameters.ParseParams.Metrics | parameters.RefineMassCharge)
            {
                peakData = AnalyzePeaks.AnalyzeAllPeaks(centroidStreams, retentionTimes, precursorMasses, precursorScans, Index);

                if (parameters.RefineMassCharge)
                {
                    MonoIsoPredictor.RefineMonoIsoMassChargeValues(centroidStreams, precursorMasses, trailerExtras, peakData, precursorScans);
                }

                metaData = MetaDataProcessingDDA.AggregateMetaDataDDA(centroidStreams, segmentScans, methodData, precursorScans,
                                                                      trailerExtras, precursorMasses, retentionTimes, scanDependents, reactions, Index);
            }

            if (parameters.ParseParams.Quant)
            {
                quantData = Quantification.Quantify(centroidStreams, segmentScans, parameters, methodData, Index);
            }

            if (parameters.ParseParams.Metrics)
            {
                rawMetrics = MetaDataProcessingDDA.GetMetricsDataDDA(metaData, methodData, staticRawFile.FileName, retentionTimes, Index, peakData, precursorScans, quantData);
                MetricsWriter.WriteMatrix(rawMetrics, null, staticRawFile.FileName, parameters.ParseParams.OutputDirectory);
            }

            if (parameters.ParseParams.Parse | parameters.ParseParams.Quant)
            {
                string matrixFileName = ReadWrite.GetPathToFile(parameters.ParseParams.OutputDirectory, staticRawFile.FileName, "_Matrix.txt");

                /*
                 * ParseWriter writerDDA = new ParseWriter(matrixFileName, centroidStreams, segmentScans, metaData, retentionTimes,
                 * precursorMasses, precursorScans, peakData, trailerExtras, Index, quantData);
                 * writerDDA.WriteMatrixDDA(methodData.AnalysisOrder);
                 */
                MatrixWriter.ParseQuantDDA(matrixFileName, centroidStreams, segmentScans, metaData, retentionTimes,
                                           precursorMasses, precursorScans, peakData, trailerExtras, Index, quantData);
            }

            if (parameters.ParseParams.WriteMgf)
            {
                //ParseWriter writerMGF = new ParseWriter(centroidStreams, segmentScans, parameters, retentionTimes, precursorMasses, precursorScans, trailerExtras, methodData, Index);
                //writerMGF.WriteMGF(staticRawFile.FileName);

                MgfWriter.WriteMGF(staticRawFile.FileName, centroidStreams, segmentScans, parameters, retentionTimes, precursorMasses, precursorScans, trailerExtras, methodData, Index);
            }

            if (parameters.ParseParams.Chromatogram != null)
            {
                ChromatogramWriter.WriteChromatogram(centroidStreams, segmentScans, retentionTimes, methodData, Index, parameters, staticRawFile.FileName);
            }
        }
Esempio n. 6
0
        public static void WriteChromatogram(this RawDataCollection rawData, IRawDataPlus rawFile, MSOrderType order, bool TIC, bool BP, string outputDirectory)
        {
            List <Operations> operations = new List <Operations>()
            {
                Operations.RetentionTimes
            };
            //MSOrderType order = (MSOrderType)msOrder;
            MassAnalyzerType analyzer = rawData.methodData.MassAnalyzers[order];

            if (analyzer == MassAnalyzerType.MassAnalyzerFTMS)
            {
                if (order == MSOrderType.Ms)
                {
                    operations.Add(Operations.Ms1CentroidStreams);
                }
                if (order == MSOrderType.Ms2)
                {
                    operations.Add(Operations.Ms2CentroidStreams);
                }
                if (order == MSOrderType.Ms3)
                {
                    operations.Add(Operations.Ms3CentroidStreams);
                }
            }
            else
            {
                if (order == MSOrderType.Ms)
                {
                    operations.Add(Operations.Ms1SegmentedScans);
                }
                if (order == MSOrderType.Ms2)
                {
                    operations.Add(Operations.Ms2SegmentedScans);
                }
                if (order == MSOrderType.Ms3)
                {
                    operations.Add(Operations.Ms3SegmentedScans);
                }
            }

            CheckIfDone.Check(rawData, rawFile, operations);

            int[] scans = rawData.scanIndex.ScanEnumerators[order];

            if (TIC)
            {
                ProgressIndicator progress = new ProgressIndicator(scans.Length, String.Format("Writing {0} TIC chromatogram", order));
                progress.Start();
                string fileName = ReadWrite.GetPathToFile(outputDirectory, rawData.rawFileName, "_" + order + "_TIC_chromatogram.txt");

                using (StreamWriter f = new StreamWriter(fileName))
                {
                    f.WriteLine("RetentionTime\tIntensity");

                    if (analyzer == MassAnalyzerType.MassAnalyzerFTMS)
                    {
                        foreach (int scan in scans)
                        {
                            if (rawData.centroidStreams[scan].Intensities.Length > 0)
                            {
                                f.WriteLine("{0}\t{1}", rawData.retentionTimes[scan], rawData.centroidStreams[scan].Intensities.Sum());
                            }
                            else
                            {
                                f.WriteLine("{0}\t{1}", rawData.retentionTimes[scan], 0);
                            }
                            progress.Update();
                        }
                    }
                    else
                    {
                        foreach (int scan in scans)
                        {
                            if (rawData.segmentedScans[scan].Intensities.Length > 0)
                            {
                                f.WriteLine("{0}\t{1}", rawData.retentionTimes[scan], rawData.segmentedScans[scan].Intensities.Sum());
                            }
                            else
                            {
                                f.WriteLine("{0}\t{1}", rawData.retentionTimes[scan], 0);
                            }
                            progress.Update();
                        }
                    }
                }
                progress.Done();
            }
            if (BP)
            {
                ProgressIndicator progress = new ProgressIndicator(scans.Length, String.Format("Writing {0} base peak chromatogram", order));
                progress.Start();

                string fileName = ReadWrite.GetPathToFile(outputDirectory, rawData.rawFileName, "_" + order + "_BP_chromatogram.txt");

                using (StreamWriter f = new StreamWriter(fileName))
                {
                    f.WriteLine("RetentionTime\tIntensity");

                    if (analyzer == MassAnalyzerType.MassAnalyzerFTMS)
                    {
                        foreach (int scan in scans)
                        {
                            if (rawData.centroidStreams[scan].Intensities.Length > 0)
                            {
                                f.WriteLine("{0}\t{1}", rawData.retentionTimes[scan], rawData.centroidStreams[scan].Intensities.Max());
                            }
                            else
                            {
                                f.WriteLine("{0}\t{1}", rawData.retentionTimes[scan], 0);
                            }
                            progress.Update();
                        }
                    }
                    else
                    {
                        foreach (int scan in scans)
                        {
                            if (rawData.segmentedScans[scan].Intensities.Length > 0)
                            {
                                f.WriteLine("{0}\t{1}", rawData.retentionTimes[scan], rawData.segmentedScans[scan].Intensities.Max());
                            }
                            else
                            {
                                f.WriteLine("{0}\t{1}", rawData.retentionTimes[scan], 0);
                            }
                            progress.Update();
                        }
                    }
                }
                progress.Done();
            }
        }
Esempio n. 7
0
        public static void WriteMatrix(RawDataCollection rawData, ScanMetaDataCollection metaData, IRawDataPlus rawFile, QuantDataCollection quantData = null, string outputDirectory = null)
        {
            string fileName = ReadWrite.GetPathToFile(outputDirectory, rawData.rawFileName, "_Matrix.txt");

            CheckIfDone.Check(rawData, rawFile, new List <Operations> {
                Operations.ScanIndex, Operations.MethodData, Operations.PrecursorScans,
                Operations.RetentionTimes, Operations.PrecursorMasses, Operations.TrailerExtras, Operations.MetaData
            });

            using (StreamWriter f = new StreamWriter(fileName)) //Open a new file
            {
                List <int> scans;

                if (!rawData.isBoxCar)
                {
                    scans = rawData.scanIndex.ScanEnumerators[rawData.scanIndex.AnalysisOrder].ToList();
                }
                else
                {
                    scans = rawData.precursorScans.Keys.ToList();
                    scans.Sort();
                }

                ProgressIndicator progress = new ProgressIndicator(scans.Count(), "Writing matrix to disk");

                f.Write("MS3ScanNumber\tMS2ScanNumber\tMS1ScanNumber\tQuantScanRetTime\tParentScanRetTime\tDutyCycle" +
                        "\tMS2ScansPerCycle\tParentIonMass\tMonoisotopicMass\tPrecursorCharge\tMS1IsolationInterference");

                if (!rawData.isBoxCar)
                {
                    f.Write("\tParentPeakFound");
                }

                if (rawData.Performed.Contains(Operations.PeakArea) & !rawData.isBoxCar)
                {
                    f.Write("\tParentPeakArea");
                }

                if (!rawData.isBoxCar)
                {
                    f.Write("\tPeakFirstScan\tPeakMaxScan\tPeakLastScan\tBaseLinePeakWidth(s)\tPeakParentScanIntensity\tPeakMaxIntensity");
                }
                f.Write("\tMS1IonInjectionTime\tMS2IonInjectionTime" +
                        "\tMS3IonInjectionTime\tHCDEnergy\tMS1MedianIntensity\tMS2MedianIntensity\t");

                if (quantData != null)
                {
                    string reagents = quantData.LabelingReagents;
                    foreach (string label in new LabelingReagents().Reagents[reagents].Labels)
                    {
                        f.Write(label + "Intensity\t");
                    }
                    foreach (string label in new LabelingReagents().Reagents[reagents].Labels)
                    {
                        f.Write(label + "Mass\t");
                    }
                    foreach (string label in new LabelingReagents().Reagents[reagents].Labels)
                    {
                        f.Write(label + "Noise\t");
                    }
                    foreach (string label in new LabelingReagents().Reagents[reagents].Labels)
                    {
                        f.Write(label + "Resolution\t");
                    }
                    foreach (string label in new LabelingReagents().Reagents[reagents].Labels)
                    {
                        f.Write(label + "Baseline\t");
                    }
                }

                f.Write("\n");

                foreach (int scan in scans)
                {
                    int ms3scan, ms2scan, masterScan;

                    if (rawData.scanIndex.AnalysisOrder == MSOrderType.Ms3)
                    {
                        ms3scan    = rawData.precursorScans[scan].MS3Scan;
                        ms2scan    = rawData.precursorScans[scan].MS2Scan;
                        masterScan = rawData.precursorScans[scan].MasterScan;
                    }
                    else
                    {
                        ms3scan    = -1;
                        ms2scan    = rawData.precursorScans[scan].MS2Scan;
                        masterScan = rawData.precursorScans[scan].MasterScan;
                    }

                    f.Write(ms3scan.ToString() + "\t" + ms2scan.ToString() + "\t" + masterScan.ToString() + "\t");

                    f.Write(rawData.retentionTimes[scan].ToString() + "\t" + rawData.retentionTimes[masterScan].ToString() + "\t");
                    f.Write(metaData[masterScan].DutyCycle.ToString() + "\t" + metaData[masterScan].MS2ScansPerCycle.ToString() + "\t");

                    f.Write(rawData.precursorMasses[ms2scan].ParentMZ.ToString() + "\t");
                    f.Write(rawData.precursorMasses[ms2scan].MonoisotopicMZ.ToString() + "\t");

                    f.Write(rawData.trailerExtras[ms2scan].ChargeState.ToString() + "\t");

                    f.Write(rawData.metaData[scan].Ms1IsolationInterference.ToString() + "\t");

                    if (!rawData.isBoxCar)
                    {
                        f.Write(rawData.peakData[ms2scan].PeakFound.ToString() + "\t");
                    }

                    if (rawData.Performed.Contains(Operations.PeakArea) & !rawData.isBoxCar)
                    {
                        f.Write(rawData.peakData[ms2scan].Area.ToString() + "\t");
                    }

                    if (!rawData.isBoxCar)
                    {
                        f.Write(rawData.peakData[ms2scan].FirstScan.ToString() + "\t");
                        f.Write(rawData.peakData[ms2scan].MaxScan.ToString() + "\t");
                        f.Write(rawData.peakData[ms2scan].LastScan.ToString() + "\t");
                        f.Write((rawData.peakData[ms2scan].BaselineWidth * 60).ToString() + "\t");
                        f.Write(rawData.peakData[ms2scan].ParentIntensity.ToString() + "\t");
                        f.Write(rawData.peakData[ms2scan].MaximumIntensity.ToString() + "\t");
                    }

                    f.Write(rawData.trailerExtras[masterScan].InjectionTime.ToString() + "\t");

                    if (rawData.scanIndex.AnalysisOrder == MSOrderType.Ms3)
                    {
                        f.Write(rawData.trailerExtras[ms2scan].InjectionTime.ToString() + "\t");
                        f.Write(rawData.trailerExtras[ms3scan].InjectionTime.ToString() + "\t");
                    }
                    else
                    {
                        f.Write(rawData.trailerExtras[ms2scan].InjectionTime.ToString() + "\t");
                        f.Write("-1\t");
                    }

                    f.Write(rawData.trailerExtras[scan].HCDEnergy + "\t");

                    f.Write(metaData[masterScan].IntensityDistribution.P50 + "\t");
                    f.Write(metaData[ms2scan].IntensityDistribution.P50 + "\t");

                    if (quantData != null)
                    {
                        foreach (string label in quantData[scan].Keys)
                        {
                            f.Write(quantData[scan][label].Intensity + "\t");
                        }
                        foreach (string label in quantData[scan].Keys)
                        {
                            f.Write(quantData[scan][label].Mass + "\t");
                        }
                        foreach (string label in quantData[scan].Keys)
                        {
                            f.Write(quantData[scan][label].Noise + "\t");
                        }
                        foreach (string label in quantData[scan].Keys)
                        {
                            f.Write(quantData[scan][label].Resolution + "\t");
                        }
                        foreach (string label in quantData[scan].Keys)
                        {
                            f.Write(quantData[scan][label].Baseline + "\t");
                        }
                    }

                    f.Write("\n");

                    progress.Update();
                }
                progress.Done();
            }
        }
Esempio n. 8
0
        public static void WriteMGF(RawDataCollection rawData, IRawDataPlus rawFile, string outputDirectory, double cutoff = 0, int[] scans = null, double intensityCutoff = 0.01)
        {
            double intCutoff = 0;
            string fileName  = ReadWrite.GetPathToFile(outputDirectory, rawData.rawFileName, ".mgf");

            MassAnalyzerType ms2MassAnalyzer = rawData.methodData.MassAnalyzers[MSOrderType.Ms2];

            List <Operations> operations = new List <Operations> {
                Operations.ScanIndex, Operations.MethodData, Operations.TrailerExtras, Operations.RetentionTimes
            };

            if (ms2MassAnalyzer == MassAnalyzerType.MassAnalyzerFTMS)
            {
                operations.Add(Operations.Ms2CentroidStreams);
            }
            else
            {
                operations.Add(Operations.Ms2SegmentedScans);
            }

            CheckIfDone.Check(rawData, rawFile, operations);

            const int BufferSize = 65536;                                                         // 64 Kilobytes

            using (StreamWriter f = new StreamWriter(fileName, false, Encoding.UTF8, BufferSize)) //Open a new file, the MGF file
            {
                // if the scans argument is null, use all scans
                if (scans == null)
                {
                    scans = rawData.scanIndex.ScanEnumerators[MSOrderType.Ms2];
                }

                ProgressIndicator progress = new ProgressIndicator(scans.Count(), String.Format("Writing MGF file"));

                foreach (int i in scans)
                {
                    f.WriteLine("\nBEGIN IONS");
                    f.WriteLine("RAWFILE={0}", rawData.rawFileName);
                    f.WriteLine("TITLE=Spectrum_{0}", i);
                    f.WriteLine("SCAN={0}", i);
                    f.WriteLine("RTINSECONDS={0}", rawData.retentionTimes[i]);
                    f.WriteLine("PEPMASS={0}", rawData.trailerExtras[i].MonoisotopicMZ);
                    f.WriteLine("CHARGE={0}", rawData.trailerExtras[i].ChargeState);

                    if (ms2MassAnalyzer == MassAnalyzerType.MassAnalyzerFTMS)
                    {
                        CentroidStreamData centroid = rawData.centroidStreams[i];

                        if (centroid.Intensities.Length > 0)
                        {
                            intCutoff = centroid.Intensities.Max() * intensityCutoff;
                        }
                        else
                        {
                            intCutoff = 0;
                        }

                        for (int j = 0; j < centroid.Masses.Length; j++)
                        {
                            //f.WriteLine(Math.Round(centroid.Masses[j], 4).ToString() + " " + Math.Round(centroid.Intensities[j], 4).ToString());
                            if (centroid.Masses[j] > cutoff & centroid.Intensities[j] > intCutoff)
                            {
                                f.WriteLine("{0} {1}", Math.Round(centroid.Masses[j], 5), Math.Round(centroid.Intensities[j], 4));
                            }
                        }
                    }
                    else
                    {
                        SegmentedScanData segments = rawData.segmentedScans[i];

                        if (segments.Intensities.Length > 0)
                        {
                            intCutoff = segments.Intensities.Max() * intensityCutoff;
                        }
                        else
                        {
                            intCutoff = 0;
                        }

                        for (int j = 0; j < segments.Positions.Length; j++)
                        {
                            if (segments.Positions[j] > cutoff & segments.Intensities[j] > intCutoff)
                            {
                                f.WriteLine("{0} {1}", Math.Round(segments.Positions[j], 5), Math.Round(segments.Intensities[j], 4));
                            }
                        }
                    }

                    f.WriteLine("END IONS");

                    progress.Update();
                }
                progress.Done();
            }
            Utilities.ConsoleUtils.ClearLastLine();
        }