/// <summary> /// Find the next match of the pattern. /// </summary> /// <param name="element">A gap followed by a pattern.</param> /// <param name="seq">Sequence where the pattern is searched in.</param> /// <param name="position">Current start position within the sequence.</param> /// <returns>Returns a match object or null if there is no match with the /// given similarity or higer. </returns> private Match NextMatch (ProfileElement element, Sequence seq, int position) { Match match; int pos; IPattern pattern = element.Pattern; while (element.CurrGap <= element.MaxGap) { pos = position + element.CurrGap; match = pattern.Match(seq, pos); element.CurrGap += pattern.Increment; if (match != null) return (match); } return (null); }
/// <summary> /// Find the match with the highest score for a gap followed by a pattern. /// </summary> /// <param name="element">A gap followed by a pattern.</param> /// <param name="seq">Sequence where the pattern is searched in.</param> /// <param name="position">Current start position within the sequence.</param> /// <returns> /// Returns a match object or null if there is no match with the /// given similarity or higher. /// </returns> private Match MaxMatch (ProfileElement element, Sequence seq, int position) { Match match; int start = position + element.MinGap; int end = position + element.MaxGap; IPattern pattern = element.Pattern; maxMatch.Set(null, 0, 0, 0, -Double.MaxValue); for (int pos = start; pos <= end; pos++) { do { match = pattern.Match(seq, pos); if (match != null && match.Similarity > maxMatch.Similarity) maxMatch.Set(match); } while (pattern.Increment == 0); } return (maxMatch.Similarity < Threshold ? null : maxMatch); }
/// <summary> /// Getter for the index of the given profile element. /// </summary> /// <param name="element">Profile element.</param> /// <returns> /// Index of the given profile element within the profile or -1 if /// the profile element is not part of the profile. /// </returns> public int IndexOf(ProfileElement element) { return (patternList.IndexOf(element)); }
/// <summary> /// Adds a pattern preceeded by a gap of variable length to the profile. /// </summary> /// <param name="elementIndex"> /// Index to a preceding profile element. If the index /// smaller than zero it is assumed that there is no preceding profile element. /// In this case minGap and maxGap must be zero! /// Please note that the same pattern can not be added twice except it it /// a copy (with its own internal match object). /// </param> /// <param name="alignment"> /// Alignment the gap is based on, e.g. END, START of the /// the preceding profile element or NONE if there is no preceding profile element /// or no gap. /// </param> /// <param name="minGap"> The min length</param> /// <param name="maxGap"> /// Maximum gap length. Must be greater than or equal to the /// minimum gap length. /// </param> /// <param name="pattern">Any object which implements the pattern interface.</param> /// <returns>Returns a reference to the added {ProfileElement}.</returns> public ProfileElement Add (int elementIndex, int alignment, int minGap, int maxGap, IPattern pattern) { if (IndexOf(pattern) >= 0) throw new ArgumentException ("The same pattern can not be added twice to a profile!"); ProfileElement element = new ProfileElement (this[elementIndex], alignment, minGap, maxGap, pattern); patternList.Add(element); Matched.Add(pattern.Matched); return (element); }
/// <summary> /// /// Adds a pattern preceeded by a gap of variable length to the profile. /// </summary> /// <param name="refElement"> /// refElement Reference to the preceding profile element. Null if there /// is none. If there is gap then there must be a preceding profile element /// defined! /// </param> /// <param name="alignment">Alignment the gap is based on, e.g. END, START of the /// the preceding profile element or NONE if there is no preceding profile /// element or no gap.</param> /// <param name="minGap">Minimum gap length.</param> /// <param name="maxGap">Maximum gap length. Must be greater than or equal to the /// minimum gap length.</param> /// <param name="pattern">Any object which implements the pattern interface.</param> /// <returns></returns> public ProfileElement Add (ProfileElement refElement, int alignment, int minGap, int maxGap, IPattern pattern) { ProfileElement element = new ProfileElement (refElement, alignment, minGap, maxGap, pattern); patternList.Add(element); Matched.Add(pattern.Matched); return (element); }
/// <summary> /// Creates a profile element. A profile element is a pattern with a /// preceding gap to another profile element. /// </summary> /// <param name="refElement">Reference to the preceding profile element. Null if there /// is none. If there is gap then there must be a preceding profile element /// defined! /// </param> /// <param name="alignment"> /// Alignment the gap is based on, e.g. END, START of the /// the preceding profile element or NONE if there is no preceding profile element /// or no gap. /// </param> /// <param name="minGap">Minimum gap length.</param> /// <param name="maxGap">Maximum gap length. Must be greater than or equal to the /// minimum gap length.</param> /// <param name="pattern">A pattern.</param> public ProfileElement (ProfileElement refElement, int alignment, int minGap, int maxGap, IPattern pattern) { if (minGap > maxGap) throw new ArgumentException ("Minimum gap length is greater than maximum gap length."); else if ((refElement == null || alignment == NONE) && (minGap != 0 || maxGap != 0)) throw new ArgumentException ("Missing reference or alignment to proceding pattern in gap definition."); this.RefElement = refElement; this.Alignment = alignment; this.MinGap = minGap; this.CurrGap = minGap; this.MaxGap = maxGap; this.Pattern = pattern; }