Beispiel #1
0
        public void OverlapGraphTest()
        {
            string input = @">Rosalind_0498
                             AAATAAA
                             >Rosalind_2391
                             AAATTTT
                             >Rosalind_2323
                             TTTTCCC
                             >Rosalind_0442
                             AAATCCC
                             >Rosalind_5013
                             GGGTGGG";

            var expected = new List <Tuple <string, string> > ()
            {
                Tuple.Create("Rosalind_0498", "Rosalind_2391"),
                Tuple.Create("Rosalind_0498", "Rosalind_0442"),
                Tuple.Create("Rosalind_2391", "Rosalind_2323")
            };

            var result = new List <Tuple <string, string> > (
                OverlapGrapher.calculateGraph(3, FASTA.read(new StringReader(input))));

            Assert.AreEqual(expected.Count, result.Count);

            foreach (var pair in expected.Zip(result, (a, b) => Tuple.Create(a, b)))
            {
                Assert.AreEqual(pair.Item1, pair.Item2);
            }
        }
Beispiel #2
0
        public void TestConsensus()
        {
            string input = @">Rosalind_1
            ATCCAGCT
            >Rosalind_2
            GGGCAACT
            >Rosalind_3
            ATGGATCT
            >Rosalind_4
            AAGCAACC
            >Rosalind_5
            TTGGAACT
            >Rosalind_6
            ATGCCATT
            >Rosalind_7
            ATGGCACT";

            var profile = new Profile(8);

            foreach (var pair in FASTA.read(new StringReader(input)))
            {
                var seq = pair.Item2.Select(b => (Base)Enum.Parse(typeof(Base), b.ToString()));
                profile.add(seq);
            }

            var expectedConcensus = "ATGCAACT".Select(b => (Base)Enum.Parse(typeof(Base), b.ToString()));
            IDictionary <Base, IList <uint> > expectedProfile = new Dictionary <Base, IList <uint> > ()
            {
                { Base.A, new List <uint> ()
                  {
                      5, 1, 0, 0, 5, 5, 0, 0
                  } },
                { Base.C, new List <uint> ()
                  {
                      0, 0, 1, 4, 2, 0, 6, 1
                  } },
                { Base.G, new List <uint> ()
                  {
                      1, 1, 6, 3, 0, 1, 0, 0
                  } },
                { Base.T, new List <uint> ()
                  {
                      1, 5, 0, 0, 0, 1, 1, 6
                  } }
            };

            Assert.That(profile.consensus, Is.EqualTo(expectedConcensus));

            foreach (Base b in Enum.GetValues(typeof(Base)))
            {
                Assert.That(
                    new List <uint>(profile[b]),
                    Is.EqualTo(expectedProfile[b]));
            }
        }
Beispiel #3
0
        private static void SharedMotifCLI(IDictionary <string, ValueObject> args)
        {
            string filename = args ["<filename>"].ToString();

            using (var infile = new FileStream(filename, FileMode.Open))
                using (var reader = new StreamReader(infile)) {
                    var tracker = FASTA.read(reader)
                                  .Select(p => p.Item2)
                                  .Aggregate(new MotifTracker(), (trk, s) => trk.add(s));
                    Console.WriteLine(
                        tracker.motifs.Where(x => x.Length == tracker.maxLen).First());
                }
        }
Beispiel #4
0
        private static void OverlapGraph(IDictionary <string, ValueObject> args)
        {
            string filename = args ["<filename>"].ToString();

            using (var infile = new FileStream(filename, FileMode.Open))
                using (var reader = new StreamReader(infile)) {
                    var result = OverlapGrapher.calculateGraph(3, FASTA.read(reader));
                    foreach (var pair in result)
                    {
                        Console.WriteLine("{0} {1}", pair.Item1, pair.Item2);
                    }
                }
        }
Beispiel #5
0
        public void TestSharedMotif()
        {
            const string input    = @">Rosalind_1
                GATTACA
                >Rosalind_2
                TAGACCA
                >Rosalind_3
                ATACA";
            const string expected = "AC";

            var tracker = FASTA.read(new StringReader(input))
                          .Aggregate(new MotifTracker(),
                                     (trk, p) => trk.add(p.Item2));

            Assert.IsTrue(tracker.motifs.Contains(expected));
        }
Beispiel #6
0
        private static void Consensus(IDictionary <string, ValueObject> args)
        {
            string filename = args ["<filename>"].ToString();

            int size = 0;

            using (var infile = new FileStream(filename, FileMode.Open)) {
                var reader = new StreamReader(infile);

                foreach (var pair in FASTA.read(reader))
                {
                    size = pair.Item2.Length;
                }
            }

            var profile = new Profile((uint)size);

            using (var infile = new FileStream(filename, FileMode.Open)) {
                var reader = new StreamReader(infile);

                foreach (var pair in FASTA.read(reader))
                {
                    var seq = pair.Item2.Select(b => (Base)Enum.Parse(typeof(Base), b.ToString()));
                    profile.add(seq);
                }
            }

            Console.WriteLine(string.Join("", profile.consensus));

            Console.Write("A: ");
            Console.WriteLine(string.Join(" ", profile [Base.A]));
            Console.Write("C: ");
            Console.WriteLine(string.Join(" ", profile [Base.C]));
            Console.Write("G: ");
            Console.WriteLine(string.Join(" ", profile [Base.G]));
            Console.Write("T: ");
            Console.WriteLine(string.Join(" ", profile [Base.T]));
        }