예제 #1
0
        public void ExecuteTestCasepAllResultDecisionMaxAsCriteriaAccept2()
        {
            // arrange
            string excpectedMotif1 = "agcgt";
            string excpectedMotif2 = "cgtaa";
            string expectedSolutionStartPosition1 = "3,5,1";
            string expectedSolutionStartPosition2 = "5,0,3";

            char[][] charSets = new char[][] {
                "agtagcgtaa".ToArray(),
                "cgtgcagtgt".ToArray(),
                "aatcgtaacc".ToArray()
            };
            char[] alphabet        = new char[] { 'a', 'c', 'g', 't' };
            int    substringLength = 5;
            RegulatoryMotifsSubSequencesEnumeration enumeration = new RegulatoryMotifsSubSequencesEnumeration(charSets, alphabet, substringLength, pIsAllResult: true, pIsOptimizitaion: false, pIsSumAsCriteria: false, pAcceptibleDistance: 2)
            {
                StatisticAccumulator = new FakeRegulatoryMotifsStatisticAccumulator()
            };

            enumeration.Execute();
            // assert
            string        solutionStartPosition  = string.Join(",", enumeration.SolutionStartPosition);
            string        motifAsString          = string.Join("", enumeration.Motif);
            List <string> solutionStartPositions = enumeration.SolutionStartPositionList.Select(s => string.Join(",", s)).ToList();
            List <string> motifsAsString         = enumeration.ListOfMotif.Select(m => string.Join("", m)).ToList();

            Assert.IsTrue(motifsAsString.Any(m => m == excpectedMotif1), $"Motif1 is absent.");
            Assert.IsTrue(motifsAsString.Any(m => m == excpectedMotif2), $"Motif2 is absent.");
            Assert.IsTrue(solutionStartPositions.Any(p => p == expectedSolutionStartPosition1), $"Positions1 is absent.");
            Assert.IsTrue(solutionStartPositions.Any(p => p == expectedSolutionStartPosition2), $"Positions2 is absent.");
            Assert.IsTrue(enumeration.SolutionStartPositionList.Count >= 2, $"Wrong number of solutions.");
            Assert.IsTrue(enumeration.ListOfMotif.Count >= 2, $"Wrong number of motifs.");
        }
예제 #2
0
        public void ExecuteTestCasepNotAllResultOptimizationMaxAsCriteriaExpexted1()
        {
            // arrange
            string excpectedMotif = "agcgt";
            string expectedSolutionStartPosition = "3,5,1";
            int    expectedResult = 1;

            char[][] charSets = new char[][] {
                new char[] { 'a', 'g', 't', 't', 'g', 'c', 'g', 't', 'a', 'a' },
                new char[] { 'c', 'g', 't', 'g', 'c', 'a', 'g', 't', 'g', 't' },
                new char[] { 'a', 'a', 't', 'c', 'g', 't', 'a', 'a', 'c', 'c' }
            };
            char[] alphabet        = new char[] { 'a', 'c', 'g', 't' };
            int    substringLength = 5;
            RegulatoryMotifsSubSequencesEnumeration enumeration = new RegulatoryMotifsSubSequencesEnumeration(charSets, alphabet, substringLength, pIsAllResult: false, pIsOptimizitaion: true, pIsSumAsCriteria: false)
            {
                StatisticAccumulator = new FakeRegulatoryMotifsStatisticAccumulator()
            };

            // act
            enumeration.Execute();
            // assert
            string solutionStartPosition = string.Join(",", enumeration.SolutionStartPosition);
            string motifAsString         = string.Join("", enumeration.Motif);

            Assert.AreEqual(motifAsString, excpectedMotif, $"Motif is wrong.");
            Assert.AreEqual(solutionStartPosition, expectedSolutionStartPosition, $"Positions are wrong.");
            Assert.AreEqual(enumeration.OptimalValue, expectedResult, $"Result is wrong.");
        }
예제 #3
0
        public void ExecuteTestCasepAllResultDecisionMaxAsCriteriaAccept0()
        {
            // arrange

            char[][] charSets = new char[][] {
                "agtagcgtaa".ToArray(),
                "cgtgcagtgt".ToArray(),
                "aatcgtaacc".ToArray()
            };
            char[] alphabet        = new char[] { 'a', 'c', 'g', 't' };
            int    substringLength = 5;
            RegulatoryMotifsSubSequencesEnumeration enumeration = new RegulatoryMotifsSubSequencesEnumeration(charSets, alphabet, substringLength, pIsAllResult: true, pIsOptimizitaion: false, pIsSumAsCriteria: false, pAcceptibleDistance: 0)
            {
                StatisticAccumulator = new FakeRegulatoryMotifsStatisticAccumulator()
            };

            // act
            // cgtaa
            // cgtgc
            // cgtaa

            // agcgt
            // agtgt
            // atcgt

            enumeration.Execute();
            // assert
            Assert.AreEqual(enumeration.SolutionStartPositionList.Count, 0, $"Wrong number of solutions.");
            Assert.AreEqual(enumeration.ListOfMotif.Count, 0, $"Wrong number of motifs.");
        }
예제 #4
0
        public void ExecuteTestCasepAllResultDecisionMaxAsCriteriaAcceptible0()
        {
            // arrange
            string excpectedMotif = "agcgt";
            string expectedSolutionStartPosition = "3,5,1";

            char[][] charSets = new char[][] { new char[] { 'a', 'g', 't', 'a', 'g', 'c', 'g', 't', 'a', 'a' },
                                               new char[] { 't', 'g', 't', 'g', 'c', 'a', 'g', 'c', 'g', 't' },
                                               new char[] { 'a', 'a', 'g', 'c', 'g', 't', 't', 'a', 'c', 'c' } };
            char[] alphabet        = new char[] { 'a', 'c', 'g', 't' };
            int    substringLength = 5;
            RegulatoryMotifsSubSequencesEnumeration enumeration = new RegulatoryMotifsSubSequencesEnumeration(charSets, alphabet, substringLength)
            {
                StatisticAccumulator = new FakeRegulatoryMotifsStatisticAccumulator()
            };

            // act
            enumeration.Execute();
            // assert
            string solutionStartPosition = string.Join(",", enumeration.SolutionStartPosition);
            string motifAsString         = string.Join("", enumeration.Motif);

            Assert.AreEqual(motifAsString, excpectedMotif, $"Motif is wrong.");
            Assert.AreEqual(solutionStartPosition, expectedSolutionStartPosition, $"Positions are wrong.");
        }
예제 #5
0
        public void ProcessInputDataBuAdditionTestLength7Number3Pattern4Step987()
        {
            // arrange
            int  patternLength      = 4;
            int  acceptibleDistance = 0;
            bool isOptimizitaion    = false;
            bool isSumAsCriteria    = false;
            bool isAllResult        = true;
            int  step                 = 987987;
            int  numberOfSequence     = 3;
            int  sequenceLength       = 7;
            var  sequenceLengthes     = string.Join(",", Enumerable.Repeat(sequenceLength, numberOfSequence));
            var  statisticAccumulator = new RegulatoryMotifsStatisticAccumulator(new RegulatoryMotifSaver(), patternLength, sequenceLengthes,
                                                                                 isOptimizitaion, isSumAsCriteria, isAllResult, acceptibleDistance, bufferSize: 10000);

            statisticAccumulator.Delete("RegulatoryMotifsSubSequencesEnumeration");
            char[] alphabet         = new char[] { 'a', 'c', 'g', 't' };
            long   max              = 1L << 42; //Convert.ToInt64(Math.Pow(4,21));
            long   sequenceAsNumber = 0;
            int    size             = numberOfSequence * sequenceLength;

            int[]  sequence     = new int[size];
            char[] charSequence = new char[size];
            long[] masks        = new long [size];

            long mask = 3;

            for (int i = 0; i < size; i++)
            {
                masks[i] = mask;
                mask   <<= 2;
            }
            // act
            while (sequenceAsNumber < max)
            {
                int shift = 0;
                for (int i = 0; i < size; i++)
                {
                    sequence[i] = (int)((sequenceAsNumber & masks[i]) >> shift);
                    shift      += 2;
                }
                sequenceAsNumber += step;
                charSequence      = sequence.Select(j => alphabet[j]).ToArray();
                char[][] charSets = Enumerable.Range(0, numberOfSequence).Select(i => Enumerable.Range(0, sequenceLength).Select(j => charSequence[j * numberOfSequence + i]).ToArray()).ToArray();
                RegulatoryMotifsSubSequencesEnumeration enumeration = new RegulatoryMotifsSubSequencesEnumeration(charSets, alphabet, patternLength, pIsAllResult: false, pIsOptimizitaion: isOptimizitaion, pIsSumAsCriteria: isSumAsCriteria, pAcceptibleDistance: acceptibleDistance)
                {
                    StatisticAccumulator = statisticAccumulator
                };
                // act
                enumeration.Execute();
            }

            // assert
        }
예제 #6
0
        //--------------------------------------------------------------------------------------
        protected override bool MakeAction()
        {
            if (_fCurrentPosition == _fSize - 1 && --_stepCounter == 0)
            {
                var      currentSequence = _fCurrentSet.Select(i => _charSet[i]).ToList();
                char[][] charSets_       = Enumerable.Range(0, _numberOfSequence).Select(i => currentSequence.Skip(i * _sequenceLength).Take(_sequenceLength).ToArray()).ToArray();
                int[][]  indecies        = Enumerable.Range(0, _numberOfSequence).Select(i => Enumerable.Range(0, _sequenceLength).Select(j => j * _numberOfSequence + i).ToArray()).ToArray();
                char[][] charSets        = Enumerable.Range(0, _numberOfSequence).Select(i => Enumerable.Range(0, _sequenceLength).Select(j => currentSequence[j * _numberOfSequence + i]).ToArray()).ToArray();
                RegulatoryMotifsSubSequencesEnumeration enumeration = new RegulatoryMotifsSubSequencesEnumeration(charSets, _charSet, _patternLength, pIsAllResult: false, pIsOptimizitaion: _isOptimizitaion, pIsSumAsCriteria: _isSumAsCriteria, pAcceptibleDistance: _acceptibleDistance)
                {
                    StatisticAccumulator = _statisticAccumulator
                };
                // act
                enumeration.Execute();
                // assert

                //                _result.Add(string.Join(",", _fCurrentSet.Select(t => t.ToString())));
                _stepCounter = _step;
            }

            return(false);
        }
예제 #7
0
        public void ExecuteTestCasepNotAllResultOptimizationSumAsCriteriaExpexted351()
        {
            // arrange
            string excpectedMotif1 = "agcgt";
            string excpectedMotif2 = "cgtaa";
            string expectedSolutionStartPosition1 = "3,5,1";
            string expectedSolutionStartPosition2 = "5,0,3";
            int    expectedResult = 2;

            char[][] charSets = new char[][] {
                new char[] { 'a', 'g', 't', 'a', 'g', 'c', 'g', 't', 'a', 'a' },
                new char[] { 'c', 'g', 't', 'g', 'c', 'a', 'g', 't', 'g', 't' },
                new char[] { 'a', 'a', 't', 'c', 'g', 't', 'a', 'a', 'c', 'c' }
            };
            char[] alphabet        = new char[] { 'a', 'c', 'g', 't' };
            int    substringLength = 5;
            RegulatoryMotifsSubSequencesEnumeration enumeration = new RegulatoryMotifsSubSequencesEnumeration(charSets, alphabet, substringLength, pIsAllResult: true, pIsOptimizitaion: true, pIsSumAsCriteria: true)
            {
                StatisticAccumulator = new FakeRegulatoryMotifsStatisticAccumulator()
            };

            // act
            // cgtaa
            // cgtgc
            // cgtaa
            enumeration.Execute();
            // assert
            string        solutionStartPosition  = string.Join(",", enumeration.SolutionStartPosition);
            string        motifAsString          = string.Join("", enumeration.Motif);
            List <string> solutionStartPositions = enumeration.SolutionStartPositionList.Select(s => string.Join(",", s)).ToList();
            List <string> motifsAsString         = enumeration.ListOfMotif.Select(m => string.Join("", m)).ToList();

            Assert.IsTrue(motifsAsString.Any(m => m == excpectedMotif1), $"Motif1 is absent.");
            Assert.IsTrue(motifsAsString.Any(m => m == excpectedMotif2), $"Motif2 is absent.");
            Assert.IsTrue(solutionStartPositions.Any(p => p == expectedSolutionStartPosition1), $"Positions1 is absent.");
            Assert.IsTrue(solutionStartPositions.Any(p => p == expectedSolutionStartPosition2), $"Positions2 is absent.");
            Assert.AreEqual(enumeration.OptimalValue, expectedResult, $"Result is wrong.");
            Assert.AreEqual(enumeration.SolutionStartPositionList.Count, 2, $"Wrong number of solutions.");
        }
예제 #8
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // arrange
            string excpectedMotif = "agcgt";
            string expectedSolutionStartPosition = "3,5,1";
            int    expectedResult = 5;

            char[][] charSets = new char[][] { new char[] { 'a', 'g', 't', 'a', 'g', 'c', 'g', 't', 'a', 'a' },
                                               new char[] { 't', 'g', 't', 'g', 'c', 'a', 'g', 'c', 'g', 't' },
                                               new char[] { 'a', 'a', 'g', 'c', 'g', 't', 't', 'a', 'c', 'c' } };
            char[] alphabet        = new char[] { 'a', 'c', 'g', 't' };
            int    substringLength = 5;
            RegulatoryMotifsSubSequencesEnumeration enumeration = new RegulatoryMotifsSubSequencesEnumeration(charSets, alphabet, substringLength)
            {
                StatisticAccumulator = new FakeRegulatoryMotifsStatisticAccumulator()
            };

            // act
            enumeration.Execute();
            // assert
            string solutionStartPosition = string.Join(",", enumeration.SolutionStartPositionList);
            string motif = string.Join("", enumeration.Motif);

            if (motif != excpectedMotif)
            {
                MessageBox.Show($"Motif is wrong.");
            }
            if (solutionStartPosition != expectedSolutionStartPosition)
            {
                MessageBox.Show($"Positions are wrong.");
            }
            if (enumeration.OptimalValue != expectedResult)
            {
                MessageBox.Show($"Result is wrong.");
            }
        }