matrix.h
Go to the documentation of this file.00001 #ifndef MATRIX_H
00002 #define MATRIX_H
00003
00004 #include <string>
00005 #include <vector>
00006 #include <iostream>
00007 #include <fstream>
00008 #include "bioseq.h"
00009
00010 using namespace std;
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 void expandCombination(char** &buff, int &buffsize, int &ws, const char* alphabet, int alphabetsize);
00025
00029 class Matrix {
00030 public:
00039 Matrix() : path("/home/kzhou/proj/seqaln/matrix"),
00040 name("blosum50"), match(0), mismatch(0),
00041 words(0), wordSize(0), mat() { for (int i=0; i<26; i++) for (int j=0; j<26; j++) mat[i][j]=default_mat[i][j]; }
00046 Matrix(const string& matrixName, bool nucMatrix=false)
00047 : path("/home/kzhou/proj/seqaln/matrix"),
00048 name(matrixName), match(0), mismatch(0),
00049 words(0), wordSize(0) { read(nucMatrix); }
00053 Matrix(const Matrix& mt);
00054
00056 Matrix(int m, int mis) : match(m), mismatch(mis) { }
00057 ~Matrix();
00058 int getMinScore() const { return mins; }
00059 int getMaxScore() const { return maxs; }
00065 Matrix& operator=(const Matrix& mt);
00069 void show();
00070
00075 const char* getAlphabet() const { return aas; }
00083 int getNumberOfAlphabet() const { return numsymbol; }
00084
00088 void getWords(vector<string> &words, int ws) const;
00089 void growWord(const vector<string> &in, vector<string> &ou) const;
00090 void expandWord(char** &in, int &insize, int &ws) const;
00095 char** allwords(int ws) const;
00096 int getNumberOfWords() const { return wordsArraySize; }
00097 int getCurrentWordSize() const { return wordSize; }
00098 void showWords() const;
00109 int similarWord_debug(ostream &ous, const char* w, int ws, int cutoff=10, float fractioncutoff=0.75) const;
00113 int similarWord(vector<char*> &neighbor, const char* w, int ws, float cutoff=11, float fractioncutoff=0.8) const;
00114
00115
00116
00117
00118
00119
00120
00121 bool read(bool nucMatrix=false);
00122 bool read(const string &p, const string &n) { setPath(p); name=n; read(); }
00123
00126 void setMatrix(const string &n) { name=n; read(); }
00127
00128 void setPath(const string &p) { path=p; }
00129 int getMatchScore(const char c1, const char c2) {
00130 if (c1==c2) return match; return mismatch; }
00137 int lookup(int row, int col) const {
00138 if (row > 26 || col > 26) {
00139 cerr << "Matrix index out of bound " << row << ", " << col << endl;
00140 exit(1);
00141 }
00142 return mat[row][col]; }
00148 int lookup(char row, char col) const { return mat[aachar2num(row)][aachar2num(col)]; }
00149
00154 int score(const int* x, const int* y, const int len) const;
00155
00156
00157
00158
00159
00160
00161
00162
00163 int alpha, beta;
00164
00165 private:
00166 string path;
00167 string name;
00168 int match;
00169 int mismatch;
00170 int mat[32][32];
00171 static int default_mat[32][32];
00172 int maxs, mins;
00173 char aas[32];
00174 int numsymbol;
00175 mutable char **words;
00176 mutable int wordsArraySize;
00177 mutable int wordSize;
00178 };
00179
00180 #endif