Exemple #1
0
        public void peakDetectionOnXCaliburTest1()
        {
            Run run = new XCaliburRun(xcaliburTestfile, 6000, 7000);

            ScanSetCollection scansetCollection = new ScanSetCollection();

            for (int i = 6000; i < 6015; i++)
            {
                scansetCollection.ScanSetList.Add(new ScanSet(i));
            }

            ResultCollection results = new ResultCollection(run);

            foreach (ScanSet scanset in scansetCollection.ScanSetList)
            {
                run.CurrentScanSet = scanset;
                Task msgen = new GenericMSGenerator();
                msgen.Execute(results);

                Task peakDetector = new DeconToolsPeakDetector();
                peakDetector.Execute(results);

                Task scanResultUpdater = new ScanResultUpdater();
                scanResultUpdater.Execute(results);
            }

            Assert.AreEqual(2, results.ScanResultList.Count);
        }
Exemple #2
0
        private ScanSetCollection CreateLcScanSetCollection()
        {
            var scanSetCollection = new ScanSetCollection();

            scanSetCollection.Create(Run, WorkflowParameters.LCScanMin, WorkflowParameters.LCScanMax,
                                     WorkflowParameters.Num_LC_TimePointsSummed, 1, WorkflowParameters.ProcessMSMS);

            return(scanSetCollection);
        }
        public void ExportMultipleScansTest1()
        {
            Run run = new IMFRun(imfFilepath);

            ScanSetCollection scanSetCollection = new ScanSetCollection();

            scanSetCollection.ScanSetList.Add(new ScanSet(232));
            scanSetCollection.ScanSetList.Add(new ScanSet(233));
            scanSetCollection.ScanSetList.Add(new ScanSet(234));

            ResultCollection results = new ResultCollection(run);

            foreach (ScanSet scanset in scanSetCollection.ScanSetList)
            {
                run.CurrentScanSet = scanset;

                Task msGen = new GenericMSGenerator();
                msGen.Execute(results);

                DeconToolsV2.Peaks.clsPeakProcessorParameters detectorParams = new DeconToolsV2.Peaks.clsPeakProcessorParameters();
                detectorParams.PeakBackgroundRatio    = 3;
                detectorParams.PeakFitType            = DeconToolsV2.Peaks.PEAK_FIT_TYPE.QUADRATIC;
                detectorParams.SignalToNoiseThreshold = 3;
                detectorParams.ThresholdedData        = false;

                Task peakDetector = new DeconToolsPeakDetector(detectorParams);
                peakDetector.Execute(results);

                Task decon = new RapidDeconvolutor();
                decon.Execute(results);

                Task scanResultUpdater = new ScanResultUpdater();
                scanResultUpdater.Execute(results);
            }

            Assert.AreEqual(3, results.ScanResultList.Count);

            Assert.AreEqual(92, results.ScanResultList[0].NumPeaks);
            Assert.AreEqual(82, results.ScanResultList[1].NumPeaks);
            Assert.AreEqual(72, results.ScanResultList[2].NumPeaks);

            Assert.AreEqual(11, results.ScanResultList[0].NumIsotopicProfiles);
            Assert.AreEqual(9, results.ScanResultList[1].NumIsotopicProfiles);
            Assert.AreEqual(9, results.ScanResultList[2].NumIsotopicProfiles);

            Assert.AreEqual(830.045752112968, (Decimal)results.ScanResultList[0].BasePeak.XValue);
            Assert.AreEqual(10438, results.ScanResultList[0].BasePeak.Height);
            Assert.AreEqual(0.09454554, (Decimal)results.ScanResultList[0].BasePeak.Width);
            Assert.AreEqual(434.9167, (Decimal)results.ScanResultList[0].BasePeak.SN);

            Exporter <ResultCollection> exporter = new BasicScansExporter(scansExporterTest1output);

            exporter.Export(results);
        }
Exemple #4
0
        public void updateScanResultsOnXCaliburFileTest1()
        {
            Run run = new XCaliburRun(xcaliburTestfile, 6000, 7000);

            ScanSetCollection scansetCollection = new ScanSetCollection();

            for (int i = 6000; i < 6015; i++)
            {
                scansetCollection.ScanSetList.Add(new ScanSet(i));
            }

            ResultCollection results = new ResultCollection(run);

            foreach (ScanSet scanset in scansetCollection.ScanSetList)
            {
                run.CurrentScanSet = scanset;
                Task msgen = new GenericMSGenerator(0, 2000);
                msgen.Execute(results);

                Task peakDetector = new DeconToolsPeakDetector();
                peakDetector.Execute(results);

                Task rapid = new RapidDeconvolutor();
                rapid.Execute(results);

                Task scanResultUpdater = new ScanResultUpdater();
                scanResultUpdater.Execute(results);
            }

            Assert.AreEqual(2, results.ScanResultList.Count);
            Assert.AreEqual(1, results.ScanResultList[0].SpectrumType);
            Assert.AreEqual(481.274105402604, (decimal)results.ScanResultList[0].BasePeak.XValue);
            Assert.AreEqual(353, results.ScanResultList[0].NumIsotopicProfiles);

            Assert.AreEqual(2052, results.ScanResultList[0].NumPeaks);
            //Assert.AreEqual(2132, results.ScanResultList[0].NumPeaks);
            Assert.AreEqual(32.6941466666667, (decimal)results.ScanResultList[0].ScanTime);
            Assert.AreEqual(6005, results.ScanResultList[0].ScanSet.PrimaryScanNumber);

            Assert.AreEqual(362, results.ScanResultList[1].NumIsotopicProfiles);
            //Assert.AreEqual(370, results.ScanResultList[1].NumIsotopicProfiles);
            Assert.AreEqual(715, results.ResultList.Count);
        }
Exemple #5
0
        public void MSGeneratorOnXCaliburFileTest2()
        {
            Run run = new XCaliburRun(xcaliburTestfile, 6000, 7000);

            ScanSetCollection scansetCollection = new ScanSetCollection();

            for (int i = 6000; i < 6015; i++)
            {
                scansetCollection.ScanSetList.Add(new ScanSet(i));
            }

            ResultCollection results = new ResultCollection(run);

            foreach (ScanSet scanset in scansetCollection.ScanSetList)
            {
                run.CurrentScanSet = scanset;
                Task msgen = new GenericMSGenerator();
                msgen.Execute(results);
            }

            Assert.AreEqual(0, results.ScanResultList.Count);   //Scan results are now created by the ScanResultUpdaterTask
        }
        public XYData GetBaseChromXYData(Run run, int startScan, int stopScan, double baseMZValue)
        {
            //note: currently 'GenerateChromatogram' results in 0's being padded on both sides of start and stop scans.
            var xydata = PeakChromGen.GenerateChromatogram(run, startScan, stopScan, baseMZValue, ChromTolerance, ChromToleranceUnit);

            XYData basePeakChromXYData;

            if (xydata == null || xydata.Xvalues.Length < 3)
            {
                basePeakChromXYData = new XYData();

                if (xydata == null)
                {
                    basePeakChromXYData.Xvalues = new double[0];
                    basePeakChromXYData.Yvalues = new double[0];
                }
                else
                {
                    basePeakChromXYData.Xvalues = xydata.Xvalues;
                    basePeakChromXYData.Yvalues = xydata.Yvalues;
                }
            }
            else
            {
                basePeakChromXYData = Smoother.Smooth(xydata);
            }

            var scanSetCollection = new ScanSetCollection();

            scanSetCollection.Create(run, startScan, stopScan, 1, 1, false);

            var validScanNums = scanSetCollection.ScanSetList.Select(p => (double)p.PrimaryScanNumber).ToArray();

            basePeakChromXYData = FillInAnyMissingValuesInChromatogram(validScanNums, basePeakChromXYData);
            return(basePeakChromXYData);
        }
        public void ChromAnalysisForAllSelectedPrecursors()
        {
            var isDataSmoothed = true;

            var numPointsInSmoothing = 9;
            var smoother             = new DeconTools.Backend.ProcessingTasks.Smoothers.SavitzkyGolaySmoother(numPointsInSmoothing, 2);

            var graphGenerator = new BasicGraphControl();

            var thermoFile1 = @"\\protoapps\UserData\Slysz\DeconTools_TestFiles\Orbitrap\QC_Shew_08_04-pt5-2_11Jan09_Sphinx_08-11-18.RAW";
            var run         = new RunFactory().CreateRun(thermoFile1);

            var outputFolderForChromGraphs = @"\\protoapps\DataPkgs\Public\2012\684_DeconMSn_research1\ChromatogramImages";

            if (!Directory.Exists(outputFolderForChromGraphs))
            {
                Directory.CreateDirectory(outputFolderForChromGraphs);
            }

            var scanSetCollection = new ScanSetCollection();
            var scanStart         = run.MinLCScan;
            var scanStop          = run.MaxLCScan;

            scanSetCollection.Create(run, scanStart, scanStop, 1, 1, true);
            var sb = new StringBuilder();

            var expectedPeaksFile = Path.Combine(run.DataSetPath, run.DatasetName + "_peaks.txt");

            if (!File.Exists(expectedPeaksFile))
            {
                var peakCreatorParams = new PeakDetectAndExportWorkflowParameters();
                peakCreatorParams.PeakBR = 1.75;

                var peakCreator = new PeakDetectAndExportWorkflow(run, peakCreatorParams);
                peakCreator.Execute();
            }

            var peakImporter = new PeakImporterFromText(expectedPeaksFile);

            peakImporter.ImportPeaks(run.ResultCollection.MSPeakResultList);

            double ppmTol = 50;
            var    peakChromatogramGenerator = new PeakChromatogramGenerator(ppmTol, Globals.ChromatogramGeneratorMode.MZ_BASED);
            var    scansetList = scanSetCollection.ScanSetList;

            var scanCounter = 0;
            var currentBin  = 0;

            foreach (var scanSet in scansetList)
            {
                run.CurrentScanSet = scanSet;

                var currentScanLevel = run.GetMSLevel(scanSet.PrimaryScanNumber);


                if (currentScanLevel > 1)
                {
                    scanCounter++;
                    var precursorInfo = run.GetPrecursorInfo(scanSet.PrimaryScanNumber);

                    var scanInfo = run.GetScanInfo(scanSet.PrimaryScanNumber);

                    var scanWindowSize = 400;
                    var startScan      = scanSet.PrimaryScanNumber - scanWindowSize / 2;
                    var stopScan       = scanSet.PrimaryScanNumber + scanWindowSize / 2;

                    run.XYData = peakChromatogramGenerator.GenerateChromatogram(run, startScan, stopScan, precursorInfo.PrecursorMZ, ppmTol);

                    if (run.XYData == null)
                    {
                        run.XYData         = new XYData();
                        run.XYData.Xvalues = new double[] { 0, 1, 2 };
                        run.XYData.Yvalues = new double[] { 0, 1, 2 };

                        Console.WriteLine(scanSet.PrimaryScanNumber + "\t" + precursorInfo.MSLevel + "\t" + precursorInfo.PrecursorMZ +
                                          "\t" + precursorInfo.PrecursorScan + "--------- NO XYData!!! -------------");
                    }
                    else
                    {
                        if (isDataSmoothed)
                        {
                            run.XYData = smoother.Smooth(run.XYData);
                        }
                    }

                    Console.WriteLine(scanSet.PrimaryScanNumber + "\t" + precursorInfo.MSLevel + "\t" + precursorInfo.PrecursorMZ +
                                      "\t" + precursorInfo.PrecursorScan);

                    graphGenerator.GenerateGraph(run.XYData.Xvalues, run.XYData.Yvalues);

                    var line = graphGenerator.GraphPane.CurveList[0] as LineItem;
                    line.Line.IsVisible = true;
                    line.Symbol.Size    = 2;
                    line.Symbol.Type    = SymbolType.Circle;

                    graphGenerator.GraphPane.XAxis.Title.Text          = "scan";
                    graphGenerator.GraphPane.YAxis.Title.Text          = "intensity";
                    graphGenerator.GraphPane.XAxis.Scale.MinAuto       = true;
                    graphGenerator.GraphPane.YAxis.Scale.MinAuto       = false;
                    graphGenerator.GraphPane.YAxis.Scale.Min           = 0;
                    graphGenerator.GraphPane.XAxis.Scale.FontSpec.Size = 12;
                    graphGenerator.AddVerticalLineToGraph(scanSet.PrimaryScanNumber, 3);
                    graphGenerator.AddAnnotationRelativeAxis(scanInfo, 0.3, 0.1);

                    if (scanCounter > 500)
                    {
                        currentBin++;
                        scanCounter = 0;
                    }
                    var currentOutputFolder = Path.Combine(outputFolderForChromGraphs, "bin" + currentBin);
                    if (!Directory.Exists(currentOutputFolder))
                    {
                        Directory.CreateDirectory(currentOutputFolder);
                    }


                    var baseFilename = Path.Combine(currentOutputFolder,
                                                    scanSet.PrimaryScanNumber.ToString().PadLeft(5, '0') + "_mz" + precursorInfo.PrecursorMZ);

                    string outputGraphFilename;

                    string outputXYData;

                    if (isDataSmoothed)
                    {
                        outputGraphFilename = baseFilename + "_smoothed_chrom.png";
                        outputXYData        = baseFilename + "_smoothed_xydata.txt";
                    }
                    else
                    {
                        outputXYData        = baseFilename + "_xydata.txt";
                        outputGraphFilename = baseFilename + "_chrom.png";
                    }


                    graphGenerator.SaveGraph(outputGraphFilename);
                    TestUtilities.WriteToFile(run.XYData, outputXYData);
                }
            }

            Console.WriteLine(sb.ToString());
        }
Exemple #8
0
        public void BasePeakChromatogramTests()
        {
            var filename = @"D:\Data\UIMF\Sarc_P13_C10_1186_23Sep11_Cheetah_11-09-06.uimf";
            var run      = new RunFactory().CreateRun(filename);

            var scanSetCollection = new ScanSetCollection();

            //scanSetCollection.Create(run, 500, 550,1,1);
            scanSetCollection.Create(run, run.MinLCScan, run.MaxLCScan, 1, 1);

            var imsScanSetCollection = new IMSScanSetCollection();

            imsScanSetCollection.Create(run, 60, 250, 1, 1);

            var msgen = MSGeneratorFactory.CreateMSGenerator(run.MSFileType);

            var peakDet = new DeconToolsPeakDetectorV2();

            peakDet.PeakToBackgroundRatio  = 4;
            peakDet.SignalToNoiseThreshold = 2;
            peakDet.IsDataThresholded      = true;

            var outputFile = @"C:\Users\d3x720\Documents\PNNL\My_DataAnalysis\2013\Saturation_Correction\chromOuput.txt";

            using (var writer = new StreamWriter(outputFile))
            {
                for (var lcscan = 0; lcscan < scanSetCollection.ScanSetList.Count; lcscan++)
                {
                    Console.WriteLine("lcscan= " + lcscan);

                    var scanSet = scanSetCollection.ScanSetList[lcscan];
                    run.CurrentScanSet = scanSet;

                    var sb = new StringBuilder();

                    var numImsScans = imsScanSetCollection.ScanSetList.Count;

                    for (var imsScan = 0; imsScan < numImsScans; imsScan++)
                    {
                        var imsscanSet = (IMSScanSet)imsScanSetCollection.ScanSetList[imsScan];
                        ((UIMFRun)run).CurrentIMSScanSet = imsscanSet;

                        var basePeakIntensity = 0;

                        try
                        {
                            msgen.Execute(run.ResultCollection);
                            peakDet.Execute(run.ResultCollection);

                            basePeakIntensity = GetMaxPeak(run.PeakList);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("skipping lcscan " + lcscan + " --- it is empty");
                        }


                        sb.Append(basePeakIntensity);

                        if (imsScan != numImsScans - 1) // if not the last value, add delimiter
                        {
                            sb.Append("\t");
                        }
                    }
                    writer.WriteLine(sb.ToString());
                }
            }
        }
        public void Get3DElutionProfileFromPeakLevelData(Run run, int minScan, int maxScan, double minMZ, double maxMZ, out int[] scans, out double[] mzBins, out float[] intensities, double binWidth = 0.01, bool applyLogTransform = false)
        {
            var msPeakList = run.ResultCollection.MSPeakResultList;

            Check.Require(msPeakList != null && msPeakList.Count > 0, "Run is missing peaks. Elution profile is based on peak-level info");

            Check.Require(binWidth > 0, "Binwidth must be greater than 0");


            var scanSetCollection = new ScanSetCollection();

            scanSetCollection.Create(run, minScan, maxScan, 1, 1, false);


            //create bins
            var numBins = (int)Math.Round((maxMZ - minMZ) / binWidth);

            mzBins = new double[numBins];
            var firstBinMZ = minMZ;

            for (var i = 0; i < numBins; i++)
            {
                mzBins[i] = firstBinMZ + i * binWidth;
            }


            //iterate over scans and collected MzIntensityArray for each scan

            var intensityList = new List <float>();



            scans = scanSetCollection.ScanSetList.Select(p => p.PrimaryScanNumber).ToArray();

            //gather relevant peaks.
            var scanTolerance = 5;     // TODO:   keep an eye on this

            minScan = scans.First();
            maxScan = scans.Last();

            var indexOfLowerScan = getIndexOfClosestScanValue(msPeakList, minScan, 0, msPeakList.Count - 1, scanTolerance);
            var indexOfUpperScan = getIndexOfClosestScanValue(msPeakList, maxScan, 0, msPeakList.Count - 1, scanTolerance);

            var currentIndex = indexOfLowerScan;

            var filteredPeakList = new List <MSPeakResult>();

            while (currentIndex <= indexOfUpperScan)
            {
                var currentPeak = msPeakList[currentIndex];

                if (currentPeak.XValue >= minMZ && currentPeak.XValue <= maxMZ)
                {
                    filteredPeakList.Add(currentPeak);
                }
                currentIndex++;
            }



            foreach (var scan in scans)
            {
                var peaksForScan = filteredPeakList.Where(n => n.Scan_num == scan).ToList();

                var intensitiesForScan = new float[numBins];

                foreach (var msPeakResult in peaksForScan)
                {
                    var targetBin = (int)Math.Round((msPeakResult.XValue - firstBinMZ) / binWidth);

                    if (targetBin < intensitiesForScan.Length)
                    {
                        intensitiesForScan[targetBin] += (float)Math.Round(msPeakResult.Height);
                    }
                }

                intensityList.AddRange(intensitiesForScan);
            }

            if (applyLogTransform)
            {
                intensities = intensityList.Select(p => (float)Math.Log(p)).ToArray();
            }
            else
            {
                intensities = intensityList.ToArray();
            }

            Scans       = scans;
            Intensities = intensities;
            MzBins      = mzBins;
        }