Example #1
0
 /// <summary>
 /// Start quantification.
 /// </summary>
 private void MetroButtonQuantification_Click(object sender, EventArgs e)
 {
     // Perform the quantification
     Quantification.DoQuantification();
     // Add the quantification results to the list
     AddQuantResultsToGrid(metroGridQuantification);
 }
Example #2
0
        /// <summary>
        /// Change the parent mass tolerence
        /// </summary>
        private void MetroTextBoxPMTolerance_TextChanged(object sender, EventArgs e)
        {
            // Parse the parent mass tolerence
            int tolerance = int.Parse(metroTextBoxPMTolerance.Text);

            // Calculate a new PPM for the new tolerence
            Quantification.ReturnPPM(tolerance);
        }
Example #3
0
        /// <summary>
        /// Change the retention time.
        /// </summary>
        private void MetroTextBoxRTInterval_TextChanged(object sender, EventArgs e)
        {
            // Parse the retention time
            int interval = int.Parse(metroTextBoxRTInterval.Text);

            // Calculate a new PPM for the new interval.
            Quantification.ReturnRTInterval(interval);
        }
Example #4
0
        public void GenerationCount(IManager manager)
        {
            List <int> pattern = Quantification.CountGenerations(manager);

            for (int cnt = 1; cnt < manager.NumberOfGenerations; cnt++)
            {
                this.writer.Write("Animals in Gerenation no." + cnt + ": " + pattern[cnt - 1]);
            }
        }
Example #5
0
        public void ItFailsWithTooFewOccurences()
        {
            parser = P.Repeat <string, string>(
                P.Literal("asd"),
                Quantification.AtLeast(5)
                ).CreateParser();

            parser.Parse("asd");
            Assert.False(parser.Success);
            Assert.AreEqual(1, parser.MatchCount);
        }
Example #6
0
        public void Bee_Pattern_Run()
        {
            //Arrange
            //Create animal number pattern
            IManager manager = new SimpleManager
            {
                Animals = new List <IAnimal>
                {
                    new Bee("Bee0", new Drone(), 1)
                }
            };

            //Act
            manager.Run();
            List <int> pattern = new List <int>(Quantification.CountGenerations(manager));

            //Assert
            for (int patternCnt = 1; patternCnt <= manager.NumberOfGenerations; patternCnt++)
            {
                Assert.AreEqual((int)Gensim.Helpers.Math.Fibonacci(patternCnt), pattern[patternCnt - 1]);
            }
        }
Example #7
0
        public void Human_Pattern_Run()
        {
            //Arrange
            //Create animal number pattern
            IManager manager = new SimpleManager
            {
                Animals = new List <IAnimal>
                {
                    new Human("Human0", new Man(), 1)
                }
            };

            //Act
            manager.Run();
            List <int> pattern = new List <int>(Quantification.CountGenerations(manager));

            //Assert
            for (int patternCnt = 0; patternCnt < manager.NumberOfGenerations; patternCnt++)
            {
                Assert.AreEqual((int)System.Math.Pow(2, patternCnt), pattern[patternCnt]);
            }
        }
Example #8
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);
                }
            }
        }
Example #9
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);
            }
        }