コード例 #1
0
        //Returns an empirical formula string with or without PTMs.
        //Accounts for the PTMs using the Averagine formula.
        //Parses out the PTMs and calculates the empirical formula for the known unmodified sequence.
        //Adds or subtracts the PTM formula from the sequence formula based on the overall mass of the PTMs
        public string GetEmpiricalFormulaFromSequence(string code, bool cysteinesAreModified = false)
        {
            var ptmFormula       = "";
            var sequenceFormula  = "";
            var empiricalFormula = "";

            var ptmMass = PtmMassFromCode(code);

            ptmFormula = IsotopicDistributionCalculator.Instance.GetAveragineFormulaAsString(Math.Abs(ptmMass), false);

            sequenceFormula = SequenceToEmpiricalFormula(code, cysteinesAreModified);

            if (ptmMass < 0)
            {
                empiricalFormula = EmpiricalFormulaUtilities.SubtractFormula(sequenceFormula, ptmFormula);
            }
            else
            {
                empiricalFormula = EmpiricalFormulaUtilities.AddFormula(sequenceFormula, ptmFormula);
            }

            //TEMPORARY HANDLING OF BAD TARGETS WITH PTM > SEQUENCE
            //CHECK THE UPDATEMISSINGTARGETINFO IN IQTARGETUTILITES WHEN CHANGING
            if (String.IsNullOrEmpty(empiricalFormula))
            {
                empiricalFormula = "C0H0N0O0S0";
            }
            return(empiricalFormula);
        }
コード例 #2
0
        public void addUnimodFormulaTest1()
        {
            var testPeptide = "SAMPLER";

            var peptideUtils = new PeptideUtils();
            var baseFormula  = peptideUtils.GetEmpiricalFormulaForPeptideSequence(testPeptide);

            var mod        = "H3 C2 N O";
            var modFormula = EmpiricalFormulaUtilities.AddFormula(baseFormula, mod);

            Console.WriteLine("Unmodified peptide= " + baseFormula);
            Console.WriteLine("Modified peptide= " + modFormula);

            Assert.AreEqual("C35H61N11O12S", modFormula);
        }
コード例 #3
0
        public List <IqTarget> Import()
        {
            var targets = GetMassTagDataFromDb();

            if (IsEmpiricalFormulaExtracted)
            {
                GetModDataFromDb(_targetsContainingMods);

                var peptideUtils = new PeptideUtils();

                foreach (IqTargetDms iqTarget in targets)
                {
                    var baseEmpiricalFormula = peptideUtils.GetEmpiricalFormulaForPeptideSequence(iqTarget.Code);
                    if (!string.IsNullOrEmpty(iqTarget.ModDescription))
                    {
                        var target = iqTarget;
                        var mods   = (from n in _massTagModData where n.Item1 == target.ID select n);

                        foreach (var tuple in mods)
                        {
                            var modString = tuple.Item4;

                            try
                            {
                                baseEmpiricalFormula = EmpiricalFormulaUtilities.AddFormula(baseEmpiricalFormula, modString);
                            }
                            catch (Exception ex)
                            {
                                IqLogger.Log.Debug("Failed to calculate empirical formula for the Target " + target.ID + " (" + ex.Message + ")" +
                                                   "; Having trouble with the mod: " + modString + "; This Target was NOT imported!!");
                            }
                        }
                    }

                    iqTarget.EmpiricalFormula = baseEmpiricalFormula;

                    if (IsMonoMassCalculatedFromEmpiricalFormula)
                    {
                        iqTarget.MonoMassTheor = EmpiricalFormulaUtilities.GetMonoisotopicMassFromEmpiricalFormula(iqTarget.EmpiricalFormula);
                    }
                }
            }

            return(targets);
        }
コード例 #4
0
        public void AddPhosphorylationTest1()
        {
            const string testPeptide  = "SAMPLER";
            var          peptideUtils = new PeptideUtils();
            var          formula      = peptideUtils.GetEmpiricalFormulaForPeptideSequence(testPeptide);

            const string phosphorylationMod = "HPO3";

            var empiricalFormula = EmpiricalFormulaUtilities.AddFormula(formula, phosphorylationMod);

            var massUnmodified = EmpiricalFormulaUtilities.GetMonoisotopicMassFromEmpiricalFormula(formula);
            var massModified   = EmpiricalFormulaUtilities.GetMonoisotopicMassFromEmpiricalFormula(empiricalFormula);
            var diff           = Math.Round(massModified - massUnmodified, 1, MidpointRounding.AwayFromZero);

            Console.WriteLine(formula + "\t" + massUnmodified);
            Console.WriteLine(empiricalFormula + "\t" + massModified);
            Console.WriteLine("diff= " + diff);

            Assert.AreEqual(80.0, diff);
        }
コード例 #5
0
        public void AddAcetylationTest1()
        {
            var testPeptide  = "SAMPLER";
            var peptideUtils = new PeptideUtils();
            var formula      = peptideUtils.GetEmpiricalFormulaForPeptideSequence(testPeptide);

            var acetylationFormula = "C2H2O";

            var empiricalFormula = EmpiricalFormulaUtilities.AddFormula(formula, acetylationFormula);

            var massUnmodified = EmpiricalFormulaUtilities.GetMonoisotopicMassFromEmpiricalFormula(formula);
            var massModified   = EmpiricalFormulaUtilities.GetMonoisotopicMassFromEmpiricalFormula(empiricalFormula);
            var diff           = Math.Round(massModified - massUnmodified, 1, MidpointRounding.AwayFromZero);

            Console.WriteLine(formula + "\t" + massUnmodified);
            Console.WriteLine(empiricalFormula + "\t" + massModified);

            Console.WriteLine("diff= " + diff);

            Assert.AreEqual(42.0, diff);
        }
コード例 #6
0
ファイル: IqCodeParser.cs プロジェクト: trishorts/DeconTools
        //Returns an empirical formula string with or without PTMs.
        //Accounts for the PTMs using the Averagine formula.
        //Parses out the PTMs and calculates the empirical formula for the known unmodified sequence.
        //Adds or subtracts the PTM formula from the sequence formula based on the overall mass of the PTMs
        public string GetEmpiricalFormulaFromSequence(string code)
        {
            string PTM_Formula      = "";
            string SequenceFormula  = "";
            string EmpiricalFormula = "";

            double ptm_mass = PTMMassFromCode(code);

            PTM_Formula = IsotopicDistributionCalculator.Instance.GetAveragineFormulaAsString(Math.Abs(ptm_mass), false);

            SequenceFormula = SequenceToEmpiricalFormula(code);

            if (ptm_mass < 0)
            {
                EmpiricalFormula = EmpiricalFormulaUtilities.SubtractFormula(SequenceFormula, PTM_Formula);
            }
            else
            {
                EmpiricalFormula = EmpiricalFormulaUtilities.AddFormula(SequenceFormula, PTM_Formula);
            }
            return(EmpiricalFormula);
        }
コード例 #7
0
        private void CalculateEmpiricalFormulas(TargetCollection data)
        {
            var peptideUtils = new PeptideUtils();

            foreach (var targetBase in data.TargetList)
            {
                var peptide = (PeptideTarget)targetBase;
                var baseEmpiricalFormula = peptideUtils.GetEmpiricalFormulaForPeptideSequence(peptide.Code);

                if (peptide.ContainsMods)
                {
                    TargetBase peptide1 = peptide;
                    var        mods     = (from n in _massTagModData where n.Item1 == peptide1.ID select n);

                    foreach (var tuple in mods)
                    {
                        baseEmpiricalFormula = EmpiricalFormulaUtilities.AddFormula(baseEmpiricalFormula, tuple.Item4);
                    }
                }

                peptide.EmpiricalFormula = baseEmpiricalFormula;
            }
        }
コード例 #8
0
        public string GetEmpiricalFormulaForSequenceWithMods(string code)
        {
            // Check for pyroglutamate modification
            var containsPyroglutamateMod = false;

            if (_modPyroglutamate.IsMatch(code))
            {
                containsPyroglutamateMod = true;
                // Remove the modification from the string
                var pieces = _modPyroglutamate.Match(code).Groups;
                code = pieces["prefix"].Value + pieces["modified"].Value + pieces["suffix"].Value;
            }

            // Check for acetylation modification
            var containsAcetylationMod = false;

            if (_modAcetylation.IsMatch(code))
            {
                containsAcetylationMod = true;
                // Remove the modification from the string
                var pieces = _modAcetylation.Match(code).Groups;
                code = pieces["prefix"].Value + pieces["modified"].Value + pieces["suffix"].Value;
            }

            // Check for phosphorylation modification
            // TODO: this function does not account for the fact that phosphorylation could occur multiple times
            var containsPhosphorylationMod = false;

            if (_modPhosphorylation.IsMatch(code))
            {
                containsPhosphorylationMod = true;
                // Remove the modification from the string
                var pieces = _modPhosphorylation.Match(code).Groups;
                code = pieces["prefix"].Value + pieces["modified"].Value + pieces["suffix"].Value;
            }

            // If the peptide sequence still has modifications, we can't get the empirical formula
            if (code.Contains("("))
            {
                return(String.Empty);
            }

            // Get the empirical formula as if the peptide sequence was unmodified
            var empiricalFormula = _peptideUtils.GetEmpiricalFormulaForPeptideSequence(code);

            // Apply modifications to empirical formula
            if (containsPyroglutamateMod)
            {
                empiricalFormula = EmpiricalFormulaUtilities.SubtractFormula(empiricalFormula, "H3N1");
            }
            if (containsAcetylationMod)
            {
                empiricalFormula = EmpiricalFormulaUtilities.AddFormula(empiricalFormula, "C2H2O");
            }
            if (containsPhosphorylationMod)
            {
                empiricalFormula = EmpiricalFormulaUtilities.AddFormula(empiricalFormula, "HPO3");
            }

            return(empiricalFormula);
        }
コード例 #9
0
        public override TargetCollection Import()
        {
            var targetCollection = new TargetCollection();

            targetCollection.TargetList.Clear();

            GetMassTagDataFromDB(targetCollection, MassTagsToBeRetrieved);

            GetModDataFromDB(targetCollection, MassTagsToBeRetrieved);

            var peptideUtils = new PeptideUtils();

            var troubleSomePeptides = new List <TargetBase>();

            foreach (var targetBase in targetCollection.TargetList)
            {
                var peptide = (PeptideTarget)targetBase;
                var baseEmpiricalFormula = peptideUtils.GetEmpiricalFormulaForPeptideSequence(peptide.Code);

                if (peptide.ContainsMods)
                {
                    var peptide1 = peptide;
                    var mods     = (from n in _massTagModData where n.Item1 == peptide1.ID select n);

                    foreach (var tuple in mods)
                    {
                        var modString = tuple.Item4;

                        try
                        {
                            baseEmpiricalFormula = EmpiricalFormulaUtilities.AddFormula(baseEmpiricalFormula, modString);
                        }
                        catch
                        {
                            Console.WriteLine("Failed to calculate empirical formula for the Target " + peptide.ID +
                                              "; Having trouble with the mod: " + modString + "; This Target was NOT imported!!");

                            troubleSomePeptides.Add(peptide);
                        }
                    }
                }

                try
                {
                    peptide.EmpiricalFormula = baseEmpiricalFormula;
                }
                catch
                {
                    Console.WriteLine("Failed to calculate empirical formula for the Target " + peptide.ID +
                                      "; Cannot parse this formula: " + peptide.EmpiricalFormula + "; This Target was NOT imported!!");

                    troubleSomePeptides.Add(peptide);
                }
            }

            var cleanTargetList = new List <TargetBase>();

            //filter out the bad peptides (the once with errors during empirical formula parsing)
            foreach (var peptide in targetCollection.TargetList)
            {
                if (!troubleSomePeptides.Contains(peptide))
                {
                    cleanTargetList.Add(peptide);
                }
            }

            targetCollection.TargetList = cleanTargetList;

            if (ChargeStateRangeBasedOnDatabase)
            {
                targetCollection.ApplyChargeStateFilter(ChargeStateFilterThreshold);
            }
            else
            {
                var chargeStateTargets = new List <TargetBase>();

                foreach (var targetBase in targetCollection.TargetList)
                {
                    var minCharge = 1;
                    var maxCharge = 100;

                    for (var charge = minCharge; charge <= maxCharge; charge++)
                    {
                        var mz = targetBase.MonoIsotopicMass / charge + Globals.PROTON_MASS;

                        if (mz < MaxMZForChargeStateRange)
                        {
                            if (mz < MinMZForChargeStateRange)
                            {
                                break;
                            }

                            TargetBase chargeStateTarget = new PeptideTarget((PeptideTarget)targetBase);
                            chargeStateTarget.ChargeState = (short)charge;
                            chargeStateTarget.MZ          = chargeStateTarget.MonoIsotopicMass / charge + Globals.PROTON_MASS;
                            chargeStateTarget.ObsCount    = -1;
                            chargeStateTargets.Add(chargeStateTarget);
                        }
                    }
                }

                targetCollection.TargetList = chargeStateTargets.OrderBy(p => p.ID).ThenBy(p => p.ChargeState).ToList();
            }

            return(targetCollection);
        }