Esempio n. 1
0
 public void AddFrequencies(KNucleotide other)
 {
     foreach (var kvp in other.frequencies)
     {
         Count count;
         if (frequencies.TryGetValue(kvp.Key, out count))
         {
             count.V += kvp.Value.V;
         }
         else
         {
             frequencies[kvp.Key] = kvp.Value;
         }
     }
 }
 public void AddFrequencies(KNucleotide other)
 {
     foreach (var kvp in other.frequencies)
     {
         KNucleotideNode kNucleotideNode;
         if (frequencies.TryGetValue(kvp.Key, out kNucleotideNode))
         {
             kNucleotideNode.V += kvp.Value.V;
         }
         else
         {
             frequencies[kvp.Key] = kvp.Value;
         }
     }
 }
    public static void Main(string[] args)
    {
        string       line;
        StreamReader source = new StreamReader(Console.OpenStandardInput());
        var          input  = new List <string>();

        while ((line = source.ReadLine()) != null)
        {
            if (line[0] == '>' && line.Substring(1, 5) == "THREE")
            {
                break;
            }
        }

        while ((line = source.ReadLine()) != null)
        {
            char c = line[0];
            if (c == '>')
            {
                break;
            }
            if (c != ';')
            {
                input.Add(line.ToUpper());
            }
        }

        KNucleotide kn = new KNucleotide(input.GetBytes());

        input = null;
        for (int f = 1; f < 3; f++)
        {
            kn.WriteFrequencies(f);
        }
        foreach (var seq in
                 new[] { "GGT", "GGTA", "GGTATT", "GGTATTTTAATT",
                         "GGTATTTTAATTTATAGT" })
        {
            kn.WriteCount(seq);
        }
    }
Esempio n. 4
0
    public static void Main(string[] args)
    {
        string        line;
        StreamReader  source = new StreamReader(Console.OpenStandardInput());
        StringBuilder input  = new StringBuilder();

        while ((line = source.ReadLine()) != null)
        {
            if (line[0] == '>' && line.Substring(1, 5) == "THREE")
            {
                break;
            }
        }

        while ((line = source.ReadLine()) != null)
        {
            char c = line[0];
            if (c == '>')
            {
                break;
            }
            if (c != ';')
            {
                input.Append(line.ToUpper());
            }
        }

        KNucleotide kn = new KNucleotide(input.ToString());

        input = null;
        kn.WriteFrequencies(1);
        kn.WriteFrequencies(2);

        kn.WriteCount("GGT");
        kn.WriteCount("GGTA");
        kn.WriteCount("GGTATT");
        kn.WriteCount("GGTATTTTAATT");
        kn.WriteCount("GGTATTTTAATTTATAGT");
    }
Esempio n. 5
0
    public static void Main(string[] args)
    {
        string       line;
        StreamReader source = new StreamReader(Console.OpenStandardInput());
        var          input  = new List <string>();

        while ((line = source.ReadLine()) != null)
        {
            if (line[0] == '>' && line.Substring(1, 5) == "THREE")
            {
                break;
            }
        }

        while ((line = source.ReadLine()) != null)
        {
            char c = line[0];
            if (c == '>')
            {
                break;
            }
            if (c != ';')
            {
                input.Add(line.ToUpper());
            }
        }

        var lengths = new [] { 1, 2, 3, 4, 6, 12, 18 };

        TaskCount = lengths.Aggregate(0, (cnt, len) => cnt + len);
        kna       = new KNucleotide[TaskCount];

        var bytes = input.GetBytes();

        lengths.Aggregate(0, (cnt, len) =>
        {
            for (int i = 0; i < len; i++)
            {
                kna[cnt + i] = new KNucleotide(bytes, len, i);
            }
            return(cnt + len);
        });

        var threads = new Thread[Environment.ProcessorCount];

        for (int i = 0; i < threads.Length; i++)
        {
            (threads[i] = new Thread(CountFrequencies)).Start();
        }

        foreach (var t in threads)
        {
            t.Join();
        }

        var seqs = new[] { null, null,
                           "GGT", "GGTA", "GGTATT", "GGTATTTTAATT",
                           "GGTATTTTAATTTATAGT" };

        int index = 0;

        lengths.Aggregate(0, (cnt, len) =>
        {
            if (len < 3)
            {
                for (int i = 1; i < len; i++)
                {
                    kna[cnt].AddFrequencies(kna[cnt + i]);
                }
                kna[cnt].WriteFrequencies();
            }
            else
            {
                var fragment = seqs[index];
                int freq     = 0;
                for (int i = 0; i < len; i++)
                {
                    freq += kna[cnt + i].GetCount(fragment);
                }
                Console.WriteLine("{0}\t{1}", freq, fragment);
            }
            index++;
            return(cnt + len);
        });
    }