//internal Pattern(string name) { PatternName = name; }

        /// <summary>
        /// Construct a pattern with a given name usually passed from child class
        /// </summary>
        /// <param name="name"> name of element</param>
        public Pattern(string name)
        {
            match = new QUT.Bio.BioPatML.Patterns.Match(this);
            Threshold = 0.0;
            PatternName = name;
            Impact = 1.0; //start it with a default value
        }
		public void TestCopy () {
			Match m = new Match( voidPattern, null, 3, 2, +1, 1 );
			Match sub1 = new Match( voidPattern, null, 4, 2, +1, 0.5 );

			sub1.Impact = 0.5;

			Match sub2 = new Match( voidPattern, null, 5, 2, +1, 0.1 );
			sub2.Impact = 0.7;

			m.SubMatches.Add( sub1 );
			m.SubMatches.Add( sub2 );

			Match mc = m.Clone();

			Assert.AreEqual( 2, m.SubMatches.Count );
			Assert.AreEqual( 2, mc.SubMatches.Count );
			Assert.IsTrue( mc != m );
			Assert.IsTrue( sub1 != mc.SubMatches[0] );
			Assert.IsTrue( sub2 != mc.SubMatches[1] );
			Assert.AreEqual( 3, mc.Start );
			Assert.AreEqual( 4, mc.SubMatches[0].Start );
			Assert.AreEqual( 5, mc.SubMatches[1].Start );
			Assert.AreEqual( 0.5, mc.SubMatches[0].Impact, 1e-10 );
			Assert.AreEqual( 0.7, mc.SubMatches[1].Impact, 1e-10 );
		}
		public void TestConstructor () {
			Sequence seq = new Sequence( AlphabetType.DNA, "atcg" );
			Match m = new Match( voidPattern, seq, 3, 2, +1, 1 );
			Assert.AreEqual( 3, m.Start );
			Assert.AreEqual( 2, m.Length );
			Assert.AreEqual( 1, m.Strand );
			Assert.AreEqual( seq, m.BaseSequence );
			Assert.AreEqual( "cg", m.Letters() );
			Assert.AreEqual( 1.0, m.Similarity, 1e-3 );
		}
		public void TestSubMatch () {
			Sequence seq1 = new Sequence( AlphabetType.DNA, "tttggccaaagcc" );

			Match m = new Match( null );
			Match sub1 = new Match( null );
			Match sub2 = new Match( null );
			Assert.AreEqual( 0, m.SubMatches.Count );
			m.SubMatches.Add( sub1 );
			m.SubMatches.Add( sub2 );

			Assert.AreEqual( 2, m.SubMatches.Count );
			Assert.AreEqual( sub1, m.SubMatches[0] );
			Assert.AreEqual( sub2, m.SubMatches[1] );
		}
		public void TestSetGet () {
			Sequence seq = new Sequence( AlphabetType.DNA, "atcg" );
			Match m = new Match( null );
			m.Set( seq, 3, 4, +1, 0.75 );
			Assert.AreEqual( seq, m.BaseSequence );
			Assert.AreEqual( 3, m.Start );
			Assert.AreEqual( 4, m.Length );
			Assert.AreEqual( 1, m.Strand );
			Assert.AreEqual( 0.75, m.Similarity, 1e-3 );
			Assert.AreEqual( 1, m.CalcMismatches() );
			Assert.AreEqual( 3, m.Matches );
		}
		public void TestToString () {
			Sequence seq = new Sequence( AlphabetType.DNA, "actgactg" );
			Match m = new Match( voidPattern, null, 3, 2, +1, 1 );
			m.SetSequence( seq );

			Assert.AreEqual( "{3, 2, 1, 1, tg}", m.ToString() ); //change the expected result from usual 1.0 to 1

			m.SubMatches.Add( new Match( voidPattern, null, 4, 2, -1, 0.5 ) );
			m.SubMatches[ 0 ].SetSequence( seq );
			m.SubMatches.Add( new Match( voidPattern, null, 5, 3, +1, 0.1 ) );
			m.SubMatches[ 1 ].SetSequence( seq );

			Assert.AreEqual( "{3, 2, 1, 1, tg, {4, 2, -1, 0.5, tc}, {5, 3, 1, 0.1, act}}",
				 m.ToString() ); //see original code for actual result, i trim away the 1 decimal placing to pass the
			//test as there wont be much impact
		}
		public void TestCalcSimilarity () {
			Match m = new Match( null );
			Match sub1 = new Match( voidPattern, null, 0, 0, +1, 1.0 );
			Match sub2 = new Match( voidPattern, null, 0, 0, +1, 0.5 );

			m.SubMatches.Add( sub1 );
			m.SubMatches.Add( sub2 );

			m.CalcSimilarity();
			Assert.AreEqual( 0.75, m.Similarity, 1e-3 );
		}
 /// <summary>
 /// Constructs an empty profile.
 /// </summary>
 /// <param name="name">Name for element profile best</param>
 /// <param name="threshold">Similarity threshold.</param>
 public ProfileBest(string name, double threshold)
     : base (name)
 {
     maxMatch = new Match(this);
     Threshold = threshold;
 }
		public void TestCalcStartEnd () {
			Match m = new Match( null );
			Match sub1 = new Match( voidPattern, null, 2, 2, +1, 0.0 );
			Match sub2 = new Match( voidPattern, null, 3, 2, +1, 0.0 );

			m.SubMatches.Add( sub1 );
			m.SubMatches.Add( sub2 );
			m.CalcStartEnd();

			Assert.AreEqual( 2, m.SubMatches.Count );
			Assert.AreEqual( 2, m.Start );
			Assert.AreEqual( 3, m.Length );
			Assert.AreEqual( 4, m.End );
		}
Exemplo n.º 10
0
        /// <summary>
        /// Creates a deep copy of the given match object.
        /// </summary>
        /// <param name="match">Match object to copy.</param>
        /// <returns>Returns a deep copy.</returns>
        public Match Clone(Match match)
        {
            Match newMatch = new Match(null);
            newMatch.Set(match);

            newMatch.SubMatchedList = null;


            for (int i = 0; i < match.SubMatchNumber; i++)
                newMatch.Add(Clone(match.GetSubMatch(i)));

            return (newMatch);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Replaces a sub match which replaces the sub match for the given index.
 /// </summary>
 /// <param name="index">Index of the sub match to replace.</param>
 /// <param name="match">Match to set.</param>
 public void ReplaceSubMatch(int index, Match match)
 {
     MatchedList.Insert(index, match);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Adds a sub match to the list of sub matches at the given index position.
        /// </summary>
        /// <param name="index">Index position for insertion.</param>
        /// <param name="match">Match to add.</param>
        public void Add(int index, Match match)
        {
            if (MatchedList == null)
                MatchedList = (new FeatureList("SubMatches"));

            MatchedList.Add(index, match);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Setter for a match object on base of another match object.
        /// </summary>
        /// <param name="match">Match object with initial values.</param>
        public void Set(Match match)
        {
            Set(match.BaseSequence, match.Start, match.Length,
                match.Strand, match.Similarity);

            this.MatchPattern = match.MatchPattern;
            //this.Name = match.MatchPattern.PatternName;
            this.impact = match.impact;

            FeatureList subMatchList = match.SubMatchedList;

            if (subMatchList != null)
            {
                if (MatchedList == null)
                {
                    FeatureList matchList = new FeatureList("SubMatches");

                    for (int i = 0; i < subMatchList.Count; i++)
                        matchList.Add(Clone((Match)subMatchList.Feature(i)));

                    MatchedList = matchList;

                }
                else
                {
                    for (int i = 0; i < subMatchList.Count; i++)
                        ((Match)MatchedList.Feature(i)).Set((Match)subMatchList.Feature(i));
                }
            }
            else
                MatchedList = null;
        }
        /// <summary>
        /// Implementation of the pattern interface. A match is successful if
        /// every pattern of the profile matches successfully and the mean
        /// similarity is higher or equal than the profile similarity threshold
        /// <see cref="QUT.Bio.BioPatML.Patterns.IMatcher">IMatcher Match Method</see>
        /// </summary>
        /// <param name="sequence"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        public override Match Match(BioPatML.Sequences.Sequence sequence, int position)
        {
            Match match = Matched;
            Match maxMatch = null;
            int patternNumber = patternList.Count;

            for (int index = 0; index < patternNumber; index++)
            {
                ProfileElement element = this[index];
                position = index > 0 ? element.GapStart : position;
                maxMatch = MaxMatch(element, sequence, position);
                if (maxMatch == null)
                    return (null);
                element.Pattern.Matched.Set(maxMatch);
            }

            match.CalcSimilarity();
            if (match.Similarity < Threshold)
                return (null);

            match.CalcStartEnd();
            match.Strand = sequence.Strand;
            match.SetSequence(sequence);

            return (match);
        }
		public void TestSetMatch () {
			Sequence seq = new Sequence( AlphabetType.DNA, "atcg" );
			Match m1 = new Match( null );
			Match m2 = new Match( null );

			m1.Set( seq, 3, 2, +1, 0.5 );
			m2.Set( m1 );

			Assert.AreEqual( seq, m2.BaseSequence );
			Assert.AreEqual( 3, m2.Start );
			Assert.AreEqual( 2, m2.Length );
			Assert.AreEqual( 1, m2.Strand );
			Assert.AreEqual( 0.5, m2.Similarity, 1e-3 );
			Assert.AreEqual( "cg", m2.Letters() );
		}
		public void TestCalcLength () {
			Match m = new Match( null );
			Match sub1 = new Match( voidPattern, null, 2, 2, +1, 0.0 );
			Match sub2 = new Match( voidPattern, null, 3, 4, +1, 0.0 );

			m.SubMatches.Add( sub1 );
			m.SubMatches.Add( sub2 );

			Assert.AreEqual( 2, sub1.CalcLength() );
			Assert.AreEqual( 4, sub2.CalcLength() );
			Assert.AreEqual( 6, m.CalcLength() );
		}
 /// <summary>
 /// Default constructor, constructing an empty profile best
 /// </summary>
 public ProfileBest() : base("ProfileBest" + Id.ToString()) { maxMatch = new Match(this); }