Пример #1
0
bool AlphabetTools::checkAlphabetCodingSize(const Alphabet& alphabet) throw (AlphabetException)
{
  if (alphabet.getNumberOfChars() == 0)
    return true;  // Will this really happen?
  size_t size = alphabet.intToChar(0).size();
  for (int i = 1; i < static_cast<int>(alphabet.getNumberOfTypes()); ++i)
  {
    if (alphabet.intToChar(i).size() != size)
      return false;
  }
  return true;
}
Пример #2
0
unsigned int AlphabetTools::getAlphabetCodingSize(const Alphabet& alphabet) throw (AlphabetException)
{
  if (!checkAlphabetCodingSize(alphabet))
    throw AlphabetException("Bad alphabet in function Alphabet::getAlphabetCodingSize().");
  return static_cast<unsigned int>(alphabet.intToChar(0).size());
}
Пример #3
0
int RNY::getRNY(int i, int j, int k, const Alphabet& alph) const throw (BadCharException)
{
  if (alph.getAlphabetType() != "DNA alphabet")
  {
    throw AlphabetException ("RNY::getRNY : Sequence must be DNA",
                             &alph);
  }

  char li = alph.intToChar(i)[0];
  char lj = alph.intToChar(j)[0];
  char lk = alph.intToChar(k)[0];

  int r = 0;
  int s = 0;

  switch (li)
  {
  case 'A':
  case 'G':
    r += 0;
    break;
  case 'C':
    r += 1;
    break;
  case 'T':
    r += 2;
    break;
  case '-':
  case 'N':
    s += 1;
    break;
  default:
    throw BadCharException(&li, "RNY::getRNY(int,int;int,alph): Specified base unknown.");
  }

  r *= 4;
  s *= 2;

  switch (lj)
  {
  case 'A':
    r += 0;
    break;
  case 'G':
    r += 1;
    break;
  case 'C':
    r += 2;
    break;
  case 'T':
    r += 3;
    break;
  case '-':
  case 'N':
    s += 1;
    break;
  default:
    throw BadCharException(&lj, "RNY::getRNY(int,int;int,alph): Specified base unknown.");
  }

  r *= 3;
  s *= 2;

  switch (lk)
  {
  case 'A':
    r += 0;
    break;
  case 'G':
    r += 1;
    break;
  case 'C':
  case 'T':
    r += 2;
    break;
  case '-':
  case 'N':
    s += 1;
    break;
  default:
    throw BadCharException(&lk, "RNY::getRNY(int,int;int,alph): Specified base unknown.");
  }

  return 50 * s + r;
}