~ubuntu-branches/ubuntu/oneiric/libbpp-seq/oneiric

« back to all changes in this revision

Viewing changes to src/Bpp/Seq/Alphabet/AlphabetTools.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Dutheil
  • Date: 2011-06-09 11:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110609110000-hnfrd9it0np58l54
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// File: AlphabetTools.cpp
 
3
// Created by: Julien Dutheil
 
4
// Created on: Fri Oct 10 17:27:39 2003
 
5
//
 
6
 
 
7
#include "AlphabetTools.h"
 
8
#include <Bpp/Text/TextTools.h>
 
9
 
 
10
using namespace bpp;
 
11
 
 
12
// From the STL:
 
13
#include <ctype.h>
 
14
#include <iostream>
 
15
 
 
16
using namespace std;
 
17
 
 
18
/**********************************************************************************************/
 
19
 
 
20
const DNA AlphabetTools::DNA_ALPHABET;
 
21
const RNA AlphabetTools::RNA_ALPHABET;
 
22
const ProteicAlphabet AlphabetTools::PROTEIN_ALPHABET;
 
23
const DefaultAlphabet AlphabetTools::DEFAULT_ALPHABET;
 
24
 
 
25
/**********************************************************************************************/
 
26
 
 
27
int AlphabetTools::getType(char state)
 
28
{
 
29
  if(state == '-') return -1;
 
30
  state = toupper(state);
 
31
  bool d = DNA_ALPHABET.isCharInAlphabet(TextTools::toString(state));
 
32
  bool r = RNA_ALPHABET.isCharInAlphabet(TextTools::toString(state));
 
33
  bool p = PROTEIN_ALPHABET.isCharInAlphabet(TextTools::toString(state));
 
34
 
 
35
  if(!d && !r && !p) return 0; //Unknown character
 
36
  else if(d && !r && !p) return 1; //DNA specific
 
37
  else if(!d && r && !p) return 2; //RNA specific
 
38
  else if(!d && !r && p) return 3; //Protein specific
 
39
  else if(d && r && !p) return 4; //Nucleotide specific 
 
40
  else if(d && !r && p) return 5; //DNA or Protein specific 
 
41
  else if(!d && r && p) return 6; //RNA or Protein specific 
 
42
  else return 7; //Non-specific character
 
43
}
 
44
 
 
45
/**********************************************************************************************/
 
46
 
 
47
bool AlphabetTools::checkAlphabetCodingSize(const Alphabet & alphabet) throw (AlphabetException)
 
48
{
 
49
  if(alphabet.getNumberOfChars() == 0) return true; //Will this really happen?
 
50
  unsigned int size = alphabet.intToChar(0).size();
 
51
  for(unsigned int i = 1; i < alphabet.getNumberOfTypes(); i++)
 
52
  {
 
53
    if(alphabet.intToChar(i).size() != size) return false;
 
54
  }
 
55
  return true;
 
56
}
 
57
 
 
58
/**********************************************************************************************/
 
59
 
 
60
bool AlphabetTools::checkAlphabetCodingSize(const Alphabet * alphabet) throw (AlphabetException)
 
61
{
 
62
  return checkAlphabetCodingSize(* alphabet);
 
63
}
 
64
 
 
65
/**********************************************************************************************/
 
66
 
 
67
int AlphabetTools::getAlphabetCodingSize(const Alphabet & alphabet) throw (AlphabetException)
 
68
{
 
69
  if(!checkAlphabetCodingSize(alphabet)) throw AlphabetException("Bad alphabet in function Alphabet::getAlphabetCodingSize().");
 
70
  return alphabet.intToChar(0).size();
 
71
}
 
72
 
 
73
/**********************************************************************************************/
 
74
 
 
75
int AlphabetTools::getAlphabetCodingSize(const Alphabet * alphabet) throw (AlphabetException)
 
76
{
 
77
  return getAlphabetCodingSize(* alphabet);
 
78
}
 
79
 
 
80
/**********************************************************************************************/
 
81