public void TestMotifPattern_Motif () {
			BiopatMLFilePath = "BioPaperTestData/MotifPattern/Motif.xml";

			using ( BioPatMBF_Reader gbReader = new BioPatMBF_Reader() ) {
				BioList = gbReader.Read( Global.GetResourceReader( _singleDnaSeqGenBankFilename ) );
			}

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

			FeatureList Matches = BioList[0].Search( SearchPosition, BioList[0].Length, MyPatterns.Pattern );

			//According to Jacobi library total matches should be 57 
			Assert.AreEqual( 57, Matches.Count );
			Assert.AreEqual( "Pribnow-box", Matches.Name );
			//Perform some random checks from the 57 list

			Match matched = (Match) Matches[10]; //try get the 11th matched

			Assert.AreEqual( 0.66, matched.Similarity, 1e-2 );
			Assert.AreEqual( 6, matched.Length );
			Assert.AreEqual( "ttttat", matched.Letters() );

			//try the first match
			matched = (Match) Matches[0];
			Assert.AreEqual( AlphabetFactory.Instance( AlphabetType.DNA ), matched.Alphabet );
			Assert.AreEqual( 6, matched.Length );
			Assert.AreEqual( 0.5, matched.Similarity, 1e-2 );

			// Check the last match
			matched = (Match) Matches[56];
			Assert.AreEqual( 0.5, matched.Similarity, 1e-2 );
			Assert.AreEqual( "tttctt", matched.Letters() );

		}
        public void TestStructuredPattern_SeriesAll()
        {
            BiopatMLFilePath = "BioPaperTestData/StructuredPattern/SeriesAll.xml";

            using (BioPatMBF_Reader gbReader = new BioPatMBF_Reader())
            {
				BioList = gbReader.Read( Global.GetResourceReader( _singleDnaSeqGenBankFilename ) );
            }

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

			FeatureList Matches = BioList[0].Search( SearchPosition, BioList[0].Length, MyPatterns.Pattern );

            //expecting 49 matches based on the old jacobi result
            Assert.AreEqual(49, Matches.Count);

            Match matched = (Match)Matches[0]; //Query the 1st matched from the list of matches
            Assert.AreEqual(3, matched.SubMatches.Count); //should have 3 sub matches

            Assert.AreEqual("aattt", matched.SubMatches[0].Letters());
            Assert.AreEqual("tataagtg", matched.SubMatches[1].Letters());
            Assert.AreEqual("ttcaa", matched.SubMatches[2].Letters());

            //And finally the main matched
            Assert.AreEqual("aattttataagtgttcaa", matched.Letters());
        }
Пример #3
0
        /// <summary>
        /// Reads the parameters and populate the attributes for this pattern.
        /// </summary>
        /// <param name="node">Any Pattern node</param>
        /// <param name="definition">The container encapsulating this pattern</param>
        public override void ReadNode
            (XmlNode node, Definition definition)
        {
            base.ReadNode(node, definition);
            Impact = XMLHelper.GetAttrValDouble(node, "impact");

        }
 public void SetUp()
 {
     this.BiopatMLFilePath = string.Empty;
     this.BioList = null;
     this.MyPatterns = null;
     SearchPosition = 1;
 }
 public void TestConstructor()
 {
     Definition definition = new Definition("test", new VoidPattern("VoidPattern"));
     Assert.AreEqual("test", definition.Name);
     Assert.AreEqual("VoidPattern", definition.Pattern.Name);
     Assert.IsNotNull(definition.Pattern);
     Assert.IsNotNull(definition.Definitions);
 }
		public void TestConstructor () {
			Definition container = new Definition();
			container.Definitions.Add( new Definition( "Def", new Any( "Any", 1, 3, 1 ) ) );
			Use use = new Use { Name = "Use" };
			use.ReferTo( container, "Def" );
			Assert.AreEqual( "Use", use.Name );
			Assert.AreEqual( "Def", use.ReferencedDefinition.Name );
		}
        /// <summary>
        /// Adds a definition to the list. The name of the definition must be unique.
        /// No two definitions with the same name can be stored in the list.
        /// </summary>
        /// <exception cref="System.ArgumentException">thrown when name already exist</exception>
        /// <param name="definition">Definition to add.</param>
        public void Add(Definition definition)
        {
            String name = definition.DefinitionName;

            if (NamesDictionary.ContainsKey(name))
                throw new ArgumentException("Duplicate definition name: " + name);

            NamesDictionary.Add(name, definition);
        }
		/// <summary>
		/// Process the processed BioPatML XML file and returns 
		/// a Definition containning a list of search patterns
		/// </summary>
		/// <param name="doc">Loads in a premade document</param>
		/// <returns>A definition containning a collection of sub patterns, if exist.</returns>
		public static Definition Read ( XDocument doc ) {

			if ( doc.Root.Name != "BioPatML" ) {
				throw new ArgumentException( "Top level node should be 'BioPatML'" );
			}

			Definition result = new Definition();
			result.Parse( doc.Root.Element( "Definition" ) );
			return result;
		}
		/// <summary> Saves a definition as an xml document. </summary>
		/// <param name="definition"></param>
		/// <returns></returns>

		public static XDocument Write ( Definition definition ) {
			XDocument result = XDocument.Parse( 
				@"<BioPatML 
					xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
					xsi:noNamespaceSchemaLocation='BioPatML.xsd' />"
			);

			result.Root.Add( definition.ToXml() );

			return result;
		}
 public void TestSubDefinition()
 {
     DefinitionList definitions = new DefinitionList();
     Definition definition = new Definition("test1", new VoidPattern("VoidPattern1"));
     definition.Definitions.Add(new Definition("test11", new VoidPattern("VoidPattern11")));
     definitions.Add(definition);
     definitions.Add(new Definition("test2", new VoidPattern("VoidPattern2")));
     definitions.Add(new Definition("test3", new VoidPattern("VoidPattern3")));
     Assert.AreEqual("VoidPattern1", definitions.definition("test1").Pattern.Name);
     Assert.AreEqual("VoidPattern11", definitions.definition("test1.test11").Pattern.Name);
     Assert.AreEqual("VoidPattern2", definitions.definition("test2").Pattern.Name);
     Assert.AreEqual("VoidPattern3", definitions.definition("test3").Pattern.Name);
     Assert.AreEqual(null, definitions.definition("test4"));
 }
 public void TestDefinition()
 {
     DefinitionList definitions = new DefinitionList();
     Definition definition = new Definition("test1");
     definition.Definitions.Add(new Definition("test11"));
     definitions.Add(definition);
     definitions.Add(new Definition("test2"));
     definitions.Add(new Definition("test3"));
     Assert.AreEqual("test1", definitions.definition("test1").Name);
     Assert.AreEqual("test11", definitions.definition("test1.test11").Name);
     Assert.AreEqual("test2", definitions.definition("test2").Name);
     Assert.AreEqual("test3", definitions.definition("test3").Name);
     Assert.AreEqual(null, definitions.definition("test4"));
 }
		public void TestMatch ()
        {
			Definition def = new Definition();
			def.Definitions.Add( new Definition("Def", new Motif("Motif", AlphabetType.DNA, "atg", 0.0)) );
            Sequence seq = new Sequence(AlphabetType.DNA, "atgc");
            Use use = new Use{ Name = "Use" };
			use.ReferTo( def, "Def" );
            Match match = use.Match(seq, 1);
            Assert.AreEqual(use, match.MatchPattern);
            Assert.AreEqual(1, match.Start);
            Assert.AreEqual(3, match.Length);
            Assert.AreEqual(1, match.Strand);
            Assert.AreEqual(1.0, match.Similarity, 1e-2);
        }
        /// <summary>
        /// Reads the parameters and populate the attributes for this pattern.
        /// </summary>
        /// <param name="node">Series Pattern node</param>
        /// <param name="definition">The container encapsulating this pattern</param>
        public override void ReadNode(XmlNode node, Definition definition)
        {
            PatternName = XMLHelper.GetAttrValueString(node, "name");
            Threshold = XMLHelper.GetAttrValDouble(node, "threshold");
            Impact = XMLHelper.GetAttrValDouble(node, "impact");

            node = node.FirstChild;
            while (node != null)
            {
                if (node.NodeType == XmlNodeType.Element)
                    Add(PatternComplex.ReadPattern(node, definition));

                node = node.NextSibling;
            }
        }
		public void TestRegionalPattern_Gap () {
			BiopatMLFilePath = "BioPaperTestData/RegionalPattern/RegionalGap.xml";

			BioPatMBF_Reader gbReader = new BioPatMBF_Reader();
			BioList = gbReader.Read( Global.GetResourceReader( _singleProteinSeqGenBankFilename ) );
			MyPatterns = DefinitionIO.Read( Global.GetResourceReader( BiopatMLFilePath ) );

			FeatureList Matches = BioList[0].Search( SearchPosition, BioList[0].Length, MyPatterns.Pattern );

			//Total matches according to old jacobi is 309
			Assert.AreEqual( 410, Matches.Count );
			//Checks the first match 
			Assert.AreEqual( "MT", Matches[0].MainSequence.Letters( Matches[0].Start, Matches[0].End ) );
			//Checks if the last Match is in correect start and end pos
			Assert.AreEqual( "CE", Matches[409].MainSequence.Letters( Matches[409].Start, Matches[409].End ) );
		}
        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);
        }
 /// <summary>
 /// Reads the parameters and populate the attributes for this pattern.
 /// </summary>
 /// <param name="definition">Definition wrapping this node element</param>
 /// <param name="node">The node with name Void</param>
 public override void ReadNode(XmlNode node, Definition definition)
 {
     PatternName = XMLHelper.GetAttrValueString(node, "name");
     Impact = XMLHelper.GetAttrValDouble(node, "impact");
 }
        /// <summary>
        /// Reads the parameters and populate the attributes for this pattern.
        /// 
        /// Hides the ReadNode method for PatternComplex
        /// </summary>
        /// <param name="node">Profile Pattern node</param>
        /// <param name="definition">The container encapsulating this pattern</param>
        public new void ReadNode(XmlNode node, Definition definition)
        {
            Dictionary<String, ProfileElement> map = new Dictionary<string, ProfileElement>();

            PatternName = XMLHelper.GetAttrValueString(node, "name");
            Threshold = XMLHelper.GetAttrValDouble(node, "threshold");
            Impact = XMLHelper.GetAttrValDouble(node, "impact");

            node = node.FirstChild;

            while (node != null)
            {
                if (node.Name.Equals("Region"))
                {
                    String name = XMLHelper.GetAttrValueString(node, "name");
                    String reference = XMLHelper.GetAttrValueString(node, "reference");
                    int minGap = XMLHelper.GetAttrValInt(node, "minGap");
                    int maxGap = XMLHelper.GetAttrValInt(node, "maxGap");
                    String align = XMLHelper.GetAttrValueString(node, "alignment");

                    //Has confusing method Pattern
                    IPattern pattern = QUT.Bio.BioPatML.Patterns.Pattern.ReadPattern
                                                                    (node.FirstChild, definition);

                    ProfileElement refElement = null;
                    if (reference != null)
                    {
                        refElement = map[reference];
                        if (refElement == null)    
                            throw new ArgumentException
                                ("Unknown reference : " + reference);
                        
                    }

                    refElement = Add(refElement, StringToAlignment(align), minGap, maxGap, pattern);
                    map.Add(name, refElement);
                }

                node = node.NextSibling;
            }

        }
        /// <summary>
        /// Reads the parameters and populate the attributes for this pattern.
        /// </summary>
        /// <param name="node">Motif Pattern node</param>
        /// <param name="definition">The container encapsulating this pattern</param>
        public override void ReadNode(XmlNode node, Definition definition)
        {
            PatternName = XMLHelper.GetAttrValueString(node, "name");

            Parse(XMLHelper.GetAttrValueString(node, "alphabet"),
                    XMLHelper.GetAttrValueString(node, "motif"));

            Threshold = XMLHelper.GetAttrValDouble(node, "threshold");
            Impact = XMLHelper.GetAttrValDouble(node, "impact");
        }
        /// <summary>
        /// Implementation of the pattern interface.
        /// <see cref="QUT.Bio.BioPatML.Patterns.IPattern">IPattern ReadNode(Node)</see>
        /// </summary>
        /// <param name="node">The Set[ALL/Best] Element</param>
        /// <param name="definition"></param>
        public override void ReadNode(XmlNode node, Definition definition)
        {
            PatternName = (XMLHelper.GetAttrValueString(node, "name"));
            Threshold = (XMLHelper.GetAttrValDouble(node, "threshold"));
            Impact = (XMLHelper.GetAttrValDouble(node, "impact"));

            Set(definition.Patterns[XMLHelper.GetAttrValueString(node, "pattern")],
                                                XMLHelper.GetAttrValueString(node, "mode"));

            node = node.FirstChild;

            while (node != null)
            {
                if (node.Name.Equals("Pairing"))
                {
                    char original = XMLHelper.GetAttrValueString(node, "original")[0];
                    char repeat = XMLHelper.GetAttrValueString(node, "repeat")[0];
                    double weight = XMLHelper.GetAttrValDouble(node, "weight");
                    Weight(original, repeat, weight);
                }

                node = node.NextSibling;
            }
        }
        /// <summary>
        /// Reads a list of definitions at the specified node. 
        /// This method recursivly calls the reading methods of the different definitions.
        /// </summary>
        /// <param name="node">Node of the XML the reading starts with.</param>
        /// <param name="def">Definition which definition list will be extend with
        /// all read definitions.</param>
        public static void ReadNode(XmlNode node, Definition def)
        {
            node = node.FirstChild;
            
            while (node != null)
            {
                if (node.Name.Equals("Definition"))
                    def.Definitions.Add(Definition.ReadNode(node));

                else
                    if (node.Name.Equals("Import"))
                        def.Definitions.Add(XMLHelper.GetAttrValueString(node, "uri"));


                node = node.NextSibling;
            }
        }
        /// <summary>
        /// Reads the parameters and populate the attributes for this pattern.
        /// </summary>
        /// <param name="node">Any Pattern node</param>
        /// <param name="definition">The container encapsulating this pattern</param>
        public override void ReadNode(XmlNode node, Definition definition)
        {
            PatternName      = XMLHelper.GetAttrValueString(node, "name");
            Threshold = XMLHelper.GetAttrValDouble(node, "threshold");
            Impact    = XMLHelper.GetAttrValDouble(node, "impact");

            Set(PatternComplex.ReadPattern(node.FirstChild, definition),
                        XMLHelper.GetAttrValInt(node, "minimum"),
                        XMLHelper.GetAttrValInt(node, "maximum"));
        }
Пример #22
0
        /// <summary>
        /// Implementation of the pattern interface.
        /// Reads in the Gap node and populate the attributes accordingly.
        /// <see cref="QUT.Bio.BioPatML.Patterns.IPattern">IPattern</see>
        /// </summary>
        /// <param name="node"></param>
        /// <param name="definition"></param>
        public override void ReadNode(XmlNode node, Definition definition)
        {
            base.ReadNode(node, definition);
            Threshold = XMLHelper.GetAttrValDouble(node, "threshold");
            Impact    = XMLHelper.GetAttrValDouble(node, "impact");
            String weightstr = XMLHelper.GetTextContent(node, "Weights");

            Weights = (weightstr == null ? null : PrimitiveParse.StringToDoubleArray(weightstr));

        }
        /// <summary>
        /// Reads the parameters and populate the attributes for this pattern.
        /// </summary>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when sequences in blocks are missing.</exception>
        /// <param name="node"></param>
        /// <param name="definition">The Definition element where the node sits in</param>
        public override void ReadNode
            (XmlNode node, Definition definition)
        {
            PatternName = (XMLHelper.GetAttrValueString(node, "name"));
            Threshold = (XMLHelper.GetAttrValDouble(node, "threshold"));
            Impact = (XMLHelper.GetAttrValDouble(node, "impact"));

            PWMalphabet = AlphabetFactory.Instance
                        (XMLHelper.GetAttrValueString(node, "alphabet"));
            SequenceList seqList = new SequenceList();

            node = node.FirstChild;
            while (node != null)
            {
                if (node.Name.Equals("Sequence"))
                {
                    String letters = node.InnerText.Trim();

                    if (letters == null)
                        throw new ArgumentNullException
                            ("Sequences in Block are missing!");

                    seqList.Add(new Sequence(PWMalphabet, letters, false));
                }
                node = node.NextSibling;
            }

            Estimate(seqList, null);
        }
        /// <summary>
        /// A static method for reading the definition of a pattern.
        /// </summary>
        /// <param name="node">The definition node with the starting tag of Definition</param>
        /// <returns></returns>
        public static Definition ReadNode(XmlNode node)
        {
            Definition definition = new Definition(XMLHelper.GetAttrValueString(node, "name"));
            node = node.FirstChild;

            while (node != null)
            {
                if (node.Name.Equals("Annotations"))
                { /*AnnotationList.read(node, definition);*/}

                else
                    if (node.Name.Equals("Parameters"))
                    { /*ParameterList.read(node, definition);*/}

                else
                    if (node.Name.Equals("Definitions"))
                       DefinitionList.ReadNode(node, definition);


                else
                    if (node.NodeType == XmlNodeType.Element)
                       Pattern.ReadPattern(node, definition);

                node = node.NextSibling;
            }

            return definition;
        }
        /// <summary>
        /// Reads the parameters and populate the attributes for this pattern.
        /// </summary>
        /// <param name="node">Any Pattern node that extends pattern flexible </param>
        /// <param name="definition">The container encapsulating this pattern</param>
        public override void ReadNode(XmlNode node, Definition definition)
        {

            PatternName = (XMLHelper.GetAttrValueString(node, "name"));

            Set(XMLHelper.GetAttrValInt       (node, "minimum"),
                    XMLHelper.GetAttrValInt   (node, "maximum"),
                    XMLHelper.GetAttrValDouble(node, "increment"));
        }
 /// <summary>
 /// Reads the parameters for a pattern at the given node.
 /// </summary>
 /// <param name="node">The Alignment pattern node</param>
 /// <param name="definition">Definition encapsulating the pattern</param>
 public override void ReadNode(System.Xml.XmlNode node, Definition definition)
 {
     PatternName = (XMLHelper.GetAttrValueString(node, "name"));
     Impact = (XMLHelper.GetAttrValDouble(node, "impact"));
     Set(definition.Patterns[XMLHelper.GetAttrValueString(node, "pattern")],
            XMLHelper.GetAttrValueString(node, "position"),
            XMLHelper.GetAttrValInt(node, "offset"));
 }
 /// <summary>
         /// 
         /// </summary>
         /// <param name="node"></param>
         /// <param name="definition"></param>
         public virtual void ReadNode(XmlNode node, Definition definition)
         {
             throw new NotImplementedException();
         }
		public void TestRegionalPattern_Composition () {
			BiopatMLFilePath = "BioPaperTestData/RegionalPattern/RegionalComposition.xml";

			using ( BioPatMBF_Reader gbReader = new BioPatMBF_Reader() ) {
				BioList = gbReader.Read( Global.GetResourceReader( _singleProteinSeqGenBankFilename ) );
			}

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

			FeatureList Matches = BioList[0].Search( SearchPosition, BioList[0].Length, MyPatterns.Pattern );

			//Total matches according to old jacobi is 309
			Assert.AreEqual( 49, Matches.Count );
			//Checks the first match 
			Assert.AreEqual( "GATLFKTRCLQCHTV", Matches[0].MainSequence.Letters( Matches[0].Start, Matches[0].End ) );
			//Check see if the pattern used to match has the correct name for its matches
			Assert.AreEqual( "transmembrane domain", Matches.Name );
			Assert.AreEqual( 12, Matches[0].Start );
			Assert.AreEqual( 26, Matches[0].End );
			//Checks if the last Match is in correect start and end pos
			Assert.AreEqual( "KDRNDLITYLKKACE", Matches[48].MainSequence.Letters( Matches[48].Start, Matches[48].End ) );
		}
 /// <summary>
 /// Reads the parameters and populate the attributes for this pattern.
 /// </summary>
 /// <param name="node">Constraint Pattern node</param>
 /// <param name="definition">The container encapsulating this pattern</param>
 public override void ReadNode(XmlNode node, Definition definition)
 {
     PatternName = (XMLHelper.GetAttrValueString(node, "name"));
     Impact = (XMLHelper.GetAttrValDouble(node, "impact"));
     Position = (XMLHelper.GetAttrValueString(node, "position"));
     Offset = (XMLHelper.GetAttrValInt(node, "offset"));
 }
        /// <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;
        }