/// <summary> /// Compares two symbol and returns the "similarity" (weight) between the symbols /// </summary> /// <param name="symbol1">First symbol.</param> /// <param name="symbol2">Second symbol.</param> /// <returns>Returns the "similarity" (weight) between the symbols.</returns> protected double Compare (Symbol symbol1, Symbol symbol2) { if (repeat.weights == null) return symbol1.Equals(symbol2) ? 1.0 : 0.0; return repeat.Weight(symbol1, symbol2); }
public void SetUp() { alphabet = new TestAlphabetClass(); alphabet2 = new TestAlphabetClass(); sym1 = new Symbol('a', "Ade", "Adenine"); sym2 = new Symbol('u', "Ura", "Uracil"); sym3 = new SymbolMeta('-', "GAP", "Gap"); }
/** Tests the construction of symbols */ public void TestConstructor() { char[] adenine = { 'A', 'd', 'e', 'n', 'i', 'n', 'e' }; Symbol sym1 = new Symbol('a', "Ade", "Adenine"); Symbol sym2 = new Symbol('a', "Ade", new String(adenine)); Assert.AreEqual('a', sym1.Letter); Assert.AreEqual("Adenine", sym1.Name); Assert.AreEqual(sym1, sym1.Complement); Assert.IsTrue(sym1.Name == sym2.Name); }
/** Tests the comparions of symbols */ public void TestEquals() { char[] adenine = { 'A', 'd', 'e', 'n', 'i', 'n', 'e' }; Symbol sym1 = new Symbol('a', "Ade", new string(adenine)); Symbol sym2 = new Symbol('a', "Ade", "Adenine"); Symbol sym3 = new Symbol('u', "Ura", "Uracil"); Assert.AreEqual(true, sym1.Equals(sym2)); Assert.AreEqual(true, sym2.Equals(sym1)); Assert.AreEqual(false, sym1.Equals(sym3)); Assert.AreEqual(false, sym3.Equals(sym1)); }
/** Tests the replacement of symbols within the symbol set */ public void TestReplace() { SymbolMeta sym = new SymbolMeta('X', "XXX", "Unknown"); Symbol sym1 = new Symbol('a', "Ade", "Adenine"); Symbol sym2 = new Symbol('u', "Ura", "Uracil"); Symbol sym3 = new Symbol('t', "Thy", "Thymine"); sym.Add(sym1); sym.Add(sym2); Assert.AreEqual(2, sym.SymbolNumber); sym.Replace(sym2, sym3); Assert.AreEqual(2, sym.SymbolNumber); Assert.AreEqual(sym3, sym[1]); }
/** Tests the removal of symbols from the symbol set */ public void TestRemove() { SymbolMeta sym = new SymbolMeta('X', "XXX", "Unknown"); Symbol sym1 = new Symbol('a', "Ade", "Adenine"); Symbol sym2 = new Symbol('u', "Ura", "Uracil"); sym.Remove(sym1); sym.Add(sym1); sym.Add(sym2); Assert.AreEqual(2, sym.SymbolNumber); sym.Remove(sym1); Assert.AreEqual(1, sym.SymbolNumber); Assert.AreEqual(sym2, sym[0]); }
/** Tests the comparision with a meta symbol */ public void TestEquals() { SymbolMeta sym = new SymbolMeta('X', "XXX", "Unknown"); Symbol sym2 = new Symbol('a', "Ade", "Adenine"); Symbol sym3 = new Symbol('u', "Ura", "Uracil"); Assert.AreEqual(true, sym.Equals(sym2)); Assert.AreEqual(true, sym2.Equals(sym)); sym.Add(sym2); Assert.AreEqual(true, sym.Equals(sym2)); Assert.AreEqual(true, sym2.Equals(sym)); Assert.AreEqual(false, sym.Equals(sym3)); Assert.AreEqual(false, sym3.Equals(sym)); sym.Add(sym3); Assert.AreEqual(true, sym.Equals(sym)); Assert.AreEqual(true, sym.Equals(sym2)); Assert.AreEqual(true, sym.Equals(sym3)); }
/// <summary> /// Constructs a <see cref="QUT.Bio.BioPatML.Symbols.SymbolArray"> Symbol Array </see> /// base on the given symbol array. /// <para></para> /// Note - the symbol array is not copied. Any changes in the /// symbol array will effect the content of SymbolArray as well. /// <para></para> /// Furthermore there is no check if the symbols within the array are valid. /// </summary> /// <param name="alphabet"> The alphabet the symbols in the array belong to. </param> /// <param name="symbols"> Array of symbols. </param> public SymbolArray (Alphabet alphabet, Symbol[] symbols) { Symbols = symbols; SymAlphabet = alphabet; }
public void TearDown() { this.alphabet = null; this.alphabet2 = null; this.sym1 = null; this.sym2 = null; this.sym3 = null; }
/// <summary> /// Determines if a the given amino acid is aliphatic or not. /// /// Classification according to http://en.wikipedia.org/wiki/Amino_acid wiki amino acid /// </summary> /// <param name="symbol"> Symbol to classify. </param> /// <returns> /// Returns true: if the amino acid is aliphatic, false: otherwise. /// </returns> public bool IsAliphatic ( Symbol symbol ) { if ( symbol is SymbolAA ) return ( (SymbolAA) symbol ).IsAliphatic; return false; }
/// <summary> /// Gets a pairing weight /// </summary> /// <param name="symbol1">First symbol.</param> /// <param name="symbol2">Second symbol</param> /// <returns>Returns the weight for the given pairing of symbols.</returns> public double Weight(Symbol symbol1, Symbol symbol2) { return Weight(symbol1.Letter, symbol2.Letter); }
/// <summary> /// Determines if a the given amino acid is negatively charged or not. /// /// Classification according to http://en.wikipedia.org/wiki/Amino_acid"> wiki amino acid /// </summary> /// <param name="symbol">Symbol to classify.</param> /// <returns> /// Returns true: if the amino acid is negatively charged, false: otherwise. /// </returns> public bool IsNegative ( Symbol symbol ) { if ( symbol is SymbolAA ) return ( (SymbolAA) symbol ).IsNegative; return false; }
/// <summary> /// Determines if a the given amino acid is small or not. /// /// Classification according to http://en.wikipedia.org/wiki/Amino_acid wiki amino acid /// </summary> /// <param name="symbol">Symbol to classify.</param> /// <returns> /// Returns true: if the amino acid is small, false: otherwise. /// </returns> public bool IsSmall ( Symbol symbol ) { if ( symbol is SymbolAA ) return ( (SymbolAA) symbol ).IsSmall; return false; }
/// <summary> /// Gets for the bin index the given symbol belongs to. /// </summary> /// <param name="symbol"> The symbol. </param> /// <returns> Bin index, or -1 if the symbol isn't contained </returns> public int CalSymIndex(Symbol symbol) { Counter counter = null; if(DictionaryCounter.ContainsKey(symbol.Name)) counter = DictionaryCounter[symbol.Name]; if (counter == null) return (-1); return (counter.binIndex); }
/// <summary> /// Creates a counter instance. /// </summary> /// <param name="counts"> Counter for the symbol. </param> /// <param name="symbol"> The symbol itself. </param> /// <param name="binIndex"> Index of the histogram where the symbol belongs to. </param> public Counter (int counts, Symbol symbol, int binIndex) { this.counts = counts; this.symbol = symbol; this.binIndex = binIndex; }
/// <summary> /// Getter for the histogram value (=counts) for the specified object. /// </summary> /// <param name="symbol"> Symbol </param> /// <returns> Histogram value (=counts) for the given object. Zero if the /// symbol is not in the histogram. </returns> public int HistoValue(Symbol symbol) { Counter counter = null; if(DictionaryCounter.ContainsKey(symbol.Name)) counter = DictionaryCounter[symbol.Name]; if (counter == null) //unknown symbol return (0); return (counter.counts); }
/// <summary> /// Returns the relative frequency of the given symbol within the histogram. /// </summary> /// <param name="symbol"> A symbol. </param> /// <returns> Returns the relative frequency or zero if the symbol is unknown. </returns> public double Frequency(Symbol symbol) { return (sum > 0 ? (double)HistoValue(symbol) / sum : 0); }
/// <summary> /// Adds an symbol to the histogram with a given number of counts. /// </summary> /// <param name="symbol"> A symbol. </param> /// <param name="counts"> Counts for the given symbol. </param> public void Add(Symbol symbol, int counts) { Counter counter = null; //did the C# style if (DictionaryCounter.ContainsKey(symbol.Name)) counter = DictionaryCounter[symbol.Name]; if (counter == null) { counter = new Counter(counts, symbol, list.Count); DictionaryCounter.Add(symbol.Name, counter); list.Add(counter); sum++; } else { counter.counts += counts; sum += counts; } }
/// <summary> /// Adds a symbol to the histogram. /// </summary> /// <param name="symbol"> The symbol to add. </param> public void Add(Symbol symbol) { Add(symbol, 1); }
/// <summary> /// Setter for a pairing weight. /// </summary> /// <param name="symbol1">First symbol.</param> /// <param name="symbol2">Second symbol.</param> /// <param name="weight">Weight for the given pairing of symbols. Has to be in interval [0,1]</param> internal void Weight(Symbol symbol1, Symbol symbol2, double weight) { Weight(symbol1.Letter, symbol2.Letter, weight); }
/// <summary> Determines if a the given amino acid is hydrophobic or not. /// /// Classification according to http://en.wikipedia.org/wiki/Amino_acid"> wiki amino acid /// /// </summary> /// <param name="symbol"> Symbol to classify. </param> /// <returns> Returns true: if the amino acid is hydrophobic, false: otherwise. </returns> public bool IsHydrophobic ( Symbol symbol ) { if ( symbol is SymbolAA ) return ( (SymbolAA) symbol ).IsHydrophobic; return false; }
/// <summary> /// Gets the symbol weight /// </summary> /// <param name="symbol">Symbol</param> /// <returns>Returns the weight for the Symbol or the default weight if no weight /// for the symbol is defined.</returns> public double Weight(Symbol symbol) { //Fix on 17 March if(SymDictionary.ContainsKey(symbol)) return SymDictionary[symbol]; return defaultWeight; }
/// <summary> /// Determines if a the given amino acid is polar or not. /// /// Classification according to http://en.wikipedia.org/wiki/Amino_acid wiki amino acid /// </summary> /// <param name="symbol"> Symbol to classify. </param> /// <returns> Returns true: if the amino acid is polar, false: otherwise. </returns> public bool IsPolar ( Symbol symbol ) { if ( symbol is SymbolAA ) return ( (SymbolAA) symbol ).IsPolar; return false; }
/// <summary> /// Replaces the first occurrences of a symbol(symbol1) with a specified replacement symbol (symbol2). /// </summary> /// <param name="symbol1"> First symbol (to be replaced). </param> /// <param name="symbol2"> Second symbol (replacement). </param> public void Replace(Symbol symbol1, Symbol symbol2) { int index = symbolset.IndexOf(symbol1); if (index >= 0) { symbolset.RemoveAt(index); symbolset.Insert(index, symbol2); } }
/// <summary> /// Determines if a the given amino acid is charged or not. /// /// Classification according to http://en.wikipedia.org/wiki/Amino_acid"> wiki amino acid /// </summary> /// <param name="symbol">Symbol to classify.</param> /// <returns> /// Returns true: if the amino acid is charged, false: otherwise. /// </returns> public bool IsCharged ( Symbol symbol ) { if ( symbol is SymbolAA ) return ( (SymbolAA) symbol ).IsCharged; return false; }
/// <summary> /// Returns true if the symbol set is empty or if the given symbol is in the /// symbol set. /// </summary> /// <param name="symbol"> Given object </param> /// <returns> See summary </returns> public override Boolean Equals(Symbol symbol) { if (symbolset == null || symbol.Name == this.Name) return true; for (int i = 0; i < SymbolNumber; i++) if (this[i].Name == symbol.Name) return true; return false; }
/// <summary> /// Determines if a the given amino acid is tiny or not. /// Classification according to http://en.wikipedia.org/wiki/Amino_acid wiki Amino acid /// </summary> /// <param name="symbol">Symbol to classify.</param> /// <returns>Returns true: if the amino acid is tiny, false: otherwise.</returns> public bool IsTiny ( Symbol symbol ) { if ( symbol is SymbolAA ) return ( (SymbolAA) symbol ).IsTiny; return false; }
/// <summary> /// Adds a symbol to the set of symbols described by this meta symbol. /// </summary> /// <param name="symbol"> The symbol to add. </param> public void Add(Symbol symbol) { if (symbolset == null) this.symbolset = new List<Symbol>(); symbolset.Add(symbol); }
/// <summary> /// Removes the given symbol from the symbol set. /// </summary> /// <param name="symbol"></param> public void Remove(Symbol symbol) { if (symbolset != null) if(symbolset.Contains(symbol)) symbolset.Remove(symbol); }
/// <summary> /// Creates a map with all DNA symbols. This constructor is private /// to ensure that there will be always only one DNA alphabet. Use /// the Instance() method or the <see cref="QUT.Bio.BioPatML.Alphabets.AlphabetFactory"> AlphabetFactory </see> to create to create /// the alphabet. /// <para></para> /// Unknown symbols will be mapped to 'n'. /// /// </summary> private DnaAlphabet () : base( "DNA" ) { #region Prefixed set of DNA symbols Add( new SymbolMeta( 'n', "Any", "Any Nucleotide" ) ); Add( new SymbolMeta( 'x', "Any", "Any Nucleotide" ) ); Add( new SymbolMeta( '.', "NON", "No Nucleotide" ) ); Add( new SymbolMeta( '-', "Gap", "Gap" ) ); Add( new Symbol( 'g', "Gua", "Guanine" ) ); Add( new Symbol( 'a', "Ade", "Adenine" ) ); Add( new Symbol( 't', "Thy", "Thymine" ) ); Add( new Symbol( 'c', "Cyt", "Cytosine" ) ); #endregion #region Meta symbols of DNA Add( new SymbolMeta( 'm', "A/C", "Ade or Cyt" ) ); Add( new SymbolMeta( 'r', "A/G", "Ade or Gua" ) ); Add( new SymbolMeta( 'w', "A/T", "Ade or Thy" ) ); Add( new SymbolMeta( 's', "C/G", "Cyt or Gua" ) ); Add( new SymbolMeta( 'y', "C/T", "Cyt or Thy" ) ); Add( new SymbolMeta( 'k', "G/T", "Gua or Thy" ) ); Add( new SymbolMeta( 'v', "ACG", "Ade or Cyt or Gua" ) ); Add( new SymbolMeta( 'h', "ACT", "Ade or Cyt or Thy" ) ); Add( new SymbolMeta( 'd', "AGT", "Ade or Gua or Thy" ) ); Add( new SymbolMeta( 'b', "CGT", "Cyt or Gua or Thy" ) ); #endregion #region Complements this['g'].Complement = ( this['c'] ); this['a'].Complement = ( this['t'] ); this['t'].Complement = ( this['a'] ); this['c'].Complement = ( this['g'] ); this['m'].Complement = ( this['k'] ); this['r'].Complement = ( this['y'] ); this['w'].Complement = ( this['w'] ); this['s'].Complement = ( this['s'] ); this['y'].Complement = ( this['r'] ); this['k'].Complement = ( this['m'] ); this['v'].Complement = ( this['b'] ); this['h'].Complement = ( this['d'] ); this['d'].Complement = ( this['h'] ); this['b'].Complement = ( this['v'] ); #endregion #region equivalents // equals symbols ( (SymbolMeta) this['.'] ).Add( this['.'] ); ( (SymbolMeta) this['-'] ).Add( this['-'] ); ( (SymbolMeta) this['m'] ).Add( this['a'] ); ( (SymbolMeta) this['m'] ).Add( this['c'] ); ( (SymbolMeta) this['r'] ).Add( this['a'] ); ( (SymbolMeta) this['r'] ).Add( this['g'] ); ( (SymbolMeta) this['w'] ).Add( this['a'] ); ( (SymbolMeta) this['w'] ).Add( this['t'] ); ( (SymbolMeta) this['s'] ).Add( this['c'] ); ( (SymbolMeta) this['s'] ).Add( this['g'] ); ( (SymbolMeta) this['y'] ).Add( this['c'] ); ( (SymbolMeta) this['y'] ).Add( this['t'] ); ( (SymbolMeta) this['k'] ).Add( this['g'] ); ( (SymbolMeta) this['k'] ).Add( this['t'] ); ( (SymbolMeta) this['v'] ).Add( this['a'] ); ( (SymbolMeta) this['v'] ).Add( this['c'] ); ( (SymbolMeta) this['v'] ).Add( this['g'] ); ( (SymbolMeta) this['h'] ).Add( this['a'] ); ( (SymbolMeta) this['h'] ).Add( this['c'] ); ( (SymbolMeta) this['h'] ).Add( this['t'] ); ( (SymbolMeta) this['d'] ).Add( this['a'] ); ( (SymbolMeta) this['d'] ).Add( this['g'] ); ( (SymbolMeta) this['d'] ).Add( this['t'] ); ( (SymbolMeta) this['b'] ).Add( this['c'] ); ( (SymbolMeta) this['b'] ).Add( this['g'] ); ( (SymbolMeta) this['b'] ).Add( this['t'] ); ( (SymbolMeta) this['n'] ).Add( this['a'] ); ( (SymbolMeta) this['n'] ).Add( this['t'] ); ( (SymbolMeta) this['n'] ).Add( this['c'] ); ( (SymbolMeta) this['n'] ).Add( this['g'] ); ( (SymbolMeta) this['x'] ).Add( this['a'] ); ( (SymbolMeta) this['x'] ).Add( this['t'] ); ( (SymbolMeta) this['x'] ).Add( this['c'] ); ( (SymbolMeta) this['x'] ).Add( this['g'] ); #endregion defaultSymbol = this['n']; }