Exemplo n.º 1
0
        public void TestDoWaterShedAlgorithmByBin()
        {
            var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF";
            var uimfUtil     = new UimfUtil(fileLocation);
            var smoother     = new SavitzkyGolaySmoother(5, 2);

            var bin = 73009;
            var intensityPointList = uimfUtil.GetXic(bin, UIMFData.FrameType.MS1);

            var pointList = WaterShedMapUtil.BuildWatershedMap(intensityPointList).ToList();

            var preSmoothedFeatureList = FeatureDetection.DoWatershedAlgorithm(pointList).ToList();

            Console.WriteLine(DateTime.Now + "\tBefore Smoothing:\tNumPoints = " + pointList.Count + "\tNumFeatures = " + preSmoothedFeatureList.Count);

            foreach (var featureBlob in preSmoothedFeatureList)
            {
                var mostIntensePoint = featureBlob.PointList.First();
                Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity);
            }
            Console.WriteLine("******************************************************");

            var newPointList = WaterShedMapUtil.BuildWatershedMap(intensityPointList);

            smoother.Smooth(ref newPointList);
            var smoothedFeatureList = FeatureDetection.DoWatershedAlgorithm(newPointList).ToList();

            Console.WriteLine(DateTime.Now + "\tAfter Smoothing:\tNumPoints = " + newPointList.Count() + "\tNumFeatures = " + smoothedFeatureList.Count);
            foreach (var featureBlob in smoothedFeatureList)
            {
                var mostIntensePoint = featureBlob.PointList.First();
                Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get a smoothed XIC.
        /// </summary>
        /// <param name="smoother">Smoother to smooth XIC.</param>
        /// <param name="xic">XIC to smooth.</param>
        /// <returns>Array of smoothed XIC points.</returns>
        public static XicPoint[] SmoothXic(SavitzkyGolaySmoother smoother, IList <XicPoint> xic)
        {
            var xicP = new double[xic.Count];

            for (var i = 0; i < xic.Count; i++)
            {
                xicP[i] = xic[i].Intensity;
            }

            double[] smoothedPoints;
            try
            {
                smoothedPoints = smoother.Smooth(xicP);
            }
            catch (IndexOutOfRangeException)
            {
                smoothedPoints = xicP;
            }

            var smoothedXic = new XicPoint[xicP.Length];

            for (var i = 0; i < xicP.Length; i++)
            {
                smoothedXic[i] = new XicPoint(xic[i].ScanNum, xic[i].Mz, smoothedPoints[i]);
            }

            return(smoothedXic);
        }
        public void SmoothWithOldDeconToolsSmootherTest1()
        {
            var sampleXYDataFile = Path.Combine(FileRefs.TestFileBasePath, "sampleXYData1.txt");

            Assert.IsTrue(File.Exists(sampleXYDataFile));

            var smoother = new SavitzkyGolaySmoother(3, 3, true);

            var xydata         = TestUtilities.LoadXYDataFromFile(sampleXYDataFile);
            var smoothedXYData = smoother.Smooth(xydata);


            Assert.AreEqual(xydata.Xvalues.Length, smoothedXYData.Xvalues.Length);


            var sb = new StringBuilder();

            sb.Append("xval\tnonSmoothed_Y\tsmoothed_Y\n");
            for (var i = 0; i < xydata.Xvalues.Length; i++)
            {
                sb.Append(xydata.Xvalues[i] + "\t" + xydata.Yvalues[i] + "\t" + smoothedXYData.Yvalues[i] + Environment.NewLine);
            }

            Console.WriteLine(sb.ToString());
        }
Exemplo n.º 4
0
        public MassCalibrationResults(SortedDictionary <double, int> rawResults)
        {
            _smoother  = new SavitzkyGolaySmoother(13, 2);
            RawResults = rawResults;

            FindPpmErrorAndWidth();
        }
Exemplo n.º 5
0
        protected virtual void DoMainInitialization()
        {
            ValidateParameters();

            TheorFeatureGen = new JoshTheorFeatureGenerator(DeconTools.Backend.Globals.LabellingType.NONE, 0.005);
            ChromGen        = new PeakChromatogramGenerator(WorkflowParameters.ChromGenTolerance, WorkflowParameters.ChromGeneratorMode,
                                                            DeconTools.Backend.Globals.IsotopicProfileType.UNLABELLED,
                                                            WorkflowParameters.ChromGenToleranceUnit)
            {
                TopNPeaksLowerCutOff              = 0.333,
                ChromWindowWidthForAlignedData    = (float)WorkflowParameters.ChromNETTolerance * 2,
                ChromWindowWidthForNonAlignedData = (float)WorkflowParameters.ChromNETTolerance * 2
            };

            //only

            var allowNegativeValues = false;

            ChromSmoother     = new SavitzkyGolaySmoother(WorkflowParameters.ChromSmootherNumPointsInSmooth, 2, allowNegativeValues);
            ChromPeakDetector = new ChromPeakDetector(WorkflowParameters.ChromPeakDetectorPeakBR, WorkflowParameters.ChromPeakDetectorSigNoise);
            ChromPeakSelector = CreateChromPeakSelector(WorkflowParameters);

            ChromPeakAnalyzer = new ChromPeakAnalyzer(WorkflowParameters);

            IterativeTffParameters = new IterativeTFFParameters();
            IterativeTffParameters.ToleranceInPPM = WorkflowParameters.MSToleranceInPPM;

            MsfeatureFinder = new IterativeTFF(IterativeTffParameters);
            FitScoreCalc    = new IsotopicProfileFitScoreCalculator();

            InterferenceScorer = new InterferenceScorer();

            ResultValidator        = new ResultValidatorTask();
            ChromatogramCorrelator = new IqChromCorrelator(WorkflowParameters.ChromSmootherNumPointsInSmooth, 0.05, WorkflowParameters.ChromGenTolerance);
        }
Exemplo n.º 6
0
        public void TestBuildWaterShedMap()
        {
            var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF";
            var uimfUtil     = new UimfUtil(fileLocation);

            var    targetMz     = 643.27094937;
            double ppmTolerance = 50;

            var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM);

            var smoother = new SavitzkyGolaySmoother(5, 2);

            smoother.Smooth(ref intensityBlock);

            var pointList = WaterShedMapUtil.BuildWatershedMap(intensityBlock, 0, 0).ToList();

            Console.WriteLine(intensityBlock.Length);


            Assert.AreEqual(270000, intensityBlock.Length);
            Assert.AreEqual(12969, pointList.Count);

            Assert.AreEqual(pointList[1000].Intensity, 14.844082, 0.0001);
            Assert.AreEqual(pointList[5000].Intensity, 5.760, 0.0001);
        }
Exemplo n.º 7
0
        public void BadCorrelationTest1()
        {
            var dataset =
                @"\\protoapps\UserData\Slysz\Standard_Testing\Targeted_FeatureFinding\O16O18_standard_testing\Test1_VladAlz\RawData\Alz_P01_A01_097_26Apr12_Roc_12-03-15.RAW";

            var run = new RunFactory().CreateRun(dataset);

            var peaksDataFile = dataset.ToLower().Replace(".raw", "_peaks.txt");
            var peakImporter  = new PeakImporterFromText(peaksDataFile);

            peakImporter.ImportPeaks(run.ResultCollection.MSPeakResultList);


            double chromToleranceInPPM = 10;
            var    startScan           = 2340;
            var    stopScan            = 2440;

            var smoother = new SavitzkyGolaySmoother(9, 2);

            var testMZVal1 = 719.80349;

            var peakChromGen = new PeakChromatogramGenerator(chromToleranceInPPM);

            run.XYData = peakChromGen.GenerateChromatogram(run, startScan, stopScan, testMZVal1, chromToleranceInPPM);
            run.XYData = smoother.Smooth(run.XYData);

            var chromdata1 = run.XYData.TrimData(startScan, stopScan);

            var testMZVal2 = 722.325;

            run.XYData = peakChromGen.GenerateChromatogram(run, startScan, stopScan, testMZVal2, chromToleranceInPPM);
            run.XYData = smoother.Smooth(run.XYData);

            var chromdata2 = run.XYData.TrimData(startScan, stopScan);



            //chromdata1.Display();
            //Console.WriteLine();
            //chromdata2.Display();

            ChromatogramCorrelatorBase correlator = new ChromatogramCorrelator(3);
            double slope       = 0;
            double intercept   = 0;
            double rsquaredVal = 0;

            correlator.GetElutionCorrelationData(chromdata1, chromdata2, out slope, out intercept, out rsquaredVal);


            Console.WriteLine("slope = \t" + slope);
            Console.WriteLine("intercept = \t" + intercept);
            Console.WriteLine("rsquared = \t" + rsquaredVal);


            for (var i = 0; i < chromdata1.Xvalues.Length; i++)
            {
                Console.WriteLine(chromdata1.Xvalues[i] + "\t" + chromdata1.Yvalues[i] + "\t" + chromdata2.Yvalues[i]);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Finds the XIC based on the m/z and scan parameters.
        /// </summary>
        /// <param name="mz"></param>
        /// <param name="scan"></param>
        /// <returns></returns>
        public List <XYData> FindXic(double mz, int scan, bool shouldSmooth)
        {
            LcmsFeatureTarget target = new LcmsFeatureTarget();

            target.ID              = 0;
            target.MZ              = mz;
            target.ScanLCTarget    = scan;
            target.ElutionTimeUnit = Globals.ElutionTimeUnit.ScanNum;
            m_run.CurrentMassTag   = target;
            var result = m_run.ResultCollection.GetTargetedResult(m_run.CurrentMassTag);

            double chromPeakGeneratorTolInPPM = MzPpmWindow;

            Globals.ChromatogramGeneratorMode chromGeneratorMode = Globals.ChromatogramGeneratorMode.MZ_BASED;

            var chromGen = new PeakChromatogramGenerator(chromPeakGeneratorTolInPPM,
                                                         chromGeneratorMode);

            chromGen.NETWindowWidthForNonAlignedData = Convert.ToSingle(NetWindow);

            int pointsToSmooth = 5;
            var chromSmoother  = new SavitzkyGolaySmoother(pointsToSmooth, 2);

            double chromPeakDetectorPeakBR   = 1;
            double chromPeakDetectorSigNoise = 1;
            var    chromPeakDetector         = new ChromPeakDetector(chromPeakDetectorPeakBR,
                                                                     chromPeakDetectorSigNoise);

            ChromPeakSelectorParameters chromPeakSelectorParameters = new ChromPeakSelectorParameters();
            var chromPeakSelector = new BasicChromPeakSelector(chromPeakSelectorParameters);

            //this generates an extracted ion chromatogram
            // Since we are not using the built in generator,
            chromGen.Execute(m_run.ResultCollection);

            //this smooths the data - very important step!
            if (shouldSmooth)
            {
                chromSmoother.Execute(m_run.ResultCollection);
            }

            //this detects peaks within an extracted ion chromatogram
            chromPeakDetector.Execute(m_run.ResultCollection);

            //this selects the peak
            chromPeakSelector.Parameters.PeakSelectorMode = Globals.PeakSelectorMode.ClosestToTarget;
            chromPeakSelector.Execute(m_run.ResultCollection);

            //Here's the chromatogram data...
            List <XYData> data = new List <XYData>();

            for (int i = 0; i < m_run.XYData.Xvalues.Length; i++)
            {
                XYData datum = new XYData(m_run.XYData.Xvalues[i], m_run.XYData.Yvalues[i]);
                data.Add(datum);
            }

            return(data);
        }
        /// <summary>
        /// The find peak using watershed.
        /// </summary>
        /// <param name="intensityPoints">
        /// The intensity Points.
        /// </param>
        /// <param name="smoother">
        /// The smoother.
        /// </param>
        /// <param name="featureFilterLevel">
        /// The feature Filter Level.
        /// </param>
        /// <returns>
        /// The <see cref="IList"/>.
        /// </returns>
        public static List<FeatureBlob> FindPeakUsingWatershed(List<IntensityPoint> intensityPoints, SavitzkyGolaySmoother smoother, double featureFilterLevel)
        {
            IEnumerable<Point> pointList = WaterShedMapUtil.BuildWatershedMap(intensityPoints);

            // Ignore the smoother for now as it distort peak apexs arbitrarily.
            smoother.Smooth(ref pointList);

            // Peak Find Chromatogram
            List<FeatureBlob> featureBlobs = FeatureDetection.DoWatershedAlgorithm(pointList).ToList();

            // Preliminary filtering: reject small feature peaks.
            featureBlobs = FeatureDetection.FilterFeatureList(featureBlobs, featureFilterLevel).ToList();

            return featureBlobs;
        }
Exemplo n.º 10
0
        public void Test3DSmooth()
        {
            var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF";
            var uimfUtil     = new UimfUtil(fileLocation);

            var    targetMz     = 643.27094937;
            double ppmTolerance = 50;

            var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, DataReader.FrameType.MS1, DataReader.ToleranceType.PPM);

            var smoother = new SavitzkyGolaySmoother(5, 2);

            smoother.Smooth(ref intensityBlock);

            Console.WriteLine(intensityBlock.Length);
        }
Exemplo n.º 11
0
        protected override void InitializeProcessingTasks()
        {
            MSGenerator  = MSGeneratorFactory.CreateMSGenerator(Run.MSFileType);
            PeakDetector = PeakDetectorFactory.CreatePeakDetector(NewDeconToolsParameters);


            var moreSensitivePeakToBackgroundRatio = NewDeconToolsParameters.PeakDetectorParameters.PeakToBackgroundRatio / 2;
            var moreSensitiveSigNoiseThresh        = NewDeconToolsParameters.PeakDetectorParameters.SignalToNoiseThreshold;

            _moreSensitiveMS1PeakDetector = new DeconToolsPeakDetectorV2(moreSensitivePeakToBackgroundRatio,
                                                                         moreSensitiveSigNoiseThresh, NewDeconToolsParameters.PeakDetectorParameters.PeakFitType,
                                                                         NewDeconToolsParameters.PeakDetectorParameters.IsDataThresholded);

            _superSensitiveMS1PeakDetector = new DeconToolsPeakDetectorV2(0, 0, NewDeconToolsParameters.PeakDetectorParameters.PeakFitType,
                                                                          NewDeconToolsParameters.PeakDetectorParameters.IsDataThresholded);


            Deconvolutor = DeconvolutorFactory.CreateDeconvolutor(NewDeconToolsParameters);


            //Will initialize these but whether or not they are used are determined elsewhere
            ZeroFiller = new DeconToolsZeroFiller(NewDeconToolsParameters.MiscMSProcessingParameters.ZeroFillingNumZerosToFill);
            Smoother   = new SavitzkyGolaySmoother(NewDeconToolsParameters.MiscMSProcessingParameters.SavitzkyGolayNumPointsInSmooth,
                                                   NewDeconToolsParameters.MiscMSProcessingParameters.SavitzkyGolayOrder);

            FitScoreCalculator = new DeconToolsFitScoreCalculator();

            ResultValidator = new ResultValidatorTask();


            PeakToMSFeatureAssociator = new PeakToMSFeatureAssociator();


            _ms2PeakDetectorForCentroidData = new DeconToolsPeakDetectorV2(0, 0, Globals.PeakFitType.QUADRATIC, true)
            {
                RawDataType = Globals.RawDataType.Centroided
            };


            _ms2PeakDetectorForProfileData = new DeconToolsPeakDetectorV2(NewDeconToolsParameters.PeakDetectorParameters.PeakToBackgroundRatio,
                                                                          NewDeconToolsParameters.PeakDetectorParameters.SignalToNoiseThreshold,
                                                                          NewDeconToolsParameters.PeakDetectorParameters.PeakFitType,
                                                                          NewDeconToolsParameters.PeakDetectorParameters.IsDataThresholded);

            Check.Ensure(Deconvolutor is ThrashDeconvolutorV2, "Error. Currently the DeconMSn workflow only works with the ThrashV2 deconvolutor. Selected deconvolutor= " + Deconvolutor);
        }
        protected ChromatogramCorrelatorBase(int numPointsInSmoother, double minRelativeIntensityForChromCorr,
                                             double chromTolerance, Globals.ToleranceUnit toleranceUnit = Globals.ToleranceUnit.PPM)
        {
            SavitzkyGolaySmoothingOrder = 2;
            NumPointsInSmoother         = numPointsInSmoother;

            ChromTolerance = chromTolerance;
            MinimumRelativeIntensityForChromCorr = minRelativeIntensityForChromCorr;

            ChromToleranceUnit = toleranceUnit;

            PeakChromGen = new PeakChromatogramGenerator(ChromTolerance, Globals.ChromatogramGeneratorMode.MOST_ABUNDANT_PEAK,
                                                         Globals.IsotopicProfileType.UNLABELLED, toleranceUnit);


            Smoother = new SavitzkyGolaySmoother(NumPointsInSmoother, SavitzkyGolaySmoothingOrder, false);
        }
        public void SmoothWithNewDeconToolsSmootherTest1()
        {
            var sampleXYDataFile = Path.Combine(FileRefs.TestFileBasePath, "sampleXYData1.txt");

            Assert.IsTrue(File.Exists(sampleXYDataFile));

            var smoother = new SavitzkyGolaySmoother(7, 2);

            var xydata = TestUtilities.LoadXYDataFromFile(sampleXYDataFile);

            var numSmooths = 2000;

            var stopwatch = new Stopwatch();

            stopwatch.Start();


            var smoothedXYData = new XYData();

            for (var i = 0; i < numSmooths; i++)
            {
                smoothedXYData = smoother.Smooth(xydata);
            }

            stopwatch.Stop();


            Console.WriteLine("Average time for smoothing (milliseconds) = " + stopwatch.ElapsedMilliseconds / (double)numSmooths);

            Assert.AreEqual(xydata.Xvalues.Length, smoothedXYData.Xvalues.Length);


            var sb = new StringBuilder();

            sb.Append("xval\tnonSmoothed_Y\tsmoothed_Y\n");
            for (var i = 0; i < xydata.Xvalues.Length; i++)
            {
                sb.Append(xydata.Xvalues[i] + "\t" + xydata.Yvalues[i] + "\t" + smoothedXYData.Yvalues[i] + Environment.NewLine);
            }

            // Console.WriteLine(sb.ToString());
        }
Exemplo n.º 14
0
        public void TestDoWaterShedAlgorithmAllBins()
        {
            var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF";
            var uimfUtil     = new UimfUtil(fileLocation);

            // ReSharper disable once UnusedVariable
            var numberOfBins = uimfUtil.GetNumberOfBins();

            var smoother = new SavitzkyGolaySmoother(5, 2);

            for (var i = 73009; i <= 84000; i++)
            {
                var mz = uimfUtil.GetMzFromBin(i);
                var intensityPointList = uimfUtil.GetXic(mz, 25, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM);
                //List<IntensityPoint> intensityPointList = uimfUtil.GetXic(i, DataReader.FrameType.MS1);

                //SavitzkyGolaySmoother smoother = new SavitzkyGolaySmoother(9, 2);
                //smoother.Smooth(ref intensityBlock);

                //int boundX = intensityBlock.GetUpperBound(0);
                //int boundY = intensityBlock.GetUpperBound(1);

                //TextWriter smoothedWriter = new StreamWriter("smoothedRaw.csv");
                //for (int j = 0; j < boundX; j++)
                //{
                //    StringBuilder row = new StringBuilder();
                //    for (int k = 0; k < boundY; k++)
                //    {
                //        row.Append(intensityBlock[j, k] + ",");
                //    }
                //    smoothedWriter.WriteLine(row.ToString());
                //}

                //smoothedWriter.Close();

                var pointList = WaterShedMapUtil.BuildWatershedMap(intensityPointList);
                smoother.Smooth(ref pointList);
                var featureList = FeatureDetection.DoWatershedAlgorithm(pointList);

                Console.WriteLine(DateTime.Now + "\tBin = " + i + "\tNumPoints = " + pointList.Count() + "\tNumFeatures = " + featureList.Count());
            }
        }
Exemplo n.º 15
0
        public void CorrelationTest2_UsingExecutorMethod()
        {
            var run = new RunFactory().CreateRun(FileRefs.RawDataMSFiles.OrbitrapStdFile1);

            var peakImporter = new PeakImporterFromText(FileRefs.PeakDataFiles.OrbitrapPeakFile_scans5500_6500);

            peakImporter.ImportPeaks(run.ResultCollection.MSPeakResultList);

            var mt = TestUtilities.GetMassTagStandard(1);

            run.CurrentMassTag = mt;

            var unlabelledTheorGenerator = new JoshTheorFeatureGenerator();

            unlabelledTheorGenerator.GenerateTheorFeature(mt);


            double chromToleranceInPPM = 10;
            var    startScan           = 5460;
            var    stopScan            = 5755;

            var smoother = new SavitzkyGolaySmoother(3, 2);

            var peakChromGen = new PeakChromatogramGenerator(chromToleranceInPPM);

            run.XYData = peakChromGen.GenerateChromatogram(run, startScan, stopScan, mt.IsotopicProfile.Peaklist[0].XValue, chromToleranceInPPM);
            run.XYData = smoother.Smooth(run.XYData);

            var result = run.ResultCollection.GetTargetedResult(mt);

            ChromatogramCorrelatorBase correlator = new ChromatogramCorrelator(3);
            var corrData = correlator.CorrelatePeaksWithinIsotopicProfile(run, mt.IsotopicProfile, startScan, stopScan);

            Debug.Assert(corrData.CorrelationDataItems != null, "corrData.CorrelationDataItems != null");
            Assert.AreEqual(0.98m, (decimal)Math.Round((double)corrData.CorrelationDataItems[1].CorrelationRSquaredVal, 2));

            foreach (var item in corrData.CorrelationDataItems)
            {
                Console.WriteLine(item.CorrelationRSquaredVal);
            }
        }
        public void smootherTest1()
        {
            Run run = new MSScanFromTextFileRun(FileRefs.RawDataMSFiles.TextFileMS_std1);

            Task msgen = new GenericMSGenerator();

            msgen.Execute(run.ResultCollection);

            var peakdetector = new DeconToolsPeakDetectorV2(3, 3, Globals.PeakFitType.QUADRATIC, true);

            peakdetector.Execute(run.ResultCollection);

            Assert.AreEqual(84, run.PeakList.Count);

            Task smoother = new SavitzkyGolaySmoother(7, 2, false);

            smoother.Execute(run.ResultCollection);

            peakdetector.Execute(run.ResultCollection);

            Assert.AreEqual(46, run.PeakList.Count);
        }
Exemplo n.º 17
0
        protected virtual void DoMainInitialization()
        {
            ValidateParameters();

            _theorFeatureGen = new JoshTheorFeatureGenerator(DeconTools.Backend.Globals.LabellingType.NONE, 0.005);
            _chromGen        = new PeakChromatogramGenerator(_workflowParameters.ChromGenTolerance, _workflowParameters.ChromGeneratorMode,
                                                             DeconTools.Backend.Globals.IsotopicProfileType.UNLABELLED,
                                                             _workflowParameters.ChromGenToleranceUnit)
            {
                TopNPeaksLowerCutOff              = 0.333,
                ChromWindowWidthForAlignedData    = (float)_workflowParameters.ChromNETTolerance * 2,
                ChromWindowWidthForNonAlignedData = (float)_workflowParameters.ChromNETTolerance * 2
            };

            //only

            var allowNegativeValues = false;

            _chromSmoother     = new SavitzkyGolaySmoother(_workflowParameters.ChromSmootherNumPointsInSmooth, 2, allowNegativeValues);
            _chromPeakDetector = new ChromPeakDetectorMedianBased(_workflowParameters.ChromPeakDetectorPeakBR, _workflowParameters.ChromPeakDetectorSigNoise);



            _chromPeakSelector = CreateChromPeakSelector(_workflowParameters);

            _iterativeTFFParameters = new IterativeTFFParameters();
            _iterativeTFFParameters.ToleranceInPPM = _workflowParameters.MSToleranceInPPM;

            _msfeatureFinder        = new IterativeTFF(_iterativeTFFParameters);
            _fitScoreCalc           = new IsotopicProfileFitScoreCalculator();
            _resultValidator        = new ResultValidatorTask();
            _chromatogramCorrelator = new ChromatogramCorrelator(_workflowParameters.ChromSmootherNumPointsInSmooth, 0.01, _workflowParameters.ChromGenTolerance);

            ChromatogramXYData = new XYData();
            MassSpectrumXYData = new XYData();
            ChromPeaksDetected = new List <ChromPeak>();
        }
Exemplo n.º 18
0
        public void TestDoWaterShedAlgorithm()
        {
            var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF";
            var uimfUtil     = new UimfUtil(fileLocation);

            var    targetMz     = 582.32181703760114;
            double ppmTolerance = 25;

            var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM);

            var smoother = new SavitzkyGolaySmoother(11, 2);

            smoother.Smooth(ref intensityBlock);

            var pointList   = WaterShedMapUtil.BuildWatershedMap(intensityBlock, 0, 0);
            var featureList = FeatureDetection.DoWatershedAlgorithm(pointList);

            foreach (var featureBlob in featureList)
            {
                var mostIntensePoint = featureBlob.PointList.First();
                Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity);
            }
            Console.WriteLine("******************************************************");

            var intensityPointList = uimfUtil.GetXic(targetMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM);

            var newPointList = WaterShedMapUtil.BuildWatershedMap(intensityPointList);

            smoother.Smooth(ref newPointList);
            var newFeatureList = FeatureDetection.DoWatershedAlgorithm(newPointList);

            foreach (var featureBlob in newFeatureList)
            {
                var mostIntensePoint = featureBlob.PointList.First();
                Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity);
            }
        }
Exemplo n.º 19
0
        public void TestComputingApexProfiles()
        {
            var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF";
            var uimfUtil     = new UimfUtil(fileLocation);
            var smoother     = new SavitzkyGolaySmoother(5, 2);

            var    targetMz  = 964.40334;
            double tolerance = 20;

            var intensityPointList = uimfUtil.GetXic(targetMz, tolerance, UIMFData.FrameType.MS1,
                                                     DataReader.ToleranceType.PPM);
            var pointList = WaterShedMapUtil.BuildWatershedMap(intensityPointList);

            smoother.Smooth(ref pointList);
            var featureBlobs = FeatureDetection.DoWatershedAlgorithm(pointList);
            IEnumerable <FeatureBlobStatistics> featureBlobStatList = featureBlobs.Select(featureBlob => featureBlob.Statistics).ToList();

            foreach (var f in featureBlobStatList)
            {
                Console.WriteLine(
                    "LC: [{0},{1}], IMS: [{2},{3}], Apex: [{4},{5}] SumIntensities: {6}, NumPoints: {7}",
                    f.ScanLcMin,
                    f.ScanLcMax,
                    f.ScanImsMin,
                    f.ScanImsMax,
                    f.ScanLcRep,
                    f.ScanImsRep,
                    f.SumIntensities,
                    f.NumPoints
                    );
                Console.WriteLine("LC Apex profile");
                Console.WriteLine(string.Join(",", f.LcApexPeakProfile));
                Console.WriteLine("IMS Apex profile");
                Console.WriteLine(string.Join(",", f.ImsApexPeakProfile));
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Get XICs for the ion.
        /// </summary>
        /// <param name="pointsToSmooth">Smoothing window width. </param>
        /// <param name="o">Object required for the cache.</param>
        /// <returns>The XICs for this ion</returns>
        private IList <XicDataPoint> GetXic(int pointsToSmooth, object o)
        {
            if (this.xic == null)
            {
                this.xic = this.GetXic();
            }

            var     x       = this.xic;
            IonType ionType = null;

            if (this.IsFragmentIon)
            {
                ionType = this.IonType;
            }

            // smooth
            if (pointsToSmooth > 2)
            {
                var smoother = new SavitzkyGolaySmoother(pointsToSmooth, 2);
                x = IonUtils.SmoothXic(smoother, x);
            }

            return(x.Where((t, i) => i <= 1 || i >= x.Count - 1 ||
                           !this.xic[i - 1].Intensity.Equals(t.Intensity) ||
                           !this.xic[i + 1].Intensity.Equals(t.Intensity))
                   .Select(
                       t => new XicDataPoint(
                           this.Lcms.GetElutionTime(t.ScanNum),
                           t.ScanNum,
                           t.Intensity,
                           this.Index,
                           this.Label)
            {
                IonType = ionType
            }).ToList());
        }
        public SaturationDetector(string uimfFileLocation)
        {
            _uimfReader = new DataReader(uimfFileLocation);
            _smoother = new SavitzkyGolaySmoother(9, 2);
            _peakDetector = new ChromPeakDetector(0.0001, 0.0001);
            _theoreticalFeatureGenerator = new JoshTheorFeatureGenerator();

            if (!_uimfReader.DoesContainBinCentricData())
            {
                DataWriter dataWriter = new DataWriter(uimfFileLocation);
                dataWriter.CreateBinCentricTables();
            }

            IterativeTFFParameters msFeatureFinderParameters = new IterativeTFFParameters
            {
                MinimumRelIntensityForForPeakInclusion = 0.0000000001,
                PeakDetectorMinimumPeakBR = 0,
                PeakDetectorPeakBR = 5.00000000000002,
                PeakBRStep = 0.25,
                PeakDetectorSigNoiseRatioThreshold = 0.00000000001,
                ToleranceInPPM = 50
            };
            _msFeatureFinder = new IterativeTFF(msFeatureFinderParameters);
        }
Exemplo n.º 22
0
        public void TestFragmentCorrelation()
        {
            var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF";
            var uimfUtil     = new UimfUtil(fileLocation);

            var    parentMz     = 643.27094937;
            double ppmTolerance = 50;

            var parentIntensityBlock = uimfUtil.GetXicAsArray(parentMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM);

            var smoother = new SavitzkyGolaySmoother(5, 2);

            smoother.Smooth(ref parentIntensityBlock);

            // ReSharper disable RedundantArgumentDefaultValue
            var parentPointList = WaterShedMapUtil.BuildWatershedMap(parentIntensityBlock, 0, 0);
            // ReSharper restore RedundantArgumentDefaultValue

            var parentFeature = FeatureDetection.DoWatershedAlgorithm(parentPointList).First();

            using (var fragmentReader = new StreamReader(@"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\testFiles\fragments.csv"))
            {
                while (!fragmentReader.EndOfStream)
                {
                    var dataLine = fragmentReader.ReadLine();
                    if (string.IsNullOrWhiteSpace(dataLine))
                    {
                        continue;
                    }

                    var mzString = dataLine.Trim();
                    var targetMz = double.Parse(mzString);

                    TextWriter unsmoothedWriter = new StreamWriter("unsmoothedRaw" + targetMz + ".csv");

                    var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, UIMFData.FrameType.MS2, DataReader.ToleranceType.PPM);

                    var boundX = intensityBlock.GetUpperBound(0);
                    var boundY = intensityBlock.GetUpperBound(1);

                    for (var i = 0; i < boundX; i++)
                    {
                        var row = new StringBuilder();
                        for (var j = 0; j < boundY; j++)
                        {
                            row.Append(intensityBlock[i, j] + ",");
                        }
                        unsmoothedWriter.WriteLine(row.ToString());
                    }

                    unsmoothedWriter.Close();

                    smoother.Smooth(ref intensityBlock);

                    TextWriter smoothedWriter = new StreamWriter("smoothedRaw" + targetMz + ".csv");
                    for (var i = 0; i < boundX; i++)
                    {
                        var row = new StringBuilder();
                        for (var j = 0; j < boundY; j++)
                        {
                            row.Append(intensityBlock[i, j] + ",");
                        }
                        smoothedWriter.WriteLine(row.ToString());
                    }

                    smoothedWriter.Close();

                    // ReSharper disable RedundantArgumentDefaultValue
                    var pointList = WaterShedMapUtil.BuildWatershedMap(intensityBlock, 0, 0);
                    // ReSharper restore RedundantArgumentDefaultValue

                    var featureList = FeatureDetection.DoWatershedAlgorithm(pointList);

                    featureList = featureList.Where(x => x.PointList.Count > 50).OrderByDescending(x => x.PointList.Count);

                    Console.WriteLine("******************************************************");
                    Console.WriteLine("targetMz = " + targetMz);

                    foreach (var featureBlob in featureList)
                    {
                        // ReSharper disable once UnusedVariable
                        var rSquared = FeatureCorrelator.CorrelateFeatures(parentFeature, featureBlob);

                        //Point mostIntensePoint = featureBlob.PointList.OrderByDescending(x => x.Intensity).First();
                        //Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity + "\tRSquared = " + rSquared);
                    }
                }
            }
        }
Exemplo n.º 23
0
        private IEnumerable <UMCLight> RefineFeatureXics(IList <UMCLight> features)
        {
            // Here we smooth the points...and remove any features with from and trailing zero points
            var numberOfPoints = NumberOfPoints;
            var smoother       = new SavitzkyGolaySmoother(numberOfPoints, CONST_POLYNOMIAL_ORDER, false);

            foreach (var feature in features)
            {
                var map = feature.CreateChargeMap();

                // Clear the MS Feature List
                // Because we're going to refine each charge state then fix the length of the feature
                // from it's known max abundance value.
                feature.MsFeatures.Clear();


                // Work on a single charge state since XIC's have different m/z values
                foreach (var chargeFeatures in map.Values)
                {
                    var xic        = new List <XYData>();
                    var msFeatures = chargeFeatures.Where(x => x.Abundance > 0).OrderBy(x => x.Scan).ToList();
                    msFeatures.ForEach(x => xic.Add(new XYData(x.Scan, x.Abundance)));

                    var points = smoother.Smooth(xic);
                    if (msFeatures.Count <= 0)
                    {
                        continue;
                    }

                    // Find the biggest peak...
                    var    maxScanIndex = 0;
                    double maxAbundance = 0;
                    for (var i = 0; i < msFeatures.Count; i++)
                    {
                        msFeatures[i].Abundance = Convert.ToInt64(points[i].Y);

                        if (maxAbundance < msFeatures[i].Abundance)
                        {
                            maxScanIndex = i;
                            maxAbundance = msFeatures[i].Abundance;
                        }
                    }

                    // Then find when the feature goes to zero
                    // Start from max to left
                    var startIndex = maxScanIndex;

                    // If we hit zero, then keep
                    for (; startIndex > 0; startIndex--)
                    {
                        if (msFeatures[startIndex].Abundance < 1)
                        {
                            break;
                        }
                    }

                    // Start from max to right
                    var stopIndex = maxScanIndex;
                    for (; stopIndex < msFeatures.Count - 1; stopIndex++)
                    {
                        if (msFeatures[stopIndex].Abundance < 1)
                        {
                            break;
                        }
                    }

                    // Add the features back
                    for (var i = startIndex; i <= stopIndex; i++)
                    {
                        msFeatures[i].Abundance = Convert.ToInt64(points[i].Y);
                        feature.AddChildFeature(msFeatures[i]);
                    }
                }

                // Clean up
            }
            return(features.Where(x => x.MsFeatures.Count > 0).ToList());
        }
Exemplo n.º 24
0
        public void TestDoWaterShedAlgorithmOutput()
        {
            var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF";
            var uimfUtil     = new UimfUtil(fileLocation);

            var    targetMz     = 643.27094937;
            double ppmTolerance = 50;

            TextWriter unsmoothedWriter = new StreamWriter("unsmoothedRaw.csv");

            var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM);

            var boundX = intensityBlock.GetUpperBound(0);
            var boundY = intensityBlock.GetUpperBound(1);

            for (var i = 0; i < boundX; i++)
            {
                var row = new StringBuilder();
                for (var j = 0; j < boundY; j++)
                {
                    row.Append(intensityBlock[i, j] + ",");
                }
                unsmoothedWriter.WriteLine(row.ToString());
            }

            unsmoothedWriter.Close();

            var smoother = new SavitzkyGolaySmoother(5, 2);

            smoother.Smooth(ref intensityBlock);

            TextWriter smoothedWriter = new StreamWriter("smoothedRaw.csv");

            for (var i = 0; i < boundX; i++)
            {
                var row = new StringBuilder();
                for (var j = 0; j < boundY; j++)
                {
                    row.Append(intensityBlock[i, j] + ",");
                }
                smoothedWriter.WriteLine(row.ToString());
            }

            smoothedWriter.Close();

            var pointList   = WaterShedMapUtil.BuildWatershedMap(intensityBlock, 0, 0);
            var featureList = FeatureDetection.DoWatershedAlgorithm(pointList).ToList();

            Console.WriteLine(featureList.Count);

            var sortedFeatureList = featureList.OrderByDescending(x => x.PointList.Count);

            TextWriter intensityWriter = new StreamWriter("intensities.csv");

            foreach (var featureBlob in sortedFeatureList)
            {
                var mostIntensePoint = featureBlob.PointList.First();
                Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity);
                intensityWriter.WriteLine(mostIntensePoint.Intensity.ToString(CultureInfo.InvariantCulture));
            }
        }
Exemplo n.º 25
0
        public void TestDoWaterShedAlgorithmPrecursorAndFragments()
        {
            var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF";
            var uimfUtil     = new UimfUtil(fileLocation);

            var    parentMz     = 643.27094937;
            double ppmTolerance = 50;

            var parentIntensityBlock = uimfUtil.GetXicAsArray(parentMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM);

            var smoother = new SavitzkyGolaySmoother(5, 2);

            smoother.Smooth(ref parentIntensityBlock);

            // ReSharper disable RedundantArgumentDefaultValue
            var parentPointList = WaterShedMapUtil.BuildWatershedMap(parentIntensityBlock, 0, 0);
            // ReSharper restore RedundantArgumentDefaultValue

            var parentFeature = FeatureDetection.DoWatershedAlgorithm(parentPointList).First();

            var statistics = parentFeature.Statistics;
            var scanLcMin  = statistics.ScanLcMin;
            var scanLcMax  = statistics.ScanLcMax;
            var scanImsMin = statistics.ScanImsMin;
            var scanImsMax = statistics.ScanImsMax;

            using (var fragmentReader = new StreamReader(@"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\testFiles\OneFragment.csv"))
            {
                while (!fragmentReader.EndOfStream)
                {
                    var dataLine = fragmentReader.ReadLine();
                    if (string.IsNullOrWhiteSpace(dataLine))
                    {
                        continue;
                    }

                    var mzString = dataLine.Trim();
                    var targetMz = double.Parse(mzString);

                    TextWriter unsmoothedWriter = new StreamWriter("unsmoothedRaw" + targetMz + ".csv");

                    var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, UIMFData.FrameType.MS2, scanLcMin, scanLcMax, scanImsMin, scanImsMax, DataReader.ToleranceType.PPM);

                    var boundX = intensityBlock.GetUpperBound(0);
                    var boundY = intensityBlock.GetUpperBound(1);

                    for (var i = 0; i < boundX; i++)
                    {
                        var row = new StringBuilder();
                        for (var j = 0; j < boundY; j++)
                        {
                            row.Append(intensityBlock[i, j] + ",");
                        }
                        unsmoothedWriter.WriteLine(row.ToString());
                    }

                    unsmoothedWriter.Close();

                    smoother.Smooth(ref intensityBlock);

                    TextWriter smoothedWriter = new StreamWriter("smoothedRaw" + targetMz + ".csv");
                    for (var i = 0; i < boundX; i++)
                    {
                        var row = new StringBuilder();
                        for (var j = 0; j < boundY; j++)
                        {
                            row.Append(intensityBlock[i, j] + ",");
                        }
                        smoothedWriter.WriteLine(row.ToString());
                    }

                    smoothedWriter.Close();

                    var pointList   = WaterShedMapUtil.BuildWatershedMap(intensityBlock, scanLcMin, scanImsMin).ToList();
                    var featureList = FeatureDetection.DoWatershedAlgorithm(pointList).ToList();

                    Assert.AreEqual(430, pointList.Count);
                    Assert.AreEqual(37, featureList.Count);

                    Console.WriteLine("******************************************************");
                    Console.WriteLine("targetMz = " + targetMz);

                    for (var i = 0; i < featureList.Count; i++)
                    {
                        var featureBlob      = featureList[i];
                        var mostIntensePoint = featureBlob.PointList.OrderByDescending(x => x.Intensity).First();
                        Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity);
                        if (i != 1)
                        {
                            continue;
                        }

                        // Num Points = 34	LC = 138	IMS = 122	Intensity = 79.5697959183673
                        Assert.AreEqual(34, featureBlob.PointList.Count);
                        Assert.AreEqual(138, mostIntensePoint.ScanLc);
                        Assert.AreEqual(122, mostIntensePoint.ScanIms);
                        Assert.AreEqual(79.569796, mostIntensePoint.Intensity, 0.0001);
                    }
                }
            }
        }
        private void FindFeatures()
        {
            m_FeatureFinderBackgroundWorker.ReportProgress(0, "Finding 3-D Features for Precursor and Fragments");

            var seqGraph = SequenceGraph.CreateGraph(m_aminoAcidSet, CurrentPeptide);
            // var scoringGraph = seqGraph.GetScoringGraph(0);
            // var precursorIon = scoringGraph.GetPrecursorIon(this.CurrentChargeState);
            // var monoMz = precursorIon.GetMz();

            var sequence     = new Sequence(CurrentPeptide, m_aminoAcidSet);
            var precursorIon = sequence.GetPrecursorIon(CurrentChargeState);
            var monoMz       = precursorIon.GetMonoIsotopicMz();

            var uimfPointList      = UimfUtil.GetXic(monoMz, CurrentTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM);
            var watershedPointList = WaterShedMapUtil.BuildWatershedMap(uimfPointList);

            var smoother = new SavitzkyGolaySmoother(11, 2);

            smoother.Smooth(ref watershedPointList);

            FeatureList = FeatureDetection.DoWatershedAlgorithm(watershedPointList).ToList();

            IsotopeFeaturesDictionary.Clear();
            var precursorTargetList = CurrentChargeState == 2 ? new List <string> {
                "-1", "0.5", "1", "1.5", "2", "3"
            } : new List <string> {
                "-1", "1", "2", "3"
            };

            foreach (var precursorTarget in precursorTargetList)
            {
                var targetMz = precursorIon.GetIsotopeMz(double.Parse(precursorTarget));

                var isotopeUimfPointList      = UimfUtil.GetXic(targetMz, CurrentTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM);
                var isotopeWatershedPointList = WaterShedMapUtil.BuildWatershedMap(isotopeUimfPointList);

                var isotopeFeatures = FeatureDetection.DoWatershedAlgorithm(isotopeWatershedPointList).ToList();
                IsotopeFeaturesDictionary.Add(precursorTarget, isotopeFeatures);
            }

            LcSlicePlot  = new PlotModel();
            ImsSlicePlot = new PlotModel();

            FragmentFeaturesDictionary.Clear();
            // var sequence = new Sequence(this.CurrentPeptide, m_aminoAcidSet);
            var ionTypeDictionary = sequence.GetProductIons(m_ionTypeFactory.GetAllKnownIonTypes());

            double fragmentCount = ionTypeDictionary.Count;
            var    index         = 0;

            foreach (var ionTypeKvp in ionTypeDictionary)
            {
                var ionTypeTuple = ionTypeKvp.Key;

                var ion        = ionTypeKvp.Value;
                var fragmentMz = ion.GetMonoIsotopicMz();

                uimfPointList      = UimfUtil.GetXic(fragmentMz, CurrentTolerance, UIMFData.FrameType.MS2, DataReader.ToleranceType.PPM);
                watershedPointList = WaterShedMapUtil.BuildWatershedMap(uimfPointList);
                smoother.Smooth(ref watershedPointList);

                var fragmentFeatureBlobList = FeatureDetection.DoWatershedAlgorithm(watershedPointList).ToList();
                FragmentFeaturesDictionary.Add(ionTypeTuple, fragmentFeatureBlobList);

                index++;
                var progress = (int)((index / fragmentCount) * 100);
                m_FeatureFinderBackgroundWorker.ReportProgress(progress);
            }

            OnPropertyChanged("FeatureList");
            OnPropertyChanged("LcSlicePlot");
            OnPropertyChanged("ImsSlicePlot");
        }
Exemplo n.º 27
0
        /// <summary>
        /// Finds the XIC based on the m/z and scan parameters.
        /// </summary>
        /// <param name="mz"></param>
        /// <param name="scan"></param>
        /// <returns></returns>
        public List<PNNLOmics.Data.XYData> FindXic(double mz, int scan, bool shouldSmooth)
        {
            LcmsFeatureTarget target    = new LcmsFeatureTarget();
            target.ID                   = 0;
            target.MZ                   = mz;
            target.ScanLCTarget         = scan;
            target.ElutionTimeUnit      = Globals.ElutionTimeUnit.ScanNum;
            m_run.CurrentMassTag        = target;
            var result                  = m_run.ResultCollection.GetTargetedResult(m_run.CurrentMassTag);

            double chromPeakGeneratorTolInPPM = MzPpmWindow;
            Globals.ChromatogramGeneratorMode chromGeneratorMode = Globals.ChromatogramGeneratorMode.MZ_BASED;

            var chromGen = new PeakChromatogramGenerator(   chromPeakGeneratorTolInPPM,
                                                            chromGeneratorMode);
            chromGen.NETWindowWidthForNonAlignedData = Convert.ToSingle(NetWindow);

            int pointsToSmooth  = 5;
            var chromSmoother   = new SavitzkyGolaySmoother(pointsToSmooth, 2);

            double chromPeakDetectorPeakBR   = 1;
            double chromPeakDetectorSigNoise = 1;
            var chromPeakDetector            = new ChromPeakDetector(   chromPeakDetectorPeakBR,
                                                                        chromPeakDetectorSigNoise);

            ChromPeakSelectorParameters chromPeakSelectorParameters = new ChromPeakSelectorParameters();
            var chromPeakSelector = new BasicChromPeakSelector(chromPeakSelectorParameters);

            //this generates an extracted ion chromatogram
            // Since we are not using the built in generator,
            chromGen.Execute(m_run.ResultCollection);

            //this smooths the data - very important step!
            if (shouldSmooth)
            {
                chromSmoother.Execute(m_run.ResultCollection);
            }

            //this detects peaks within an extracted ion chromatogram
            chromPeakDetector.Execute(m_run.ResultCollection);

            //this selects the peak
            chromPeakSelector.Parameters.PeakSelectorMode = Globals.PeakSelectorMode.ClosestToTarget;
            chromPeakSelector.Execute(m_run.ResultCollection);

            //Here's the chromatogram data...
            List<PNNLOmics.Data.XYData> data = new List<PNNLOmics.Data.XYData>();

            for (int i = 0; i < m_run.XYData.Xvalues.Length; i++)
            {
                PNNLOmics.Data.XYData datum = new PNNLOmics.Data.XYData(m_run.XYData.Xvalues[i], m_run.XYData.Yvalues[i]);
                data.Add(datum);
            }

            return data;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LcImsPeptideSearchWorkfow"/> class.
        /// </summary>
        /// <param name="uimfFileLocation">
        /// The uimf file location.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        public LcImsPeptideSearchWorkfow(string uimfFileLocation, LcImsPeptideSearchParameters parameters)
        {
            this._buildWatershedStopWatch = new Stopwatch();
            this._smoothStopwatch = new Stopwatch();
            this._featureFindStopWatch = new Stopwatch();
            this._featureFindCount = 0;
            this._pointCount = 0;
            this._uimfFileLocation = uimfFileLocation;

            this._uimfReader = new DataReader(uimfFileLocation);

            // Append bin-centric table to the uimf if not present.
            if (!this._uimfReader.DoesContainBinCentricData())
            {
                DataWriter dataWriter = new DataWriter(uimfFileLocation);
                dataWriter.CreateBinCentricTables();
            }

            this._parameters = parameters;
            this._smoother = new SavitzkyGolaySmoother(parameters.NumPointForSmoothing, 2);
            this._theoreticalFeatureGenerator = new JoshTheorFeatureGenerator();
            this._leftOfMonoPeakLooker = new LeftOfMonoPeakLooker();
            this._peakDetector = new ChromPeakDetector(0.0001, 0.0001);
            this._isotopicPeakFitScoreCalculator = new PeakLeastSquaresFitter();

            IterativeTFFParameters msFeatureFinderParameters = new IterativeTFFParameters
            {
                MinimumRelIntensityForForPeakInclusion = 0.0001,
                PeakDetectorMinimumPeakBR = 0.0001,
                PeakDetectorPeakBR = 5.0002,
                PeakBRStep = 0.25,
                PeakDetectorSigNoiseRatioThreshold = 0.0001,
                ToleranceInPPM = parameters.MassToleranceInPpm
            };
            this._msFeatureFinder = new IterativeTFF(msFeatureFinderParameters);
            this.NumberOfFrames = this._uimfReader.GetGlobalParams().NumFrames;
            this.NumberOfScans = this._uimfReader.GetFrameParams(1).Scans;
        }
Exemplo n.º 29
0
        public void OptimizePeakDetectionSettings()
        {
            string testDatasetPath =
                @"D:\Data\From_Vlad\Bruker\2013_01_29_ALZ_CTRL_5_0p5_1_01_228.d";



            int[] scanList = new int[] { 200 };

            Run run = new RunFactory().CreateRun(testDatasetPath);



            var peakDetector = new DeconToolsPeakDetector();

            peakDetector.PeakToBackgroundRatio  = 7;
            peakDetector.SignalToNoiseThreshold = 5;
            peakDetector.IsDataThresholded      = false;

            var msgen = MSGeneratorFactory.CreateMSGenerator(run.MSFileType);
            var decon = new HornDeconvolutor();

            decon.MaxFitAllowed = 0.6;


            double[] peakBRList = new double[] { 5, 7, 9, 11, 15, 21 };

            double[] sigNoiseList = new double[] { 2, 3, 4, 5 };

            var smoother = new SavitzkyGolaySmoother(5, 2);


            foreach (var scan in scanList)
            {
                ScanSet scanSet = new ScanSet(scan);


                run.CurrentScanSet = scanSet;

                msgen.Execute(run.ResultCollection);

                foreach (var peakBRVal in peakBRList)
                {
                    foreach (var sigNoiseVal in sigNoiseList)
                    {
                        run.ResultCollection.IsosResultBin.Clear();

                        smoother.Execute(run.ResultCollection);

                        peakDetector.PeakToBackgroundRatio  = peakBRVal;
                        peakDetector.SignalToNoiseThreshold = sigNoiseVal;

                        peakDetector.Execute(run.ResultCollection);
                        decon.Execute(run.ResultCollection);

                        int numFeatures   = run.ResultCollection.IsosResultBin.Count;
                        int numPeaks      = run.PeakList.Count;
                        int numHQFeatures = run.ResultCollection.IsosResultBin.Count(p => p.IsotopicProfile.Score < 0.25);

                        double ratioFeaturesToPeaks = (double)numHQFeatures / numPeaks;

                        Console.WriteLine(scan + "\t" + peakBRVal + "\t" + sigNoiseVal + "\t" + numPeaks + "\t" + numFeatures + "\t" + numHQFeatures +
                                          "\t" + ratioFeaturesToPeaks.ToString("0.000"));
                    }
                }
            }
        }
Exemplo n.º 30
0
        protected override void DoPostInitialization()
        {
            base.DoPostInitialization();
            ValidateParameters();

            theorFeatureGen    = new JoshTheorFeatureGenerator(DeconTools.Backend.Globals.LabellingType.NONE, 0.005);
            theorN15FeatureGen = new JoshTheorFeatureGenerator(DeconTools.Backend.Globals.LabellingType.N15, 0.005);

            chromGenN14 = new PeakChromatogramGenerator(_workflowParameters.ChromGenTolerance, _workflowParameters.ChromGeneratorMode);
            chromGenN14.TopNPeaksLowerCutOff = 0.333;

            chromGenN15 = new PeakChromatogramGenerator(_workflowParameters.ChromGenTolerance, DeconTools.Backend.Globals.ChromatogramGeneratorMode.MOST_ABUNDANT_PEAK, DeconTools.Backend.Globals.IsotopicProfileType.LABELLED);
            chromGenN15.TopNPeaksLowerCutOff = 0.333;

            var pointsToSmooth = (_workflowParameters.ChromSmootherNumPointsInSmooth + 1) / 2;

            chromSmoother     = new SavitzkyGolaySmoother(_workflowParameters.ChromSmootherNumPointsInSmooth, 2);
            chromPeakDetector = new ChromPeakDetector(_workflowParameters.ChromPeakDetectorPeakBR, _workflowParameters.ChromPeakDetectorSigNoise);

            var smartchrompeakSelectorParams = new SmartChromPeakSelectorParameters();

            smartchrompeakSelectorParams.MSFeatureFinderType          = DeconTools.Backend.Globals.TargetedFeatureFinderType.ITERATIVE;
            smartchrompeakSelectorParams.MSPeakDetectorPeakBR         = _workflowParameters.MSPeakDetectorPeakBR;
            smartchrompeakSelectorParams.MSPeakDetectorSigNoiseThresh = _workflowParameters.MSPeakDetectorSigNoise;
            smartchrompeakSelectorParams.MSToleranceInPPM             = _workflowParameters.MSToleranceInPPM;
            smartchrompeakSelectorParams.NETTolerance         = (float)_workflowParameters.ChromNETTolerance;
            smartchrompeakSelectorParams.NumScansToSum        = _workflowParameters.NumMSScansToSum;
            smartchrompeakSelectorParams.NumChromPeaksAllowed = 10;
            smartchrompeakSelectorParams.IterativeTffMinRelIntensityForPeakInclusion = 0.5;


            chromPeakSelectorN14 = new SmartChromPeakSelector(smartchrompeakSelectorParams);


            var chromPeakSelectorParameters = new ChromPeakSelectorParameters();

            chromPeakSelectorParameters.NumScansToSum    = _workflowParameters.NumMSScansToSum;
            chromPeakSelectorParameters.NETTolerance     = (float)_workflowParameters.ChromNETTolerance;
            chromPeakSelectorParameters.PeakSelectorMode = DeconTools.Backend.Globals.PeakSelectorMode.N15IntelligentMode;


            chromPeakSelectorN15 = new BasicChromPeakSelector(chromPeakSelectorParameters);
            chromPeakSelectorN15.IsotopicProfileType = DeconTools.Backend.Globals.IsotopicProfileType.LABELLED;

            msPeakDetector = new DeconToolsPeakDetectorV2(_workflowParameters.MSPeakDetectorPeakBR,
                                                          _workflowParameters.MSPeakDetectorSigNoise, DeconTools.Backend.Globals.PeakFitType.QUADRATIC, false);


            var iterativeTFFParameters = new IterativeTFFParameters();

            iterativeTFFParameters.ToleranceInPPM = _n14N15Workflow2Parameters.TargetedFeatureFinderToleranceInPPM;
            iterativeTFFParameters.MinimumRelIntensityForForPeakInclusion = 0.33;
            iterativeTFFParameters.IsotopicProfileType = DeconTools.Backend.Globals.IsotopicProfileType.UNLABELLED;
            unlabelledProfilefinder = new IterativeTFF(iterativeTFFParameters);

            iterativeTFFParameters = new IterativeTFFParameters();
            iterativeTFFParameters.ToleranceInPPM = _n14N15Workflow2Parameters.TargetedFeatureFinderToleranceInPPM;
            iterativeTFFParameters.MinimumRelIntensityForForPeakInclusion = 0.33;
            iterativeTFFParameters.IsotopicProfileType = DeconTools.Backend.Globals.IsotopicProfileType.LABELLED;
            labelledProfileFinder = new IterativeTFF(iterativeTFFParameters);

            quantifier = new N14N15QuantifierTask(_n14N15Workflow2Parameters.NumPeaksUsedInQuant, _workflowParameters.MSToleranceInPPM);

            fitScoreCalc = new IsotopicProfileFitScoreCalculator();

            var minRelativeIntensityForScore = 0.2;

            resultValidatorN14 = new ResultValidatorTask(minRelativeIntensityForScore, true);

            resultValidatorN15 = new LabelledIsotopicProfileScorer(minRelativeIntensityForScore);

            ChromatogramXYData = new XYData();
            MassSpectrumXYData = new XYData();
            ChromPeaksDetected = new List <ChromPeak>();
        }
Exemplo n.º 31
0
        public void CorrelationTest1()
        {
            //TODO: test something

            var run = new RunFactory().CreateRun(FileRefs.RawDataMSFiles.OrbitrapStdFile1);

            var peakImporter = new PeakImporterFromText(FileRefs.PeakDataFiles.OrbitrapPeakFile_scans5500_6500);

            peakImporter.ImportPeaks(run.ResultCollection.MSPeakResultList);

            var mt = TestUtilities.GetMassTagStandard(1);

            run.CurrentMassTag = mt;

            var unlabelledTheorGenerator = new JoshTheorFeatureGenerator();

            unlabelledTheorGenerator.GenerateTheorFeature(mt);


            double chromToleranceInPPM = 10;
            var    startScan           = 5460;
            var    stopScan            = 5755;

            var smoother = new SavitzkyGolaySmoother(3, 2);

            var peakChromGen = new PeakChromatogramGenerator(chromToleranceInPPM);

            run.XYData = peakChromGen.GenerateChromatogram(run, startScan, stopScan, mt.IsotopicProfile.Peaklist[0].XValue, chromToleranceInPPM);
            run.XYData = smoother.Smooth(run.XYData);

            var chromdata1 = run.XYData.TrimData(startScan, stopScan);


            run.XYData = peakChromGen.GenerateChromatogram(run, startScan, stopScan, mt.IsotopicProfile.Peaklist[3].XValue, chromToleranceInPPM);
            run.XYData = smoother.Smooth(run.XYData);

            var chromdata2 = run.XYData.TrimData(startScan, stopScan);

            //chromdata1.Display();
            //Console.WriteLine();
            //chromdata2.Display();

            ChromatogramCorrelatorBase correlator = new ChromatogramCorrelator(3);
            double slope       = 0;
            double intercept   = 0;
            double rsquaredVal = 0;

            correlator.GetElutionCorrelationData(chromdata1, chromdata2, out slope, out intercept, out rsquaredVal);

            Console.WriteLine(mt);

            Console.WriteLine("slope = \t" + slope);
            Console.WriteLine("intercept = \t" + intercept);
            Console.WriteLine("rsquared = \t" + rsquaredVal);


            for (var i = 0; i < chromdata1.Xvalues.Length; i++)
            {
                Console.WriteLine(chromdata1.Xvalues[i].ToString("0") + "\t" + chromdata1.Yvalues[i].ToString("0") + "\t" + chromdata2.Yvalues[i]);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CrossSectionWorkfow"/> class.
        /// </summary>
        /// <param name="uimfFileLocation">
        /// The uimf file location.
        /// </param>
        /// <param name="outputDirectory">
        /// The output directory.
        /// </param>
        /// <param name="logFileName">
        /// The log file name.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        public CrossSectionWorkfow(string uimfFileLocation, string outputDirectory, CrossSectionSearchParameters parameters)
        {
            this.uimfReader = new DataReader(uimfFileLocation);

            // Append bin-centric table to the uimf if not present.
            if (!this.uimfReader.DoesContainBinCentricData())
            {
                DataWriter dataWriter = new DataWriter(uimfFileLocation);
                dataWriter.CreateBinCentricTables();
            }

            this.Parameters = parameters;

            this.smoother = new SavitzkyGolaySmoother(parameters.NumPointForSmoothing, 5);

            this.theoreticalFeatureGenerator = new JoshTheorFeatureGenerator();
            this.peakDetector = new ChromPeakDetector(0.0001, 0.0001);

            this.NumberOfFrames = this.uimfReader.GetGlobalParams().NumFrames;
            this.NumberOfScans = this.uimfReader.GetFrameParams(1).Scans;
            this.SampleCollectionDate = this.uimfReader.GetGlobalParams().GetValue(GlobalParamKeyType.DateStarted);

            this.DatasetName = Path.GetFileNameWithoutExtension(uimfFileLocation);
            this.OutputPath = outputDirectory;
            this.DatasetPath = uimfFileLocation;

            this.Parameters = parameters;

            if (outputDirectory == string.Empty)
            {
                outputDirectory = Directory.GetCurrentDirectory();
            }

            if (!outputDirectory.EndsWith("\\"))
            {
                outputDirectory += "\\";
            }

            if (!Directory.Exists(outputDirectory))
            {
                try
                {
                    Directory.CreateDirectory(outputDirectory);
                }
                catch (Exception)
                {
                    Console.WriteLine("Failed to create directory.");
                    throw;
                }
            }

            this.OutputPath = outputDirectory;
        }
Exemplo n.º 33
0
 static Xic()
 {
     Smoother = new SavitzkyGolaySmoother(9, 2);
 }
        public void TestScoring()
        {
            string formula = "C9H13ClN6";
             string fileLocation = Cae;
             MolecularTarget target = new MolecularTarget(formula, IonizationMethod.Protonated, "CAE");

             Console.WriteLine("CompositionWithoutAdduct: " + target.CompositionWithoutAdduct);
             Console.WriteLine("Monoisotopic ViperCompatibleMass: " + target.MonoisotopicMass);

             CrossSectionSearchParameters parameters = new CrossSectionSearchParameters(driftTubeLength);

             var smoother = new SavitzkyGolaySmoother(parameters.NumPointForSmoothing, 2);

             CrossSectionWorkfow workflow = new CrossSectionWorkfow(fileLocation, "output", parameters);

             Console.WriteLine("Ionization method: " + target.Adduct);
             Console.WriteLine("Targeting centerMz: " + target.MassWithAdduct);

             // Generate Theoretical Isotopic Profile
             List<Peak> theoreticalIsotopicProfilePeakList = null;
             if (target.CompositionWithAdduct != null)
             {
                 string empiricalFormula = target.CompositionWithAdduct.ToPlainString();
                 var theoreticalFeatureGenerator = new JoshTheorFeatureGenerator();
                 IsotopicProfile theoreticalIsotopicProfile = theoreticalFeatureGenerator.GenerateTheorProfile(empiricalFormula, 1);
                 theoreticalIsotopicProfilePeakList = theoreticalIsotopicProfile.Peaklist.Cast<Peak>().ToList();
             }

             // Generate VoltageSeparatedAccumulatedXICs
             var uimfReader = new DataReader(fileLocation);
             Console.WriteLine("Input file: {0}", fileLocation);
             VoltageSeparatedAccumulatedXiCs accumulatedXiCs = new VoltageSeparatedAccumulatedXiCs(uimfReader, target.MassWithAdduct, parameters.MzWindowHalfWidthInPpm, driftTubeLength);

             Console.WriteLine();

             // For each voltage, find 2D XIC features
             foreach (VoltageGroup voltageGroup in accumulatedXiCs.Keys)
             {
                 Console.WriteLine("Voltage group: {0} V, Frame {1}-{2}, {3:F2}K, {4:F2}Torr",
                     voltageGroup.MeanVoltageInVolts,
                     voltageGroup.FirstFrameNumber,
                     voltageGroup.LastFrameNumber,
                     voltageGroup.MeanTemperatureInKelvin,
                     voltageGroup.MeanPressureInTorr);

                 List<IntensityPoint> intensityPoints = accumulatedXiCs[voltageGroup].IntensityPoints;
                 List<FeatureBlob> featureBlobs = PeakFinding.FindPeakUsingWatershed(intensityPoints, smoother, parameters.FeatureFilterLevel);
                 List<StandardImsPeak> standardPeaks = featureBlobs.Select(featureBlob => new StandardImsPeak(featureBlob, uimfReader, voltageGroup,  target.MassWithAdduct, parameters.MzWindowHalfWidthInPpm)).ToList();

                 // feature scorings and Target selection.
                 double globalMaxIntensity = IMSUtil.MaxIntensityAfterFrameAccumulation(voltageGroup, uimfReader);

                 // Check each XIC Peak found
                 foreach (var featurePeak in standardPeaks)
                 {
                     // Evaluate feature scores.
                    double intensityScore = FeatureScoreUtilities.IntensityScore(featurePeak, globalMaxIntensity);

                    double isotopicScoreAngle = FeatureScoreUtilities.IsotopicProfileScore(
                         featurePeak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.Angle,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreDistance = FeatureScoreUtilities.IsotopicProfileScore(
                         featurePeak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.EuclideanDistance,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScorePerson = FeatureScoreUtilities.IsotopicProfileScore(
                         featurePeak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.PearsonCorrelation,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreBhattacharyya = FeatureScoreUtilities.IsotopicProfileScore(
                         featurePeak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.Bhattacharyya,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreDistanceAlternative = FeatureScoreUtilities.IsotopicProfileScore(
                         featurePeak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.EuclideanDistanceAlternative,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double peakShapeScore = FeatureScoreUtilities.PeakShapeScore(featurePeak, workflow.uimfReader, workflow.Parameters.MzWindowHalfWidthInPpm, workflow.Parameters.DriftTimeToleranceInMs, voltageGroup, globalMaxIntensity, workflow.NumberOfScans);

                     // Report all features.
                     Console.WriteLine(" feature found at scan number {0}", featurePeak.PeakApex.DriftTimeCenterInScanNumber);
                     Console.WriteLine("     IntensityScore: {0}", intensityScore);
                     Console.WriteLine("     peakShapeScore: {0}", peakShapeScore);
                     Console.WriteLine("     isotopicScore - Angle:    {0}", isotopicScoreAngle);
                     Console.WriteLine("     isotopicScore - Distance: {0}", isotopicScoreDistance);
                     Console.WriteLine("     isotopicScore - Distance2:{0}", isotopicScoreDistanceAlternative);
                     Console.WriteLine("     isotopicScore - Pearson:  {0}", isotopicScorePerson);
                     Console.WriteLine("     isotopicScore - Bhattacharyya: {0}", isotopicScoreBhattacharyya);

                     Console.WriteLine();
                 }

                 Console.WriteLine();
             }

             workflow.Dispose();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LibraryMatchWorkflow"/> class.
        /// </summary>
        /// <param name="uimfFileLocation">
        /// The UIMF file location.
        /// </param>
        /// <param name="outputDirectory">
        /// The output directory.
        /// </param>
        /// <param name="resultFileName">
        /// The result file name.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        public LibraryMatchWorkflow(string uimfFileLocation, string outputDirectory, string resultFileName, LibraryMatchParameters parameters)
        {
            this.uimfReader = new DataReader(uimfFileLocation);

            // Append bin-centric table to the uimf if not present.
            if (!this.uimfReader.DoesContainBinCentricData())
            {
                DataWriter dataWriter = new DataWriter(uimfFileLocation);
                dataWriter.CreateBinCentricTables();
            }

            this.Parameters = parameters;
            this.smoother = new SavitzkyGolaySmoother(parameters.NumPointForSmoothing, 2);

            this.NumberOfFrames = this.uimfReader.GetGlobalParams().NumFrames;
            this.NumberOfScans = this.uimfReader.GetFrameParams(1).Scans;

            this.DatasetName = Path.GetFileNameWithoutExtension(uimfFileLocation);

            this.Parameters = parameters;

            this.ResultFileName = resultFileName;

            if (outputDirectory == string.Empty)
            {
                outputDirectory = Directory.GetCurrentDirectory();
            }

            if (!outputDirectory.EndsWith("\\"))
            {
                outputDirectory += "\\";
            }

            if (!Directory.Exists(outputDirectory))
            {
                try
                {
                    Directory.CreateDirectory(outputDirectory);
                }
                catch (Exception)
                {
                    Console.WriteLine("Failed to create directory.");
                    throw;
                }
            }

            this.OutputPath = outputDirectory;

            Trace.Listeners.Clear();
            ConsoleTraceListener consoleTraceListener = new ConsoleTraceListener(false);
            consoleTraceListener.TraceOutputOptions = TraceOptions.DateTime;
            string result = this.OutputPath + this.ResultFileName;
            this.resultFileWriter = File.AppendText(result);
            TextWriterTraceListener resultFileTraceListener = new TextWriterTraceListener(this.resultFileWriter)
            {
                Name = "this.DatasetName" + "_Result",
                TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime
            };

            Trace.Listeners.Add(consoleTraceListener);
            Trace.Listeners.Add(resultFileTraceListener);
            Trace.AutoFlush = true;
        }
Exemplo n.º 36
0
        public void Test1()
        {
            var testFile =
                @"D:\Data\Orbitrap\BrianIQTesting\QC_Shew_11_02_pt5-b_6Jun11_Sphinx_11-03-27.RAW";
            var peaksTestFile =
                @"D:\Data\Orbitrap\BrianIQTesting\QC_Shew_11_02_pt5-b_6Jun11_Sphinx_11-03-27_peaks.txt";


            var run = RunUtilities.CreateAndLoadPeaks(testFile, peaksTestFile);

            var target = new LcmsFeatureTarget();

            target.ID = 0;


            target.MZ              = 715.39214;
            target.ScanLCTarget    = 7343;
            target.ElutionTimeUnit = Globals.ElutionTimeUnit.ScanNum;
            run.CurrentMassTag     = target;

            var result = run.ResultCollection.GetTargetedResult(run.CurrentMassTag);

            double chromPeakGeneratorTolInPPM = 20;
            var    chromGeneratorMode         = Globals.ChromatogramGeneratorMode.MZ_BASED;

            var chromGen = new PeakChromatogramGenerator(chromPeakGeneratorTolInPPM, chromGeneratorMode);

            // If we want to use the Execute Command
            //BLL .1 and .5 NET windows work.   .02 NET window does not BR and SN was set to 1 however)
            chromGen.ChromWindowWidthForNonAlignedData = .02F;


            var pointsToSmooth = 5;
            var chromSmoother  = new SavitzkyGolaySmoother(pointsToSmooth, 2);

            //BLL We also tried to set the BR and SIG NOISE to 0.  This did not work
            var chromPeakDetectorPeakBR   = 0.5;
            var chromPeakDetectorSigNoise = 0.5;
            var chromPeakDetector         = new ChromPeakDetector(chromPeakDetectorPeakBR, chromPeakDetectorSigNoise);


            var chromPeakSelectorParameters = new ChromPeakSelectorParameters();

            chromPeakSelectorParameters.PeakSelectorMode = Globals.PeakSelectorMode.ClosestToTarget;
            var chromPeakSelector = new BasicChromPeakSelector(chromPeakSelectorParameters);

            var smartChromPeakParameters = new SmartChromPeakSelectorParameters();


            var smartChromPeakSelector = new SmartChromPeakSelector(smartChromPeakParameters);


            //this generates an extracted ion chromatogram
            // Since we are not using the built in generator,
            chromGen.Execute(run.ResultCollection);

            //this smooths the data - very important step!

            //BLL. This didnt work for me when we first started, instead of using the NET window above.
            //chromGen.GenerateChromatogram(run,
            //                                target.ScanLCTarget - 300,
            //                                target.ScanLCTarget + 300,
            //                                target.MZ,
            //                                chromPeakGeneratorTolInPPM);
            chromSmoother.Execute(run.ResultCollection);

            //this detects peaks within an extracted ion chromatogram
            chromPeakDetector.Execute(run.ResultCollection);

            //this selects the peak
            chromPeakSelector.Execute(run.ResultCollection);
            //smartChromPeakSelector.Execute(run.ResultCollection);


            //TestUtilities.DisplayXYValues(run.XYData);
            TestUtilities.DisplayPeaks(run.PeakList);



            Console.WriteLine("Number of peaks detected = " + run.PeakList.Count);
            Console.WriteLine("Selected peak= " + result.ChromPeakSelected);
        }
        public void TestFormulaPerturbance()
        {
            List<Tuple<string, string>> formulas = new List<Tuple<string, string>>();

             // truth
             formulas.Add(new Tuple<string, string>("True formula", "C12H10O4S"));
             formulas.Add(new Tuple<string, string>("1 extra H", "C12H11O4S"));
             formulas.Add(new Tuple<string, string>("2 extra H", "C12H12O4S"));
             formulas.Add(new Tuple<string, string>("3 extra H", "C12H13O4S"));
             formulas.Add(new Tuple<string, string>("3 extra H", "C12H14O4S"));
             formulas.Add(new Tuple<string, string>("4 extra H", "C12H15O4S"));
             formulas.Add(new Tuple<string, string>("5 extra H", "C12H16O4S"));
             formulas.Add(new Tuple<string, string>("1 less H", "C12H9O4S"));
             formulas.Add(new Tuple<string, string>("2 less H", "C12H8O4S"));
             formulas.Add(new Tuple<string, string>("3 less H", "C12H7O4S"));
             formulas.Add(new Tuple<string, string>("4 less H", "C12H6O4S"));
             Console.WriteLine("[Intensity], [Distance1], [Distance2], [Angle], [Pearson], [Bucha]");

             string fileLocation = BPSNegative;
             CrossSectionSearchParameters parameters = new CrossSectionSearchParameters(driftTubeLength);
             CrossSectionWorkfow workflow = new CrossSectionWorkfow(fileLocation, "output", parameters);

             foreach (var form in formulas)
             {
                 bool found = false;

                 MolecularTarget target = new MolecularTarget(form.Item2, new IonizationAdduct(IonizationMethod.Deprotonated), form.Item1);
                 Console.Write(form.Item1 + ": ");
                 var smoother = new SavitzkyGolaySmoother(parameters.NumPointForSmoothing, 2);

                 // Generate Theoretical Isotopic Profile
                 List<Peak> theoreticalIsotopicProfilePeakList = null;
                 if (target.CompositionWithAdduct != null)
                 {
                     string empiricalFormula = target.CompositionWithAdduct.ToPlainString();
                     var theoreticalFeatureGenerator = new JoshTheorFeatureGenerator();
                     IsotopicProfile theoreticalIsotopicProfile = theoreticalFeatureGenerator.GenerateTheorProfile(empiricalFormula, 1);
                     theoreticalIsotopicProfilePeakList = theoreticalIsotopicProfile.Peaklist.Cast<Peak>().ToList();
                 }

                 // Generate VoltageSeparatedAccumulatedXICs
                 var uimfReader = new DataReader(fileLocation);
                 VoltageSeparatedAccumulatedXiCs accumulatedXiCs = new VoltageSeparatedAccumulatedXiCs(uimfReader, target.MassWithAdduct, parameters.MzWindowHalfWidthInPpm, parameters.DriftTubeLengthInCm);

                 var voltageGroup = accumulatedXiCs.Keys.First();

                 // Find peaks using multidimensional peak finder.
                 List<IntensityPoint> intensityPoints = accumulatedXiCs[voltageGroup].IntensityPoints;
                 List<FeatureBlob> featureBlobs = PeakFinding.FindPeakUsingWatershed(intensityPoints, smoother, parameters.FeatureFilterLevel);
                 List<StandardImsPeak> standardPeaks = featureBlobs.Select(featureBlob => new StandardImsPeak(featureBlob, uimfReader, voltageGroup,  target.MassWithAdduct, parameters.MzWindowHalfWidthInPpm)).ToList();

                 // feature scorings and Target selection.
                 double globalMaxIntensity = IMSUtil.MaxIntensityAfterFrameAccumulation(voltageGroup, uimfReader);

                 // Check each XIC Peak found
                 foreach (var peak in standardPeaks)
                 {
                     // Evaluate feature scores.
                     double intensityScore = FeatureScoreUtilities.IntensityScore(peak, globalMaxIntensity);

                     double isotopicScoreAngle = FeatureScoreUtilities.IsotopicProfileScore(
                         peak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.Angle,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreDistance = FeatureScoreUtilities.IsotopicProfileScore(
                         peak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.EuclideanDistance,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScorePerson = FeatureScoreUtilities.IsotopicProfileScore(
                         peak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.PearsonCorrelation,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreBhattacharyya = FeatureScoreUtilities.IsotopicProfileScore(
                         peak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.Bhattacharyya,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreDistanceAlternative = FeatureScoreUtilities.IsotopicProfileScore(
                         peak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.EuclideanDistanceAlternative,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double peakShapeScore = FeatureScoreUtilities.PeakShapeScore(peak, workflow.uimfReader, workflow.Parameters.MzWindowHalfWidthInPpm, workflow.Parameters.DriftTimeToleranceInMs, voltageGroup, globalMaxIntensity, workflow.NumberOfScans);

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", intensityScore);
                         found = true;
                     }

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", isotopicScoreDistance);
                         found = true;
                     }

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", isotopicScoreDistanceAlternative);
                         found = true;
                     }

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", isotopicScoreAngle);
                         found = true;
                     }

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", isotopicScorePerson);
                         found = true;
                     }

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", isotopicScoreBhattacharyya);
                         found = true;
                     }
                 }

                 if (!found)
                 {
                     Console.Write("No features");
                 }

                 Console.WriteLine();
             }

             // Manually dispose so it doesn't interfere with other tests.
             workflow.Dispose();
        }
Exemplo n.º 38
0
        public void TestDoWaterShedAlgorithmPrecursorAndFragments()
        {
            var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF";
            var uimfUtil     = new UimfUtil(fileLocation);

            var    parentMz     = 643.27094937;
            double ppmTolerance = 50;

            var parentIntensityBlock = uimfUtil.GetXicAsArray(parentMz, ppmTolerance, DataReader.FrameType.MS1, DataReader.ToleranceType.PPM);

            var smoother = new SavitzkyGolaySmoother(5, 2);

            smoother.Smooth(ref parentIntensityBlock);

            var parentPointList = WaterShedMapUtil.BuildWatershedMap(parentIntensityBlock, 0, 0);
            var parentFeature   = FeatureDetection.DoWatershedAlgorithm(parentPointList).First();

            var statistics = parentFeature.Statistics;
            var scanLcMin  = statistics.ScanLcMin;
            var scanLcMax  = statistics.ScanLcMax;
            var scanImsMin = statistics.ScanImsMin;
            var scanImsMax = statistics.ScanImsMax;

            using (TextReader fragmentReader = new StreamReader(@"..\..\..\testFiles\OneFragment.csv"))
            {
                var line = "";
                while ((line = fragmentReader.ReadLine()) != null)
                {
                    var mzString = line.Trim();
                    var targetMz = double.Parse(mzString);

                    TextWriter unsmoothedWriter = new StreamWriter("unsmoothedRaw" + targetMz + ".csv");

                    var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, DataReader.FrameType.MS2, scanLcMin, scanLcMax, scanImsMin, scanImsMax, DataReader.ToleranceType.PPM);

                    var boundX = intensityBlock.GetUpperBound(0);
                    var boundY = intensityBlock.GetUpperBound(1);

                    for (var i = 0; i < boundX; i++)
                    {
                        var row = new StringBuilder();
                        for (var j = 0; j < boundY; j++)
                        {
                            row.Append(intensityBlock[i, j] + ",");
                        }
                        unsmoothedWriter.WriteLine(row.ToString());
                    }

                    unsmoothedWriter.Close();

                    smoother.Smooth(ref intensityBlock);

                    TextWriter smoothedWriter = new StreamWriter("smoothedRaw" + targetMz + ".csv");
                    for (var i = 0; i < boundX; i++)
                    {
                        var row = new StringBuilder();
                        for (var j = 0; j < boundY; j++)
                        {
                            row.Append(intensityBlock[i, j] + ",");
                        }
                        smoothedWriter.WriteLine(row.ToString());
                    }

                    smoothedWriter.Close();

                    var pointList   = WaterShedMapUtil.BuildWatershedMap(intensityBlock, scanLcMin, scanImsMin);
                    var featureList = FeatureDetection.DoWatershedAlgorithm(pointList);

                    Console.WriteLine("******************************************************");
                    Console.WriteLine("targetMz = " + targetMz);

                    foreach (var featureBlob in featureList)
                    {
                        var mostIntensePoint = featureBlob.PointList.OrderByDescending(x => x.Intensity).First();
                        Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity);
                    }
                }
            }
        }