| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : di_protdist.hxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // =============================================================== // |
|---|
| 10 | |
|---|
| 11 | #ifndef DI_PROTDIST_HXX |
|---|
| 12 | #define DI_PROTDIST_HXX |
|---|
| 13 | |
|---|
| 14 | #ifndef AP_SEQ_SIMPLE_PRO_HXX |
|---|
| 15 | #include <AP_seq_simple_pro.hxx> |
|---|
| 16 | #endif |
|---|
| 17 | |
|---|
| 18 | const int di_max_aa = stop; // must be 20 |
|---|
| 19 | const int di_max_paa = unk; // includes virtual aa |
|---|
| 20 | const int di_resolution = 1000; // max res |
|---|
| 21 | const int di_max_dist = 10; // max dist |
|---|
| 22 | |
|---|
| 23 | // stop is first non real AA == 20 |
|---|
| 24 | |
|---|
| 25 | enum di_codetype { |
|---|
| 26 | universal, ciliate, mito, vertmito, flymito, yeastmito |
|---|
| 27 | }; |
|---|
| 28 | enum di_cattype { |
|---|
| 29 | none, similarity, kimura, pam, chemical, hall, george |
|---|
| 30 | }; |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | typedef double di_aa_matrix[di_max_aa][di_max_aa]; |
|---|
| 34 | typedef double di_paa_matrix[di_max_paa][di_max_paa]; |
|---|
| 35 | typedef char di_bool_matrix[di_max_paa][di_max_paa]; |
|---|
| 36 | |
|---|
| 37 | class DI_ENTRY; |
|---|
| 38 | class AP_smatrix; |
|---|
| 39 | |
|---|
| 40 | class di_protdist : virtual Noncopyable { |
|---|
| 41 | static double pameigs[20]; |
|---|
| 42 | static double pamprobs[20][20]; |
|---|
| 43 | di_codetype whichcode; |
|---|
| 44 | di_cattype whichcat; |
|---|
| 45 | |
|---|
| 46 | long spp; // number of species |
|---|
| 47 | long chars; // number of characters |
|---|
| 48 | |
|---|
| 49 | // spp = number of species chars = number of sites in actual sequences |
|---|
| 50 | |
|---|
| 51 | double freqa, freqc, freqg, freqt, ttratio, xi, xv, ease, fracchange; |
|---|
| 52 | DI_ENTRY **entries; // link to entries |
|---|
| 53 | aas trans[4][4][4]; |
|---|
| 54 | double pi[20]; |
|---|
| 55 | long cat[di_max_aa]; |
|---|
| 56 | double eig[di_max_aa]; |
|---|
| 57 | double exptteig[di_max_aa]; |
|---|
| 58 | di_aa_matrix prob, eigvecs; |
|---|
| 59 | |
|---|
| 60 | di_paa_matrix *(slopes[di_resolution*di_max_dist]); |
|---|
| 61 | // huge cash for many slopes |
|---|
| 62 | di_paa_matrix *(curves[di_resolution*di_max_dist]); |
|---|
| 63 | di_bool_matrix *(infs[di_resolution*di_max_dist]); |
|---|
| 64 | |
|---|
| 65 | di_paa_matrix *akt_slopes; |
|---|
| 66 | di_paa_matrix *akt_curves; |
|---|
| 67 | di_bool_matrix *akt_infs; |
|---|
| 68 | double weight[2]; // weight akt slope 1 -> linear interpolation |
|---|
| 69 | AP_smatrix *matrix; // link to output matrix |
|---|
| 70 | |
|---|
| 71 | // Local variables for makedists, propagated globally for c version: |
|---|
| 72 | double p, dp, d2p; |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | void cats(di_cattype wcat); |
|---|
| 76 | void maketrans(); |
|---|
| 77 | void code(); |
|---|
| 78 | void transition(); |
|---|
| 79 | void givens(di_aa_matrix a, long i, long j, long n, double ctheta, double stheta, bool left); |
|---|
| 80 | void coeffs(double x, double y, double *c, double *s, double accuracy); |
|---|
| 81 | void tridiag(di_aa_matrix a, long n, double accuracy); |
|---|
| 82 | void shiftqr(di_aa_matrix a, long n, double accuracy); |
|---|
| 83 | void qreigen(di_aa_matrix prob, long n); |
|---|
| 84 | void pameigen(); |
|---|
| 85 | |
|---|
| 86 | void predict(double tt, long nb1, long nb2); |
|---|
| 87 | int tt_2_pos(double tt); // double to cash index |
|---|
| 88 | double pos_2_tt(int pos); // cash index to pos |
|---|
| 89 | void build_exptteig(double tt); |
|---|
| 90 | void build_predikt_table(int pos); // build akt_slopes akt_curves |
|---|
| 91 | void build_akt_predikt(double tt); // build akt_slopes akt_curves |
|---|
| 92 | |
|---|
| 93 | double predict_slope(int b1, int b2) { return akt_slopes[0][b1][b2]; } |
|---|
| 94 | double predict_curve(int b1, int b2) { return akt_curves[0][b1][b2]; } |
|---|
| 95 | char predict_infinity(int b1, int b2) { return akt_infs[0][b1][b2]; } |
|---|
| 96 | |
|---|
| 97 | void clean_slopes(); |
|---|
| 98 | |
|---|
| 99 | public: |
|---|
| 100 | di_protdist(di_codetype codei, di_cattype cati, long nentries, DI_ENTRY **entries, long seq_len, AP_smatrix *matrixi); |
|---|
| 101 | ~di_protdist(); |
|---|
| 102 | |
|---|
| 103 | GB_ERROR makedists(bool *aborted_flag); // calculate the distance matrix |
|---|
| 104 | }; |
|---|
| 105 | |
|---|
| 106 | #else |
|---|
| 107 | #error di_protdist.hxx included twice |
|---|
| 108 | #endif // DI_PROTDIST_HXX |
|---|