コード例 #1
0
        public static double[][] Convolute(double[][] distrib1, double[][] distrib2, double massPrecision, double weightCutoff)
        {
            double[] masses1  = distrib1[0];
            double[] masses2  = distrib2[0];
            double[] weights1 = distrib1[1];
            double[] weights2 = distrib2[1];
            double[] masses   = new double[masses1.Length * masses2.Length];
            double[] weights  = new double[masses1.Length * masses2.Length];
            int      count    = 0;

            for (int i = 0; i < masses1.Length; i++)
            {
                for (int j = 0; j < masses2.Length; j++)
                {
                    masses[count]  = masses1[i] + masses2[j];
                    weights[count] = weights1[i] * weights2[j];
                    count++;
                }
            }
            int[] o = ArrayUtils.Order(masses);
            masses  = ArrayUtils.SubArray(masses, o);
            weights = ArrayUtils.SubArray(weights, o);
            double[][] x = ChemElement.FilterMasses(masses, weights, massPrecision);
            masses  = x[0];
            weights = x[1];
            if (!double.IsNaN(weightCutoff))
            {
                x       = ChemElement.FilterWeights(masses, weights, weightCutoff);
                masses  = x[0];
                weights = x[1];
            }
            return(new[] { masses, weights });
        }
コード例 #2
0
ファイル: ChemElement.cs プロジェクト: neuhauser/compbio-base
        public static void DecodeComposition(string composition, Dictionary <string, ChemElement> elements, out int[] counts,
                                             out string[] comp, out double[] monoMasses, out double[] averageMasses)
        {
            string[] matches = composition.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            counts        = new int[matches.Length];
            comp          = new string[matches.Length];
            monoMasses    = new double[matches.Length];
            averageMasses = new double[matches.Length];
            Regex pattern2 = new Regex("\\(([-]*[0-9]+)\\)");
            Regex pattern3 = new Regex("[0-9]+");

            for (int i = 0; i < matches.Length; i++)
            {
                string key;
                if (pattern2.IsMatch(matches[i]))
                {
                    Match  match = pattern2.Match(matches[i]);
                    string temp  = match.Value;
                    key       = matches[i].Replace(temp, "");
                    counts[i] = Convert.ToInt32(temp.Replace("(", "").Replace(")", "").Trim());
                }
                else
                {
                    key       = matches[i];
                    counts[i] = 1;
                }
                if (elements.ContainsKey(key))
                {
                    ChemElement element = elements[key];
                    comp[i]          = element.Symbol;
                    monoMasses[i]    = element.MonoIsotopicMass;
                    averageMasses[i] = element.AtomicWeight;
                }
                else if (pattern3.IsMatch(key))
                {
                    Match  match = pattern3.Match(key);
                    string key2  = key.Replace(match.Value, "");
                    if (elements.ContainsKey(key2 + "x"))
                    {
                        ChemElement element = elements[key2 + "x"];
                        monoMasses[i]    = element.MonoIsotopicMass;
                        averageMasses[i] = element.AtomicWeight;
                        comp[i]          = element.Symbol;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    throw new Exception();
                }
            }
        }
コード例 #3
0
ファイル: ChemElement.cs プロジェクト: neuhauser/compbio-base
 private static int GetElementIndexByName(string label, IList <ChemElement> chemElements)
 {
     for (int i = 0; i < chemElements.Count; i++)
     {
         ChemElement element = chemElements[i];
         if (element.Symbol.Equals(label))
         {
             return(i);
         }
     }
     throw new Exception("Never get here.");
 }
コード例 #4
0
        public double[][] GetIsotopeDistribution(double massPrecision)
        {
            if (AtomType.Length == 0)
            {
                return(new[] { new double[] { 0 }, new double[] { 1 } });
            }
            ChemElement element = ChemElement.Elements[AtomType[0]];

            double[][] distrib = element.GetIsotopeDistribution(AtomCount[0]);
            for (int i = 1; i < AtomType.Length; i++)
            {
                element = ChemElement.Elements[AtomType[i]];
                distrib = Convolute(distrib, element.GetIsotopeDistribution(AtomCount[i]), massPrecision, 1e-6);
            }
            return(distrib);
        }
コード例 #5
0
ファイル: ChemElement.cs プロジェクト: neuhauser/compbio-base
        private static void SetNaturalVersion(ChemElement ce, IList <ChemElement> chemElements)
        {
            string label = ce.Symbol;

            if (label.Equals("D"))
            {
                ce.NaturalVersion = GetElementIndexByName("H", chemElements);
                return;
            }
            if (label.Equals("T"))
            {
                ce.NaturalVersion = GetElementIndexByName("H", chemElements);
                return;
            }
            if (!label.EndsWith("x"))
            {
                throw new Exception("Never get here.");
            }
            label             = label.Substring(0, label.Length - 1);
            ce.NaturalVersion = GetElementIndexByName(label, chemElements);
        }
コード例 #6
0
        public bool ContainsOnly(string[] elems)
        {
            HashSet <int> types = new HashSet <int>();

            string[] symbols = ChemElement.GetSymbols();
            foreach (string elem in elems)
            {
                int ind = ArrayUtils.IndexOf(symbols, elem);
                if (ind < 0)
                {
                    throw new Exception("Element is not contained: " + elem);
                }
                types.Add(ind);
            }
            foreach (int atomType in AtomType)
            {
                if (!types.Contains(atomType))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #7
0
ファイル: ChemElement.cs プロジェクト: neuhauser/compbio-base
 private static void SetNaturalVersion(ChemElement ce, IList<ChemElement> chemElements)
 {
     string label = ce.Symbol;
     if (label.Equals("D")){
         ce.NaturalVersion = GetElementIndexByName("H", chemElements);
         return;
     }
     if (label.Equals("T")){
         ce.NaturalVersion = GetElementIndexByName("H", chemElements);
         return;
     }
     if (!label.EndsWith("x")){
         throw new Exception("Never get here.");
     }
     label = label.Substring(0, label.Length - 1);
     ce.NaturalVersion = GetElementIndexByName(label, chemElements);
 }