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 TestPattern()
        {
            Series series1 = new SeriesBest("Series1", 1.0);
            series1.Add(new VoidPattern("VoidPattern1"));
            series1.Add(new VoidPattern("VoidPattern2"));
            Series series2 = new SeriesBest("Series2", 1.0);
            series2.Add(new VoidPattern("VoidPattern21"));
            series2.Add(series1);

            Definition definition = new Definition("test");
            definition.Pattern = (series2);
            Assert.AreEqual("Series2", definition.Pattern.Name);
            Assert.AreEqual("VoidPattern21", definition.Patterns[1].Name);
            Assert.AreEqual("Series1", definition.Patterns[2].Name);
            Assert.AreEqual("VoidPattern1", definition.Patterns[3].Name);
            Assert.AreEqual("VoidPattern2", definition.Patterns[4].Name);
        }
        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());
        }
		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 );
		}
        /// <summary>
        /// 
        /// Reads a pattern from a starting specified node. This method
        /// recursivly calls the reading methods of the different patterns.
        /// </summary>
        /// <param name="node">Node of the pattern the reading starts with.</param>
        /// <param name="definition">Pattern definition which pattern list will be extended 
        /// with the pattern and all its sub-patterns read.
        /// </param>
        /// <returns>The read pattern or null if there is no pattern to read.</returns>
        /// <exception cref="System.SystemException">Thrown when unknown pattern was found</exception>
        public static IPattern ReadPattern
                    (XmlNode node, Definition definition)
        {
            while (node != null
                    && node.NodeType != XmlNodeType.Element)

                node = node.NextSibling; //Iterate thru the list of nodes until it is an element

            IPattern pattern = null;
            String mode = XMLHelper.GetAttrValueString(node, "mode");

            switch (node.Name)
            {
                case "Any":
                    pattern = new Any();
                    break;

                case "Alignment":
                    pattern = new Alignment();
                    break;

                case "Composition" :
                    pattern = new Composition();
                    break;

                case "Constraint":
                    pattern = new Constraint();
                    break;

                case "Iteration":
                    pattern = new Iteration();
                    break;

                case "Logic":
                    pattern = new Logic();
                    break;

                case "Motif":
                    pattern = new Motif();
                    break;

                case "PWM":
                    pattern = new PWM();
                    break;

                case "Regex":
                    pattern = new RegularExp();
                    break;

                case "Prosite":
                    pattern = new Prosite();
                    break;

                case "Block":
                    pattern = new Block();
                    break;

                case "Gap":
                    pattern = new Gap();
                    break;

                case "Repeat":
                    pattern = new Repeat();
                    break;

                case "Series":
                    pattern = mode.Equals("ALL") ? 
                        pattern = new SeriesAll() : pattern = new SeriesBest();
                    break;

                case "Set":
                    pattern = mode.Equals("ALL") ?
                       pattern = new SetAll() : pattern = new SetBest();
                    break;

                case "Void":
                    pattern = new VoidPattern();
                    break;

                case "Use":
                    pattern = new Use();
                    break;

                throw new SystemException
                    ("Unknown pattern found: " + node.Name);
 
            }

 
            pattern.ReadNode(node, definition);      // read the node data and initialize the pattern
            definition.Patterns.Add
                            (0, pattern); //Always adding the element to last index
 
            return pattern;
        }
		/** 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 );
		}