コード例 #1
0
ファイル: ScanAssigner.cs プロジェクト: gwilson9/GlycoTools
        private static ThermoMzPeak GetPeak(PSM psm, double oxoniumIon, ThermoRawFile rawFile)
        {
            DoubleRange         rangeOxonium = DoubleRange.FromPPM(oxoniumIon, 20);
            List <ThermoMzPeak> peaks;

            ThermoSpectrum spec = rawFile.GetSpectrum(psm.scanNumber);

            if (spec.TryGetPeaks(rangeOxonium, out peaks))
            {
                peaks = peaks.OrderBy(x => x.SignalToNoise).ToList();
            }

            double       diff       = double.MaxValue;
            ThermoMzPeak returnPeak = null;

            foreach (ThermoMzPeak peak in peaks)
            {
                var currDiff = Math.Abs(peak.MZ - oxoniumIon);
                if (currDiff < diff)
                {
                    diff       = currDiff;
                    returnPeak = peak;
                }
            }
            return(returnPeak);
        }
コード例 #2
0
ファイル: Examples.cs プロジェクト: yhayirsevertr/CSMSL
        private static void ChemicalFormulaGeneratorExample()
        {
            //// Create a generator with formula bounds. In this case, every formula needs to have at least H2 but no more than C4H2
            //ChemicalFormulaGenerator generator = new ChemicalFormulaGenerator(new ChemicalFormula("H2"), new ChemicalFormula("C4H2"));

            //var formulas = generator.FromMass(0, 100).ToList();
            //foreach (var formula in formulas)
            //{
            //    WriteFormulaToConsole(formula);
            //}

            //Console.WriteLine("Unique Formulas: " + formulas.Count);

            // Create a generator with formula bounds. In this case, every formula needs to have at least H2 but no more than C4H2
            ChemicalFormulaGenerator generator = new ChemicalFormulaGenerator(new ChemicalFormula("C10000N1000H1000O1000"));

            DoubleRange range = DoubleRange.FromPPM(new ChemicalFormula("C62H54N42O24").MonoisotopicMass, 0.1);
            double      mass  = range.Mean;
            int         count = 0;

            foreach (var formula in generator.FromMass(range).Validate())
            {
                Console.WriteLine("{0,-15} {1:F10} {2,-5:G5} ppm", formula, formula.MonoisotopicMass,
                                  Tolerance.GetTolerance(formula.MonoisotopicMass, mass, ToleranceUnit.PPM));
                count++;
            }
            Console.WriteLine("Unique Formulas: " + count);
        }
コード例 #3
0
ファイル: ScanAssigner.cs プロジェクト: gwilson9/GlycoTools
        public static int GetSpectraCountOxonium(List <int> spectrumList, double oxoniumIon1, double oxoniumIon2, ThermoRawFile rawFile)
        {
            int count = 0;


            foreach (int scan in spectrumList)
            {
                ThermoSpectrum spectrum = rawFile.GetSpectrum(scan);

                bool                oxoniumIsPresent = false;
                DoubleRange         rangeOxonium1    = DoubleRange.FromPPM(oxoniumIon1, 20);
                List <ThermoMzPeak> peaks;
                if (spectrum.TryGetPeaks(rangeOxonium1, out peaks))
                {
                    peaks = peaks.OrderBy(x => x.SignalToNoise).ToList();
                }

                if (peaks.Count > 0)
                {
                    if (peaks[0].SignalToNoise > 3)
                    {
                        oxoniumIsPresent = true;
                    }
                }

                if (oxoniumIon2 > 0)
                {
                    DoubleRange         rangeOxonium2 = DoubleRange.FromPPM(oxoniumIon2, 20);
                    List <ThermoMzPeak> peaks2;
                    if (spectrum.TryGetPeaks(rangeOxonium2, out peaks2))
                    {
                        peaks2 = peaks2.OrderBy(x => x.SignalToNoise).ToList();
                    }

                    if (peaks2.Count > 0)
                    {
                        if (peaks2[0].SignalToNoise > 3)
                        {
                            oxoniumIsPresent = true;
                        }
                    }
                }

                if (oxoniumIsPresent)
                {
                    count++;
                }
            }


            return(count);
        }
コード例 #4
0
        public LFQProcessor(string rawFilePath, string peptidePath)
        {
            var rawFile = new ThermoRawFile(rawFilePath);

            rawFile.Open();

            List <int> msOneScanNumbers = new List <int>();

            foreach (var scane in rawFile)
            {
                if (scane.MsnOrder == 1)
                {
                    msOneScanNumbers.Add(scane.SpectrumNumber);
                }
            }

            ReadInTargets(peptidePath, rawFile);

            if (rawFile.GetMzAnalyzer(msOneScanNumbers[0]).Equals(MZAnalyzerType.Orbitrap))
            {
                var firstSpectrumRT = rawFile.GetRetentionTime(rawFile.FirstSpectrumNumber);
                var lastSpectrumRT  = rawFile.GetRetentionTime(rawFile.LastSpectrumNumber);

                foreach (var pep in targetPeptides)
                {
                    // Initial peak boundaries
                    var startTime = Math.Max(pep.parentMS1Time - 2, firstSpectrumRT);
                    var stopTime  = Math.Min(pep.parentMS1Time + 2, lastSpectrumRT);

                    pep.startLookupTime = startTime;
                    pep.stopLookupTime  = stopTime;
                    pep.FirstScan       = rawFile.GetSpectrumNumber(pep.startLookupTime);
                    pep.LastScan        = rawFile.GetSpectrumNumber(pep.stopLookupTime);
                    //10 ppm maass error for peak picking
                    pep.lookupRange = DoubleRange.FromPPM(pep.UserMZ, 10);
                }

                foreach (var ms1 in msOneScanNumbers)
                {
                    var spectrum = rawFile.GetSpectrum(ms1);
                    GetXICs(spectrum, ms1, rawFile.GetRetentionTime(ms1));
                }
            }
        }
コード例 #5
0
        public List <PSM> crunch(List <PSM> psms)
        {
            var rawFile = new ThermoRawFile(rawpath);

            rawFile.Open();

            List <int> msOneScanNumbers = new List <int>();

            foreach (var scan in rawFile)
            {
                if (scan.MsnOrder == 1)
                {
                    msOneScanNumbers.Add(scan.SpectrumNumber);
                }
            }
            //ReadInTargets(peptidesPath, rawFile);

            foreach (PSM psm in psms)
            {
                LFPeptide pep = psmToLFPeptide(psm, rawFile);
                targetPeptides.Add(pep);
            }

            // Question: how do we sync the list of PSMs with the intensity of the LFPeptide
            // They will be in same order

            List <LFPeptide> pepsWithSmooth = new List <LFPeptide>();

            if (rawFile.GetMzAnalyzer(msOneScanNumbers[0]).Equals(MZAnalyzerType.Orbitrap))
            {
                var firstSpectrumRT = rawFile.GetRetentionTime(rawFile.FirstSpectrumNumber);
                var lastSpectrumRT  = rawFile.GetRetentionTime(rawFile.LastSpectrumNumber);

                foreach (var pep in targetPeptides)
                {
                    var startTime = Math.Max(pep.parentMS1Time - 2, firstSpectrumRT);
                    var stopTime  = Math.Min(pep.parentMS1Time + 2, lastSpectrumRT);
                    pep.startLookupTime = startTime;
                    pep.stopLookupTime  = stopTime;
                    pep.FirstScan       = rawFile.GetSpectrumNumber(pep.startLookupTime);
                    pep.LastScan        = rawFile.GetSpectrumNumber(pep.stopLookupTime);
                    pep.lookupRange     = DoubleRange.FromPPM(pep.UserMZ, 10);
                }

                foreach (var ms1 in msOneScanNumbers)
                {
                    var spectrum = rawFile.GetSpectrum(ms1);
                    GetXICs(spectrum, ms1, rawFile.GetRetentionTime(ms1));
                    rawFile.ClearCachedScans();

                    List <LFPeptide> peptidesForExtract = targetPeptides.Where(x => x.doneBuildingXIC && !x.extractedXIC).ToList();
                    foreach (var pep in peptidesForExtract)
                    {
                        try
                        {
                            pep.SmoothLibrary = Smoothing.GetRollingAveragePeaks(pep, 11, true);
                            if (pep.SmoothLibrary.Count != 0)
                            {
                                ExtractFeatures.GetApexPeak(pep, true);
                                ExtractFeatures.GetFWHMWindow(pep);
                                LFPeptide pepSmooth = (LFPeptide)pep.Clone();
                                pepsWithSmooth.Add(pepSmooth);
                                pep.XICLibrary.Clear();
                            }
                        }catch (Exception e)
                        {/**
                          * System.Windows.Forms.MessageBox.Show("XICLibraryCount: " + pep.XICLibrary.Count
                          + "Peptide: " + pep.sequence
                          + "\n" + e.ToString());
                          **/
                        }
                    }
                }

                List <LFPeptide> peptidesToWrite = targetPeptides.Where(x => x.doneBuildingXIC && !x.extractedXIC).ToList();

                //Changed from psms.Count to pepswithsmooth.Count
                //for(int i = 0; i < psms.Count; i++)
                for (int i = 0; i < pepsWithSmooth.Count; i++)
                {
                    /**
                     * if(psms[i].scanTime == 20.45)
                     * {
                     *  double[] xs = new double[pepsWithSmooth[i].SmoothLibrary.Count];
                     *  double[] ys = new double[pepsWithSmooth[i].SmoothLibrary.Count];
                     *
                     *  StreamWriter writer = new StreamWriter(@"C:\Users\gwilson\Desktop\GlycoQuant - Injs\TLN[NGlycan_1216.42286271]CSGAHVK_0.5_2_PolynomialFit.csv");
                     *  for (int k = 0; k < pepsWithSmooth[i].SmoothLibrary.Count; k++)
                     *  {
                     *      xs[k] = pepsWithSmooth[i].SmoothLibrary[k].RT;
                     *      ys[k] = pepsWithSmooth[i].SmoothLibrary[k].Intensity;
                     *
                     *      //writer.WriteLine(pepsWithSmooth[i].SmoothLibrary[k].RT + "," + pepsWithSmooth[i].SmoothLibrary[k].Intensity);
                     *
                     *
                     *      if (pepsWithSmooth[i].SmoothLibrary[k].RT > targetPeptides[i].LeftFWHM.RT && pepsWithSmooth[i].SmoothLibrary[k].RT < targetPeptides[i].RightFWHM.RT)
                     *      {
                     *          writer.WriteLine(pepsWithSmooth[i].SmoothLibrary[k].RT + "," + pepsWithSmooth[i].SmoothLibrary[k].Intensity);
                     *      }
                     *
                     *  }
                     *
                     *  double[] p = Fit.Polynomial(xs, ys, 3)
                     *
                     *  for(int j = 0; j < p.Length; j++)
                     *  {
                     *      //writer.WriteLine()
                     *  }
                     *
                     *  writer.Close();
                     * }
                     **/


                    double intensity = 0;

                    try
                    {
                        for (int j = 0; j < pepsWithSmooth[i].SmoothLibrary.Count - 1; j++)
                        {
                            // Intensity is the sum of peak intensities from Left FWHM to Right FWHM

                            /**
                             * if (pepsWithSmooth[i].SmoothLibrary[j].RT > targetPeptides[i].LeftFWHM.RT && pepsWithSmooth[i].SmoothLibrary[j].RT < targetPeptides[i].RightFWHM.RT)
                             * {
                             *  intensity += pepsWithSmooth[i].SmoothLibrary[j].Intensity;
                             * }
                             **/

                            // Retention times
                            double RT1 = pepsWithSmooth[i].SmoothLibrary[j].RT;
                            double RT2 = pepsWithSmooth[i].SmoothLibrary[j + 1].RT;

                            // Intensities
                            double int1 = pepsWithSmooth[i].SmoothLibrary[j].Intensity;
                            double int2 = pepsWithSmooth[i].SmoothLibrary[j + 1].Intensity;

                            //Rectangle area
                            double rectArea = (RT2 - RT1) * Math.Min(int1, int2);

                            //Triangle Area
                            double triArea = ((RT2 - RT1) * Math.Abs(int1 - int2)) / 2;

                            intensity += rectArea + triArea;
                        }
                    }
                    catch (Exception e)
                    {
                        Console.ReadKey();
                    }

                    psms[i].intensity = intensity;

                    //psms[i].intensity = targetPeptides[i].apexPeakLibrary.Intensity;
                }

                rawFile.Dispose();

                return(psms);
            }

            rawFile.Dispose();
            return(psms);
        }