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 //int aachar2num(char a);
00013 //declared in bioseq.h
00014 /*
00015 int max(int i1, int i2, int i3) {
00016    return max(max(i1,i2),i3);
00017 }
00018 int max(int i1, int i2) {
00019    if (i1>i2) return i1;
00020    return i2;
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]; /*read();*/ }
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; // debug function
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       /* return true for success, false for failure.
00116        * if nucMatrix is set, then it will use the 
00117        * hashbase() function defined in codon.h to
00118        * convert Base Char to integer, other than the generic 
00119        * char X-'A' function
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       /* the gap score, this should have something to do 
00157        * with the matrix
00158        * g is the length of the gap.
00159        */
00160       //int gap(int g);
00161       //gap(g)=alpha + (g-1)*beta
00162       //this is used in the resursion
00163       int alpha, beta;
00164 
00165    private:
00166       string path;
00167       string name; // Blosum50, Blosum62, etc
00168       int match;
00169       int mismatch;
00170       int mat[32][32]; // use only 27 of the elements
00171       static int default_mat[32][32];
00172       int maxs, mins;
00173       char aas[32]; // amino acid symbols, at most 26 so we had enough
00174       int numsymbol; // the size of aas array
00175       mutable char **words;
00176       mutable int wordsArraySize;
00177       mutable int wordSize;  // recoreds the size of words
00178 };
00179 
00180 #endif

Generated on Wed Aug 10 11:56:55 2011 for Softwares from Orpara by  doxygen 1.5.6