libsequence  1.9.5
PathwayHelper.cc
1 /*
2 
3 Copyright (C) 2003-2009 Kevin Thornton, krthornt[]@[]uci.edu
4 
5 Remove the brackets to email me.
6 
7 This file is part of libsequence.
8 
9 libsequence is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 libsequence is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 long with libsequence. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #include <string>
25 #include <vector>
26 #include <cassert>
27 #include <cctype>
29 using std::string;
30 
31 namespace Sequence
32 {
33  Inter2_t Intermediates2(const std::string &codon1,
34  const std::string &codon2)
42  {
43  Inter2_t intermediates({{std::string(3,' '),std::string(3,' ')}});
44 
45  unsigned i,j;
46  unsigned pos[2];
47 
48  for (i = 0, j = 0; i <= 2; ++i)
49  if (char(std::toupper(codon1[i])) != char(std::toupper(codon2[i])))
50  pos[j++] = i;
51  switch (pos[0])
52  {
53  case 0:
54  intermediates[0][0] = char(std::toupper(codon2[0]));
55  intermediates[0][1] = char(std::toupper(codon1[1]));
56  intermediates[0][2] = char(std::toupper(codon1[2]));
57  break;
58  case 1:
59  intermediates[0][0] = char(std::toupper(codon1[0]));
60  intermediates[0][1] = char(std::toupper(codon2[1]));
61  intermediates[0][2] = char(std::toupper(codon1[2]));
62  break;
63  case 2:
64  intermediates[0][0] = char(std::toupper(codon1[0]));
65  intermediates[0][1] = char(std::toupper(codon1[1]));
66  intermediates[0][2] = char(std::toupper(codon2[2]));
67  break;
68  }
69 
70  switch(pos[1])
71  {
72  case 0:
73  intermediates[1][0] = char(std::toupper(codon2[0]));
74  intermediates[1][1] = char(std::toupper(codon1[1]));
75  intermediates[1][2] = char(std::toupper(codon1[2]));
76  break;
77  case 1:
78  intermediates[1][0] = char(std::toupper(codon1[0]));
79  intermediates[1][1] = char(std::toupper(codon2[1]));
80  intermediates[1][2] = char(std::toupper(codon1[2]));
81  break;
82  case 2:
83  intermediates[1][0] = char(std::toupper(codon1[0]));
84  intermediates[1][1] = char(std::toupper(codon1[1]));
85  intermediates[1][2] = char(std::toupper(codon2[2]));
86  break;
87  }
88  return intermediates;
89  }
90 
91  Inter3_t Intermediates3(const std::string &codon1, const std::string &codon2)
100  {
101  Inter3_t intermediates({{std::string(3,' '),
102  std::string(3,' '),
103  std::string(3,' '),
104  std::string(3,' '),
105  std::string(3,' '),
106  std::string(3,' '),
107  std::string(3,' '),
108  std::string(3,' '),
109  std::string(3,' ')}});
110 
111  intermediates[0][0] = char(std::toupper(codon2[0]));
112  intermediates[0][1] = char(std::toupper(codon1[1]));
113  intermediates[0][2] = char(std::toupper(codon1[2]));
114 
115  intermediates[1][0] = char(std::toupper(codon2[0]));
116  intermediates[1][1] = char(std::toupper(codon2[1]));
117  intermediates[1][2] = char(std::toupper(codon1[2]));
118 
119  intermediates[2][0] = char(std::toupper(codon2[0]));
120  intermediates[2][1] = char(std::toupper(codon1[1]));
121  intermediates[2][2] = char(std::toupper(codon2[2]));
122 
123  intermediates[3][0] = char(std::toupper(codon1[0]));
124  intermediates[3][1] = char(std::toupper(codon2[1]));
125  intermediates[3][2] = char(std::toupper(codon1[2]));
126 
127  intermediates[4][0] = char(std::toupper(codon2[0]));
128  intermediates[4][1] = char(std::toupper(codon2[1]));
129  intermediates[4][2] = char(std::toupper(codon1[2]));
130 
131  intermediates[5][0] = char(std::toupper(codon1[0]));
132  intermediates[5][1] = char(std::toupper(codon2[1]));
133  intermediates[5][2] = char(std::toupper(codon2[2]));
134 
135  intermediates[6][0] = char(std::toupper(codon1[0]));
136  intermediates[6][1] = char(std::toupper(codon1[1]));
137  intermediates[6][2] = char(std::toupper(codon2[2]));
138 
139  intermediates[7][0] = char(std::toupper(codon2[0]));
140  intermediates[7][1] = char(std::toupper(codon1[1]));
141  intermediates[7][2] = char(std::toupper(codon2[2]));
142 
143  intermediates[8][0] = char(std::toupper(codon1[0]));
144  intermediates[8][1] = char(std::toupper(codon2[1]));
145  intermediates[8][2] = char(std::toupper(codon2[2]));
146  return intermediates;
147  }
148 }
The namespace in which this library resides.
Inter2_t Intermediates2(const std::string &codon1, const std::string &codon2)
Calculate the intermediate codons between a pair of codons diverged at 2 positions.
declarations of Sequence::Intermediates2 and Sequence::Intermediates3
Inter3_t Intermediates3(const std::string &codon1, const std::string &codon2)
Calculate the intermediate codons between a pair of codons diverged at 3 positions.