public double CalcMass(string sequence, string[] fixedModifications) { Peptide peptide = new Peptide(sequence); peptide.ApplyFixedModifications(Tables.ToModifications(fixedModifications)); double result = peptide.MonoIsotopicMass; result += labelModifications.GetDeltaMass(); result += trueModifications.GetDeltaMass(); return(result); }
public static double CalcPtmScore(double ms2Tol, string ms2TolUnit, int topx, string sequence, Modification[] fixedModifications, Modification[] variableModifications, int[] modCount, double[] specMasses, float[] specIntensities, double mz, int charge, out bool incomplete, out PeptideModificationState outMods, out int counts, out double delta, out MsmsPeakAnnotation[] description, out float[] intensities, out float[] massDiffs, out Dictionary <ushort, double[]> modProb, out Dictionary <ushort, double[]> modScoreDiffs, bool alternative) { if (!AminoAcid.ValidSequence(sequence)) { incomplete = true; outMods = null; counts = 0; delta = 0; description = null; intensities = null; massDiffs = null; modProb = null; modScoreDiffs = null; return(0); } Peptide p = new Peptide(sequence); p.ApplyFixedModifications(fixedModifications); PeptideModificationState[] mpeps = p.ApplyVariableModificationsFixedNumbers(variableModifications, modCount, out incomplete); counts = mpeps.Length; double maxScore = -double.MaxValue; double maxScore2 = -double.MaxValue; PeptideModificationState bestPep = null; description = null; intensities = null; massDiffs = null; double sumScore = 0; modProb = new Dictionary <ushort, double[]>(); Dictionary <ushort, double[, ]> scoreDiffs = new Dictionary <ushort, double[, ]>(); ushort[] w = mpeps[0].GetModifications(); HashSet <ushort> um = new HashSet <ushort>(); foreach (ushort x in w) { if (x != ushort.MaxValue && !um.Contains(x)) { um.Add(x); } } ushort[] uniqueMods = um.ToArray(); foreach (ushort m in uniqueMods) { if (!modProb.ContainsKey(m)) { modProb.Add(m, new double[w.Length]); scoreDiffs.Add(m, new double[2, w.Length]); } } foreach (PeptideModificationState mpep in mpeps) { MsmsPeakAnnotation[] desc; float[] intens; float[] dm; double score = Score(specMasses, specIntensities, p, ms2Tol, ms2TolUnit, mz, charge, out desc, out intens, out dm, topx, mpep); ushort[] mm = mpep.GetModifications(); double x = Math.Exp((score - 100) * NumUtil.log10 / 10.0); for (int i = 0; i < mm.Length; i++) { if (mm[i] != ushort.MaxValue) { modProb[mm[i]][i] += x; } foreach (ushort mod in uniqueMods) { if (mm[i] == mod) { if (score > scoreDiffs[mod][0, i]) { scoreDiffs[mod][0, i] = score; } } else { if (score > scoreDiffs[mod][1, i]) { scoreDiffs[mod][1, i] = score; } } } } sumScore += x; if (score > maxScore) { maxScore2 = maxScore; maxScore = score; bestPep = mpep; description = desc; intensities = intens; massDiffs = dm; } else if (score > maxScore2) { maxScore2 = score; } } modScoreDiffs = new Dictionary <ushort, double[]>(); foreach (ushort mod in uniqueMods) { Modification modi = Tables.modificationList[mod]; modScoreDiffs.Add(mod, new double[w.Length]); for (int i = 0; i < sequence.Length; i++) { char aa = sequence[i]; if (modi.HasAA(aa)) { modScoreDiffs[mod][i] = scoreDiffs[mod][0, i] - scoreDiffs[mod][1, i]; } else { modScoreDiffs[mod][i] = double.NaN; } } } foreach (double[] y in modProb.Values) { for (int i = 0; i < y.Length; i++) { y[i] /= sumScore; } } if (maxScore2 == -double.MaxValue) { delta = maxScore; } else { delta = maxScore - maxScore2; } outMods = bestPep; return(maxScore); }