bpp-seq  2.2.0
CodonAlphabet.cpp
Go to the documentation of this file.
1 //
2 // File: CodonAlphabet.cpp
3 // Created by: Julien Dutheil
4 // Created on: Sun Oct 12 17:41:56 2003
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for sequences analysis.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #include "CodonAlphabet.h"
41 #include <Bpp/Text/TextTools.h>
42 
43 using namespace bpp;
44 
45 // From the STL:
46 #include <iostream>
47 
48 using namespace std;
49 
50 /******************************************************************************/
51 
52 int CodonAlphabet::getCodon(int pos1, int pos2, int pos3) const
53 throw (BadIntException)
54 {
55  vector<int> vint;
56  vint.push_back(pos1);
57  vint.push_back(pos2);
58  vint.push_back(pos3);
59 
60  return getWord(vint);
61 }
62 
63 /******************************************************************************/
64 
65 string CodonAlphabet::getCodon(const string & pos1, const string & pos2, const string & pos3) const
66 throw (BadCharException)
67 {
68  vector<string> vint;
69  vint.push_back(pos1);
70  vint.push_back(pos2);
71  vint.push_back(pos3);
72 
73  return getWord(vint);
74 }
75 
76 /******************************************************************************/
77 
78 int CodonAlphabet::getFirstPosition (int codon) const throw (BadIntException)
79 {
80  return getNPosition(codon,0);
81 }
82 
83 /******************************************************************************/
84 
86 {
87  return getNPosition(codon,1);
88 }
89 
90 /******************************************************************************/
91 
92 int CodonAlphabet::getThirdPosition (int codon) const throw (BadIntException)
93 {
94  return getNPosition(codon,2);
95 }
96 
97 /******************************************************************************/
98 
99 string CodonAlphabet::getFirstPosition (const string & codon) const
100 throw (BadCharException)
101 {
102  return getNPosition(codon,0);
103 }
104 
105 /******************************************************************************/
106 
107 string CodonAlphabet::getSecondPosition(const string & codon) const
108 throw (BadCharException)
109 {
110  return getNPosition(codon,1);
111 }
112 
113 /******************************************************************************/
114 
115 string CodonAlphabet::getThirdPosition (const string & codon) const
116 throw (BadCharException)
117 {
118  return getNPosition(codon,2);
119 }
120 
121 /******************************************************************************/
An alphabet exception thrown when trying to specify a bad char to the alphabet.
This alphabet is used to deal NumericAlphabet.
STL namespace.
virtual int getCodon(int pos1, int pos2, int pos3) const
Get the int code for a codon given the int code of the three underlying positions.
virtual int getFirstPosition(int codon) const
Get the int code of the first position of a codon given its int description.
virtual int getSecondPosition(int codon) const
Get the int code of the second position of a codon given its int description.
An alphabet exception thrown when trying to specify a bad int to the alphabet.
virtual int getThirdPosition(int codon) const
Get the int code of the third position of a codon given its int description.