public void TestMatch1 () {
			Sequence seq = new Sequence( AlphabetType.DNA, "taaacc" );
			SeriesAll series = new SeriesAll();
			FeatureList matches;

			series.Add( new Motif( "motif1", AlphabetType.DNA, "aa", 0.5 ) );

			matches = seq.Search( 1, seq.Length, series );
			Assert.AreEqual( 4, matches.Count );
			Assert.AreEqual( "ta", matches[ 0 ].Letters() ); //There might be some error with data structure
			Assert.AreEqual( 1, matches[ 0 ].Start );
			Assert.AreEqual( "aa", matches[ 1 ].Letters() );
			Assert.AreEqual( 2, matches[ 1 ].Start );
			Assert.AreEqual( "aa", matches[ 2 ].Letters() );
			Assert.AreEqual( 3, matches[ 2 ].Start );
			Assert.AreEqual( "ac", matches[ 3 ].Letters() );
			Assert.AreEqual( 4, matches[ 3 ].Start );

			series.Add( new Gap( "gap1", 1, 2, 1 ) );
			series.Add( new Motif( "motif2", AlphabetType.DNA, "cc", 0.5 ) );
			matches = seq.Search( 1, seq.Length, series );
			Assert.AreEqual( 3, matches.Count() );
			Assert.AreEqual( "taaac", matches[ 0 ].Letters() );
			Assert.AreEqual( 0.666, ( (Match) matches[ 0 ] ).Similarity, 1e-3 );
			Assert.AreEqual( "taaacc", matches[ 1 ].Letters() );
			Assert.AreEqual( 0.833, ( (Match) matches[ 1 ] ).Similarity, 1e-3 );
			Assert.AreEqual( "aaacc", matches[ 2 ].Letters() );
			Assert.AreEqual( 1.000, ( (Match) matches[ 2 ] ).Similarity, 1e-3 );
		}
        public void TestMatch()
        {
            Sequence seq = new Sequence(AlphabetType.DNA, "acctccgg");
            RegularExp regx = new RegularExp("test","ctc.");
            Match myMatch = regx.Match(seq, 1);

            Assert.AreEqual(null, myMatch);

            myMatch = regx.Match(seq, 3);
            Assert.AreEqual(3, myMatch.Start);
            Assert.AreEqual(4, myMatch.Length);
            Assert.AreEqual(1, myMatch.Strand);
            Assert.AreEqual(1.0, myMatch.Similarity, 1e-2);

            regx = new RegularExp("test", "acc");
            myMatch = regx.Match(seq, 1);
            Assert.AreEqual(1, myMatch.Start);

            regx = new RegularExp("test", "cgg");
            myMatch = regx.Match(seq, 6);
            Assert.AreEqual(8, myMatch.End);

            //last test
            
            //ISSUE: could be star problem
            regx = new RegularExp("test", "c.*g");
            FeatureList matches = seq.Search(0, 0, regx);
            Assert.AreEqual(4, matches.Count);
            Assert.AreEqual("cctccgg", matches[0].Letters());
            Assert.AreEqual("ctccgg", matches[1].Letters());
            Assert.AreEqual("ccgg", matches[2].Letters());
            Assert.AreEqual("cgg", matches[3].Letters());


        }
		/** Tests the match method of a sequence of patterns */
		public void TestMatch1 () {
			Sequence seq = new Sequence( AlphabetType.DNA, "baaacc" );
			ProfileAll pf = new ProfileAll();
			Motif motif;
			ProfileElement element;
			FeatureList matches;

			motif = new Motif( "motif1", AlphabetType.DNA, "aa", 0.5 );
			element = pf.Add( motif );
			matches = seq.Search( 1, seq.Length, pf );
			Assert.AreEqual( 4, matches.Count );
			Assert.AreEqual( "ba", matches[ 0 ].Letters() );
			Assert.AreEqual( 1, matches[ 0 ].Start );
			Assert.AreEqual( "aa", matches[ 1 ].Letters() );
			Assert.AreEqual( 2, matches[ 1 ].Start );
			Assert.AreEqual( "aa", matches[ 2 ].Letters() );
			Assert.AreEqual( 3, matches[ 2 ].Start );
			Assert.AreEqual( "ac", matches[ 3 ].Letters() );
			Assert.AreEqual( 4, matches[ 3 ].Start );

			motif = new Motif( "motif2", AlphabetType.DNA, "acc", 0.5 );
			element = pf.Add( element, ProfileElement.AlignmentType.END, 0, 1, motif );
			matches = seq.Search( 1, seq.Length, pf );
			Assert.AreEqual( 3, matches.Count );
			Assert.AreEqual( "baaac", matches[ 0 ].Letters() );
			Assert.AreEqual( 1, matches[ 0 ].Start );
			Assert.AreEqual( "baaacc", matches[ 1 ].Letters() );
			Assert.AreEqual( 1, matches[ 1 ].Start );
			Assert.AreEqual( "aaacc", matches[ 2 ].Letters() );
			Assert.AreEqual( 2, matches[ 2 ].Start );


			motif = new Motif( "motif3", AlphabetType.DNA, "cc", 1.0 );
			element = pf.Add( element, ProfileElement.AlignmentType.END, -2, 1, motif );
			matches = seq.Search( 1, seq.Length, pf );
			Assert.AreEqual( 3, matches.Count );
			Assert.AreEqual( "baaacc", matches[ 0 ].Letters() );
			Assert.AreEqual( 1, matches[ 0 ].Start );
			Assert.AreEqual( "baaacc", matches[ 1 ].Letters() );
			Assert.AreEqual( 1, matches[ 1 ].Start );
			Assert.AreEqual( "aaacc", matches[ 2 ].Letters() );
			Assert.AreEqual( 2, matches[ 2 ].Start );
		}
		/** Tests the calc. of increments */
		public void TestGetIncrement () {
			Sequence seq = new Sequence( AlphabetType.DNA, "aggtccagtccagcgt" );
			Profile profile = new ProfileAll();
			profile.Add( new RegularExp( "regex1", "ag" ) );
			profile.Add( -1, 1, new RegularExp( "regex2", "gt" ) );
			FeatureList matches = seq.Search( 0, 0, profile );
			Assert.AreEqual( 3, matches.Count );
			Assert.AreEqual( "aggt", matches[0].Letters() );
			Assert.AreEqual( "agt", matches[1].Letters() );
			Assert.AreEqual( "agcgt", matches[2].Letters() );
		}
        public void TestTest()
        {
            Sequence seq = new Sequence(AlphabetType.DNA, "acctccctcccgacgg");
            RegularExp regx = new RegularExp("test","ctc.");

            Match myMatch = regx.Match(seq, 3);

            Assert.IsNotNull(myMatch);

            FeatureList matches = seq.Search(0, 0, regx);
            Assert.IsNotNull(matches);
        }
		/** Tests the match method of a series of patterns with a weighted gap */
		public void TestMatchWeightedGap () {
			Sequence seq = new Sequence( AlphabetType.DNA, "taaacc" );
			SeriesAll series = new SeriesAll();

			series.Add( new Motif( "motif1", AlphabetType.DNA, "ta", 1.0 ) );
			series.Add( new Gap( "gap", 1, 2, 1, new double[] { 0, 1 }, 0.0 ) );
			series.Add( new Motif( "motif2", AlphabetType.DNA, "cc", 0.5 ) );
			FeatureList matches = seq.Search( 1, seq.Length, series );
			Assert.AreEqual( "taaac", matches[ 0 ].Letters() );
			Assert.AreEqual( 0.500, ( (Match) matches[ 0 ] ).Similarity, 1e-3 );
			Assert.AreEqual( "taaacc", matches[ 1 ].Letters() );
			Assert.AreEqual( 1.000, ( (Match) matches[ 1 ] ).Similarity, 1e-3 );
		}
		public void TestMatch () {
			Gap gap = new Gap( "test", 0, 3, 1 );
			Sequence seq = new Sequence( AlphabetType.DNA, "act" );
			FeatureList matches = seq.Search( 0, 0, gap );
			Assert.AreEqual( 9, matches.Count );
			Assert.AreEqual( "", matches[ 0 ].Letters() );
			Assert.AreEqual( "a", matches[ 1 ].Letters() );
			Assert.AreEqual( "ac", matches[ 2 ].Letters() );
			Assert.AreEqual( "act", matches[ 3 ].Letters() );
			Assert.AreEqual( "", matches[ 4 ].Letters() );
			Assert.AreEqual( "c", matches[ 5 ].Letters() );
			Assert.AreEqual( "ct", matches[ 6 ].Letters() );
			Assert.AreEqual( "", matches[ 7 ].Letters() );
			Assert.AreEqual( "t", matches[ 8 ].Letters() );
		}
		/** Tests if the match method finds the best pattern */
		public void TestMatch1 () {
			Sequence seq = new Sequence( AlphabetType.DNA, "taaacc" );
			SetBest set = new SetBest( "set1", 0.5 );
			set.Add( new Motif( "motif1", AlphabetType.DNA, "taa", 0.0 ) );
			set.Add( new Motif( "motif2", AlphabetType.DNA, "aacc", 0.0 ) );
			FeatureList matches;

			matches = seq.Search( 1, seq.Length, set );
			Assert.AreEqual( 3, matches.Count );
			Assert.AreEqual( "taa", matches[ 0 ].Letters() );
			Assert.AreEqual( 1.00, ( (Match) matches[ 0 ] ).Similarity, 1e-2 );
			Assert.AreEqual( "aaac", matches[ 1 ].Letters() );
			Assert.AreEqual( 0.75, ( (Match) matches[ 1 ] ).Similarity, 1e-2 );
			Assert.AreEqual( "aacc", matches[ 2 ].Letters() );
			Assert.AreEqual( 1.00, ( (Match) matches[ 2 ] ).Similarity, 1e-2 );
		}
        public void TestMatch()
        {
            Alphabet alphabet = DnaAlphabet.Instance();
            Sequence seq = new Sequence(AlphabetType.DNA, "acctccgg");
            Prosite prosite = new Prosite("c-t-c-x.", alphabet);
            Match match = prosite.Match(seq, 1);
            Assert.AreEqual(null, match);

            match = prosite.Match(seq, 3);
            Assert.AreEqual(3, match.Start);
            Assert.AreEqual(4, match.Length);
            Assert.AreEqual(1, match.Strand);
            Assert.AreEqual(1.0, match.Similarity, 1e-2);


            prosite = new Prosite("a-c-c.", alphabet);
            match = prosite.Match(seq, 1);
            Assert.AreEqual(1, match.Start);

            prosite = new Prosite("<a-c-c.", alphabet);
            match = prosite.Match(seq, 3);
            Assert.AreEqual(null, match);

            prosite = new Prosite("c-g-g.", alphabet);
            match = prosite.Match(seq, 6);
            Assert.AreEqual(8, match.End);

            prosite = new Prosite("c-y-y-c.", alphabet);
            Assert.IsNotNull(prosite.Match(seq, 2));

            prosite = new Prosite("c-{d}-c.", alphabet);
            //Assert.IsNotNull(prosite.Match(seq, 1)); //<-- not sure why this pattern wont work

            prosite = new Prosite("c-x(0,2)-g.", alphabet);
            FeatureList matches = seq.Search(0, 0, prosite);
            Assert.AreEqual(2, matches.Count);
            Assert.AreEqual("ccgg", matches[0].Letters());
            Assert.AreEqual("cgg", matches[1].Letters());
  
        }
		/** Tests if the match method finds the best pattern */
		public void TestMatch5 () {
			Sequence seq = new Sequence( AlphabetType.DNA, "taaacc" );
			SeriesBest series = new SeriesBest();
			FeatureList matches;

			series.Add( new Motif( "motif1", AlphabetType.DNA, "aa", 0.5 ) );
			series.Add( new Gap( "gap", 1, 3, 1 ) );
			series.Add( new Motif( "motif2", AlphabetType.DNA, "cc", 0.5 ) );
			matches = seq.Search( 1, seq.Length, series );
			Assert.AreEqual( 2, matches.Count );
			Assert.AreEqual( "taaacc", matches[ 0 ].Letters() );
			Assert.AreEqual( 0.833, ( (Match) matches[ 0 ] ).Similarity, 1e-3 );
			Assert.AreEqual( "aaacc", matches[ 1 ].Letters() );
			Assert.AreEqual( 1.000, ( (Match) matches[ 1 ] ).Similarity, 1e-3 );
		}
        public void TestStructuredPattern_Logic()
        {
            BiopatMLFilePath = "BioPaperTestData/StructuredPattern/Logic.xml";

            Sequence nuclearLocalizationSignal = new Sequence(AlphabetType.RNA, "LLLGLLLLLGLLLLLLLLGLLGGLLLLLGLLLGR");

			MyPatterns = DefinitionIO.Read( Global.GetResourceReader(   BiopatMLFilePath ) );

			FeatureList Matches = nuclearLocalizationSignal.Search( 1, nuclearLocalizationSignal.Length, MyPatterns.Pattern );

            //There should be 9 matches
            Assert.AreEqual(9, Matches.Count);

            Match matched = (Match)Matches[0];
            Assert.AreEqual("nngnnnnngnnnnnn", matched.Letters());

            matched = (Match)Matches[8];
            Assert.AreEqual("nngnnggnnnnngnn", matched.Letters());
        }
		/** Tests the match method for a pattern which matches all the time */
		public void TestMatch5 () {
			Sequence seq = new Sequence( AlphabetType.DNA, "bacgt" );
			ProfileAll pf = new ProfileAll();
			Motif motif;
			FeatureList matches;

			motif = new Motif( "motif1", AlphabetType.DNA, "aa", 0.0 );
			pf.Add( motif );

			matches = seq.Search( 1, seq.Length, pf );
			Assert.AreEqual( 4, matches.Count );
			Assert.AreEqual( "ba", matches[ 0 ].Letters() );
			Assert.AreEqual( 1, matches[ 0 ].Start );
			Assert.AreEqual( "ac", matches[ 1 ].Letters() );
			Assert.AreEqual( 2, matches[ 1 ].Start );
		}
        public void TestStructuredPattern_Iteration()
        {
            BiopatMLFilePath = "BioPaperTestData/StructuredPattern/Iteration.xml";

            Sequence seq = new Sequence(AlphabetType.DNA, "TTGAGAGATTTGCGCATC");
			MyPatterns = DefinitionIO.Read( Global.GetResourceReader(   BiopatMLFilePath ) );

			FeatureList Matches = seq.Search( 1, seq.Length, MyPatterns.Pattern );

            //There should be 3 matches
            //In this scenario only GAGA or GAGAGA is acceptable.
            Assert.AreEqual(2, Matches.Count);

            Match matched = (Match)Matches[0];
            Assert.AreEqual("gagaga", matched.Letters());

            matched = (Match)Matches[1];
            Assert.AreEqual("gaga", matched.Letters());
        }
		/** Tests the matching  */
		public void TestMatch () {
			PWM pwm = new PWM( "test", alpha, 0.5 );
			pwm.Add( 'a', "1 0 1 0" );
			pwm.Add( 'c', "0 1 0 1" );
			Sequence seq = new Sequence( AlphabetType.DNA, "aaaacac" );
			FeatureList matches = seq.Search( 0, 0, pwm );
			Assert.AreEqual( 3, matches.Count );
			Assert.AreEqual( "aaaa", matches[ 0 ].Letters() );
			Assert.AreEqual( 0.5, ( (Match) matches[ 0 ] ).Similarity, 1e-3 );
			Assert.AreEqual( "aaac", matches[ 1 ].Letters() );
			Assert.AreEqual( 0.75, ( (Match) matches[ 1 ] ).Similarity, 1e-3 );
			Assert.AreEqual( "acac", matches[ 2 ].Letters() );
			Assert.AreEqual( 1.0, ( (Match) matches[ 2 ] ).Similarity, 1e-3 );
		}
		public void TestMotifPattern_Prosite () {
			BiopatMLFilePath = "BioPaperTestData/MotifPattern/Prosite.xml";

			Sequence dnaZincFinger = new Sequence( AlphabetType.AA, "ccccccaaaaaaccccccccactcttccccccccccctctctcccgcgctcacctggctcccccccccaatccgc" );

			MyPatterns = DefinitionIO.Read( Global.GetResourceReader( BiopatMLFilePath ) );

			FeatureList Matches = dnaZincFinger.Search( SearchPosition, dnaZincFinger.Length, MyPatterns.Pattern );

			//There should be 7 matches
			Assert.AreEqual( 7, Matches.Count );
			Assert.AreEqual( "Leucine-zipper", Matches.Name );

			Match matched = (Match) Matches[4];

			Assert.AreEqual( 27, matched.Start );
			Assert.AreEqual( 54, matched.End );
			Assert.AreEqual( "CCCCCCCCCCCTCTCTCCCGCGCTCACC", matched.Letters() );

			matched = (Match) Matches[5];

			Assert.AreEqual( 34, matched.Start );
			Assert.AreEqual( 61, matched.End );
			Assert.AreEqual( "CCCCTCTCTCCCGCGCTCACCTGGCTCC", matched.Letters() );

			matched = (Match) Matches[6];
			Assert.AreEqual( 41, matched.Start );
			Assert.AreEqual( 68, matched.End );
			Assert.AreEqual( "CTCCCGCGCTCACCTGGCTCCCCCCCCC", matched.Letters() );
		}
		public void TestMotifPattern_RegularEx () {
			BiopatMLFilePath = "BioPaperTestData/MotifPattern/Regex.xml";

			Sequence dnaZincFinger = new Sequence( AlphabetType.AA, "ccccccaaaaaaccccccccactcttccccccccccctctctcccgcgctcacctggctcccccccccaatccgc" );

			MyPatterns = DefinitionIO.Read( Global.GetResourceReader( BiopatMLFilePath ) );

			FeatureList Matches = dnaZincFinger.Search( SearchPosition, dnaZincFinger.Length, MyPatterns.Pattern );

			//There should be 7 matches
			Assert.AreEqual( 7, Matches.Count );
			Assert.AreEqual( "C6 zinc-finger", Matches.Name );

			Match matched = (Match) Matches[0];

			Assert.AreEqual( 3, matched.Start );
			Assert.AreEqual( 27, matched.Length );
			Assert.AreEqual( 29, matched.End );
			Assert.AreEqual( "CCCCAAAAAACCCCCCCCACTCTTCCC", matched.Letters() );

			matched = (Match) Matches[1];

			Assert.AreEqual( 14, matched.Start );
			Assert.AreEqual( 28, matched.Length );
			Assert.AreEqual( 41, matched.End );
			Assert.AreEqual( "CCCCCCCACTCTTCCCCCCCCCCCTCTC", matched.Letters() );

			matched = (Match) Matches[2];
			Assert.AreEqual( "CCCCACTCTTCCCCCCCCCCCTCTCTCC", matched.Letters() );

			matched = (Match) Matches[3];
			Assert.AreEqual( "CTTCCCCCCCCCCCTCTCTCCCGCGCTC", matched.Letters() );
		}
        /** 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());
        }
        public void TestStructuredPattern_SeriesBest()
        {
            BiopatMLFilePath = "BioPaperTestData/StructuredPattern/SeriesBest.xml";

            Sequence sigma70Promoter = new Sequence(AlphabetType.DNA, "ttgagggggttaccatgatcggtattgtttaatattgacatttaagccgttaagctgaagtgataattaggc");

			MyPatterns = DefinitionIO.Read( Global.GetResourceReader(   BiopatMLFilePath ) );

			FeatureList Matches = sigma70Promoter.Search( 1, sigma70Promoter.Length, MyPatterns.Pattern );

            //There should be 1 matches
            Assert.AreEqual(2, Matches.Count);
            Assert.AreEqual("canonical sigma70-promoter", Matches.Name);

            Match matched = (Match)Matches[0];

            //The overall matched
            Assert.AreEqual("ttgagggggttaccatgatcggtattgtttaat", matched.Letters());
            Assert.AreEqual(0.75, matched.Similarity);
            //Check sigma 35
            Assert.AreEqual("ttgagg", matched.SubMatches[0].Letters());
            //Check sigma 10
            Assert.AreEqual("tttaat", matched.SubMatches[2].Letters());

            matched = (Match)Matches[1];
            Assert.AreEqual("ttgacatttaagccgttaagctgaagtgataat", matched.Letters());
            Assert.AreEqual(0.91, matched.Similarity, 1e-2);
        }
		/** Tests the match method for a hierarchical pattern */
		public void TestMatch3 () {
			Sequence seq = new Sequence( AlphabetType.DNA, "baaacc" );
			ProfileAll pf1 = new ProfileAll();
			ProfileAll pf2 = new ProfileAll();
			Motif motif;
			ProfileElement element;
			FeatureList matches;

			motif = new Motif( "motif1", AlphabetType.DNA, "aa", 1.0 );
			element = pf1.Add( motif );
			motif = new Motif( "motif2", AlphabetType.DNA, "aa", 1.0 );
			element = pf1.Add( element, ProfileElement.AlignmentType.START, 0, 1, motif );
			matches = seq.Search( 1, seq.Length, pf1 );
			Assert.AreEqual( 3, matches.Count );
			Assert.AreEqual( "aa", matches[ 0 ].Letters() );
			Assert.AreEqual( "aaa", matches[ 1 ].Letters() );
			Assert.AreEqual( "aa", matches[ 2 ].Letters() );

			motif = new Motif( "motif3", AlphabetType.DNA, "aa", 1.0 );
			element = pf2.Add( motif );
			motif = new Motif( "motif4", AlphabetType.DNA, "cc", 1.0 );
			element = pf2.Add( element, ProfileElement.AlignmentType.CENTER, 0, 2, motif );
			matches = seq.Search( 1, seq.Length, pf2 );
			Assert.AreEqual( 2, matches.Count );
			Assert.AreEqual( "aaacc", matches[ 0 ].Letters() );
			Assert.AreEqual( "aacc", matches[ 1 ].Letters() );

			pf1.Add( pf1[0], ProfileElement.AlignmentType.END, -1, 0, pf2 );
			pf2.Threshold = ( 1.0 );
			matches = seq.Search( 1, seq.Length, pf1 );
			Assert.AreEqual( 2, matches.Count );
			Assert.AreEqual( "aaacc", matches[ 0 ].Letters() );
			Assert.AreEqual( "aaacc", matches[ 1 ].Letters() );
		}
		/** Tests the match method of a series of patterns with two gaps */
		public void TestMatchTwoGaps () {
			Sequence seq = new Sequence( AlphabetType.DNA, "taaaagccc" );
			SeriesAll series = new SeriesAll();

			series.Add( new Motif( "motif1", AlphabetType.DNA, "ta", 1.0 ) );
			series.Add( new Gap( "gap1", 1, 2, 1 ) );
			series.Add( new Motif( "motif2", AlphabetType.DNA, "aa", 0.5 ) );
			series.Add( new Gap( "gap2", 1, 2, 1 ) );
			series.Add( new Motif( "motif3", AlphabetType.DNA, "cc", 1.0 ) );
			FeatureList matches = seq.Search( 1, seq.Length, series );
			Assert.AreEqual( 3, matches.Count );
			Assert.AreEqual( "taaaagcc", matches[0].Letters() );
			Assert.AreEqual( 1.0, ( (Match) matches[0] ).Similarity, 1e-1 );
			Assert.AreEqual( "taaaagccc", matches[1].Letters() );
			Assert.AreEqual( 1.0, ( (Match) matches[1] ).Similarity, 1e-1 );
			Assert.AreEqual( "taaaagccc", matches[2].Letters() );
			Assert.AreEqual( 0.9, ( (Match) matches[2] ).Similarity, 1e-1 );
		}
		/** Tests the match method of a series of patterns with two gaps */
		public void TestMatchSigma70 () {
			Sequence seq = new Sequence( AlphabetType.DNA, "cgagagagcg attatatcga ctaaacagaa aatgtcaaac aacttgtcaa aaaacagaag" );
			SeriesAll series = new SeriesAll();

			series.Add( new Motif( "", AlphabetType.DNA, "attata", 1.0 ) );
			series.Add( new Gap( "", 1, 200, 1 ) );
			series.Add( new Motif( "", AlphabetType.DNA, "tgtcaa", 1.0 ) );

			FeatureList matches = seq.Search( 2, seq.Length, series );
			Assert.AreEqual( 2, matches.Count );

			System.Diagnostics.Debug.WriteLine( series.ToXml().ToString() );

			//Assert.AreEqual( "taaaagcc", matches[0].Letters() );
			//Assert.AreEqual( 1.0, ( (Match) matches[0] ).Similarity, 1e-1 );
			//Assert.AreEqual( "taaaagccc", matches[1].Letters() );
			//Assert.AreEqual( 1.0, ( (Match) matches[1] ).Similarity, 1e-1 );
			//Assert.AreEqual( "taaaagccc", matches[2].Letters() );
			//Assert.AreEqual( 0.9, ( (Match) matches[2] ).Similarity, 1e-1 );
		}
		public void TestSearch () {
			Sequence seq   = new Sequence( AlphabetType.DNA, "acttacttagttaac" );
			Motif  motif = new Motif( "motif1", AlphabetType.DNA, "act", 0.5 );

			FeatureList list = seq.Search( 0, 0, motif );
			Assert.AreEqual( 3, list.Count() );
			Assert.AreEqual( 1, list[ 0 ].Start );
			Assert.AreEqual( 1.0, ( (Match) list[ 0 ] ).Similarity, 1e-1 );
			Assert.AreEqual( 5, list[ 1 ].Start );
			Assert.AreEqual( 1.0, ( (Match) list[ 1 ] ).Similarity, 1e-1 );
			Assert.AreEqual( 9, list[ 2 ].Start );
			Assert.AreEqual( 0.6, ( (Match) list[ 2 ] ).Similarity, 1e-1 );

			list = seq.Search( 11, seq.Length + 1, motif );
			Assert.AreEqual( 1, list.Count() );
			Assert.AreEqual( 14, list[ 0 ].Start );
			Assert.AreEqual( 0.6, ( (Match) list[ 0 ] ).Similarity, 1e-1 );


		}
		/** Tests the weigthed matching  */
		public void TestMatchWeighted2 () {
			Gap gap = new Gap( "test", 1, 4, 1, new double[] { 1, 5, 10 }, 0.0 );
			Sequence seq = new Sequence( AlphabetType.DNA, "act" );
			FeatureList matches = seq.Search( 0, 0, gap );
			Assert.AreEqual( 6, matches.Count );
			Assert.AreEqual( "a", matches[ 0 ].Letters() );
			Assert.AreEqual( 0.1, ( (Match) matches[ 0 ] ).Similarity, 1e-1 );
			Assert.AreEqual( "ac", matches[ 1 ].Letters() );
			Assert.AreEqual( 0.5, ( (Match) matches[ 1 ] ).Similarity, 1e-1 );
			Assert.AreEqual( "act", matches[ 2 ].Letters() );
			Assert.AreEqual( 1.0, ( (Match) matches[ 2 ] ).Similarity, 1e-1 );
			Assert.AreEqual( "c", matches[ 3 ].Letters() );
			Assert.AreEqual( 0.1, ( (Match) matches[ 3 ] ).Similarity, 1e-1 );
			Assert.AreEqual( "ct", matches[ 4 ].Letters() );
			Assert.AreEqual( 0.5, ( (Match) matches[ 4 ] ).Similarity, 1e-1 );
			Assert.AreEqual( "t", matches[ 5 ].Letters() );
			Assert.AreEqual( 0.1, ( (Match) matches[ 5 ] ).Similarity, 1e-1 );
		}
        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);
        }
        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;
        }
        public void TestStructuredPattern_SetBest()
        {
            BiopatMLFilePath = "BioPaperTestData/StructuredPattern/SetBest.xml";

            Sequence nuclearLocalizationSignal = new Sequence(AlphabetType.RNA, "RKCLQAGMNLEARKTKKRKKRKRRKRPLQMNRPLQMNR");

			MyPatterns = DefinitionIO.Read( Global.GetResourceReader(   BiopatMLFilePath ) );

			FeatureList Matches = nuclearLocalizationSignal.Search( 1, nuclearLocalizationSignal.Length, MyPatterns.Pattern );

            //There should be 1 matches
            Assert.AreEqual(1, Matches.Count);
            Assert.AreEqual("nuclear localization signal", Matches.Name);

            Match matched = (Match)Matches[0];
            Assert.AreEqual(1.0, matched.Similarity);
            Assert.AreEqual("rkkrkr", matched.Letters());
        }