示例#1
0
        public void GetIsoProfile()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            Utils.ShowStarting(methodName);

            const string protSequence =
                "AIPQSVEGQSIPSLAPMLERTTPAVVSVAVSGTHVSKQRVPDVFRYFFGPNAPQEQVQERPFRGLGSGVIIDADKGYIVTNNHVIDGADDIQVGLHDGREVKAKLIGTDSESDIALLQIEAKNLVAIKTSDSDELRVGDFAVAIGNPFGLGQTVTSGIVSALGRSGLGIEMLENFIQTDAAINSGNSGGALVNLKGELIGINTAIVAPNGGNVGIGFAIPANMVKNLIAQIAEHGEVRRGVLGIAGRDLDSQLAQGFGLDTQHGGFVNEVSAGSAAEKAGIKAGDIIVSVDGRAIKSFQELRAKVATMGAGAKVELGLIRDGDKKTVNVTLGEANQTTEKAAGAVHPMLQGASLENASKGVEITDVAQGSPAAMSGLQKGDLIVGINRTAVKDLKSLKELLKDQEGAVALKIVRGKSMLYLVLR";
            //const string annotation = "_." + protSequence + "._";
            var seqGraph = SequenceGraph.CreateGraph(new AminoAcidSet(), AminoAcid.ProteinNTerm, protSequence, AminoAcid.ProteinCTerm);

            if (seqGraph == null)
            {
                return;
            }
            seqGraph.SetSink(0);
            var neutral = seqGraph.GetSinkSequenceCompositionWithH2O() - Composition.Hydrogen;

            //Console.WriteLine(neutral);

            for (var charge = 22; charge <= 60; charge++)
            {
                var ion = new Ion(neutral, charge);
                Console.WriteLine("{0}\t{1}", charge, ion.GetMostAbundantIsotopeMz());
            }

            var ion27    = new Ion(neutral, 29);
            var isotopes = ion27.GetIsotopes(0.1);

            foreach (var isotope in isotopes)
            {
                Console.WriteLine("{0}\t{1}", ion27.GetIsotopeMz(isotope.Index), isotope.Ratio);
            }
        }
示例#2
0
        /// <summary>
        /// Calculate M/Z error of peaks in isotope envelope.
        /// </summary>
        /// <param name="peaks">The peaks to calculate error for.</param>
        /// <param name="ion">The ion to calculate theoretical isotope envelope for.</param>
        /// <param name="relativeIntensityThreshold">Relative intensity threshold for calculating isotopes</param>
        /// <param name="deconvoluted"></param>
        /// <returns>Array of ppm errors for each peak.</returns>
        public static double?[] GetIsotopePpmError(Peak[] peaks, Ion ion, double relativeIntensityThreshold, bool deconvoluted = false)
        {
            double?[] ppmErrors;
            if (!deconvoluted)
            {
                var isotopes = ion.GetIsotopes(relativeIntensityThreshold).ToArray();
                ppmErrors = new double?[isotopes.Max(i => i.Index) + 1];
                foreach (var isotope in isotopes)
                {
                    var isotopeIndex = isotope.Index;
                    if (peaks[isotopeIndex] == null)
                    {
                        ppmErrors[isotopeIndex] = null;
                    }
                    else
                    {
                        ppmErrors[isotopeIndex] = GetPeakPpmError(peaks[isotopeIndex], ion.GetIsotopeMz(isotopeIndex));
                    }
                }
            }
            else
            {
                var mz = ion.Composition.Mass;
                ppmErrors    = new double?[1];
                ppmErrors[0] = GetPeakPpmError(peaks[0], mz);
            }

            return(ppmErrors);
        }
示例#3
0
        public void TestIsoProfile()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            Utils.ShowStarting(methodName);

            const string sequence = "MWYMISAQDVENSLEKRLAARPAHLARLQELADEGRLLVAGPHPAIDSENPGDAGFSGSLVVADFDSLATAQAWADADPYFAAGVYQSVVVKPFKRVLP";
            var          aaSet    = new AminoAcidSet();
            var          comp     = aaSet.GetComposition(sequence) + Composition.H2O;
            var          ion      = new Ion(comp, 9);

            foreach (var i in ion.GetIsotopes(0.1))
            {
                Console.WriteLine(ion.GetIsotopeMz(i.Index) + "\t" + i.Ratio);
            }
        }
示例#4
0
        public void TestIsoProfile()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            ShowStarting(methodName);

            var       composition = Composition.Parse("C(82) H(149) N(23) O(24) S(3)");
            const int charge      = 3;
            var       ion         = new Ion(composition, charge);

            foreach (var isotope in ion.GetIsotopes(0.1))
            {
                Console.WriteLine("{0}\t{1}\t{2}", isotope.Index, ion.GetIsotopeMz(isotope.Index), isotope.Ratio);
            }
            Console.WriteLine(composition.Mass);
        }
示例#5
0
        public void TestXicGen()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            TestUtils.ShowStarting(methodName);

            const string specFilePath = @"D:\Research\Data\UW\Fusion\WT_D_DDA_130412065618.raw";
            var          run          = InMemoryLcMsRun.GetLcMsRun(specFilePath);

            // Test
            var tolerance = new Tolerance(30);

            const string peptide       = "AIANGQVDGFPTQEECR";
            const int    targetScanNum = 37633;
            const int    charge        = 2;

            //const string peptide = "IVDTNGAGDAFAGGFMAGLTK";
            //const int targetScanNum = 67513;
            //const int charge = 3;

            var aaSet        = new AminoAcidSet(Modification.Carbamidomethylation);
            var precursorIon = new Ion(aaSet.GetComposition(peptide) + Composition.H2O, charge);

            Console.WriteLine("Theoretical isotopomer profile:");
            foreach (var p in precursorIon.GetIsotopes(0.1))
            {
                Console.WriteLine("{0}\t{1}", precursorIon.GetIsotopeMz(p.Index), p.Ratio);
            }

            var xicArr        = new Dictionary <int, Xic>();
            var basePeakIndex = precursorIon.Composition.GetMostAbundantIsotopeZeroBasedIndex();

            for (var i = -1; i < 3; i++)
            {
                xicArr[i] = run.GetPrecursorExtractedIonChromatogram(precursorIon.GetIsotopeMz(i), tolerance, targetScanNum);
            }

            for (var i = -1; i < 3; i++)
            {
                Console.WriteLine("\nIndex: {0}", i);
                Console.WriteLine("m/z: {0}", precursorIon.GetIsotopeMz(i));
                Console.WriteLine("#XicPeaks: {0}", xicArr[i].Count);
                Console.WriteLine("Intensity: {0}", xicArr[i].GetSumIntensities() / xicArr[basePeakIndex].GetSumIntensities());
                Console.WriteLine("Correlation: {0}", xicArr[i].GetCorrelation(xicArr[basePeakIndex]));
            }
        }
示例#6
0
        public void TestPeptide()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            ShowStarting(methodName);

            //const string sequence = "MSGRGKGGKGLGKGGAKRHRKVLRDNIQGITKPAIRRLARRGGVKRISGLIYEETRGVLKVFLENVIRDAVTYTEHAKRKTVTAMDVVYALKRQGRTLYGFGG";  // Histone H4
            const string sequence = "IRDAVTYTEHAKRKTVTAMDVVYALKRQGRTLYGFGG";  // Histone H4
            //const string sequence = "MRIILLGAPGAGKGTQAQFIMEKYGIPQISTGDMLRAAVKSGSELGKQAKDIMDAGKLVTDELVIALVKERIAQEDCRNGFLLDGFPRTIPQADAMKEAGIVVDYVLEFDVPDELIVDRIVGRRVHAASGRVYHVKFNPPKVEGKDDVTGEDLTTRKDDQEETVRKRLVEYHQMTAPLIGYYQKEAEAGNTKYAKVDGTQAVADVRAALEKILG";
            //const string sequence = "MNKTQLIDVIAEKAELSKTQAKAALESTLAAITESLKEGDAVQLVGFGTFKVNHRAERTGRNPQTGKEIKIAAANVPAFVSGKALKDAVK";
            //const string sequence =
            //    "METTKPSFQDVLEFVRLFRRKNKLQREIQDVEKKIRDNQKRVLLLDNLSDYIKPGMSVEAIQGIIASMKGDYEDRVDDYIIKNAELSKERRDISKKLKAMGEMKNGEAK";
            var aaSet       = new AminoAcidSet();
            var composition = aaSet.GetComposition(sequence) + Composition.H2O;

            Console.WriteLine(composition);
            Console.WriteLine(composition.Mass);
            Console.WriteLine(composition.NominalMass);
            // 2nd isotope
            Console.WriteLine(composition.GetIsotopeMass(0));
            Console.WriteLine(composition.GetIsotopeMass(1));
            Console.WriteLine(composition.GetIsotopeMass(2));
            //Assert.AreEqual(composition.ToPlainString(), "C34H51N7O14");

            Console.WriteLine("Isotopomer Envelope:");
            foreach (var e in composition.GetIsotopomerEnvelopeRelativeIntensities())
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            Console.WriteLine("Isotope ions:");
            var ion = new Ion(composition + Composition.H2O, 13);

            foreach (var p in ion.GetIsotopes(0.1))
            {
                Console.WriteLine("{0}\t{1}", ion.GetIsotopeMz(p.Index), p.Ratio);
            }
            Console.WriteLine();
        }
示例#7
0
        public void TestGetAllIsotopePeaks()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            Utils.ShowStarting(methodName);

            const string specFilePath = @"H:\Research\GlycoTopDown\raw\User_sample_test_02252015.raw";

            if (!File.Exists(specFilePath))
            {
                Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, specFilePath);
            }

            //const int scanNum = 17338;
            const double relativeIntensity = 0.1;
            var          run  = PbfLcMsRun.GetLcMsRun(specFilePath);
            var          spec = run.GetSpectrum(17338);

            var comp = Composition.Parse("C(610) H(945) N(172) O(189) S(3)");
            var ion  = new Ion(comp + BaseIonType.B.OffsetComposition, 9);  // b127(9+)

            Console.WriteLine("Composition: " + comp + " " + comp.Mass);
            Console.WriteLine("b127(9+): " + ion.GetMonoIsotopicMz());
            Console.WriteLine("b127(9+) 0th isotope: " + ion.GetIsotopeMz(0));
            Console.WriteLine("b127(9+) 6th isotope: " + ion.GetIsotopeMz(6));

            var peaks    = spec.GetAllIsotopePeaks(ion, new Tolerance(10), relativeIntensity);
            var isotopes = ion.GetIsotopes(relativeIntensity).ToArray();

            for (var i = 0; i < isotopes.Length; i++)
            {
                if (peaks[i] == null)
                {
                    continue;
                }
                var isotopeIndex = isotopes[i].Index;
                Console.WriteLine("{0}\t{1}\t{2}\t{3}", isotopeIndex, peaks[isotopeIndex].Mz, ion.GetIsotopeMz(isotopeIndex), GetPeakPpmError(peaks[isotopeIndex], ion.GetIsotopeMz(isotopeIndex)));
            }
        }
示例#8
0
        private bool IsValid(MsGfMatch match)
        {
            var specFileKey = Path.GetFileNameWithoutExtension(match.SpecFile);

            if (specFileKey == null)
            {
                return(false);
            }

            var precursorIon   = new Ion(match.Formula, match.Charge);
            var prevMs1ScanNum = Run[specFileKey].GetPrecursorScanNum(match.ScanNum);
            var nextMs1ScanNum = Run[specFileKey].GetNextScanNum(prevMs1ScanNum, 1);

            //var isotopeMzs =
            //    precursorIon.GetIsotopes(NumIsotopesToCheckForValidation)
            //        .Select(isotope => precursorIon.GetIsotopeMz(isotope.Index)).ToArray();
            var isotopes = precursorIon.GetIsotopes(NumIsotopesToCheckForValidation).ToArray();

            Array.Sort(isotopes);   // sort by indices

            var prevMs1Spec = Run[specFileKey].GetSpectrum(prevMs1ScanNum);

            if (prevMs1Spec != null)
            {
                //if (prevMs1Spec.ContainsIon(precursorIon, ToleranceForBaseXic, 0.9)) return true;
                var isPrevIsotopeValid = false;
                foreach (var isotope in isotopes)
                {
                    var mz = precursorIon.GetIsotopeMz(isotope.Index);
                    if (prevMs1Spec.FindPeak(mz, ToleranceForBaseXic) != null)  // match
                    {
                        if (isPrevIsotopeValid)
                        {
                            return(true);
                        }
                        isPrevIsotopeValid = true;
                    }
                }
            }

            var nextMs1Spec = Run[specFileKey].GetSpectrum(nextMs1ScanNum);

            if (nextMs1Spec != null)
            {
                var isPrevIsotopeValid = false;
                foreach (var isotope in isotopes)
                {
                    var mz = precursorIon.GetIsotopeMz(isotope.Index);
                    if (nextMs1Spec.FindPeak(mz, ToleranceForBaseXic) != null)  // match
                    {
                        if (isPrevIsotopeValid)
                        {
                            return(true);
                        }
                        isPrevIsotopeValid = true;
                    }
                }
            }

            return(false);
        }
示例#9
0
        public void AnalyizeFusionDdaData()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            TestUtils.ShowStarting(methodName);

            // Parameters
            //const double relativeIntensityThreshold = 0.7;
            const double precursorTolerancePpm = 20;

            const string specFilePath = @"D:\Research\Data\UW\Fusion\WT_D_DDA_130412065618.raw";
            var          run          = InMemoryLcMsRun.GetLcMsRun(specFilePath);
            const double fdrThreshold = 0.01;

            var tolerance = new Tolerance(precursorTolerancePpm);
            var aaSet     = new AminoAcidSet(Modification.Carbamidomethylation);

            const string resultFilePath = @"D:\Research\Data\UW\Fusion\WT_D_DDA_130412065618_10ppm_TI2_SGD_Decoy.tsv";

            Console.WriteLine("IsDecoy\tPeptide\tScanNum\tCharge\tSpecEValue\tQValue\tPrecursorMz" +
                              "\tTheo0\tTheo1\tTheo2\tTheo3" +
                              "\tObs0\tCorr0\tObs1\tCorr1\tObs2\tCorr2\tObs3\tCorr3\tObs-1\tCorr-1\tObs0.5\tCorr0.5");
            foreach (var line in File.ReadLines(resultFilePath))
            {
                if (line.StartsWith("#"))
                {
                    continue;
                }
                var token = line.Split('\t');
                if (token.Length != 16)
                {
                    continue;
                }

                var qValue = Convert.ToDouble(token[14]);
                if (qValue > fdrThreshold)
                {
                    continue;
                }

                var peptide    = token[8].Replace("C+57.021", "C");
                var scanNum    = Convert.ToInt32(token[2]);
                var charge     = Convert.ToInt32(token[7]);
                var specEValue = Convert.ToDouble(token[12]);

                var protein = token[9];
                var isDecoy = protein.StartsWith("XXX_");

                var precursorIon  = new Ion(aaSet.GetComposition(peptide) + Composition.H2O, charge);
                var baseXic       = run.GetPrecursorExtractedIonChromatogram(precursorIon.GetMostAbundantIsotopeMz(), tolerance, scanNum);
                var baseIntensity = baseXic.GetSumIntensities();

                Console.Write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", (isDecoy ? 1 : 0), peptide, scanNum, charge, specEValue, qValue, precursorIon.GetMonoIsotopicMz());

                var isotopeIndices = new double[] { 0, 1, 2, 3, -1, 0.5 };
                var theoIsotopes   = precursorIon.GetIsotopes(0.01);
                var numIsotopes    = 0;
                foreach (var theoIsotope in theoIsotopes)
                {
                    Console.Write("\t" + theoIsotope.Ratio);
                    if (++numIsotopes == 4)
                    {
                        break;
                    }
                }

                foreach (var isotopeIndex in isotopeIndices)
                {
                    var isotopeMz         = precursorIon.GetIsotopeMz(isotopeIndex);
                    var xic               = run.GetPrecursorExtractedIonChromatogram(isotopeMz, tolerance, scanNum);
                    var relativeIntensity = xic.GetSumIntensities() / baseIntensity;
                    var correlation       = xic.GetCorrelation(baseXic);
                    Console.Write("\t{0}\t{1}", relativeIntensity, correlation);
                }
                Console.WriteLine();
            }
        }
示例#10
0
        public void TestFusionDdaData()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            TestUtils.ShowStarting(methodName);

            // Parameters
            const double relativeIntensityThreshold = 0.7;
            const double precursorTolerancePpm      = 20;
            //const double isotopeRatioTolerance = 2;
            //const double correlationThreshold = 0.3;
            const double fdrThreshold = 0.01;

            const string specFilePath = @"D:\Research\Data\UW\Fusion\WT_D_DDA_130412065618.raw";
            var          run          = InMemoryLcMsRun.GetLcMsRun(specFilePath);

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            var tolerance = new Tolerance(precursorTolerancePpm);
            var aaSet     = new AminoAcidSet(Modification.Carbamidomethylation);

            const string resultFilePath  = @"D:\Research\Data\UW\Fusion\oldResult\WT_D_DDA_130412065618_10ppm_TI2_SGD_Decoy.tsv";
            var          numTargets      = 0;
            var          numValidTargets = 0;
            var          numDecoys       = 0;
            var          numValidDecoys  = 0;

            foreach (var line in File.ReadLines(resultFilePath))
            {
                if (line.StartsWith("#"))
                {
                    continue;
                }
                var token = line.Split('\t');
                if (token.Length != 16)
                {
                    continue;
                }

                var qValue = Convert.ToDouble(token[14]);
                if (qValue > fdrThreshold)
                {
                    continue;
                }

                var peptide = token[8].Replace("C+57.021", "C");
                var scanNum = Convert.ToInt32(token[2]);
                var charge  = Convert.ToInt32(token[7]);
                var protein = token[9];
                var isDecoy = protein.StartsWith("XXX_");
                if (isDecoy)
                {
                    numDecoys++;
                }
                else
                {
                    numTargets++;
                }

                var precursorIon  = new Ion(aaSet.GetComposition(peptide) + Composition.H2O, charge);
                var basePeakIndex = precursorIon.Composition.GetMostAbundantIsotopeZeroBasedIndex();
                var baseXic       = run.GetPrecursorExtractedIonChromatogram(precursorIon.GetMostAbundantIsotopeMz(), tolerance, scanNum);
                var baseIntensity = baseXic.GetSumIntensities();

                var isValid = true;
                foreach (var isotope in precursorIon.GetIsotopes(relativeIntensityThreshold))
                {
                    if (isotope.Index == basePeakIndex)
                    {
                        continue;
                    }
                    var isotopeMz = precursorIon.GetIsotopeMz(isotope.Index);
                    var xic       = run.GetPrecursorExtractedIonChromatogram(isotopeMz, tolerance, scanNum);

                    if (xic.Count == 0)
                    {
                        isValid = false;
                        break;
                    }

                    //if (xic.Count > 0)
                    //{
                    //    var isotopeRatio = xic.GetSumIntensities() / baseIntensity / isotope.Item2;
                    //    var correlation = xic.GetCorrelation(baseXic);

                    //    if (isotopeRatio > 0.8 && isotopeRatio < 1.2
                    //        && correlation > 0.8)
                    //    {
                    //        isValid = true;
                    //    }
                    //}

                    // Check if isotope ratio is within tolerance
                    //if (isotopeRatio > isotopeRatioTolerance || isotopeRatio < 1 / isotopeRatioTolerance)
                    //{
                    //    isValid = false;
                    //    //Console.WriteLine("Off ratio\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", isDecoy, peptide, scanNum, charge, precursorIon.GetMonoIsotopicMz(), isotopeMz, isotopeRatio);
                    //    break;
                    //}

                    // Check if correlation is high
                    //if (correlation < correlationThreshold)
                    //{
                    //    isValid = false;
                    //    //Console.WriteLine("Low correlation\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", isDecoy, peptide, scanNum, charge, precursorIon.GetMonoIsotopicMz(), isotopeMz, correlation);
                    //    break;
                    //}
                }

                if (isValid && !isDecoy)
                {
                    numValidTargets++;
                }
                else if (isValid)
                {
                    numValidDecoys++;
                }

                //Console.WriteLine("{0}\t{1}\t{2}", peptide, scanNum, charge);
            }
            Console.WriteLine("#Targets: {0}", numTargets);
            Console.WriteLine("#ValidTargets: {0}\t{1}", numValidTargets, numValidTargets / (double)numTargets);
            Console.WriteLine("#Decoys: {0}", numDecoys);
            Console.WriteLine("#ValidDecoys: {0}\t{1}", numValidDecoys, numValidDecoys / (double)numDecoys);

            sw.Stop();

            Console.WriteLine(@"TimeForPrecursorValidation {0:f4} sec", sw.Elapsed.TotalSeconds);
        }