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:
00035 Matrix() : path("/home/kzhou/proj/seqaln/matrix"),
00036 name("blosum50"), match(0), mismatch(0),
00037 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]; }
00038 Matrix(const string& matrixName, bool nucMatrix=false)
00039 : path("/home/kzhou/proj/seqaln/matrix"),
00040 name(matrixName), match(0), mismatch(0),
00041 words(0), wordSize(0) { read(nucMatrix); }
00045 Matrix(const Matrix& mt);
00046
00047
00048 Matrix(int m, int mis) : match(m), mismatch(mis) { }
00049 ~Matrix();
00050 int getMinScore() const { return mins; }
00051 int getMaxScore() const { return maxs; }
00057 Matrix& operator=(const Matrix& mt);
00061 void show();
00062
00067 const char* getAlphabet() const { return aas; }
00068 int getNumberOfAlphabet() const { return numsymbol; }
00069
00073 void getWords(vector<string> &words, int ws) const;
00074 void growWord(const vector<string> &in, vector<string> &ou) const;
00075 void expandWord(char** &in, int &insize, int &ws) const;
00080 char** allwords(int ws) const;
00081 int getNumberOfWords() const { return wordsArraySize; }
00082 int getCurrentWordSize() const { return wordSize; }
00083 void showWords() const;
00094 int similarWord_debug(ostream &ous, const char* w, int ws, int cutoff=10, float fractioncutoff=0.75) const;
00098 int similarWord(vector<char*> &neighbor, const char* w, int ws, float cutoff=11, float fractioncutoff=0.8) const;
00099
00100
00101
00102
00103
00104
00105
00106 bool read(bool nucMatrix=false);
00107 bool read(const string &p, const string &n) { setPath(p); name=n; read(); }
00108
00111 void setMatrix(const string &n) { name=n; read(); }
00112
00113 void setPath(const string &p) { path=p; }
00114 int getMatchScore(const char c1, const char c2) {
00115 if (c1==c2) return match; return mismatch; }
00122 int lookup(int row, int col) const {
00123 if (row > 26 || col > 26) {
00124 cerr << "Matrix index out of bound " << row << ", " << col << endl;
00125 exit(1);
00126 }
00127 return mat[row][col]; }
00133 int lookup(char row, char col) const { return mat[aachar2num(row)][aachar2num(col)]; }
00134
00139 int score(const int* x, const int* y, const int len) const;
00140
00141
00142
00143
00144
00145
00146
00147
00148 int alpha, beta;
00149
00150 private:
00151 string path;
00152 string name;
00153 int match;
00154 int mismatch;
00155 int mat[32][32];
00156 static int default_mat[32][32];
00157 int maxs, mins;
00158 char aas[32];
00159 int numsymbol;
00160 mutable char **words;
00161 mutable int wordsArraySize;
00162 mutable int wordSize;
00163 };
00164
00165 #endif