/// <summary> /// Implementation of the IMatcher interface. An any pattern matches any sequence. /// <see cref="QUT.Bio.BioPatML.Patterns.IMatcher">IMatcher interface</see>. /// </summary> /// <param name="sequence">Sequence to compare with.</param> /// <param name="position">Matching position.</param> /// <returns>The matched item</returns> public Match Match(Sequence sequence, int position) { Match match = Composition.Matched; CurrLength = (int)(Composition.MinLength + Counter * Composition.IncLength + 0.5); CurrLength = Math.Min(CurrLength, Composition.MaxLength); increment = 0; Counter++; double sum = 0.0; for (int len = 0; len < CurrLength; len++) sum += Composition.Weight(sequence.GetSymbol(position + len)); if (CurrLength >= Composition.MaxLength) { increment = 1; Counter = 0; } double similarity = sum / (CurrLength * Composition.maxWeight); if (similarity < Composition.Threshold) return null; match.Set(sequence, position, CurrLength, sequence.Strand, similarity); return match; }
/// <summary> /// The standard override match method that performs match base on /// inverted match algortihm /// </summary> /// <param name="sequence">sequence to compare</param> /// <param name="position">matching position</param> /// <returns></returns> public override Match Match(Sequence sequence, int position) { Init(); for (int i = 0; i < matchLen; i++) { remSim -= (1.0 - Compare(matchSeq.GetSymbol(matchLen - i), sequence.GetSymbol(position + i))); if (remSim / matchLen < repeat.Threshold) return (null); } repeat.Matched.Set(sequence, position, matchLen, matchSeq.Strand, remSim / matchLen); return repeat.Matched; }
/// <summary> /// Implementation of the IMatcher interface. An any pattern matches any sequence. /// <see cref="QUT.Bio.BioPatML.Patterns.IMatcher">IMatcher interface</see>. /// </summary> /// <param name="sequence">Sequence to compare with.</param> /// <param name="position">Matching position.</param> /// <returns>The matched item</returns> public Match Match(Sequence sequence, int position) { Match match = Matched; int maxLen = Composition.MaxLength; int minLen = Composition.MinLength; double incLen = Composition.IncLength; double sum = 0.0; for (int len = 1; len <= minLen; len++) sum += Composition.Weight(sequence.GetSymbol(position + len - 1)); double bestSum = sum; int bestLen = minLen; for (int len = minLen + 1; len <= maxLen; len++) { sum += Composition.Weight(sequence.GetSymbol(position + len - 1)); double diff = len - minLen; double rest = Math.Abs(diff - incLen * (int)(diff / incLen + 0.5)); if (sum / len >= bestSum / bestLen && rest < 0.5) { bestSum = sum; bestLen = len; } } double similarity = bestSum / (bestLen * Composition.MaxWeight); if (similarity < Composition.Threshold) return null; match.Set(sequence, position, bestLen, sequence.Strand, similarity); return match; }
/// <summary> /// Implementation of the IMatcher interface. An any pattern matches any sequence. /// <see cref="QUT.Bio.BioPatML.Patterns.IMatcher">IMatcher interface</see>. /// </summary> /// <param name="sequence">Sequence to compare with.</param> /// <param name="position">Matching position.</param> /// <returns>A match object containning the search result</returns> public override Match Match (Sequence sequence, int position) { int length = MotifSymbols.Count; int mismatches = 0; int maxMismatches = (int)(length * (1 - Threshold)); for (int i = 0; i < length; i++) if (!MotifSymbols[i].Equals(sequence.GetSymbol(position + i))) if (++mismatches > maxMismatches) return (null); Matched.Set(sequence, position, length, sequence.Strand, (Double)(length - mismatches) / length); return (Matched); }
/// <summary> /// Adds all symbols contained in the given sequence to the histogram. /// </summary> /// <param name="sequence"> The sequence with sysmbols to add. </param> public void Add(Sequence sequence) { for (int pos = 1; pos <= sequence.Length; pos++) Add(sequence.GetSymbol(pos)); }
public void TestGet () { Sequence seq = new Sequence( AlphabetType.AA, "artg", true ); Assert.AreEqual( 'T', seq.GetSymbol( -5 ).Letter ); Assert.AreEqual( 'T', seq.GetSymbol( -1 ).Letter ); Assert.AreEqual( 'G', seq.GetSymbol( 0 ).Letter ); Assert.AreEqual( 'A', seq.GetSymbol( 1 ).Letter ); Assert.AreEqual( 'R', seq.GetSymbol( 2 ).Letter ); Assert.AreEqual( 'T', seq.GetSymbol( 3 ).Letter ); Assert.AreEqual( 'G', seq.GetSymbol( 4 ).Letter ); Assert.AreEqual( 'A', seq.GetSymbol( 5 ).Letter ); Assert.AreEqual( 'A', seq.GetSymbol( 9 ).Letter ); }
/// <summary> Creates a paragraph representing a feature. /// </summary> /// <param name="letters">the sequence of characters to render</param> /// <param name="hitStart">Start position of the hit</param> /// <param name="hitEnd">End position of hit</param> /// <returns></returns> static public Paragraph GetHitDetails ( Sequence sequence, int hitStart, int hitEnd ) { int sequenceLength = sequence.Length; Paragraph resultPara = new Paragraph(); int displayStartPos = CalcStartPosition( hitStart ); int nextLineBreak = displayStartPos; //for (int i = 0; i < letters.Length; i++) for ( int i = displayStartPos; i < CalcEndPosition( hitEnd, sequenceLength ); i++ ) { Run lineDesc = new Run { FontFamily = new FontFamily( "Courier" ), FontWeight = FontWeights.Normal, FontSize = 14 }; // Add 3 blank spaces for every set of 10 characters if ( i % 10 == 0 ) lineDesc.Text += ( "\t\t" ); // break lines after fixed number of characters. if ( i == 0 ) { //first line definitely a new line lineDesc.Text += NEWLINE + "Line " + CompileNumber( ( i + 1 ), sequenceLength ) + " ... " + CompileNumber( ( i + 1 + CHARACTERS_PER_LINE ), sequenceLength ) + "\t\t"; resultPara.Inlines.Add( lineDesc ); //Add the lines string into paragraph first lineDesc = new Run { FontFamily = new FontFamily( "Courier" ), FontWeight = FontWeights.Normal, FontSize = 14 }; //renew out run nextLineBreak += CHARACTERS_PER_LINE; //set the next break } else if ( i == nextLineBreak ) { lineDesc.Text += NEWLINE + "Line " + CompileNumber( ( i + 1 ), sequenceLength ) + " ... " + CompileNumber( ( i + 1 + CHARACTERS_PER_LINE ), sequenceLength ) + "\t\t"; resultPara.Inlines.Add( lineDesc ); //Add the lines string into paragraph first lineDesc = new Run { FontFamily = new FontFamily( "Courier" ), FontWeight = FontWeights.Normal, FontSize = 14 }; //renew out run nextLineBreak += CHARACTERS_PER_LINE; //set the next break } char currentLetter = sequence.GetSymbol( i ).Letter; if ( i >= hitStart && i <= hitEnd ) { lineDesc.FontWeight = FontWeights.Bold; lineDesc.Foreground = new SolidColorBrush( Colors.Black ); } else { // else we set the attribute of run to be normal alphabet coloring SetRunAttr( lineDesc, currentLetter ); } lineDesc.Text += currentLetter + " "; // otherwise append the character resultPara.Inlines.Add( lineDesc ); } return resultPara; }