/** Tests the conversion of prosite patterns to regular expressions */ public void TestConvertPattern() { Alphabet alphabet = DnaAlphabet.Instance(); Prosite prosite = new Prosite(); Assert.AreEqual("actg", prosite.Convert("actg.", alphabet).ToString()); Assert.AreEqual("[ac].[ag].{4}[^e[agt]]$", prosite.Convert("[ac]-x-r-x(4)-{ed}>.", alphabet).ToString()); Assert.AreEqual("^a.[tg]{2}.{0,1}[ag]", prosite.Convert("<a-x-[tg](2)-x(0,1)-r.", alphabet).ToString()); }
/** Tests the conversion of char to regular expressions */ public void TestConvertChar() { Alphabet alphabet = DnaAlphabet.Instance(); Prosite prosite = new Prosite(); Assert.AreEqual("a", prosite.Convert('a', alphabet)); Assert.AreEqual("[ag]", prosite.Convert('r', alphabet)); Assert.AreEqual("0", prosite.Convert('0', alphabet)); Assert.AreEqual(",", prosite.Convert(',', alphabet)); }
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()); }
/// <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; }