예제 #1
0
        /// <summary>
        /// Returns true if the given element is a balanced isotopic label, where the only
        /// thing changing is the isotopes of the atoms in question.
        /// </summary>
        private static bool IsIsotopicDiff(IEnumerable <elem_ref_t> element)
        {
            var dictSymToCount = element.ToDictionary(el => el.symbol, el => int.Parse(el.number));

            foreach (var pair in dictSymToCount.ToArray())
            {
                string labelSym   = pair.Key;
                int    labelCount = pair.Value;
                char   monoChar;
                if (DICT_HEAVY_LABELS.TryGetValue(labelSym, out monoChar))
                {
                    // Must be adding labeled atoms and removing unlabeled atoms
                    if (labelCount < 0)
                    {
                        return(false);
                    }

                    string monoSym = monoChar.ToString(CultureInfo.InvariantCulture);
                    int    monoCount;
                    if (!dictSymToCount.TryGetValue(monoSym, out monoCount))
                    {
                        return(false);
                    }
                    if (labelCount + monoCount != 0)
                    {
                        return(false);
                    }
                    dictSymToCount.Remove(monoSym);
                    dictSymToCount.Remove(labelSym);
                }
            }
            return(dictSymToCount.Count == 0);
        }
예제 #2
0
        /// <summary>
        /// Check for label atoms in the given sequence matching the given aa, and create a corresponding string if found.
        /// </summary>
        private static bool CheckLabelAtoms(mod_t mod, char[] aas, out string labelAtomsFormula)
        {
            labelAtomsFormula = "";
            bool hasLabelAtoms = true;

            if (mod.title.StartsWith("Label"))
            {
                foreach (var element in mod.delta.element)
                {
                    char elementMatch;
                    if (hasLabelAtoms && DICT_HEAVY_LABELS.TryGetValue(element.symbol, out elementMatch))
                    {
                        foreach (char aa in aas)
                        {
                            int numInFormula = ParseSeqMassCalcFormula(aa, elementMatch);
                            if (!Equals(element.number, numInFormula.ToString(CultureInfo.InvariantCulture)))
                            {
                                hasLabelAtoms = false;
                                break;
                            }
                        }
                        if (!string.IsNullOrEmpty(labelAtomsFormula))
                        {
                            labelAtomsFormula += '|';
                        }

                        var symbol       = element.symbol;
                        var elementIndex = symbol.IndexOfAny(new[] { 'N', 'C', 'O', 'H' });
                        labelAtomsFormula += "LabelAtoms." + symbol[elementIndex] + symbol.Remove(elementIndex);
                    }
                    else if (element.symbol.Length == 1 && DICT_HEAVY_LABELS.ContainsValue(element.symbol[0]))
                    {
                        foreach (char aa in aas)
                        {
                            int numInFormula = ParseSeqMassCalcFormula(aa, element.symbol[0]);
                            if ((Int32.Parse(element.number) * -1) > numInFormula)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            if (!hasLabelAtoms || string.IsNullOrEmpty(labelAtomsFormula))
            {
                labelAtomsFormula = "LabelAtoms.None";
            }
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Create a Skyline chemical formula given a modification from the XML.
        /// </summary>
        private static string BuildFormula(IEnumerable <elem_ref_t> elements)
        {
            string positive = "";
            string negative = " - ";

            foreach (elem_ref_t element in elements)
            {
                int    num    = Int32.Parse(element.number);
                string symbol = element.symbol;
                char   aa;
                symbol = DICT_HEAVY_LABELS.TryGetValue(symbol, out aa) ? aa.ToString(CultureInfo.InvariantCulture) + '\'' : symbol;
                if (num < 0)
                {
                    negative += symbol + (num == -1 ? "" : (num * -1).ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    positive += symbol + (num == 1 ? "" : num.ToString(CultureInfo.InvariantCulture));
                }
            }
            string formula = positive + (negative.Length > 3 ? negative : "");

            return(positive.Length > 0 ? formula : formula.Replace(" ", ""));
        }