Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private void LoadRawFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            _rawFile = new ThermoRawFile(filePath);
            _rawFile.Open();

            _scanNumbers.Clear();
            _scanNumbers.RaiseListChangedEvents = false;
            for (int i = _rawFile.FirstSpectrumNumber; i < _rawFile.LastSpectrumNumber; i++)
            {
                if (_rawFile.GetMsnOrder(i) > 1)
                {
                    _scanNumbers.Add(i);
                }
            }
            _scanNumbers.RaiseListChangedEvents = true;
            _scanNumbers.ResetBindings();


            textBox1.Text = filePath;
        }
Ejemplo n.º 3
0
 public static void ReadInTargets(string filePath, ThermoRawFile rawFile)
 {
     targetPeptides = new List <LFPeptide>();
     using (var csv = new CsvReader(new StreamReader(filePath), true, '\t'))
     {
         int      fieldCount = csv.FieldCount;
         string[] headers    = csv.GetFieldHeaders();
         //"Spectrum number"
         //"Peptide"
         //"Charge"
         //"Precursor Theoretical m/z (Th)"
         while (csv.ReadNextRecord())
         {
             var pep = new LFPeptide
             {
                 ms2ScanNumber = int.Parse(csv["Spectrum Number"]),
                 sequence      = csv["Peptide"],
                 charge        = int.Parse(csv["Charge"]),
                 TheoreticalMZ = double.Parse(csv["Precursor Theoretical m/z (Th)"])
             };
             pep.parentMS1     = rawFile.GetParentSpectrumNumber(pep.ms2ScanNumber);
             pep.parentMS1Time = rawFile.GetRetentionTime(pep.parentMS1);
             pep.UserMZ        = rawFile.GetPrecursorMz(pep.ms2ScanNumber);
             targetPeptides.Add(pep);
         }
     }
 }
 public void ProcessSpectrum(ThermoRawFile rawfile, int spectrumNumber)
 {
     foreach (var mzFeature in mzFeatures)
     {
         mzFeature.MatchIntensities(rawfile.GetSpectrum(spectrumNumber), spectrumNumber);
     }
 }
Ejemplo n.º 5
0
 public static void LoopOverEveryScan()
 {
     using (ThermoRawFile rawFile = new ThermoRawFile("Resources/ThermoRawFileMS1MS2.raw"))
     {
         rawFile.Open();
         foreach (var scan in rawFile)
         {
             Console.WriteLine("{0,-4} {1,3} {2,-6:F4} {3,-5} {4,7} {5,-10} {6} {7}", scan.SpectrumNumber, scan.MsnOrder, scan.RetentionTime,
                               scan.Polarity, scan.MassSpectrum.Count, scan.MzAnalyzer, scan.MzRange, scan.MassSpectrum.IsHighResolution);
         }
     }
 }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            Convertor convertor = new Convertor();

            convertor.Protease          = Protease.Trypsin;
            convertor.FastaDatabaseFile = @"C:\Users\Derek\Documents\Compass Tests\OmssaConvertor\CONCAT_Uniprot_yeast_canonicalIsoforms_20jan2013.fasta";
            convertor.MissedClevages    = 3;
            convertor.FixedMods.Add(3);
            ThermoRawFile rawFile = new ThermoRawFile(@"C:\Users\Derek\Documents\Compass Tests\OmssaConvertor\10sep2013_yeast_control_2.raw");

            convertor.Convert(@"C:\Users\Derek\Documents\Compass Tests\OmssaConvertor\10sep2013_yeast_control_2_ITMS_HCD30.00.csv", rawFile);
        }
Ejemplo n.º 7
0
        public static void RecalibrateThermoRawFile()
        {
            List <ISpectrum> spectra = new List <ISpectrum>();

            using (ThermoRawFile rawFile = new ThermoRawFile("Resources/ThermoRawFileMS1MS2.raw"))
            {
                rawFile.Open();
                for (int i = rawFile.FirstSpectrumNumber; i <= rawFile.LastSpectrumNumber; i++)
                {
                    ThermoSpectrum spectrum          = rawFile.GetLabeledSpectrum(i);
                    ThermoSpectrum correctedSpectrum = spectrum.CorrectMasses((mz) => mz - 5); // shift all masses 5 Th lower
                    spectra.Add(correctedSpectrum);
                }
            }
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            var file = new ThermoRawFile(@"C:\Users\stepa\Data\MouseForShaker\04-29-13_B6_Frac9_9p5uL.raw");

            file.Open();

            Console.WriteLine(file.ToString());
            Console.WriteLine(file.monoisotopicPrecursorSelectionEnabled);

            file = new ThermoRawFile(@"C:\Users\stepa\Data\jurkat\Original\120426_Jurkat_highLC_Frac5.raw");
            file.Open();

            Console.WriteLine(file.ToString());
            Console.WriteLine(file.monoisotopicPrecursorSelectionEnabled);
            Console.Read();
        }
Ejemplo n.º 9
0
        public void LoadThermoTest2()
        {
            ThermoRawFile a = new ThermoRawFile(@"05-13-16_cali_MS_60K-res_MS.raw");

            a.Open();
            Assert.AreEqual(360, a.LastSpectrumNumber);
            var ok = a.GetScan(1).MassSpectrum.GetNoises();

            Assert.AreEqual(2401.57, ok[0], 0.01);
            ThermoSpectrum ok2 = a.GetScan(1).MassSpectrum.newSpectrumExtract(0, 500);

            Assert.GreaterOrEqual(1000, a.GetScan(1).MassSpectrum.newSpectrumExtract(0, 500).LastX);
            Assert.AreEqual(2, a.GetScan(1).MassSpectrum.newSpectrumFilterByY(5e6).Count);
            var ye = a.GetScan(1).MassSpectrum.CopyTo2DArray();

            Assert.AreEqual(1, ye[4, 1119]);
            Assert.AreEqual("(195.0874,1.0214E+07) z = +1 SN = 4170.38", a.GetScan(1).MassSpectrum.PeakWithHighestY.ToString());
            Assert.AreEqual(77561752, a.GetTIC(1));
            Assert.AreEqual(144, a.GetSpectrumNumber(2));



            Assert.AreEqual(0.98, a.GetElapsedScanTime(100), 0.01);

            var cromatogram = a.GetTICChroma();

            Assert.AreEqual(360, cromatogram.Count);
            Assert.AreEqual(0.01, cromatogram.FirstTime, 0.002);
            Assert.AreEqual(2.788433333, cromatogram.PeakWithHighestY.Time, 0.0001);
            Assert.AreEqual(2.788433333, cromatogram.GetApex(0, 5).Time, 0.0001);

            var newSpectrum = new ThermoSpectrum(a.GetScan(51).MassSpectrum);

            Assert.AreEqual(22246 / 5574.8, newSpectrum.GetSignalToNoise(1), 0.01);


            Assert.AreEqual(1, newSpectrum.GetCharges()[1]);
            Assert.AreEqual(102604, newSpectrum.GetResolutions()[1]);

            Assert.AreEqual(181, newSpectrum.newSpectrumExtract(500, 1000).Count);

            Assert.AreEqual(0, newSpectrum.newSpectrumExtract(-3, -2).Count);

            var hm = newSpectrum.newSpectrumExtract(501, 502);

            Assert.AreEqual(0, hm.Count);
        }
Ejemplo n.º 10
0
        public LFPeptide psmToLFPeptide(PSM psm, ThermoRawFile rawFile)
        {
            var pep = new LFPeptide
            {
                ms2ScanNumber = psm.scanNumber,
                sequence      = psm.peptide.Sequence,
                charge        = psm.charge,
                TheoreticalMZ = psm.mzCalc
            };

            pep.parentMS1     = rawFile.GetParentSpectrumNumber(pep.ms2ScanNumber);
            pep.parentMS1Time = rawFile.GetRetentionTime(pep.parentMS1);
            //pep.UserMZ = psm.mzObs;
            pep.UserMZ = rawFile.GetPrecursorMz(pep.ms2ScanNumber);

            return(pep);
        }
Ejemplo n.º 11
0
        private void UpdatePsmInformation(IList <InputFile> csvFiles, string rawFolder, bool useMedian = true)
        {
            Log("Reading MS data...");
            MSDataFile.CacheScans = false;
            List <string> rawFileNames = Directory.EnumerateFiles(rawFolder, "*.raw", SearchOption.AllDirectories).ToList();

            foreach (InputFile csvFile in csvFiles)
            {
                string rawFileName = csvFile.RawFileName;
                if (string.IsNullOrEmpty(rawFileName))
                {
                    throw new ArgumentException("Cannot parse the file name for: " + csvFile.FilePath);
                }
                csvFile.RawFilePath = "";
                foreach (string file in rawFileNames)
                {
                    string name = Path.GetFileNameWithoutExtension(file);

                    if (name != null && !rawFileName.Equals(name))
                    {
                        continue;
                    }
                    csvFile.RawFilePath = file;
                    break;
                }
                if (string.IsNullOrEmpty(csvFile.RawFilePath))
                {
                    throw new ArgumentException("Cannot find the associated raw file for: " + csvFile.FilePath);
                }
            }

            // update the precursor mass error
            foreach (InputFile csvFile in csvFiles)
            {
                using (MSDataFile dataFile = new ThermoRawFile(csvFile.RawFilePath))
                {
                    dataFile.Open();
                    csvFile.UpdatePsmInformation(dataFile, _is2DFDR, useMedian, _evalueThresholdPPMError);
                }
                if (_is2DFDR)
                {
                    Log(string.Format("{0:F2} ppm {1} precursor mass error in {2}",
                                      csvFile.SystematicPrecursorMassError, useMedian ? "median" : "average", csvFile.Name));
                }
            }
        }
Ejemplo n.º 12
0
        public void LoadThermoTest()
        {
            ThermoRawFile a = new ThermoRawFile(@"Shew_246a_LCQa_15Oct04_Andro_0904-2_4-20.RAW");

            a.Open();
            a.Open();
            Assert.AreEqual(1, a.FirstSpectrumNumber);
            Assert.AreEqual(3316, a.LastSpectrumNumber);
            Assert.AreEqual(3316, a.LastSpectrumNumber);

            var scan = a.GetScan(53);

            Assert.AreEqual(1.2623333333333333, scan.RetentionTime);
            Assert.AreEqual(1, scan.MsnOrder);
            Assert.AreEqual("controllerType=0 controllerNumber=1 scan=53", scan.id);
            Assert.AreEqual("+ c ESI Full ms [400.00-2000.00]", scan.ScanFilter);


            var spectrum = a.GetScan(53).MassSpectrum;

            var peak = spectrum.PeakWithHighestY;

            Assert.AreEqual(75501, peak.Intensity);

            Assert.AreEqual(1, spectrum.newSpectrumFilterByY(7.5e4).Count);
            Assert.AreEqual(2, spectrum.newSpectrumExtract(new DoubleRange(923, 928)).Count);


            Assert.AreEqual(double.NaN, spectrum.GetSignalToNoise(1));

            Assert.AreEqual("1.3", a.GetSofwareVersion());
            double ya;

            a.GetScan(948).TryGetSelectedIonGuessIntensity(out ya);
            Assert.AreEqual(4125760, ya);

            Assert.AreEqual("LCQ", a.GetInstrumentName());
            Assert.AreEqual("LCQ", a.GetInstrumentModel());

            Assert.AreEqual(0, a.GetMSXPrecursors(1289).Count);
            Assert.AreEqual(1, a.GetMSXPrecursors(1290).Count);
            Assert.AreEqual(1194.53, a.GetMSXPrecursors(1290).First());

            MzmlMethods.CreateAndWriteMyIndexedMZmlwithCalibratedSpectra(a, Path.Combine(Path.GetDirectoryName(a.FilePath), Path.GetFileNameWithoutExtension(a.FilePath)) + ".mzML");
        }
Ejemplo n.º 13
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));
                }
            }
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            var file = new ThermoRawFile(args[0]);

            file.Open();

            Console.WriteLine(file);

            var ye = file.GetScan(14317);

            Console.WriteLine(ye);

            var spectrum = ye.MassSpectrum;

            Console.WriteLine(spectrum);


            Console.WriteLine(spectrum[2088]);
            Console.WriteLine(spectrum[2089]);
            Console.WriteLine(spectrum[2090]);
            Console.WriteLine(spectrum[2091]);
            Console.WriteLine(spectrum[2092]);
            Console.WriteLine(spectrum[2093]);
            Console.WriteLine(spectrum[2094]);
            Console.WriteLine(spectrum[2095]);
            Console.WriteLine(spectrum[2096]);

            Console.WriteLine(spectrum[2089].Charge);
            Console.WriteLine(spectrum[2089].Intensity);
            Console.WriteLine(spectrum[2089].MZ);
            Console.WriteLine(spectrum[2089].Noise);
            Console.WriteLine(spectrum[2089].Resolution);
            Console.WriteLine(spectrum[2089].SignalToNoise);

            Console.Read();
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            UsefulProteomicsDatabases.Loaders.LoadElements("elements.dat");
            var tol = 0.01;

            var Compound1 = new Peptide("NNNNN");

            var regularMZ = new IsotopicDistribution(Compound1.GetChemicalFormula(), 0.1, 0.001).Masses.Select(b => b.ToMassToChargeRatio(1)).ToList();

            Console.WriteLine("NNNNN mz: " + string.Join(", ", regularMZ));

            var withAmmoniaLoss = Compound1.GetChemicalFormula();

            withAmmoniaLoss.Add(new ChemicalFormula("N-1H-2"));
            var withAmmoniaLossMZ = new IsotopicDistribution(withAmmoniaLoss, 0.1, 0.001).Masses.Select(b => b.ToMassToChargeRatio(1)).ToList();

            Console.WriteLine("withAmmoniaLoss mz: " + string.Join(", ", withAmmoniaLossMZ));

            var deamidated = Compound1.GetChemicalFormula();

            deamidated.Add(new ChemicalFormula("H-1N-1O"));
            var deamidatedMZ = new IsotopicDistribution(deamidated, 0.1, 0.001).Masses.Select(b => b.ToMassToChargeRatio(1)).ToList();

            Console.WriteLine("deamidated mz: " + string.Join(", ", deamidatedMZ));

            List <List <double> > allDistributions = new List <List <double> >()
            {
                regularMZ, withAmmoniaLossMZ, deamidatedMZ
            };

            foreach (var arg in args)
            {
                var file = new ThermoRawFile(arg);
                file.Open();
                string output_filepath = file.FilePath.Remove(file.FilePath.IndexOf(".raw"), ".raw".Length); //removes .raw at end for output
                using (System.IO.StreamWriter shiftsFile = new System.IO.StreamWriter(output_filepath + ".tsv"))
                {
                    shiftsFile.WriteLine(file.FilePath);
                    Console.WriteLine(file.FilePath);

                    foreach (var scan in file)
                    {
                        if (scan.MsnOrder == 1)
                        {
                            double bestIntensity = 0;
                            double monoError     = double.NaN;
                            foreach (var dist in allDistributions)
                            {
                                ThermoMzPeak monoisotopicPeak = null;
                                try { monoisotopicPeak = scan.MassSpectrum.newSpectrumExtract(dist[0] - tol, dist[0] + tol).PeakWithHighestY; }
                                catch { }
                                if (monoisotopicPeak != null && bestIntensity < monoisotopicPeak.Intensity)
                                {
                                    bestIntensity = monoisotopicPeak.Intensity;
                                    monoError     = dist[0] - monoisotopicPeak.MZ;
                                }
                            }
                            shiftsFile.WriteLine(scan.ScanNumber + "\t" + monoError);
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="argFullPath"></param>
 /// <param name="argFileType">ThermoRawFile</param>
 public ThermoRawReader(string argFullPath)
 {
     _fullFilePath = argFullPath;
     _raw          = new CSMSL.IO.Thermo.ThermoRawFile(_fullFilePath);
     _raw.Open();
 }
Ejemplo n.º 19
0
        public void crunch(string rawFilePath, string byonicResultsPath, string outputFolderPath)
        {
            List <PSM> allPsmsQuant = new List <PSM>();

            OnUpdateProgress(0.25);

            ThermoRawFile rawFile = new ThermoRawFile(@rawFilePath);

            rawFile.Open();

            String file = Path.GetFileNameWithoutExtension(byonicResultsPath);

            StreamReader byonicFile    = new StreamReader(byonicResultsPath);
            StreamWriter outputSummary = new StreamWriter(@outputFolderPath + "\\" + file + "_summary.csv");
            //StreamWriter outputList = new StreamWriter(@outputFolderPath + "\\" + file + "_list.txt");


            //Write Headers
            //outputList.WriteLine("Prot.Rank\tSequence\tPeptideParseFriendly\tPeptide\tPos.\tMods(variable)\tGlycans\t"+
            //                     "PEP2D\tPEP1D\t|Log Prob|\tScore\tDeltaScore\tDelta Mod.Score\tCharge\tObs.m/z\t"+
            //                     "Precursor Theoretical m/z (Th)\tppmerr.\tObs.MH\tCalc.MH\tCleavage\tGlycansPos.\tProteinName" +
            //                     "\tProt.Id\tScanTime\tSpectrum Number\tMods(fixed)\tFDR2D\tFDR1D\t"+
            //                     "FDR uniq.2D\tFDR uniq.1D\tq-value2D\tq-value1D\tisGlycoPeptide\tmodsPassedCheck" +
            //                     "\tpositionPassedCheck\tfragmentation\tMasterScan");

            List <int> HCDscans       = new List <int>();
            List <int> ETDscans       = new List <int>();
            int        totalMSMSscans = 0;

            //these will have decoys and targets, so only use is for FDR calc (FDR calc will be at PSM level)
            List <PSM> allPSMs      = new List <PSM>();
            List <PSM> hcdPSMs      = new List <PSM>();
            List <PSM> etdPSMs      = new List <PSM>();
            List <PSM> allGlycoPSMs = new List <PSM>();
            List <PSM> hcdGlycoPSMs = new List <PSM>();
            List <PSM> etdGlycoPSMs = new List <PSM>();

            //use this to print file to use in next program
            //List<PSM> masterListPSMs = new List<PSM>();

            //these will have no decoys, so use for counts and other processing
            Dictionary <string, List <PSM> > allPSMsNODECOY      = new Dictionary <string, List <PSM> >();
            Dictionary <string, List <PSM> > hcdPSMsNODECOY      = new Dictionary <string, List <PSM> >();
            Dictionary <string, List <PSM> > etdPSMsNODECOY      = new Dictionary <string, List <PSM> >();
            Dictionary <string, List <PSM> > allGlycoPSMsNODECOY = new Dictionary <string, List <PSM> >();
            Dictionary <string, List <PSM> > hcdGlycoPSMsNODECOY = new Dictionary <string, List <PSM> >();
            Dictionary <string, List <PSM> > etdGlycoPSMsNODECOY = new Dictionary <string, List <PSM> >();


            for (int i = rawFile.FirstSpectrumNumber; i <= rawFile.LastSpectrumNumber; i++)
            {
                if (rawFile.GetMsnOrder(i) == 2)
                {
                    if (rawFile.GetDissociationType(i).ToString().Equals("HCD"))
                    {
                        HCDscans.Add(i);
                    }
                    if (rawFile.GetDissociationType(i).ToString().Equals("ETD"))
                    {
                        ETDscans.Add(i);
                    }
                    totalMSMSscans++;
                }
            }

            //Added to accomodate PRM exps
            bool isPRM = false;

            using (var csv = new CsvReader(byonicFile, true, '\t'))
            {
                while (csv.ReadNextRecord())
                {
                    try
                    {
                        List <int> glycanPositionsList = new List <int>();

                        string PID                = "NA";//csv["PID"];
                        string protRank           = csv["ProtRank"];
                        string byonicSequence     = csv["Sequence"];
                        string peptidesToBeParsed = csv["PeptideParseFriendly"];

                        // NEW
                        string aminoAcidSequence = peptidesToBeParsed.Split(',')[0];
                        string byonicIntensity   = "NA"; //csv["Intensity"];

                        int    peptideStartPosition = int.Parse(csv["Pos."]);
                        string modsToBeParsed       = csv["Mods(variable)"];
                        string glycansToBeParsed    = csv["Glycans"];
                        double PEP2D         = double.Parse(csv["PEP2D"]);
                        double PEP1D         = double.Parse(csv["PEP1D"]);
                        double logProb       = 0; // double.Parse(csv["|Log Prob|"]);
                        double score         = double.Parse(csv["Score"]);
                        double deltaScore    = double.Parse(csv["DeltaScore"]);
                        double deltaModScore = double.Parse(csv["Delta Mod.Score"]);
                        int    charge        = int.Parse(csv["z"]);
                        double mzObs         = double.Parse(csv["Obs.m/z"]);
                        double mzCalc        = double.Parse(csv["Calc.m/z"]);
                        //double ppmError = double.Parse(csv["ppmerr."]);
                        string ppmError        = csv["ppmerr."];
                        double obsMH           = double.Parse(csv["Obs.MH"]);
                        double calcMH          = double.Parse(csv["Calc.MH"]);
                        string cleavage        = csv["Cleavage"];
                        string glycanPositions = csv["GlycansPos."];
                        string proteinName     = csv["ProteinName"];
                        int    protID          = int.Parse(csv["Prot.Id"]);
                        double scanTime        = double.Parse(csv["ScanTime"]);
                        int    scanNumber      = int.Parse(csv["Scan #"]);
                        string modsFixed       = csv["Mods(fixed)"];
                        double FDR2D           = double.Parse(csv["FDR2D"]);
                        double FDR1D           = double.Parse(csv["FDR1D"]);
                        double FDR2Dunique     = double.Parse(csv["FDR uniq.2D"]);
                        double FDR1Dunique     = double.Parse(csv["FDR uniq.1D"]);
                        double qvalue2D        = double.Parse(csv["q-value2D"]);
                        double qvalue1D        = double.Parse(csv["q-value1D"]);

                        // Flags to be used
                        bool isGlycoPeptide       = false;
                        bool modsPassedCheck      = false;
                        bool positionsPassedCheck = false;

                        if (modsToBeParsed.Contains("Glycan"))
                        {
                            isGlycoPeptide = true;
                        }

                        string fragmentation = rawFile.GetDissociationType(scanNumber).ToString();

                        //ThermoSpectrum spectrum = rawFile.GetSpectrum(scanNumber);

                        string[] parsedPeptide = peptidesToBeParsed.Split(',');
                        Peptide  peptide       = new Peptide(parsedPeptide[0]);

                        //string[] parsedSequenceWithMods = sequence.Split('.');
                        //string uniqueSequence = parsedSequenceWithMods[1];

                        string uniqueSequence = byonicSequence.Substring(2, byonicSequence.Length - 4);
                        //Console.WriteLine(uniqueSequence);
                        //Console.WriteLine(newSequence);
                        //Console.ReadKey();
                        //add to master list here

                        if (!String.IsNullOrEmpty(modsToBeParsed))
                        {
                            string[] modsParsedArrary = modsToBeParsed.Split(';');
                            for (int i = 0; i < modsParsedArrary.Length; i++)
                            {
                                string mod = modsParsedArrary[i];
                                //Console.WriteLine(mod);
                                //Console.ReadKey();
                                if (mod[0].Equals(' '))
                                {
                                    mod = mod.Substring(1);
                                }

                                if (mod.Contains("NGlycan") && !mod[0].Equals('N'))
                                {
                                    modsPassedCheck = false;
                                }

                                if (mod.Contains("NGlycan") && mod[0].Equals('N'))
                                {
                                    modsPassedCheck = true;
                                }

                                if (mod.Contains("OGlycan") && mod[0].Equals('S'))
                                {
                                    modsPassedCheck = true;
                                }
                                if (mod.Contains("OGlycan") && mod[0].Equals('T'))
                                {
                                    modsPassedCheck = true;
                                }
                            }
                        }

                        if (!String.IsNullOrEmpty(glycanPositions))
                        {
                            string[] glycansPosParsedArray = glycanPositions.Split(';');
                            for (int i = 0; i < glycansPosParsedArray.Length; i++)
                            {
                                int glycanPos = Convert.ToInt32(glycansPosParsedArray[i]);
                                glycanPositionsList.Add(glycanPos);
                            }
                        }

                        OnUpdateProgress(0.5);
                        if (glycanPositionsList.Count != glycanPositionsList.Distinct().Count())
                        {
                            positionsPassedCheck = false;
                        }
                        else
                        {
                            positionsPassedCheck = true;
                        }


                        int masterScan = 0;

                        try
                        {
                            masterScan = rawFile.GetParentSpectrumNumber(scanNumber);
                        }catch (Exception e)
                        {
                            // Included for PRM (MS2 has not master scan)
                            isPRM = true;
                        }

                        PSM psm = new PSM(peptide, PID, protRank, peptidesToBeParsed, peptideStartPosition, modsToBeParsed, glycansToBeParsed,
                                          PEP2D, PEP1D, logProb, score, deltaScore, deltaModScore, charge, mzObs, mzCalc, ppmError,
                                          obsMH, calcMH, cleavage, glycanPositions, proteinName, protID, scanTime, scanNumber, modsFixed, FDR2D, FDR1D,
                                          FDR2Dunique, FDR1Dunique, qvalue2D, qvalue1D, isGlycoPeptide, fragmentation, byonicSequence,
                                          modsPassedCheck, masterScan, positionsPassedCheck, byonicIntensity);//, spectrum);


                        allPSMs.Add(psm);

                        if (fragmentation.Equals("HCD"))
                        {
                            hcdPSMs.Add(psm);
                        }
                        if (fragmentation.Equals("ETD"))
                        {
                            etdPSMs.Add(psm);
                        }

                        if (isGlycoPeptide)
                        {
                            allGlycoPSMs.Add(psm);
                            if (fragmentation.Equals("HCD"))
                            {
                                hcdGlycoPSMs.Add(psm);
                            }
                            if (fragmentation.Equals("ETD"))
                            {
                                etdGlycoPSMs.Add(psm);
                            }
                        }

                        if (!proteinName.Contains("DECOY") && !proteinName.Contains("Reverse") && modsPassedCheck && positionsPassedCheck)
                        {
                            if (!allPSMsNODECOY.ContainsKey(uniqueSequence))
                            {
                                allPSMsNODECOY.Add(uniqueSequence, new List <PSM>());
                            }
                            allPSMsNODECOY[uniqueSequence].Add(psm);

                            if (fragmentation.Equals("HCD"))
                            {
                                if (!hcdPSMsNODECOY.ContainsKey(uniqueSequence))
                                {
                                    hcdPSMsNODECOY.Add(uniqueSequence, new List <PSM>());
                                }
                                hcdPSMsNODECOY[uniqueSequence].Add(psm);
                            }

                            if (fragmentation.Equals("ETD"))
                            {
                                if (!etdPSMsNODECOY.ContainsKey(uniqueSequence))
                                {
                                    etdPSMsNODECOY.Add(uniqueSequence, new List <PSM>());
                                }
                                etdPSMsNODECOY[uniqueSequence].Add(psm);
                            }

                            if (isGlycoPeptide)
                            {
                                if (!allGlycoPSMsNODECOY.ContainsKey(uniqueSequence))
                                {
                                    allGlycoPSMsNODECOY.Add(uniqueSequence, new List <PSM>());
                                }
                                allGlycoPSMsNODECOY[uniqueSequence].Add(psm);

                                if (fragmentation.Equals("HCD"))
                                {
                                    if (!hcdGlycoPSMsNODECOY.ContainsKey(uniqueSequence))
                                    {
                                        hcdGlycoPSMsNODECOY.Add(uniqueSequence, new List <PSM>());
                                    }
                                    hcdGlycoPSMsNODECOY[uniqueSequence].Add(psm);
                                }

                                if (fragmentation.Equals("ETD"))
                                {
                                    if (!etdGlycoPSMsNODECOY.ContainsKey(uniqueSequence))
                                    {
                                        etdGlycoPSMsNODECOY.Add(uniqueSequence, new List <PSM>());
                                    }
                                    etdGlycoPSMsNODECOY[uniqueSequence].Add(psm);
                                }
                            }
                        }



                        /**
                         * psm.Peak126 = GetPeak(psm, 126.055, rawFile);
                         * psm.Peak138 = GetPeak(psm, 138.055, rawFile);
                         * psm.Peak144 = GetPeak(psm, 144.065, rawFile);
                         * psm.Peak168 = GetPeak(psm, 168.066, rawFile);
                         * psm.Peak186 = GetPeak(psm, 186.076, rawFile);
                         * psm.Peak204 = GetPeak(psm, 204.087, rawFile);
                         * psm.Peak274 = GetPeak(psm, 274.092, rawFile);
                         * psm.Peak292 = GetPeak(psm, 292.103, rawFile);
                         * psm.Peak366 = GetPeak(psm, 366.140, rawFile);
                         **/

                        double GlcNAcToGalNAcratio = 0;

                        /*
                         * outputList.Write("PID\tProt.Rank\tSequence\tPeptideParseFriendly\tPos.\tMods(variable)\tGlycans\tPEP2D\tPEP1D\t|Log Prob|\tScore\tDeltaScore\tDelta Mod.Score\tz\tObs.m/z\t");
                         * outputList.Write("Calc.m/z\tppmerr.\tObs.m/z\tCalc.m/z\tCleavage\tGlycansPos.\tProteinName\tProt.Id\tScanTime\tScan #\tMods(fixed)\tFDR2D\tFDR1D\t");
                         * outputList.WriteLine("FDR uniq.2D\tFDR uniq.1D\tq-value2D\tq-value1D\tisGlycoPeptide\tmodsPassedCheck\tpositionPassedCheck\tfragmentation\tPeak126\tPeak138\tPeak144\tPeak168\tPeak186\tPeak204\tPeak274\tPeak292\tPeak366");
                         */

                        //outputList.WriteLine(protRank + "\t" + byonicSequence + "\t" + peptidesToBeParsed + "\t" + aminoAcidSequence + "\t" +
                        //                     peptideStartPosition + "\t" + modsToBeParsed + "\t" + glycansToBeParsed + "\t" + PEP2D + "\t" + PEP1D + "\t" +
                        //                     logProb + "\t" + score + "\t" + deltaScore + "\t" + deltaModScore + "\t" + charge + "\t" + mzObs + "\t" + mzCalc +
                        //                     "\t" + ppmError + "\t" + obsMH + "\t" + calcMH + "\t" + cleavage + "\t" + glycanPositions + "\t" + proteinName + "\t" +
                        //                     protID + "\t" + scanTime + "\t" + scanNumber + "\t" + modsFixed + "\t" + FDR2D + "\t" + FDR1D + "\t" + FDR2Dunique +
                        //                     "\t" + FDR1Dunique + "\t" + qvalue2D + "\t" + qvalue1D + "\t" + isGlycoPeptide + "\t" + modsPassedCheck + "\t" +
                        //                     positionsPassedCheck + "\t" + fragmentation + "\t" + masterScan);
                    } catch (Exception e)
                    {
                        Console.WriteLine();
                    }
                }
            }

            //24 7,Console.ReadKey();
            //For Nick's LFQ
            if (!isPRM)
            {
                try
                {
                    LFQProcessor lfqs = new LFQProcessor(@rawFilePath);
                    allPsmsQuant = lfqs.crunch(allPSMs);
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show(e.ToString());
                }
            }
            else
            {
                allPsmsQuant = allPSMs;
            }


            // Start LFQ Writer
            StreamWriter quantWriter = new StreamWriter(@outputFolderPath + "\\" + file + "_list_Quant.txt");

            quantWriter.WriteLine("Prot.Rank\tSequence\tPeptideParseFriendly\tPeptide\tPos.\tMods(variable)\tGlycans" +
                                  "\tPEP2D\tPEP1D\t|Log Prob|\tScore\tDeltaScore\tDelta Mod.Score\tCharge\tObs.m/z\t" +
                                  "Precursor Theoretical m/z (Th)\tppmerr.\tObs.MH\tCalc.MH\tCleavage\tGlycansPos.\tProteinName" +
                                  "\tProt.Id\tScanTime\tSpectrum Number\tMods(fixed)\tFDR2D\tFDR1D\t" +
                                  "FDR uniq.2D\tFDR uniq.1D\tq-value2D\tq-value1D\tisGlycoPeptide\tmodsPassedCheck" +
                                  "\tpositionPassedCheck\tfragmentation\tMasterScan\tLFQ Intensity");

            foreach (PSM psmQ in allPsmsQuant)
            {
                //if(psmQ.logProb > 1 && psmQ.score > 150 && psmQ.deltaModScore > 10)
                if (psmQ.score > 50)
                {
                    quantWriter.WriteLine(psmQ.protRank + "\t" + psmQ.byonicSequence + "\t" + psmQ.peptidesToBeParsed + "\t" + psmQ.peptide.Sequence + "\t" +
                                          psmQ.peptideStartPosition + "\t" + psmQ.modsToBeParsed + "\t" + psmQ.glycansToBeParsed + "\t" + psmQ.PEP2D + "\t" + psmQ.PEP1D + "\t" + psmQ.logProb +
                                          "\t" + psmQ.score + "\t" + psmQ.deltaScore + "\t" + psmQ.deltaModScore + "\t" + psmQ.charge + "\t" + psmQ.mzObs + "\t" + psmQ.mzCalc + "\t" + psmQ.ppmError +
                                          "\t" + psmQ.obsMH + "\t" + psmQ.calcMH + "\t" + psmQ.cleavage + "\t" + psmQ.glycanPositions + "\t" + psmQ.proteinName + "\t" + psmQ.protID + "\t" + psmQ.scanTime +
                                          "\t" + psmQ.scanNumber + "\t" + psmQ.modsFixed + "\t" + psmQ.FDR2D + "\t" + psmQ.FDR1D + "\t" + psmQ.FDR2Dunique + "\t" + psmQ.FDR1Dunique + "\t" +
                                          psmQ.qvalue2D + "\t" + psmQ.qvalue1D + "\t" + psmQ.isGlycoPeptide + "\t" + psmQ.modsPassedCheck + "\t" + psmQ.positionPassedCheck + "\t" + psmQ.fragmentation
                                          + "\t" + psmQ.masterScan + "\t" + psmQ.intensity);
                }
            }

            quantWriter.Close();
            // End LFQ Writer


            OnUpdateProgress(0.75);
            double allPSMsFDR      = CalculateFDR(allPSMs);
            double hcdPSMsFDR      = CalculateFDR(hcdPSMs);
            double etdPSMsFDR      = CalculateFDR(etdPSMs);
            double allGlycoPSMsFDR = CalculateFDR(allGlycoPSMs);
            double hcdGlycoPSMsFDR = CalculateFDR(hcdGlycoPSMs);
            double etdGlycoPSMsFDR = CalculateFDR(etdGlycoPSMs);

            int allPSMCount      = GetPSMcount(allPSMsNODECOY);
            int hcdPSMCount      = GetPSMcount(hcdPSMsNODECOY);
            int etdPSMCount      = GetPSMcount(etdPSMsNODECOY);
            int allGlycoPSMCount = GetPSMcount(allGlycoPSMsNODECOY);
            int hcdGlycoPSMCount = GetPSMcount(hcdGlycoPSMsNODECOY);
            int etdGlycoPSMCount = GetPSMcount(etdGlycoPSMsNODECOY);

            int allPeptideCount      = allPSMsNODECOY.Count;
            int hcdPeptideCount      = hcdPSMsNODECOY.Count;
            int etdPeptideCount      = etdPSMsNODECOY.Count;
            int allGlycoPeptideCount = allGlycoPSMsNODECOY.Count;
            int hcdGlycoPeptideCount = hcdGlycoPSMsNODECOY.Count;
            int etdGlycoPeptideCount = etdGlycoPSMsNODECOY.Count;

            int hcdWithHexNAcOxonium         = GetSpectraCountOxonium(HCDscans, 204.087, 0, rawFile);
            int hcdWithHexNAcHexOxonium      = GetSpectraCountOxonium(HCDscans, 366.14, 0, rawFile);
            int hcdWithHexNAcHex2Oxonium     = GetSpectraCountOxonium(HCDscans, 528.19, 0, rawFile);
            int hcdWithHexNAcHex3Oxonium     = GetSpectraCountOxonium(HCDscans, 690.245, 0, rawFile);
            int hcdWithHexNAc2Hex3Oxonium    = GetSpectraCountOxonium(HCDscans, 893.325, 0, rawFile);
            int hcdWithHexNAcHexNeuAcOxonium = GetSpectraCountOxonium(HCDscans, 657.235, 0, rawFile);
            int hcdWithHexoseOxonium         = GetSpectraCountOxonium(HCDscans, 163.060, 0, rawFile);
            int hcdWithFucOxonium            = GetSpectraCountOxonium(HCDscans, 147.065, 0, rawFile);
            int hcdWithNeuAcOxonium          = GetSpectraCountOxonium(HCDscans, 274.092, 292.103, rawFile);
            int hcdWithNeuAcAcetylOxonium    = GetSpectraCountOxonium(HCDscans, 316.103, 334.113, rawFile);
            int hcdWithHexNAcNeuAcOxonium    = GetSpectraCountOxonium(HCDscans, 495.182, 0, rawFile);
            int hcdWithNeuGcOxonium          = GetSpectraCountOxonium(HCDscans, 290.087, 308.098, rawFile);
            int hcdWithNeuGcAcetylOxonium    = GetSpectraCountOxonium(HCDscans, 332.098, 350.108, rawFile);
            int hcdWithPhosphoHexOxonium     = GetSpectraCountOxonium(HCDscans, 243.0264, 0, rawFile);
            int etdWithHexNAcOxonium         = GetSpectraCountOxonium(ETDscans, 204.087, 0, rawFile);
            int etdWithHexNAcHexOxonium      = GetSpectraCountOxonium(ETDscans, 366.14, 0, rawFile);
            int etdWithHexNAcHex2Oxonium     = GetSpectraCountOxonium(ETDscans, 528.19, 0, rawFile);
            int etdWithHexNAcHex3Oxonium     = GetSpectraCountOxonium(ETDscans, 690.245, 0, rawFile);
            int etdWithHexNAc2Hex3Oxonium    = GetSpectraCountOxonium(ETDscans, 893.325, 0, rawFile);
            int etdWithHexNAcHexNeuAcOxonium = GetSpectraCountOxonium(ETDscans, 657.235, 0, rawFile);
            int etdWithHexoseOxonium         = GetSpectraCountOxonium(ETDscans, 163.060, 0, rawFile);
            int etdWithFucOxonium            = GetSpectraCountOxonium(ETDscans, 147.065, 0, rawFile);
            int etdWithNeuAcOxonium          = GetSpectraCountOxonium(ETDscans, 274.092, 292.103, rawFile);
            int etdWithNeuAcAcetylOxonium    = GetSpectraCountOxonium(ETDscans, 316.103, 334.113, rawFile);
            int etdWithHexNAcNeuAcOxonium    = GetSpectraCountOxonium(ETDscans, 495.182, 0, rawFile);
            int etdWithNeuGcOxonium          = GetSpectraCountOxonium(ETDscans, 290.087, 308.098, rawFile);
            int etdWithNeuGcAcetylOxonium    = GetSpectraCountOxonium(ETDscans, 332.098, 350.108, rawFile);
            int etdWithPhosphoHexOxonium     = GetSpectraCountOxonium(ETDscans, 243.0264, 0, rawFile);

            OnUpdateProgress(1.0);

            outputSummary.WriteLine(",Total,HCD,ETD");
            outputSummary.WriteLine("MS/MS Scans," + totalMSMSscans + "," + HCDscans.Count + "," + ETDscans.Count);
            outputSummary.WriteLine("PSMs (all)," + allPSMCount + "," + hcdPSMCount + "," + etdPSMCount);
            outputSummary.WriteLine("Unique Peptides (all)," + allPeptideCount + "," + hcdPeptideCount + "," + etdPeptideCount);
            outputSummary.WriteLine("FDR PSM level," + allPSMsFDR + "," + hcdPSMsFDR + "," + etdPSMsFDR);
            outputSummary.WriteLine("GlycoPSMs," + allGlycoPSMCount + "," + hcdGlycoPSMCount + "," + etdGlycoPSMCount);
            outputSummary.WriteLine("Unique GlycoPeptides," + allGlycoPeptideCount + "," + hcdGlycoPeptideCount + "," + etdGlycoPeptideCount);
            outputSummary.WriteLine("FDR GlycoPSM level," + allGlycoPSMsFDR + "," + hcdGlycoPSMsFDR + "," + etdGlycoPSMsFDR);
            outputSummary.WriteLine("Oxonium Ions /////,/////////,/////////,/////////");
            outputSummary.WriteLine("HexNAc (204.09),," + hcdWithHexNAcOxonium + "," + etdWithHexNAcOxonium);
            outputSummary.WriteLine("HexNAcHex (366.14),," + hcdWithHexNAcHexOxonium + "," + etdWithHexNAcHexOxonium);
            outputSummary.WriteLine("HexNAcHex(2) (528.19),," + hcdWithHexNAcHex2Oxonium + "," + etdWithHexNAcHex2Oxonium);
            outputSummary.WriteLine("HexNAcHex(3) (690.245),," + hcdWithHexNAcHex3Oxonium + "," + etdWithHexNAcHex3Oxonium);
            outputSummary.WriteLine("HexNAc(2)Hex(3) (893.325),," + hcdWithHexNAc2Hex3Oxonium + "," + etdWithHexNAc2Hex3Oxonium);
            outputSummary.WriteLine("HexNAcHexNeuAc (657.23),," + hcdWithHexNAcHexNeuAcOxonium + "," + etdWithHexNAcHexNeuAcOxonium);
            outputSummary.WriteLine("Hexose (163.06),," + hcdWithHexoseOxonium + "," + etdWithHexoseOxonium);
            outputSummary.WriteLine("Fucose (147.065),," + hcdWithFucOxonium + "," + etdWithFucOxonium);
            outputSummary.WriteLine("NeuAc (272.09/292.103),," + hcdWithNeuAcOxonium + "," + etdWithNeuAcOxonium);
            outputSummary.WriteLine("NeuAcAcetyl (316.103/334.113),," + hcdWithNeuAcAcetylOxonium + "," + etdWithNeuAcAcetylOxonium);
            outputSummary.WriteLine("HexNAcNeuAc (495.1382),," + hcdWithHexNAcNeuAcOxonium + "," + etdWithHexNAcNeuAcOxonium);
            outputSummary.WriteLine("NeuGc (290.087/308.098),," + hcdWithNeuGcOxonium + "," + etdWithNeuGcOxonium);
            outputSummary.WriteLine("NeuGcAcetyl (332.098/350.108),," + hcdWithNeuGcAcetylOxonium + "," + etdWithNeuGcAcetylOxonium);
            outputSummary.WriteLine("PhosphoHex (243.0264),," + hcdWithPhosphoHexOxonium + "," + etdWithPhosphoHexOxonium);

            outputSummary.Close();
            //outputList.Close();

            var glycoFragmentFinder = new glycoFragmentFinder(rawFile, "1", @outputFolderPath + "\\" + file + "_list.txt", uniprotGlycoDBFile, outputFolderPath);

            glycoFragmentFinder.crunch();


            rawFile.Dispose();

            OnUpdateProgress(0.0);
        }
Ejemplo n.º 20
0
        private List <PSM> LoadAllPSMs(string csvFile, string rawFileDirectory, List <Modification> fixedMods)
        {
            ProgressUpdate(0.0); //force the progressbar to go into marquee mode
            Log("Reading PSMs from " + csvFile);

            Dictionary <string, ThermoRawFile> rawFiles =
                Directory.EnumerateFiles(rawFileDirectory, "*.raw", SearchOption.AllDirectories)
                .ToDictionary(Path.GetFileNameWithoutExtension, file => new ThermoRawFile(file));

            _dataFiles = new HashSet <MSDataFile>();

            List <PSM> psms = new List <PSM>();

            int totalPsms = 0;

            using (CsvReader reader = new CsvReader(new StreamReader(csvFile), true))
            {
                while (reader.ReadNextRecord())
                {
                    string mods = reader["Mods"];

                    totalPsms++;

                    // Skip if there are no modifications
                    if (string.IsNullOrEmpty(mods))
                    {
                        continue;
                    }

                    // Convert the text mod line into a list of modification objects
                    List <Modification> variableMods = OmssaModification.ParseModificationLine(mods).Select(item => item.Item1).ToList();

                    // Only keep things with quantified Modifications
                    if (!variableMods.Any(mod => QuantifiedModifications.Contains(mod)))
                    {
                        continue;
                    }

                    string filename = reader["Filename/id"];
                    string rawname  = filename.Split('.')[0];

                    int scanNumber = int.Parse(reader["Spectrum number"]);

                    PSM psm = new PSM(scanNumber, rawname);
                    psm.StartResidue = int.Parse(reader["Start"]);
                    psm.Charge       = int.Parse(reader["Charge"]);
                    psm.BasePeptide  = new Peptide(reader["Peptide"].ToUpper());
                    psm.Defline      = reader["Defline"];
                    psm.ProteinGroup = reader["Best PG Name"];
                    psm.NumberOfSharingProteinGroups = int.Parse(reader["# of Sharing PGs"]);
                    psm.Filename = filename;

                    // Apply all the fix modifications
                    psm.BasePeptide.SetModifications(fixedMods);

                    int i = 0;
                    while (i < variableMods.Count)
                    {
                        if (fixedMods.Contains(variableMods[i]))
                        {
                            variableMods.RemoveAt(i);
                        }
                        else
                        {
                            i++;
                        }
                    }

                    // Save all the variable mod types
                    psm.VariabledModifications = variableMods;

                    psms.Add(psm);
                }
            }

            Log(string.Format("{0:N0} PSMs were loaded....", totalPsms));
            Log(string.Format("{0:N0} PSMs were kept.... ({1:F2} %)", psms.Count, 100.0 * (double)psms.Count / totalPsms));

            Log("Reading Spectral Data...");
            ThermoRawFile currentRawFile     = null;
            string        currentRawFileName = null;
            int           counter            = 0;

            foreach (PSM psm in psms.OrderBy(psm => psm.RawFileName))
            {
                string rawfilename = psm.RawFileName;

                if (!rawfilename.Equals(currentRawFileName))
                {
                    currentRawFileName = rawfilename;
                    if (currentRawFile != null && currentRawFile.IsOpen)
                    {
                        currentRawFile.Dispose();
                    }

                    if (!rawFiles.TryGetValue(rawfilename, out currentRawFile))
                    {
                        throw new NullReferenceException(string.Format("Raw File: {0}.raw was not found! Aborting.", rawfilename));
                    }
                    currentRawFile.Open();
                }

                psm.SetRawFile(currentRawFile);
                counter++;
                if (counter % 25 == 0)
                {
                    ProgressUpdate((double)counter / psms.Count);
                }
            }

            return(psms);
        }
Ejemplo n.º 21
0
        public void ThermoLoadError()
        {
            ThermoRawFile a = new ThermoRawFile(@"aaa.RAW");

            Assert.Throws <IOException>(() => { a.Open(); });
        }