bpp-seq  2.2.0
NucleicAcidsReplication.cpp
Go to the documentation of this file.
1 //
2 // File: NucleicAcidsReplication.cpp
3 // Created by: Julien Dutheil
4 // Created on: Fri May 20 14:40 2005
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 
41 
42 using namespace bpp;
43 
44 using namespace std;
45 
47  nuc1_(nuc1), nuc2_(nuc2), trans_()
48 {
49  trans_[-1] = -1;
50  trans_[0] = 3;
51  trans_[1] = 2;
52  trans_[2] = 1;
53  trans_[3] = 0;
54 
55  trans_[4] = 9;
56  trans_[5] = 8;
57  trans_[6] = 6;
58  trans_[7] = 7;
59  trans_[8] = 5;
60  trans_[9] = 4;
61 
62  trans_[10] = 13;
63  trans_[11] = 12;
64  trans_[12] = 11;
65  trans_[13] = 10;
66 
67  trans_[14] = 14;
68 }
69 
71 {
72  nuc1_->intToChar(state);
73  return trans_[state];
74 }
75 
76 std::string NucleicAcidsReplication::translate(const std::string& state) const throw (BadCharException)
77 {
78  int i = nuc1_->charToInt(state);
79  return nuc2_->intToChar(trans_[i]);
80 }
81 
83 {
84  if (sequence.getAlphabet()->getAlphabetType() != getSourceAlphabet()->getAlphabetType())
85  throw AlphabetMismatchException("NucleicAcidsReplication::translate", getSourceAlphabet(), getTargetAlphabet());
86  BasicSequence* tSeq = new BasicSequence(sequence.getName(), "", sequence.getComments(), getTargetAlphabet());
87  for (unsigned int i = 0; i < sequence.size(); i++)
88  {
89  tSeq->addElement(translate(sequence.getValue(i)));
90  }
91  //tSeq->setSense(!tSeq->getSense());
92  return tSeq;
93 }
94 
95 
97 {
98  nuc2_->intToChar(state);
99  return trans_[state];
100 }
101 
102 std::string NucleicAcidsReplication::reverse(const std::string& state) const throw (BadCharException)
103 {
104  int i = nuc2_->charToInt(state);
105  return nuc1_->intToChar(trans_[i]);
106 }
107 
109 {
110  if (sequence.getAlphabet()->getAlphabetType() != getTargetAlphabet()->getAlphabetType())
111  throw AlphabetMismatchException("NucleicAcidsReplication::reverse", getSourceAlphabet(), getTargetAlphabet());
112  BasicSequence* rSeq = new BasicSequence(sequence.getName(), "", sequence.getComments(), getSourceAlphabet());
113  for (unsigned int i = 0; i < sequence.size(); i++)
114  {
115  rSeq->addElement(reverse(sequence.getValue(i)));
116  }
117  //rSeq->setSense(! rSeq->getSense());
118  return rSeq;
119 }
120 
An alphabet exception thrown when trying to specify a bad char to the alphabet.
This alphabet is used to deal NumericAlphabet.
STL namespace.
int translate(int state) const
Translate a given state coded as a int from source alphabet to target alphabet.
int reverse(int state) const
Translate a given state coded as a int from target alphabet to source alphabet.
virtual void addElement(const std::string &c)
Add a character to the end of the list.
Definition: SymbolList.cpp:121
A basic implementation of the Sequence interface.
Definition: Sequence.h:207
The sequence interface.
Definition: Sequence.h:74
An alphabet exception thrown when trying to specify a bad int to the alphabet.
Exception thrown when two alphabets do not match.
NucleicAcidsReplication(const NucleicAlphabet *nuc1, const NucleicAlphabet *nuc2)
The abstract base class for nucleic alphabets.