コード例 #1
0
ファイル: RandSeq.cs プロジェクト: alspok/cs-DinucCalculation
        //Random rnd = new Random() must be decleard in the body of script
        public string RandMonoSeq(Random _rnd, int _randSeqLength, double[] _nucFrq)
        {
            Random rnd           = _rnd;
            int    randSeqLength = _randSeqLength;

            double[] nucFrq  = _nucFrq;
            string   randSeq = string.Empty;

            double[] nucFrqMod = new double[nucFrq.Length];

            double nucSum = 0;

            foreach (var item in nucFrq)
            {
                nucSum += item;
            }
            if (nucSum > 1.1 || nucSum < 0.9)
            {
                Console.WriteLine("Wrong argument sum.");
                EndRun.End();
                System.Environment.Exit(1);
            }

            for (int i = 0; i < _nucFrq.Length; i++)
            {
                if (i == 0)
                {
                    nucFrqMod[i] = nucFrq[i];
                    continue;
                }
                nucFrqMod[i] = nucFrqMod[i - 1] + nucFrq[i];
            }

            var monoNuc = new string[] { "a", "c", "g", "t" };

            for (int i = 0; i < randSeqLength; i++)
            {
                double rand = rnd.NextDouble();
                for (int j = 0; j < nucFrqMod.Length; j++)
                {
                    if (rand <= nucFrqMod[j])
                    {
                        randSeq = string.Concat(randSeq, monoNuc[j]);
                        break;
                    }
                }
            }

            return(randSeq);
        }
コード例 #2
0
        static void Main()
        {
            var testTuple  = new Tuple <int, string, string, double>(1, "one", "two", (double)2);
            var testString = testTuple.ToString();

            char[] trimChars = { '(', ')' };
            testString = testString.Trim(trimChars);
            Console.WriteLine(testTuple);
            Console.WriteLine(testString);

            var testListTuple = new List <Tuple <string, int, string, double> >();

            testListTuple.Add(Tuple.Create("one", 1, "another one", (double)1));
            testListTuple.Add(Tuple.Create("two", 2, "another two", (double)2));

            foreach (var listItem in testListTuple)
            {
                string textItem = listItem.ToString();
                Console.WriteLine(textItem.Trim(trimChars));
            }
            EndRun.End();
        }