Alphabet

From Bio++ Wiki
Revision as of 12:39, 19 October 2012 by Gueguen (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Here is a simple introduction to the Alphabet class.

HOW TO USE THAT FILE:

  • General comments are written using the * * syntaxe.
  • Code lines are switched off using '//'. To activate those lines, just remove the '//' characters!
  • You're welcome to extensively modify that file!
  • A way to compile the file is:

<source lang="bash"> WHEREISBIOPP=$HOME/local

g++ -I$WHEREISBIOPP/include -L$WHEREISBIOPP/lib -lbpp-core -lbpp-seq ExAlphabet.cpp -o exalphabet </source>


  • Here is the code:


<source lang="cpp">

/* We start by including what we'll need, and sort the inclusions a bit */

/* From the STL: */

  1. include <iostream> /* to be able to output stuff in the terminal.*/

/* We'll use the standard template library namespace: */

using namespace std;

/* From SeqLib: */

  1. include <Bpp/Seq/Alphabet.all> /* this include all alphabets in one shot */

/* All Bio++ functions are also in a namespace, so we'll use it: */

using namespace bpp;

/* Now starts the real stuff... */

int main(int args, char ** argv) {

 /*
  * We surround our code with a try-catch block, in case some error occurs:
  */
 try
   {
     cout << "Hello World!" << endl;
     /*
      * A key set of objects in Bio++ is the Alphabet family.
      * Here is how to get one of those:
      */
     //    Alphabet *alphabet = new DNA();
     //    cout << "Playing with alphabet " << alphabet->getAlphabetType() << endl;
     //
     //    string state = "A";
     //    bool test = alphabet->isCharInAlphabet("A");
     //    cout << "Test for state " << state << ": " << (test ? ":)" : ":(") << endl;
     //    if(test) cout << state << " actually stands for " << alphabet->getName(state) << endl;
     /* ----------------
      * QUESTION 1: try other states! (try to be creative or evil ;) )
      * ----------------
      */
   
     /*
      * How many of those characters are supported?
      */
     //    cout << "Numbers of characters: " << alphabet->getNumberOfChars() << endl;
     //    cout << "Numbers of types     : " << alphabet->getNumberOfTypes() << endl;
     //    cout << "Size of the alphabet : " << alphabet->getSize()          << endl;
     /* ----------------
      * QUESTION 2: do you understand those numbers? If not, you were not creative/evil enough at the previous question!
      * ----------------
      */
   
     /* ----------------
      * QUESTION 3: fetch the documentation for functions getALias, getGeneric, isGap and isUnresolved, and play a bit with them.
      * ----------------
      */
     /* ----------------
      * QUESTION 4: change the alphabet to ProteicAlphabet and then to StandardCodonAlphabet, and compare (use the documentation for help).
      * ----------------
      */
     /*
      * Alphabet link character states (human representation) to integer codes (computer representation).
      *
      * Although you'll probably never have to care about that (you're human, not a computer after all),
      * it might be good to sneak a bit in here... try the following piece of code:
      */
     //    vector<string> states = alphabet->getSupportedChars();
     //    cout << "Char\tInt" << endl;
     //    for(unsigned int i = 0; i < states.size(); i++)
     //    {
     //      cout << states[i] << "\t" << alphabet->charToInt(states[i]) << endl; 
     //    }
   }
 catch(Exception& e)
   {
     cout << "Bio++ exception:" << endl;
     cout << e.what() << endl;
     return(-1);
   }
 catch(exception& e)
   {
     cout << "Any other exception:" << endl;
     cout << e.what() << endl;
     return(-1);
   }
 return(0);

}

</source>