// $Id: cmdline2EvolObjs.h 8038 2010-06-03 20:31:23Z itaymay $ #ifndef ___CREATESPFROMARGSINFO_H #define ___CREATESPFROMARGSINFO_H #include #include "amino.h" #include "nucleotide.h" #include "codon.h" #include "sequenceContainer.h" #include "tree.h" #include "stochasticProcess.h" #include "replacementModel.h" #include "uniDistribution.h" #include "trivialAccelerator.h" #include "alphaTrivialAccelerator.h" #include "chebyshevAccelerator.h" #include "talRandom.h" #include "nucJC.h" #include "aaJC.h" #include "hky.h" #include "tamura92.h" #include "gtrModel.h" #include "logFile.h" #include "readDatMatrix.h" #include "gammaDistribution.h" #include "recognizeFormat.h" #include "replacementModelSSRV.h" #include "stochasticProcessSSRV.h" #include "someUtil.h" #include #define DEFAULT_VALUE_FOR_ALPAH 1.0 template class cmdline2EvolObjs { private: args_infoT _args_info; public: const args_infoT& getArgsInfo(void) {return(_args_info);} // constructors cmdline2EvolObjs(args_infoT &args_info) : _args_info(args_info) { checkParameterConsistancy(); } cmdline2EvolObjs(args_infoT &args_info, bool DontChack) : _args_info(args_info) { // if (!DontChack) checkParameterConsistancy(); } explicit cmdline2EvolObjs(void){}; // do nothing void installArgsInfo(args_infoT &args_info){ _args_info = args_info; checkParameterConsistancy(); } private: void checkParameterConsistancy() { if (!_args_info.homogeneous_flag) { // using Gamma ASRV if (!_args_info.alpha_given && !_args_info.optimizeAlpha_flag) errorMsg::reportError("Must use either 'alpha' or 'optimizeAlpha' when using Gamma ASRV"); } else { // using homogeneous rates if (_args_info.categories_given ||_args_info.alpha_given || _args_info.optimizeAlpha_given) errorMsg::reportError("Can't use 'categories' or 'alpha' or 'optimizeAlpha' with homogeneous rates model"); // more tests may come here } // check compatibility of alphabet and model if (_args_info.alphabet_arg == 4 && !(_args_info.nucjc_given || _args_info.k2p_given || _args_info.hky_given || _args_info.tamura92_given || _args_info.gtr_given)) errorMsg::reportError("Model type is not suitable for nucleotide alphabet"); if (_args_info.alphabet_arg == 20 && (_args_info.nucjc_given || _args_info.k2p_given || _args_info.hky_given || _args_info.tamura92_given || _args_info.gtr_given)) errorMsg::reportError("Model type is not suitable for amino-acid alphabet"); if (_args_info.nu_given) { _args_info.ssrv_flag = true; } } public: void initializeRandomSeed() { if (_args_info.seed_given) { talRandom::setSeed(_args_info.seed_arg); } } void initializeLogFile() { myLog::setLog(_args_info.Logfile_arg, _args_info.verbose_arg); } // NOTE: Unlike other cmdline2*** classes, here a pointer to an allocated obj // is returned and the user is responsible for doing delete. This is because // alphabet is an abstract class, so we can't return it by value alphabet* cmdline2Alphabet() { alphabet* alphPtr = NULL; switch (_args_info.alphabet_arg) { // allwayes defined, with default case 4: alphPtr = new nucleotide; break; case 20: alphPtr = new amino; break; case 64: case 61: case 60: case 62: alphPtr = new codon; break; default: errorMsg::reportError("alphabet size not supported"); } // Handle mulAlphabet needed in case we use an SSRV model if (_args_info.ssrv_flag) { alphabet* mulAlphPtr = new mulAlphabet(alphPtr, _args_info.categories_arg); delete alphPtr; alphPtr = mulAlphPtr; } return alphPtr; } sequenceContainer cmdline2SequenceContainer(const alphabet * const alphPtr) { ifstream ins; istream* inPtr = &cin; string sequenceFileName(_args_info.sequence_arg); if (sequenceFileName != "" && sequenceFileName != "-") { ins.open(sequenceFileName.c_str()); if (! ins.is_open()) errorMsg::reportError(string("Can not open sequence file ")+sequenceFileName); inPtr = &ins; } istream& in = *inPtr; sequenceContainer sc; if (!_args_info.ssrv_flag) { sc = recognizeFormat::read(in, alphPtr); } else { sequenceContainer scBase(recognizeFormat::read(in, (static_cast(alphPtr))->getBaseAlphabet())); sc = sequenceContainer(scBase, alphPtr); } return sc; } void takeCareOfGaps (sequenceContainer &sc) { if (_args_info.gaps_flag) { sc.removeGapPositions(); } else { sc.changeGaps2MissingData(); } } // NOTE: Unlike other cmdline2*** classes, here a pointer to an allocated obj // is returned and the user is responsible for deleting it. This is because // we need to return a NULL pointer if we are not given a tree tree *cmdline2Tree() { tree *treePtr = NULL; if (_args_info.tree_given) { // did we get a tree string treeFileName(_args_info.tree_arg); treePtr = new tree(treeFileName); } return treePtr; } // NOTE: Unlike other cmdline2*** classes, here a pointer to an allocated obj // is returned and the user is responsible for deleting it. This is because // we need to return a NULL pointer if we are not given a tree tree *cmdline2ConstraintTree() { tree *constraintTreePtr = NULL; if (_args_info.constraint_given) { // did we get a tree string constraintTreeFileName(_args_info.constraint_arg); constraintTreePtr = new tree(constraintTreeFileName); } return constraintTreePtr; } replacementModel *cmdline2ReplacementModel() { replacementModel *probModPtr=NULL; MDOUBLE ratio =_args_info.ratio_arg; MDOUBLE Ap(0.25), Cp(0.25), Gp(0.25), Tp(0.25); sscanf(_args_info.ACGprob_arg,"%lf,%lf,%lf", &Ap, &Cp, &Gp); Tp=1.0-(Ap+Cp+Gp); if (_args_info.day_given) { LOG(5,<<"Using Dayhoff replacement matrix"<setGlobalRate(_args_info.inputRate_arg); if (probModPtr) delete probModPtr; if (pijAcc) delete pijAcc; return spPtr; } stochasticProcess cmdline2StochasticProcessInternalAAOnly(distribution& dist) { replacementModel *probModPtr=NULL; pijAccelerator *pijAcc=NULL; if (_args_info.day_given) { LOG(5,<<"Using Dayhoff replacement matrix"<good()) errorMsg::reportError(string("Can't open for writing the file ")+outFileName); } return outPtr; } // NOTE: the user must check: // if the returned stream is an ofstream object (an actual file) it should be deleted // if the returned stream is an ostream object (cout) do nothing ostream *cmdline2TreeOutputStream() { ostream *outPtr; string outFileName(_args_info.treeoutputfile_arg); if (outFileName == "") outFileName="-"; if (outFileName == "-") { outPtr = &cout; } else { outPtr = new ofstream(outFileName.c_str()); if (!outPtr->good()) errorMsg::reportError(string("Can't open for writing the file ")+outFileName); } return outPtr; } void consistencyCheck (tree *treePtr, tree *constraintTreePtr) { if (treePtr!=NULL) { if (constraintTreePtr !=NULL) { /* constraints c1(*constraintTreePtr); c1.setTree(*treePtr); if (!c1.fitsConstraints()){ LOG(1,<<"Input tree does not fit constraints!"<