1 /************************************************************
2 * Copyright (c) 2005, BGI of Chinese Academy of Sciences
6 * Abstract: Declaration of GY94 class.
9 * Author: Zhang Zhang (zhanghzhang@genomics.org.cn)
12 * Note: Source codes are taken from codeml.c in PAML.
15 Goldman N, Yang Z (1994) A codon-based model of nucleotide
16 substitution for protein-coding DNA sequences. Mol. Biol.
18 *************************************************************/
27 class GY94
: public Base
{
35 string
Run(const char *seq1
, const char *seq2
);
38 /* Preprocess for calculating Ka&Ks */
39 int preProcess(const char* seq1
, const char* seq2
);
40 /* Parse substitution rates according to the given model */
41 int parseSubRates(string model
, double kappa
[]);
42 /* Construct two array according to genetic code */
43 int setmark_61_64 (void);
45 /* Encode two compared sequneces */
46 void EncodeSeqs (void);
47 /* Calculate Ka&Ks using ML */
48 int PairwiseCodon (double space
[]);
49 /* Get codons' frequencies */
50 int GetCodonFreqs(double pi
[]);
51 /* Construct transition probability matrix (64*64) */
52 int EigenQc (int getstats
, double blength
, double *S
, double *dS
, double *dN
, double Root
[], double U
[], double V
[], double kappa
[], double omega
, double Q
[]);
53 /* Return maximum-likelihood score */
54 double lfun2dSdN (double x
[], int np
);
55 /* Main fuctiion for GY method */
56 int ming2 (double *f
, double x
[], double xb
[][2], double space
[], double e
, int n
);
58 int eigenQREV (double Q
[], double pi
[], int n
, double Root
[], double U
[], double V
[], double spacesqrtpi
[]);
59 double LineSearch2 (double *f
, double x0
[], double p
[], double step
, double limit
, double e
, double space
[], int n
);
61 /* x[i]=x0[i] + t*p[i] */
62 double fun_ls(double t
, double x0
[], double p
[], double x
[], int n
);
63 double distance (double x
[], double y
[], int n
);
64 int transform (char *z
, int ls
);
65 int gradientB (int n
, double x
[], double f0
, double g
[], double space
[], int xmark
[]);
66 int H_end (double x0
[], double x1
[], double f0
, double f1
, double e1
, double e2
, int n
);
67 void HouseholderRealSym(double a
[], int n
, double d
[], double e
[]);
68 int EigenTridagQLImplicit(double d
[], double e
[], int n
, double z
[]);
69 void EigenSort(double d
[], double U
[], int n
);
70 int eigenRealSym(double A
[], int n
, double Root
[], double work
[]);
71 void FreeMemPUVR(void);
75 char *z
[2]; //sequences
77 int ls
; //sequence's length
79 int icode
; //number of genetic code
80 int ncode
; //number of non-stop codon
81 int np
, nkappa
, sspace
;
82 double fpatt
[CODON
*CODON
];
84 double kappa
; //transition/transversion
86 double pi
[CODON
]; //codons' frequencies
91 double PMat
[CODON
*CODON
],U
[CODON
*CODON
],V
[CODON
*CODON
],Root
[CODON
*CODON
];
92 int Nsensecodon
, FROM61
[CODON
], FROM64
[CODON
];
94 unsigned int w_rndu
;//=123456757;
97 string str1
, str2
; //a pair of sequences