public void TestMatch1 () {
			Sequence seq = new Sequence( AlphabetType.DNA, "taaacc" );
			SeriesBest series = new SeriesBest();
			Match match;

			series.Add( new Motif( "Motif1", AlphabetType.DNA, "aa", 0.5 ) );
			match = seq.SearchBest( 1, seq.Length, series );
			Assert.AreEqual( "aa", match.Letters() );
			Assert.AreEqual( 2, match.Position() );
			Assert.AreEqual( 1.00, match.Similarity, 1e-2 );

			series.Add( new Gap( "Gap", 0, 2, 1 ) );
			series.Add( new Motif( "motif2", AlphabetType.DNA, "cc", 0.5 ) );
			match = seq.SearchBest( 1, seq.Length, series );
			Assert.AreEqual( "aaacc", match.Letters() );
			Assert.AreEqual( 2, match.Start );
			Assert.AreEqual( 1.00, match.Similarity, 1e-2 );
		}
		public void TestMatch2 () {
			Sequence seq = new Sequence( AlphabetType.DNA, "taaaccc" );
			SeriesBest series = new SeriesBest();
			Match match;

			series.Add( new Motif( "motif1", AlphabetType.DNA, "ta", 0.5 ) );
			series.Add( new Gap( "gap", 1, 3, 1, new double[] { 1, 2, 1 }, 0.0 ) );
			series.Add( new Motif( "motif2", AlphabetType.DNA, "cc", 0.5 ) );

			match = seq.SearchBest( 1, seq.Length, series );
			Assert.AreEqual( "taaacc", match.Letters() );
			Assert.AreEqual( 1.00, match.Similarity, 1e-2 );
		}
        public void TestMatchStart()
        {
            Sequence seq = new Sequence(AlphabetType.DNA, "atgcatgc");
            Series series = new SeriesBest("test", 1.0);
            series.Add(new Constraint("test", "START", +1));
            series.Add(new Motif("motif", AlphabetType.DNA, "nnnn", 0.0));

            Match match = series.Match(seq, 2);
            Assert.AreEqual("tgca", match.Letters());
            match = series.Match(seq, 1);
            Assert.AreEqual(null, match);

            match = seq.SearchBest(0, 0, series);
            Assert.AreEqual("tgca", match.Letters());
        }
        public void TestMatchCenter()
        {
            Sequence seq = new Sequence(AlphabetType.DNA, "atgcatg");
            Series series = new SeriesBest("test", 1.0);
            series.Add(new Constraint("test", "CENTER", -1));
            series.Add(new Motif("motif", AlphabetType.DNA, "nnnn", 1.0));

            Match match = series.Match(seq, 3);
            Assert.AreEqual("gcat", match.Letters());
            match = series.Match(seq, 2);
            Assert.AreEqual(null, match);
            match = series.Match(seq, 4);
            Assert.AreEqual(null, match);

            match = seq.SearchBest(0, 0, series);
            Assert.AreEqual("gcat", match.Letters());
        }
        /** Tests the a match for an inverted repeat pattern */
        public void TestMatchInverted()
        {
            Sequence seq = new Sequence(AlphabetType.DNA, "ttaccgtttgcaattt");
            Repeat repeat = new Repeat("repeat", motif, Repeat.RepeatType.INVERTED, 0.5);
            series.Add(repeat);

            Match match = series.Match(seq, 3);
            Assert.AreEqual(0.875, match.Similarity);

            Assert.AreEqual("accgtttgcaa", match.Letters());
            Assert.AreEqual("gcaa", match.SubMatches[2].Letters());
            Assert.AreEqual(0.75, match.SubMatches[2].Similarity);
            Assert.AreEqual(10, match.SubMatches[2].Start);
            Assert.AreEqual(4, match.SubMatches[2].Length);
            Assert.AreEqual(1, match.SubMatches[2].Strand);

            match = seq.SearchBest(0, 0, series);
            Assert.AreEqual("accgtttgcaa", match.Letters());
        }
        public List<Matched> PerformSearch(string BioPatMLContent, SequenceContract sequence)
        {
            List<Matched> matchedList = new List<Matched>();
            StringReader sr = new StringReader(BioPatMLContent);
            Definition MyPatterns = null;

            using (BioPatMLPatternReader reader = new BioPatMLPatternReader())
            {
                MyPatterns = reader.ReadBioPatML(sr);
            }

            Sequence targetSequence = new Sequence(sequence.AlphabetName, sequence.Characters);
            SequenceList matches = new FeatureList();

            IPattern MatchingPattern = MyPatterns.MainPattern;

            #region If bioPatML pattern is SeriesBest OR SetBest : Search by best

            if (MatchingPattern is SeriesBest
                    || MatchingPattern is SetBest)
            {
                Match match = targetSequence.SearchBest(0, 0, MatchingPattern);
                matches.Add(match);
            }

            #endregion

            #region Else, pattern is Motif, Any, Anchor, Prosite, RegularEx : Search by normal

            else
            //The rest
            {
                matches = targetSequence.Search(1, targetSequence.Length, MatchingPattern);
            }

            #endregion

            for (int i = 0; i < matches.Count; i++)
            {
                Match matched = matches[i] as Match;

                matchedList.Add(new Matched
                                         (matched.Similarity,
                                         matched.Start, matched.End,
                                         matched.Length, matched.Letters(), sequence.Name));
            }

            return matchedList;
        }
        /** Tests a weighted repeat */
        public void TestMatchWeighted()
        {
            Sequence seq = new Sequence(AlphabetType.DNA, "ttaccgtttaacgttt");
            Repeat repeat = new Repeat("repeat", motif, Repeat.RepeatType.DIRECT, 0.1);
            series.Add(repeat);
            repeat.Weight('a', 'a', 0.3);
            repeat.Weight('c', 'a', 1.0);
            repeat.Weight('g', 'g', 0.7);

            Match match = series.Match(seq, 3);
            Assert.AreEqual(0.75, match.Similarity);
            Assert.AreEqual("accgtttaacg", match.Letters());
            Assert.AreEqual("aacg", match.SubMatches[2].Letters());
            Assert.AreEqual(0.5, match.SubMatches[2].Similarity, 1e-3);

            match = seq.SearchBest(0, 0, series);
            Assert.AreEqual("accgtttaacg", match.Letters());
        }
        public void TestMatchSubMatches()
        {
            Sequence seq = new Sequence(AlphabetType.DNA, "tttaagaacaagttt");

            Motif motif = new Motif("motif", AlphabetType.DNA, "aag", 0.5);
            Iteration iteration = new Iteration("test", motif, 1, 3, 0.0);
            Match match = seq.SearchBest(0, 0, iteration);

            Assert.AreEqual("aag", match.Letters());
            Assert.AreEqual(10, match.Start);
            Assert.AreEqual(1.0, match.Similarity);
            Assert.AreEqual("aag", match.SubMatches[0].Letters()); //sub match to properties?

            FeatureList matches = seq.Search(0, 0, iteration);
            Assert.AreEqual(3, matches.Count);
            Assert.AreEqual("aagaacaag", matches[0].Letters());
            Assert.AreEqual(0.88, ((Match)matches[0]).Similarity, 1e-2);
            Assert.AreEqual("aacaag", matches[1].Letters());
            Assert.AreEqual(0.83, ((Match)matches[1]).Similarity, 1e-2);
            Assert.AreEqual("aag", matches[2].Letters());
            Assert.AreEqual(1.00, ((Match)matches[2]).Similarity, 1e-2);
        }
		/** Test for best match searching within a sequence */
		public void TestSearchBest () {
			Sequence seq = new Sequence( AlphabetType.DNA, "acttacttagttaatt" );
			Motif motif = new Motif( "motif1", AlphabetType.DNA, "taga", 0.0 );
			Match match = seq.SearchBest( 1, -1, motif );
			Assert.AreEqual( "tagt", match.Letters() );
			Assert.AreEqual( 8, match.Start );
			Assert.AreEqual( 4, match.Length );
			Assert.AreEqual( 0.75, match.Similarity, 1e-3 );
			motif = new Motif( "motif2", AlphabetType.DNA, "aatt", 0.0 );
			match = seq.SearchBest( 1, -1, motif );
			Assert.AreEqual( 13, match.Start );
			match = seq.SearchBest( 1, seq.Length, motif );
			Assert.AreEqual( 13, match.Start );
			match = seq.SearchBest( 1, seq.Length - 1, motif );
			Assert.AreEqual( 1, match.Start );
		}
        public void TestMatchBest()
        {
            Sequence seq = new Sequence(AlphabetType.DNA, "actcctctg");
            Composition composition = new Composition("Composition", AlphabetType.DNA, 3, 8, 1.7, Composition.MatchMode.BEST, 0.0);
            composition.Add('a', 1.0);
            composition.Add('c', 2.0);
            composition.Add('t', 3.0);
            composition.DefaultWeight = (1.0);

            Match match = composition.Match(seq, 1);
            Assert.AreEqual(1, match.Start);
            Assert.AreEqual(8, match.End);
            Assert.AreEqual("actcctct", match.Letters());
            Assert.AreEqual(0.75, match.Similarity, 1e-2);

            match = seq.SearchBest(0, 0, composition);
            Assert.AreEqual(6, match.Start);
            Assert.AreEqual("tct", match.Letters());
            Assert.AreEqual(0.88, match.Similarity, 1e-2);
        }
        /** Test for match method from pattern interface */
        public void TestMatchAll()
        {
            Sequence seq = new Sequence(AlphabetType.DNA, "act");
			Composition composition = new Composition( "Composition", AlphabetType.DNA, 2, 3, 1, Composition.MatchMode.ALL, 0.0 );
            composition.Add('a', 1.0);
            composition.Add('c', 2.0);
            composition.DefaultWeight = (3.0);
            Match match = composition.Match(seq, 1);
            Assert.AreEqual(2, match.Length);
            Assert.AreEqual(1, match.Start);
            Assert.AreEqual(2, match.End);
            Assert.AreEqual("ac", match.Letters());
            Assert.AreEqual(0.5, match.Similarity, 1e-2);

            match = seq.SearchBest(0, 0, composition);
            Assert.AreEqual(2, match.Start);
            Assert.AreEqual("ct", match.Letters());
            Assert.AreEqual(0.83, match.Similarity, 1e-2);

            FeatureList matches = seq.Search(0, 0, composition);
            Assert.AreEqual(3, matches.Count);
            Assert.AreEqual("ac", matches[0].Letters());
            Assert.AreEqual("act", matches[1].Letters());
            Assert.AreEqual("ct", matches[2].Letters());
        }