00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_SEQ_SUBST_WEIGHT_MATRIX_HH
00020 #define OST_SEQ_SUBST_WEIGHT_MATRIX_HH
00021
00022 #include <ctype.h>
00023 #include <string.h>
00024 #include <boost/shared_ptr.hpp>
00025 #include <ost/config.hh>
00026 #include <ost/seq/alg/module_config.hh>
00027
00028
00029
00030
00031 namespace ost { namespace seq { namespace alg {
00032
00033 class SubstWeightMatrix;
00034
00035 typedef boost::shared_ptr<SubstWeightMatrix> SubstWeightMatrixPtr;
00036
00038 class DLLEXPORT_OST_SEQ_ALG SubstWeightMatrix {
00039
00040 public:
00041 typedef short WeightType;
00042 const static int ALPHABET_SIZE='Z'-'A'+1;
00043 enum Preset{BLOSUM45 = 0,
00044 BLOSUM62 = 1,
00045 BLOSUM80 = 2,
00046 BLOSUM100 = 3};
00051 SubstWeightMatrix():max_weight_(0),min_weight_(0) {
00052 ::memset(weights_, 0, sizeof(WeightType)*ALPHABET_SIZE*ALPHABET_SIZE);
00053 }
00054
00055 void AssignPreset(Preset p);
00056
00061 WeightType GetWeight(char aa_one, char aa_two) const
00062 {
00063 if (!(IsAlpha(aa_one) && IsAlpha(aa_two))) {
00064 return 0;
00065 }
00066 int i=Index(aa_one, aa_two);
00067 return (i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE) ? weights_[i] : 0;
00068 }
00069
00071 WeightType GetMinWeight() const { return min_weight_; }
00072
00074 WeightType GetMaxWeight() const { return max_weight_; }
00075
00080 void SetWeight(char aa_one, char aa_two, WeightType weight)
00081 {
00082 if ((IsAlpha(aa_one) && IsAlpha(aa_two))) {
00083 int i=Index(aa_one, aa_two);
00084 if (i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE) {
00085 weights_[i]=weight;
00086 min_weight_ = std::min(min_weight_,weight);
00087 max_weight_ = std::max(max_weight_,weight);
00088 }
00089 }
00090 }
00091
00092 private:
00093 int Index(char aa_one, char aa_two) const {
00094 return (toupper(aa_one)-'A')*ALPHABET_SIZE+(toupper(aa_two)-'A');
00095 }
00096
00098 bool IsAlpha(char aa) const {
00099 return (toupper(aa)>='A' && toupper(aa)<='Z');
00100 }
00101 WeightType weights_[ALPHABET_SIZE*ALPHABET_SIZE];
00102 WeightType max_weight_;
00103 WeightType min_weight_;
00104 };
00105
00106 }}}
00107
00108 #endif