// $Id: likeDist2USSRV.h 962 2006-11-07 15:13:34Z privmane $ #ifndef ___LIKE_DIST_2_USSRV_H #define ___LIKE_DIST_2_USSRV_H #include "definitions.h" #include "countTableComponent.h" #include "distanceMethod.h" #include "stochasticProcess.h" #include "logFile.h" #include "ussrvModel.h" #include using namespace std; class likeDist2USSRV : public distanceMethod { public: explicit likeDist2USSRV(const ussrvModel& model, const MDOUBLE toll =0.0001, const MDOUBLE maxPairwiseDistance = 5.0) : _model(model) ,_toll(toll),_maxPairwiseDistance(maxPairwiseDistance) {} likeDist2USSRV (const likeDist2USSRV& other): _model(other._model) ,_toll(other._toll),_maxPairwiseDistance(other._maxPairwiseDistance) {}; virtual likeDist2USSRV* clone() const {return new likeDist2USSRV(*this);} // THIS FUNCTION DOES NOT RETURN THE LOG LIKELIHOOD IN RESQ, BUT RATHER "Q", THE CONTRIBUTION of this edge // TO THE EXPECTED LOG-LIKELIHOOD (SEE SEMPHY PAPER). // NEVERTHELESS, THE t that optimizes Q is the same t that optimizes log-likelihood. const MDOUBLE giveDistance( const countTableComponentGam& ctcBase, const countTableComponentHom& ctcSSRV, MDOUBLE& resQ, const MDOUBLE initialGuess= 0.03) const; // initial guess // returns the estimated ML distance between the 2 sequences. // if score is given, it will be the log-likelihood. //!!!!!!!!!!!!!!TO DO @@@@ const MDOUBLE giveDistance(const sequence& s1, const sequence& s2, const vector * weights, MDOUBLE* score=NULL) const { LOG(4,<<"likeDist2USSRV:giveDistance : This method should never be used" << endl); return 1;} const MDOUBLE giveDistanceBrent(const countTableComponentGam& ctcBase, const countTableComponentHom& ctcSSRV, MDOUBLE& resL, MDOUBLE initialGuess) const; private: const ussrvModel& _model; const MDOUBLE _toll; const MDOUBLE _maxPairwiseDistance; }; class C_evalLikeDist2USSRV{ private: const countTableComponentGam& _ctcBase; const countTableComponentHom& _ctcSSRV; const ussrvModel& _model; public: C_evalLikeDist2USSRV(const countTableComponentGam& ctcBase, const countTableComponentHom& ctcSSRV, const ussrvModel& model):_ctcBase(ctcBase),_ctcSSRV(ctcSSRV), _model(model) {}; MDOUBLE operator() (MDOUBLE dist) { const MDOUBLE epsilonPIJ = 1e-10; MDOUBLE sumL=0.0; MDOUBLE pij; int categor, alph1,alph2; // base model const stochasticProcess& baseSp = _model.getBaseModel(); for (alph1=0; alph1 < _ctcBase.alphabetSize(); ++alph1){ for (alph2=0; alph2 < _ctcBase.alphabetSize(); ++alph2){ for (categor = 0; categor < baseSp.categories(); ++categor) { MDOUBLE rate = baseSp.rates(categor); pij= baseSp.Pij_t(alph1,alph2,dist*rate); if (pij