public void TestMatchIncrement() { Sequence seq = new Sequence(AlphabetType.DNA, "actgactg"); Composition composition = new Composition( "Composition", AlphabetType.DNA, 1, 7, 1.7, Composition.MatchMode.ALL, 0.0 ); Match match; match = composition.Match(seq, 1); Assert.AreEqual(1, match.Length); Assert.AreEqual(0, composition.Increment); Assert.AreEqual("a", match.Letters()); match = composition.Match(seq, 1); Assert.AreEqual(3, match.Length); Assert.AreEqual(0, composition.Increment); Assert.AreEqual("act", match.Letters()); match = composition.Match(seq, 1); Assert.AreEqual(4, match.Length); Assert.AreEqual(0, composition.Increment); Assert.AreEqual("actg", match.Letters()); match = composition.Match(seq, 1); Assert.AreEqual(6, match.Length); Assert.AreEqual(0, composition.Increment); Assert.AreEqual("actgac", match.Letters()); match = composition.Match(seq, 1); Assert.AreEqual(7, match.Length); Assert.AreEqual(1, composition.Increment); Assert.AreEqual("actgact", match.Letters()); }
/** Test the constructor */ public void TestConstructor1() { Composition composition = new Composition("Composition", AlphabetType.DNA, 1, 3, 3.14, Composition.MatchMode.ALL, 0.7); Assert.AreEqual("Composition", composition.Name); Assert.AreEqual(Composition.MatchMode.ALL, composition.Mode); Assert.AreEqual(1, composition.MinLength); Assert.AreEqual(3, composition.MaxLength); Assert.AreEqual(3.14, composition.IncLength); Assert.AreEqual(0.7, composition.Threshold); }
/** Test the setter for the default weight */ public void TestDefaultWeight() { Composition composition = new Composition( "Composition", AlphabetType.DNA, 1, 3, 1, Composition.MatchMode.ALL, 0.0 ); composition.DefaultWeight = (7.0); Assert.AreEqual(7.0, composition.MaxWeight); Assert.AreEqual(7.0, composition.MinWeight); composition.Add('c', 3.0); Assert.AreEqual(7.0, composition.MaxWeight); Assert.AreEqual(3.0, composition.MinWeight); }
/** Tests the adding of symbols to the composition */ public void TestAdd() { Composition composition = new Composition( "Composition", AlphabetType.DNA, 1, 3, 1, Composition.MatchMode.ALL, 0.0 ); composition.Add('a', 1.0); composition.Add('c', 3.0); composition.Add('t', 4.0); composition.Add('g', 2.0); composition.DefaultWeight = (3.5); Assert.AreEqual(4.0, composition.MaxWeight); Assert.AreEqual(1.0, composition.MinWeight); Assert.AreEqual(1.0, composition.Weight('a')); Assert.AreEqual(3.0, composition.Weight('c')); Assert.AreEqual(4.0, composition.Weight('t')); Assert.AreEqual(2.0, composition.Weight('g')); Assert.AreEqual(3.5, composition.Weight('u')); }
/// <summary> /// Main constructor for building matcher implementation on our composition pattern. /// </summary> /// <param name="composition">Composition which the matcher sits on.</param> public MatcherBest(Composition composition) { Composition = composition; }
/// <summary> /// Constructor for inner class Match All /// </summary> /// <param name="composition"></param> public MatcherAll(Composition composition) { Composition = composition; Counter = 0; }
/// <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; }
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()); }