public void EmptyPeptideFormulaIsH2O() { Peptide pepA = new Peptide(); ChemicalFormula h2O = new ChemicalFormula("H2O"); ChemicalFormula formulaB; pepA.TryGetChemicalFormula(out formulaB); Assert.AreEqual(h2O, formulaB); }
public void ClearNTerminusMod() { ChemicalFormula formula = new ChemicalFormula("Fe"); _mockPeptideEveryAminoAcid.SetModification(formula, Terminus.N); _mockPeptideEveryAminoAcid.ClearModifications(Terminus.N); Assert.IsNull(_mockPeptideEveryAminoAcid.NTerminusModification); }
internal AminoAcid(string name, char oneLetterAbbreviation, string threeLetterAbbreviation, ChemicalFormula chemicalFormula, ModificationSites site) { Name = name; Letter = oneLetterAbbreviation; Symbol = threeLetterAbbreviation; ChemicalFormula = chemicalFormula; MonoisotopicMass = ChemicalFormula.MonoisotopicMass; Site = site; }
public void AddFormulaToItself() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C4H6N2O2"); formulaA.Add(formulaA); Assert.AreEqual(formulaA, formulaB); }
public void ChemicalFormulaGeneratorContainsFormula() { ChemicalFormulaGenerator generator = new ChemicalFormulaGenerator(new ChemicalFormula("H2O")); List<ChemicalFormula> formulas = generator.AllFormulas().ToList(); ChemicalFormula ho = new ChemicalFormula("HO"); Assert.Contains(ho, formulas); }
public void ClearAllMods() { ChemicalFormula formula = new ChemicalFormula("Fe"); _mockPeptideEveryAminoAcid.SetModification(formula, ModificationSites.All); _mockPeptideEveryAminoAcid.ClearModifications(); Assert.AreEqual("ACDEFGHIKLMNPQRSTVWY", _mockPeptideEveryAminoAcid.ToString()); }
public void AddIChemicalFormulaToFormula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); IChemicalFormula formulaB = new ChemicalFormula("H2O"); ChemicalFormula formulaC = new ChemicalFormula("C2H5NO2"); formulaA.Add(formulaB); Assert.AreEqual(formulaA, formulaC); }
public void AddIsotopeToFormula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2H4NO"); Isotope h1 = Element.PeriodicTable["H"][1]; formulaA.Add(h1, 1); Assert.AreEqual(formulaA, formulaB); }
/// <summary> /// Basic overview of how chemical formulas can be used and modified /// </summary> private static void ChemicalFormulaExamples() { Console.WriteLine("**Chemical Formula Examples**"); // Simple chemical formula creation ChemicalFormula formula1 = new ChemicalFormula("C2H3NO"); WriteFormulaToConsole(formula1); // Input order does not matter ChemicalFormula formula2 = new ChemicalFormula("NH3C2O"); WriteFormulaToConsole(formula2); // Formulas are identicial if they have the exact same type of elements and count Console.WriteLine("Are {0} and {1} equivalent? {2}", formula1, formula2, formula1.Equals(formula2)); // You can modify exisiting chemical formulas in many ways. // You can add a chemical formula to a chemical formula formula1.Add(formula2); WriteFormulaToConsole(formula1); Console.WriteLine("Are {0} and {1} equivalent? {2}", formula1, formula2, formula1.Equals(formula2)); // You can completely remove an element from a chemical formula formula1.Remove("C"); WriteFormulaToConsole(formula1); // Even negative values are possible if not physically possible formula1.Remove(formula2); WriteFormulaToConsole(formula1); // Implicit arithmetic is also possible (supports +, -, and *) ChemicalFormula formula3 = formula2 - formula1; WriteFormulaToConsole(formula3); ChemicalFormula formula4 = formula3 + formula1; WriteFormulaToConsole(formula4); ChemicalFormula formula5 = formula2*5; WriteFormulaToConsole(formula5); // Formulas consist of a dictionary of isotopes and count, and by default, the most common (abundant) isotope of an element // is included (i.e. Carbon 12 instead of Carbon 13). You can explicitly state that you want another isotope in a chemical formula // by this notation: <Element Symbol>{<Mass Number>} (e.g. C{13}, N{15}, etc..) formula1 = new ChemicalFormula("C2C{13}2H3NO"); formula2 = new ChemicalFormula("C4H3NO"); WriteFormulaToConsole(formula1); WriteFormulaToConsole(formula2); Console.WriteLine("Are {0} and {1} equivalent? {2}", formula1, formula2, formula1.Equals(formula2)); // No need to specify the mass number of the most abundant isotope for an element formula3 = new ChemicalFormula("C{12}2C2H3NO"); formula4 = new ChemicalFormula("C4H3NO"); Console.WriteLine("Are {0} and {1} equivalent? {2}", formula3, formula4, formula3.Equals(formula4)); }
public void AddElementToFormula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2H3N2O"); Element n = Element.PeriodicTable["N"]; formulaA.Add(n, 1); Assert.AreEqual(formulaA, formulaB); }
/// <summary> /// /// </summary> /// <param name="argCompond"></param> /// <param name="argTheoreticalMonoIdx"></param> /// <param name="argIntensities"></param> /// <returns></returns> public static double IntensityNormalizationFactorByIsotope(COL.GlycoLib.GlycanCompound argCompond, int argNumOfLabelingSite, double[] argIntensities, float argPurity) { ChemicalFormula MonoChemFormula = new ChemicalFormula(); MonoChemFormula.Add("C", argCompond.Carbon+argCompond.Carbon13); MonoChemFormula.Add("H", argCompond.Hydrogen+argCompond.Deuterium); MonoChemFormula.Add("O", argCompond.Oxygen); //if (argCompond.Carbon13 != 0) //{ // MonoChemFormula.Add("C{13}", argCompond.Carbon13); //} //if (argCompond.Deuterium != 0) //{ // MonoChemFormula.Add("D", argCompond.Deuterium); //} if (argCompond.Sodium != 0) { MonoChemFormula.Add("Na", argCompond.Sodium); } if (argCompond.Nitrogen != 0) { MonoChemFormula.Add("N", argCompond.Nitrogen); } IsotopicDistribution ID = new IsotopicDistribution(); MZPeak[] Peaks= ID.CalculateDistribuition(MonoChemFormula,7, IsotopicDistribution.Normalization.BasePeak).GetPeaks().ToArray(); double[] isotopeRatio = new double[7]; for (int i = 0; i < 7; i++) { isotopeRatio[i] = Peaks[i].Intensity; } double[] CorrectedIntensities = (double[] )argIntensities.Clone(); //Isotope Correction for (int i = 0; i <= 2; i++) { double Ratio = CorrectedIntensities[i]/ isotopeRatio[0]; for (int j = i; j < 7; j++) { CorrectedIntensities[j] = CorrectedIntensities[j] - (isotopeRatio[j-i] * Ratio ); } } double isotopeCorrectionFactor = CorrectedIntensities[3] / argIntensities[3]; // Purity Correction //double PurityCorrection = Math.Pow(argPurity, argNumOfLabelingSite); return isotopeCorrectionFactor; }
public void RemoveElementCompletelyFromFromula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2NO"); formulaA.Remove(Element.PeriodicTable["H"]); Assert.AreEqual(formulaA, formulaB); }
public void ParsingFormulaWithSpacesAtEnd() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO "); ChemicalFormula formulaB = new ChemicalFormula("C2H3NO"); Assert.AreEqual(formulaA, formulaB); }
public static void HillNotationNoCarbonNoHydrogen() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("Ca5O14Br6"); Assert.AreEqual("Br6Ca5O14", formulaA.Formula); }
public static void HillNotationNoHydrogen() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("NC2O"); Assert.AreEqual("C2NO", formulaA.Formula); }
public static void ContainsSpecificIsotope() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H5NOO{16}"); Assert.IsTrue(formulaA.ContainsSpecificIsotope(PeriodicTable.GetElement("O")[16])); }
public static void HashCodeImmutableEquality() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO"); Assert.AreEqual(formulaA.GetHashCode(), formulaA.GetHashCode()); }
public void RemoveNonExistantIsotopeFromFromula() { ChemicalFormula formulaA = new ChemicalFormula("C2H5NO2"); ChemicalFormula formulaB = new ChemicalFormula("Fe"); ChemicalFormula formulaC = new ChemicalFormula("C2H5Fe-1NO2"); formulaA.Remove(formulaB); Assert.AreEqual(formulaA, formulaC); }
public static void UniqueIsotopesWithHeavyIsotope() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("CC{13}H3NO"); Assert.AreEqual(1, formulaA.NumberOfUniqueIsotopes); }
public static void UniqueIsotopes() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO"); Assert.AreEqual(0, formulaA.NumberOfUniqueIsotopes); }
public static void UniqueElementsWithHeavyIsotope() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("CC{13}H3NO"); Assert.AreEqual(4, formulaA.NumberOfUniqueElementsByAtomicNumber); }
public static void UniqueElements() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO"); Assert.AreEqual(4, formulaA.NumberOfUniqueElementsByAtomicNumber); }
public static void AverageMass() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C"); Assert.AreEqual(PeriodicTable.GetElement("C").AverageMass, formulaA.AverageMass); }
public static void TotalProtons2() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C{12}2H3NO"); Assert.AreEqual(30, formulaA.ProtonCount); }
public static void HydrogenCarbonRatio() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C8H4"); Assert.AreEqual(0.5, formulaA.HydrogenCarbonRatio); }
public void RemoveElementCompletelyFromFromulaWithHeavyIsotope() { ChemicalFormula formulaA = new ChemicalFormula("C2C{13}H3NO"); ChemicalFormula formulaB = new ChemicalFormula("H3NO"); formulaA.Remove(Element.PeriodicTable["C"]); Assert.AreEqual(formulaA, formulaB); }
public void RemoveFormulaFromFromula() { ChemicalFormula formulaA = new ChemicalFormula("C2H5NO2"); ChemicalFormula formulaB = new ChemicalFormula("H2O"); ChemicalFormula formulaC = new ChemicalFormula("C2H3NO"); formulaA.Remove(formulaB); Assert.AreEqual(formulaA, formulaC); }
public static void ContainsIsotopesOfYe() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("CC{13}H3NO"); Assert.IsTrue(formulaA.ContainsIsotopesOf(PeriodicTable.GetElement("C"))); }
public static void EqualsFalse() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("OCHHCHN"); Assert.IsFalse(formulaA.Equals("C")); }
public static void BadFormula() { Assert.Throws <MzLibException>(() => { ChemicalFormula.ParseFormula("!@#$"); }, "Input string for chemical formula was in an incorrect format"); }
public static void TestIsotopicDistribution2() { IsotopicDistribution.GetDistribution(ChemicalFormula.ParseFormula("AlO{16}")); }
public static void Equals() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("OCHHCHN"); Assert.AreEqual(formulaA, formulaA); }
public static void NumberOfAtoms() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO"); Assert.AreEqual(7, formulaA.AtomCount); }
public static void CatchProbStuff() { ChemicalFormula formula = (ChemicalFormula.ParseFormula("C50O50")); IsotopicDistribution.GetDistribution(formula, 0.001, 1e-50, 1e-15); }
public static void HillNotationWithHeavyIsotopeNegativeCount() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("H3NC2C{13}-2O"); Assert.AreEqual("C2C{13}-2H3NO", formulaA.Formula); }
public static void TestAnotherFormula() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("H{1}CC{13}2H3NO{16}"); Assert.AreEqual("CC{13}2H3H{1}NO{16}", formulaA.Formula); }
public static void NeutronCount() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C{12}O{16}"); Assert.AreEqual(14, formulaA.NeutronCount()); }
public static void NeutronCountFail() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("CO"); Assert.Throws <MzLibException>(() => { formulaA.NeutronCount(); }, "Cannot know for sure what the number of neutrons is!"); }
public void ParsingFormulaWithDeuterium() { ChemicalFormula formulaA = new ChemicalFormula("C2D3H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2H{2}3H3NO"); Assert.AreEqual(formulaA, formulaB); }
public void RemoveNullIsotopeFromFromula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2H3NO"); formulaA.Remove(NullIsotope); Assert.AreEqual(formulaA, formulaB); }
public static void HillNotationNoCarbon() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("BrH"); Assert.AreEqual("HBr", formulaA.Formula); }
public void TotalNeutrons() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); Assert.AreEqual(19, formulaA.GetNeutronCount()); }
public void RemoveElementCompletelyFromFromulaBySymbol() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2NO"); formulaA.Remove("H"); Assert.AreEqual(formulaA, formulaB); }
public void UniqueElements() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); Assert.AreEqual(4, formulaA.ElementCount); }
public void RemoveEmptyFormulaFromFromula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2H3NO"); formulaA.Remove(EmptyFormula); Assert.AreEqual(formulaA, formulaB); }
public void UniqueIsotopes() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); Assert.AreEqual(4, formulaA.IsotopeCount); }
public void RemoveIsotopeFromFromulaEquality() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2H3O"); formulaA.Remove("N", 1); Assert.AreEqual(formulaA, formulaB); }
public void AddLargeIsotopeToFormula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2H3NOFe"); Isotope fe = Element.PeriodicTable["Fe"].PrincipalIsotope; formulaA.Add(fe, 1); Assert.AreEqual(formulaA, formulaB); }
static void Main(string[] args) { Loaders.LoadElements(@"elements.dat"); const double averageC = 4.9384; const double averageH = 7.7583; const double averageO = 1.4773; const double averageN = 1.3577; const double averageS = 0.0417; for (int i = 11; i <= 11; i++) { double factor = Math.Pow(2, 0.5 * i); Console.WriteLine("Approx number of amino acids: " + Convert.ToInt32(factor)); ChemicalFormula chemicalFormula = new ChemicalFormula(); chemicalFormula.Add("C", Convert.ToInt32(averageC * factor)); chemicalFormula.Add("H", Convert.ToInt32(averageH * factor)); chemicalFormula.Add("O", Convert.ToInt32(averageO * factor)); chemicalFormula.Add("N", Convert.ToInt32(averageN * factor)); chemicalFormula.Add("S", Convert.ToInt32(averageS * factor)); Console.WriteLine("Formula," + chemicalFormula.Formula); Console.WriteLine("Monoisotopic mass," + chemicalFormula.MonoisotopicMass); Console.WriteLine("Average mass," + chemicalFormula.AverageMass); var numPeaks = MathNet.Numerics.Combinatorics.Combinations(Convert.ToInt32(averageC * factor) + 1, 1) * MathNet.Numerics.Combinatorics.Combinations(Convert.ToInt32(averageH * factor) + 1, 1) * MathNet.Numerics.Combinatorics.Combinations(Convert.ToInt32(averageO * factor) + 2, 2) * MathNet.Numerics.Combinatorics.Combinations(Convert.ToInt32(averageN * factor) + 1, 1) * MathNet.Numerics.Combinatorics.Combinations(Convert.ToInt32(averageS * factor) + 3, 3); Console.WriteLine("Combinatorial number of peaks," + numPeaks); IsotopicDistribution ye; double fineRes; #region Find lowest possible width that is same as widest one for zero min prob fineRes = Math.Pow(2, -1); ye = new IsotopicDistribution(chemicalFormula, fineRes, 0); int firstCount = ye.Intensities.Count; do { fineRes /= 2; ye = new IsotopicDistribution(chemicalFormula, fineRes, 0); } while (ye.Intensities.Count <= firstCount); fineRes *= 2; ye = new IsotopicDistribution(chemicalFormula, fineRes, 0); Console.WriteLine(" fineRes" + ", " + fineRes); OutputMassesAndIntensities(ye, fineRes, 0, ye.Masses.Count); for (int j = 0; j < ye.Masses.Count - 1; j++) { Console.Write((j + 1) + ","); } Console.WriteLine(""); for (int j = 0; j < ye.Masses.Count - 1; j++) { Console.Write((ye.Masses[j + 1] - ye.Masses[j]) + ","); } Console.WriteLine(""); #endregion #region Redo with only high probabilities var maxIntensity = ye.Intensities.Max(); fineRes = Math.Pow(2, -1); ye = new IsotopicDistribution(chemicalFormula, fineRes, maxIntensity / 10000); firstCount = ye.Intensities.Count; do { fineRes /= 2; ye = new IsotopicDistribution(chemicalFormula, fineRes, maxIntensity / 10000); } while (ye.Intensities.Count <= firstCount); fineRes *= 2; ye = new IsotopicDistribution(chemicalFormula, fineRes, maxIntensity / 10000); Console.WriteLine(" fineRes" + ", " + fineRes); OutputMassesAndIntensities(ye, fineRes, 0, ye.Masses.Count); #endregion //#region For 0 min probability try to reach numPeaks //fineRes = Math.Pow(2, -2); //do //{ // ye = new IsotopicDistribution(chemicalFormula, fineRes, 0); // Console.WriteLine(ye.Intensities.Count); // fineRes /= 2; //} while (ye.Intensities.Count < numPeaks); //#endregion #region For a given high resolution, use lowest allowed probability fineRes = Math.Pow(2, -18); double minProb = maxIntensity / 10000; ye = new IsotopicDistribution(chemicalFormula, fineRes, minProb); Console.WriteLine(" minProbability" + ", " + minProb); Console.WriteLine(" fineRes" + ", " + fineRes); OutputMassesAndIntensities(ye, fineRes, 0, ye.Masses.Count); #endregion #region For the selected run, zoom in var maxInt = ye.Intensities.Skip(1).Max(); var indexOfMax = ye.Intensities.IndexOf(maxInt); var massOfMax = ye.Masses[indexOfMax]; var filteredMasses = ye.Masses.Where(b => b > massOfMax - 0.5 && b < massOfMax + 0.5); var lowestIndex = ye.Masses.IndexOf(filteredMasses.First()); var highestIndex = ye.Masses.IndexOf(filteredMasses.Last()); Console.WriteLine("Zoomed in:"); OutputMassesAndIntensities(ye, fineRes, lowestIndex, highestIndex); #endregion } Console.WriteLine("done"); Console.Read(); }
public static void NumberOfAtomsOfNegativeFormula() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C-2H-3N-1O-1"); Assert.AreEqual(-7, formulaA.AtomCount); }
public void RemoveZeroIsotopeFromFromula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2H3NO"); formulaA.Remove(Element.PeriodicTable["H"][1], 0); Assert.AreEqual(formulaA, formulaB); }
public ProteoformRelation(Proteoform pf1, Proteoform pf2, ProteoformComparison relation_type, double delta_mass, string current_directory) { connected_proteoforms[0] = pf1; connected_proteoforms[1] = pf2; RelationType = relation_type; DeltaMass = delta_mass; InstanceId = instanceCounter; lock (Sweet.lollipop) instanceCounter += 1; //Not thread safe if (CH2 == null || HPO3 == null) { CH2 = ChemicalFormula.ParseFormula("C1 H2"); HPO3 = ChemicalFormula.ParseFormula("H1 O3 P1"); } if (Sweet.lollipop.neucode_labeled) { lysine_count = pf1.lysine_count; } List <PtmSet> candidate_sets = new List <PtmSet>(); if (Sweet.lollipop.et_use_notch && (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy)) { if (Sweet.lollipop.et_use_notch && !Sweet.lollipop.et_notch_ppm) { double mass = delta_mass - Sweet.lollipop.notch_tolerance_et; while (mass <= delta_mass + Sweet.lollipop.notch_tolerance_et) { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary_notches.TryGetValue( Math.Round(mass, 1), out List <PtmSet> candidates); if (candidates != null) { candidate_sets.AddRange(candidates); } mass += 0.1; } candidate_sets = candidate_sets.Distinct().ToList(); } else { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary_notches.TryGetValue(Math.Round(delta_mass, 1), out candidate_sets); } if (candidate_sets != null) { candidate_sets = candidate_sets.Where(s => Sweet.lollipop.et_notch_ppm ? Math.Abs(s.mass - delta_mass) * 1e6 / pf1.modified_mass < Sweet.lollipop.notch_tolerance_et : Math.Abs(s.mass - delta_mass) < Sweet.lollipop.notch_tolerance_et).ToList(); candidate_ptmset = candidate_sets.OrderBy(s => s.ptm_rank_sum).FirstOrDefault(); } } else if (Sweet.lollipop.ee_use_notch && (relation_type == ProteoformComparison.ExperimentalExperimental || relation_type == ProteoformComparison.ExperimentalFalse)) { if (Sweet.lollipop.ee_use_notch && !Sweet.lollipop.ee_notch_ppm) { double mass = delta_mass - Sweet.lollipop.notch_tolerance_ee; while (mass <= delta_mass + Sweet.lollipop.notch_tolerance_ee) { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary_notches.TryGetValue( Math.Round(mass, 1), out List <PtmSet> candidates); if (candidates != null) { candidate_sets.AddRange(candidates); } mass += 0.1; } candidate_sets = candidate_sets.Distinct().ToList(); } else { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary_notches.TryGetValue(Math.Round(delta_mass, 1), out candidate_sets); } if (candidate_sets != null) { candidate_sets = candidate_sets.Where(s => Sweet.lollipop.ee_notch_ppm ? Math.Abs(s.mass - delta_mass) * 1e6 / pf1.modified_mass < Sweet.lollipop.notch_tolerance_ee : Math.Abs(s.mass - delta_mass) < Sweet.lollipop.notch_tolerance_ee).ToList(); candidate_ptmset = candidate_sets.OrderBy(s => s.ptm_rank_sum).FirstOrDefault(); } } else if (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy) { if (Sweet.lollipop.peak_width_base_et > 0.09) { double mass = delta_mass - Sweet.lollipop.peak_width_base_et; while (mass <= delta_mass + Sweet.lollipop.peak_width_base_et) { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary.TryGetValue( Math.Round(mass, 1), out List <PtmSet> candidates); if (candidates != null) { candidate_sets.AddRange(candidates); } mass += 0.1; } candidate_sets = candidate_sets.Distinct().ToList(); } else { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary.TryGetValue( Math.Round(delta_mass, 1), out candidate_sets); } if (pf2 as TheoreticalProteoform != null && candidate_sets != null && candidate_sets.Count > 0) { List <PtmSet> narrower_range_of_candidates = new List <PtmSet>(); if (Sweet.lollipop.et_use_notch) { narrower_range_of_candidates = candidate_sets; } else { narrower_range_of_candidates = candidate_sets .Where(s => Math.Abs(s.mass - delta_mass) < Sweet.lollipop.peak_width_base_et).ToList(); } TheoreticalProteoform t = pf2 as TheoreticalProteoform; candidate_ptmset = Proteoform.generate_possible_added_ptmsets(narrower_range_of_candidates, Sweet.lollipop.theoretical_database.all_mods_with_mass, t, pf2.begin, pf2.end, pf2.ptm_set, Sweet.lollipop.mod_rank_first_quartile, false).OrderBy(x => x.ptm_rank_sum + Math.Abs(Math.Abs(x.mass) - Math.Abs(delta_mass)) * 10E-6) // major score: delta rank; tie breaker: deltaM, where it's always less than 1 .FirstOrDefault(); } } // Start the model (0 Da) at the mass defect of CH2 or HPO3 itself, allowing the peak width tolerance on either side double half_peak_width = RelationType == ProteoformComparison.ExperimentalTheoretical || RelationType == ProteoformComparison.ExperimentalDecoy ? Sweet.lollipop.peak_width_base_et / 2 : Sweet.lollipop.peak_width_base_ee / 2; double low_decimal_bound = half_peak_width + ((CH2.MonoisotopicMass - Math.Truncate(CH2.MonoisotopicMass)) / CH2.MonoisotopicMass) * (Math.Abs(delta_mass) <= CH2.MonoisotopicMass ? CH2.MonoisotopicMass : Math.Abs(delta_mass)); double high_decimal_bound = 1 - half_peak_width + ((HPO3.MonoisotopicMass - Math.Ceiling(HPO3.MonoisotopicMass)) / HPO3.MonoisotopicMass) * (Math.Abs(delta_mass) <= HPO3.MonoisotopicMass ? HPO3.MonoisotopicMass : Math.Abs(delta_mass)); double delta_mass_decimal = Math.Abs(delta_mass - Math.Truncate(delta_mass)); outside_no_mans_land = delta_mass_decimal <= low_decimal_bound || delta_mass_decimal >= high_decimal_bound || high_decimal_bound <= low_decimal_bound; if (Sweet.lollipop.et_use_notch && (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy)) { outside_no_mans_land = true; } if (Sweet.lollipop.ee_use_notch && (relation_type == ProteoformComparison.ExperimentalExperimental || relation_type == ProteoformComparison.ExperimentalFalse)) { outside_no_mans_land = true; } }
public void TotalProtons() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); Assert.AreEqual(22, formulaA.GetProtonCount()); }
public void IsotopesTest() { var provider = new MockElementProvider(); IElement h = provider.GetElement(1); IElement h1 = provider.GetElement(1, 1); IElement h2 = provider.GetElement(1, 2); // These two are equal. ChemicalFormula formula0 = new ChemicalFormula(new[] { new EntityCardinality <IElement>(h, 2) }); ChemicalFormula formula1 = new ChemicalFormula(new[] { new EntityCardinality <IElement>(h, 2) }); ChemicalFormula formula2 = new ChemicalFormula(new[] { new EntityCardinality <IElement>(h1, 2) }); // These two are equal. ChemicalFormula formula3 = new ChemicalFormula(new[] { new EntityCardinality <IElement>(h, 1), new EntityCardinality <IElement>(h1, 1) }); ChemicalFormula formula4 = new ChemicalFormula(new[] { new EntityCardinality <IElement>(h1, 1), new EntityCardinality <IElement>(h, 1) }); ChemicalFormula formula5 = new ChemicalFormula(new[] { new EntityCardinality <IElement>(h1, 1), new EntityCardinality <IElement>(h2, 1) }); ChemicalFormula[] formulas = new[] { formula0, formula1, formula2, formula3, formula4, formula5, }; for (int i = 0; i < 6; i++) { for (int j = i; j < 6; j++) { ChemicalFormula fi = formulas[i]; ChemicalFormula fj = formulas[j]; if ( i == j || (i == 0 && j == 1) || (i == 3 && j == 4) ) { Assert.IsTrue(fi.Equals(fj)); } else { Assert.IsFalse(fi.Equals(fj)); } } } }
public void UniqueElementsWithHeavyIsotope() { ChemicalFormula formulaA = new ChemicalFormula("CC{13}H3NO"); Assert.AreEqual(4, formulaA.ElementCount); }
public static void TestChemicalFormulaWithIsotopesTMT(string formula, double mass) { ChemicalFormula cf = ChemicalFormula.ParseFormula(formula); Assert.AreEqual(mass, ClassExtensions.RoundedDouble(cf.MonoisotopicMass)); }
public void UniqueIsotopesWithHeavyIsotope() { ChemicalFormula formulaA = new ChemicalFormula("CC{13}H3NO"); Assert.AreEqual(5, formulaA.IsotopeCount); }
public static void TestPeptideWithSetModifications() { var prot = new Protein("M", null); DigestionParams digestionParams = new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, maxModsForPeptides: 3); // if you pass Custom Protease7 this test gets really flakey. List <Modification> variableModifications = new List <Modification>(); ModificationMotif.TryGetMotif("M", out ModificationMotif motif); variableModifications.Add(new Modification(_originalId: "ProtNmod", _target: motif, _locationRestriction: "N-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass)); variableModifications.Add(new Modification(_originalId: "pepNmod", _target: motif, _locationRestriction: "Peptide N-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass)); variableModifications.Add(new Modification(_originalId: "resMod", _target: motif, _locationRestriction: "Anywhere.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass)); variableModifications.Add(new Modification(_originalId: "PepCmod", _target: motif, _locationRestriction: "Peptide C-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass)); variableModifications.Add(new Modification(_originalId: "ProtCmod", _target: motif, _locationRestriction: "C-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass)); var ye = prot.Digest(digestionParams, new List <Modification>(), variableModifications).ToList(); Assert.AreEqual(3 * 2 * 3, ye.Count); Assert.AreEqual("[H]M[H][H]", ye.Last().SequenceWithChemicalFormulas); double m1 = 5 * GetElement("H").PrincipalIsotope.AtomicMass + Residue.ResidueMonoisotopicMass['M'] + GetElement("O").PrincipalIsotope.AtomicMass; m1 = Math.Round(m1, 9, MidpointRounding.AwayFromZero); double m2 = ye.Last().MonoisotopicMass; double m3 = m1 - m2; Assert.IsTrue(m3 < 1e-9); }
public override void SetValue(string fieldName, string value) { if (MzTab.NullFieldText.Equals(value)) return; switch (fieldName) { case Fields.Identifier: Identifiers = value.Split('|').ToList(); return; case Fields.ChemicalFormula: ChemicalFormula = new ChemicalFormula(value); return; case Fields.Smiles: Smiles = value; return; case Fields.InChIKey: InChIKeys = value.Split('|').ToList(); return; case Fields.Description: Description = value; return; case Fields.ExperimentMZ: ExperimentalMZ = double.Parse(value, CultureInfo.CurrentCulture); return; case Fields.TheoreticalMZ: TheoreticalMZ = double.Parse(value, CultureInfo.CurrentCulture); return; case Fields.Charge: Charge = int.Parse(value); return; case Fields.RetentionTime: RetentionTimes = value.Split('|').Select(double.Parse).ToList(); return; case Fields.TaxID: TaxID = int.Parse(value); return; case Fields.Species: Species = value; return; case Fields.Database: Database = value; return; case Fields.DatabaseVersion: DatabaseVersion = value; return; case Fields.Reliability: Reliability = (MzTab.MetabolomicsReliabilityScore) int.Parse(value); return; case Fields.Uri: Uri = new Uri(value); return; case Fields.SpectralReference: SpectralReference = value; return; case Fields.SearchEngine: SearchEngines = value.Split('|').Select(v => new CVParamater(v)).ToList(); return; case Fields.Modifications: Modifications = value; return; } if (fieldName.Contains("[")) { string condensedFieldName; List<int> indices = MzTab.GetFieldIndicies(fieldName, out condensedFieldName); switch (condensedFieldName) { case Fields.BestSearchEngineScores: SetListValue(ref _bestSearchEngineScores, indices[0], double.Parse(value, CultureInfo.CurrentCulture)); return; case Fields.SearchEngineScorePerMsRun: SetListValue(ref _searchEngineScorePerMsRun, indices[0], indices[1], double.Parse(value, CultureInfo.CurrentCulture)); return; case Fields.AbundanceAssay: SetListValue(ref _abundanceAssays, indices[0], double.Parse(value, CultureInfo.CurrentCulture)); return; case Fields.AbundanceStudyVariable: SetListValue(ref _abundanceStudyVariables, indices[0], double.Parse(value, CultureInfo.CurrentCulture)); return; case Fields.AbundanceStDevStudyVariable: SetListValue(ref _abundanceStdevStudyVariables, indices[0], double.Parse(value, CultureInfo.CurrentCulture)); return; case Fields.AbudnanceStdErrorStudyVariable: SetListValue(ref _abundanceStandardErrorStudyVariables, indices[0], double.Parse(value, CultureInfo.CurrentCulture)); return; } } if (fieldName.StartsWith(MzTab.OptionalColumnPrefix)) { SetOptionalData(fieldName, value); return; } throw new ArgumentException("Unexpected field name: " + fieldName); }
public static void TestPeptideWithFixedModifications() { var prot = new Protein("M", null); DigestionParams digestionParams = new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, maxModsForPeptides: 3); // if you pass Custom Protease7 this test gets really flakey. List <Modification> fixedMods = new List <Modification>(); ModificationMotif.TryGetMotif("M", out ModificationMotif motif); fixedMods.Add(new Modification(_originalId: "ProtNmod", _target: motif, _locationRestriction: "N-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass)); fixedMods.Add(new Modification(_originalId: "pepNmod", _target: motif, _locationRestriction: "Peptide N-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass)); fixedMods.Add(new Modification(_originalId: "resMod", _target: motif, _locationRestriction: "Anywhere.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass)); fixedMods.Add(new Modification(_originalId: "PepCmod", _target: motif, _locationRestriction: "Peptide C-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass)); fixedMods.Add(new Modification(_originalId: "ProtCmod", _target: motif, _locationRestriction: "C-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass)); var ok = prot.Digest(digestionParams, fixedMods, new List <Modification>()).ToList(); Assert.AreEqual(1, ok.Count); Assert.AreEqual("[:pepNmod on M]M[:resMod on M][:ProtCmod on M]", ok.First().FullSequence); Assert.AreEqual("[H]M[H][H]", ok.First().SequenceWithChemicalFormulas); Assert.AreEqual(5 * GetElement("H").PrincipalIsotope.AtomicMass + Residue.ResidueMonoisotopicMass['M'] + GetElement("O").PrincipalIsotope.AtomicMass, ok.Last().MonoisotopicMass, 1e-9); }