| 1 |
#include "BeepOption.hh" |
| 2 |
#include "EdgeRateMCMC_common.hh" |
| 3 |
#include "Density2PMCMC.hh" |
| 4 |
//#include "DiscreteGammaDensity.hh" |
| 5 |
#include "DummyMCMC.hh" |
| 6 |
#include "EdgeDiscTree.hh" |
| 7 |
#include "EdgeDiscBDMCMC.hh" |
| 8 |
#include "EdgeDiscBDProbs.hh" |
| 9 |
#include "EdgeDiscGSR.hh" |
| 10 |
#include "EdgeWeightHandler.hh" |
| 11 |
#include "EdgeWeightMCMC.hh" |
| 12 |
#include "GammaDensity.hh" |
| 13 |
#include "InvGaussDensity.hh" |
| 14 |
#include "LogNormDensity.hh" |
| 15 |
#include "MatrixTransitionHandler.hh" |
| 16 |
#include "PRNG.hh" |
| 17 |
#include "Probability.hh" |
| 18 |
#include "RandomTreeGenerator.hh" |
| 19 |
#include "SeqIO.hh" |
| 20 |
#include "SequenceData.hh" |
| 21 |
#include "SimpleML.hh" |
| 22 |
#include "SiteRateHandler.hh" |
| 23 |
#include "StrStrMap.hh" |
| 24 |
#include "SubstitutionMCMC.hh" |
| 25 |
#include "TreeDiscretizers.hh" |
| 26 |
#include "TreeIO.hh" |
| 27 |
#include "TreeMCMC.hh" |
| 28 |
#include "UniformDensity.hh" |
| 29 |
|
| 30 |
#include "conf_value_from_cmake_primeDLRS.hh" |
| 31 |
|
| 32 |
// Suggestion rates. Affects perturbation frequency of the various parameters. |
| 33 |
static const double SUGG_RATIO_BD_RATES = 1.0; |
| 34 |
static const double SUGG_RATIO_G_TOPO_START = 3.0; // Initial value. |
| 35 |
static const double SUGG_RATIO_G_TOPO_FINAL = 3.0; // Final value. |
| 36 |
static const unsigned SUGG_RATIO_G_TOPO_STEPS = 1; // Steps between start and final. |
| 37 |
static const double SUGG_RATIO_G_LENGTHS = 1.0; |
| 38 |
|
| 39 |
static const int NO_OF_PARAMS = 2; |
| 40 |
static const int NO_OF_OPTIONAL_PARAMS = 1; |
| 41 |
|
| 42 |
// Program arguments. Listed in expected input order. |
| 43 |
std::string ParamSeqDataFile = ""; |
| 44 |
std::string ParamSTreeFile = ""; |
| 45 |
std::string ParamGSMapFile = ""; // Optional. |
| 46 |
|
| 47 |
// Things to print before iterating (irrespective of 'quiet' setting). |
| 48 |
std::ostringstream preamble; |
| 49 |
|
| 50 |
// All options to program (and default values) in a map. |
| 51 |
beep::option::BeepOptionMap Options; |
| 52 |
|
| 53 |
// Forward declaration of helpers. |
| 54 |
void showHelpMsg(); |
| 55 |
void readParameters(int& argIndex, int argc, char **argv); |
| 56 |
void createUnderlyingObjects(beep::MatrixTransitionHandler*& Q, beep::SequenceData*& D, |
| 57 |
beep::Tree*& S, beep::EdgeDiscretizer*& discretizer, beep::EdgeDiscTree*& DS, |
| 58 |
beep::Tree*& G, beep::StrStrMap*& gsMap); |
| 59 |
beep::Density2P* createDensity2P(std::string id, double mean, double variance); |
| 60 |
void createDefaultOptions(); |
| 61 |
void iterate(beep::StdMCMCModel& mcmcEnd, std::string runType, beep::EdgeDiscGSR& gsrModel); |
| 62 |
|
| 63 |
int main(int argc, char **argv) { |
| 64 |
using namespace beep; |
| 65 |
using namespace beep::option; |
| 66 |
using namespace std; |
| 67 |
|
| 68 |
try { |
| 69 |
// Create default options. Read options and arguments. |
| 70 |
createDefaultOptions(); |
| 71 |
int argIndex = 1; |
| 72 |
if (!Options.parseOptions(argIndex, argc, argv)) { |
| 73 |
showHelpMsg(); |
| 74 |
exit(0); |
| 75 |
} |
| 76 |
readParameters(argIndex, argc, argv); |
| 77 |
|
| 78 |
// Pseudo random number generator. |
| 79 |
PRNG rand; |
| 80 |
int seed = Options.getUnsigned("Seed"); |
| 81 |
if (seed != 0) { |
| 82 |
rand.setSeed(seed); |
| 83 |
} else { |
| 84 |
seed = rand.getSeed(); |
| 85 |
} |
| 86 |
|
| 87 |
// Create substitution matrix, sequence data, trees, etc. |
| 88 |
MatrixTransitionHandler* Q; |
| 89 |
SequenceData* D; |
| 90 |
Tree* S; |
| 91 |
EdgeDiscretizer* discretizer; |
| 92 |
EdgeDiscTree* DS; |
| 93 |
Tree* G; |
| 94 |
StrStrMap* gsMap; |
| 95 |
createUnderlyingObjects(Q, D, S, discretizer, DS, G, gsMap); |
| 96 |
|
| 97 |
// MCMC: End-of-chain. |
| 98 |
DummyMCMC mcmcDummy = DummyMCMC(); |
| 99 |
|
| 100 |
// MCMC: Birth-death rates (duplication-loss rates). |
| 101 |
pair<double, double> bdr = Options.getDoubleX2("BDRates"); |
| 102 |
EdgeDiscBDProbs* bdp = new EdgeDiscBDProbs(DS, bdr.first, bdr.second); |
| 103 |
EdgeDiscBDMCMC mcmcBDRates(mcmcDummy, bdp, SUGG_RATIO_BD_RATES); |
| 104 |
if (Options.getBool("BDRatesFixed")) { |
| 105 |
mcmcBDRates.fixRates(); |
| 106 |
}; |
| 107 |
|
| 108 |
// MCMC: Guest tree topology. |
| 109 |
UniformTreeMCMC mcmcGTopo(mcmcBDRates, *G, SUGG_RATIO_G_TOPO_START); |
| 110 |
mcmcGTopo.setChangingSuggestRatio(SUGG_RATIO_G_TOPO_FINAL, SUGG_RATIO_G_TOPO_STEPS); |
| 111 |
if (Options.getBool("GTreeFixed")) { |
| 112 |
mcmcGTopo.fixTree(); |
| 113 |
mcmcGTopo.fixRoot(); |
| 114 |
} |
| 115 |
// joelgs: There is no use turning on detailed notifications for |
| 116 |
// tree topologies, since partial updates is a bit tricky with this |
| 117 |
// discretization technique. However, we do it for edge weights. |
| 118 |
//mcmcGTopo.setDetailedNotification(true); |
| 119 |
|
| 120 |
// MCMC: Substitution rate variation over edges (IID). |
| 121 |
string erdfname = Options.getStringAlt("EdgeRateDistr"); |
| 122 |
pair<double, double> erdfp; |
| 123 |
if (Options.hasBeenParsed("EdgeRateParams")) { |
| 124 |
erdfp = Options.getDoubleX2("EdgeRateParams"); |
| 125 |
} else { |
| 126 |
// Use coarse estimate of time length to set reasonable start rate. |
| 127 |
Real tmSum = 0; |
| 128 |
for (Tree::const_iterator it = S->begin(); it != S->end(); ++it) { |
| 129 |
tmSum += S->getEdgeTime(**it); |
| 130 |
} |
| 131 |
Real tmAvg = ((tmSum - S->getTopTime()) / (S->getNumberOfNodes() - 1)); |
| 132 |
erdfp.first = 0.25 / tmAvg; |
| 133 |
erdfp.second = (erdfp.first / 2) * (erdfp.first / 2); |
| 134 |
} |
| 135 |
Density2P* erdf = createDensity2P(erdfname, erdfp.first, erdfp.second); |
| 136 |
Density2PMCMC mcmcEdgeRate(mcmcGTopo, *erdf, true); |
| 137 |
if (Options.hasBeenParsed("EdgeRateFixed") || erdfname == "UNIFORM") { |
| 138 |
mcmcEdgeRate.fixMean(); |
| 139 |
mcmcEdgeRate.fixVariance(); |
| 140 |
} |
| 141 |
|
| 142 |
// Set up GSR integrator. |
| 143 |
EdgeDiscGSR gsrModel(G, DS, gsMap, erdf, bdp); |
| 144 |
|
| 145 |
// MCMC: Edge lengths. The GSR class holds these, and may therefore be model. |
| 146 |
EdgeWeightMCMC mcmcGLengths(mcmcEdgeRate, gsrModel, SUGG_RATIO_G_LENGTHS, true); |
| 147 |
mcmcGLengths.generateWeights(true, 0.05); |
| 148 |
mcmcGLengths.setDetailedNotification(true); |
| 149 |
|
| 150 |
// Set up edge weights, equating weights with lengths. |
| 151 |
EdgeWeightHandler ewh(gsrModel); |
| 152 |
|
| 153 |
// MCMC: Disc. gamma substitution rate variation over sites. |
| 154 |
UniformDensity srdf(0, 3, true); // Uniform prior over [0,3]. |
| 155 |
ConstRateMCMC mcmcSiteRate(mcmcGLengths, srdf, *G, "Alpha"); |
| 156 |
|
| 157 |
// Set up site rate handler. |
| 158 |
unsigned srdfn = Options.getUnsigned("SiteRateCats"); |
| 159 |
SiteRateHandler srh(srdfn, mcmcSiteRate); |
| 160 |
if (srdfn == 1) { |
| 161 |
mcmcSiteRate.fixRates(); |
| 162 |
} |
| 163 |
|
| 164 |
// MCMC: Substitution. |
| 165 |
vector<string> partList; |
| 166 |
partList.push_back(string("all")); |
| 167 |
SubstitutionMCMC mcmcSubst(mcmcSiteRate, *D, *G, srh, *Q, ewh, partList); |
| 168 |
|
| 169 |
string runType = Options.getStringAlt("RunType"); |
| 170 |
|
| 171 |
// Get pre-run info. |
| 172 |
|
| 173 |
if (!Options.getBool("DoNotPrintRunInfo")) { |
| 174 |
preamble << "# Running: " << endl << "#"; |
| 175 |
for (int i = 0; i < argc; i++) { |
| 176 |
preamble << " " << argv[i]; |
| 177 |
} |
| 178 |
preamble << endl |
| 179 |
<< "# of type " << runType << " with seed " << seed |
| 180 |
<< " in directory " << getenv("PWD") << endl; |
| 181 |
} |
| 182 |
|
| 183 |
if (Options.getBool("DebugInfo")) { |
| 184 |
preamble << "# DISCTRETIZED HOST TREE TIMES:" << endl << (*DS); |
| 185 |
preamble << "# INITIAL RECONCILIATION AND PROBS:" << endl |
| 186 |
<< gsrModel.getDebugInfo(false, false); |
| 187 |
} |
| 188 |
|
| 189 |
// Iterate according to choice of execution type. |
| 190 |
iterate(mcmcSubst, runType, gsrModel); |
| 191 |
|
| 192 |
// Clean up in (somewhat) reverse order of creation. |
| 193 |
delete erdf; |
| 194 |
delete bdp; |
| 195 |
delete gsMap; |
| 196 |
delete G; |
| 197 |
delete DS; |
| 198 |
delete S; |
| 199 |
delete D; |
| 200 |
delete Q; |
| 201 |
} catch (AnError& e) { |
| 202 |
e.action(); |
| 203 |
cerr << "Use '" << argv[0] << " -h' to display help."; |
| 204 |
} catch (exception& e) { |
| 205 |
cerr << e.what() << endl; |
| 206 |
cerr << "Use '" << argv[0] << " -h' to display help."; |
| 207 |
} |
| 208 |
cerr << endl; |
| 209 |
} |
| 210 |
|
| 211 |
/************************************************************************ |
| 212 |
* Starts MCMC or hill-climbing. |
| 213 |
************************************************************************/ |
| 214 |
void iterate(beep::StdMCMCModel& mcmcEnd, std::string runType, beep::EdgeDiscGSR& gsrModel) { |
| 215 |
using namespace beep; |
| 216 |
using namespace beep::option; |
| 217 |
using namespace std; |
| 218 |
|
| 219 |
bool quiet = Options.getBool("Quiet"); |
| 220 |
|
| 221 |
// Iterate according to choice of execution type. |
| 222 |
if (runType == "PD") { |
| 223 |
// First-iteration posterior density. |
| 224 |
cout << mcmcEnd.currentStateProb() << endl; |
| 225 |
return; |
| 226 |
} |
| 227 |
|
| 228 |
// MCMC: Iterator. |
| 229 |
unsigned thinning = Options.getUnsigned("Thinning"); |
| 230 |
SimpleMCMC* iter; |
| 231 |
if (runType == "PDHC") { |
| 232 |
// Posterior density hill-climbing. |
| 233 |
iter = new SimpleML(mcmcEnd, thinning); |
| 234 |
} else { |
| 235 |
// MCMC. |
| 236 |
iter = new SimpleMCMC(mcmcEnd, thinning); |
| 237 |
|
| 238 |
// TODO: Must this be applied instead when doing LSD analysis? |
| 239 |
// iter = new SimpleMCMCPostSample(*mcmcEnd, thinning); |
| 240 |
} |
| 241 |
|
| 242 |
// Output, diagnostics, etc. |
| 243 |
string out = Options.getString("Outfile"); |
| 244 |
if (out != "") { |
| 245 |
try { |
| 246 |
iter->setOutputFile(out.c_str()); |
| 247 |
} catch (AnError& e) { |
| 248 |
e.action(); |
| 249 |
} catch (...) { |
| 250 |
cerr << "Problems opening output file '" << out << "'! " |
| 251 |
<< "Reverting to stdout." << endl; |
| 252 |
} |
| 253 |
} |
| 254 |
if (quiet) { |
| 255 |
iter->setShowDiagnostics(false); |
| 256 |
} |
| 257 |
cout << preamble.str(); |
| 258 |
|
| 259 |
// Iterate!!!! |
| 260 |
time_t t0 = time(0); |
| 261 |
clock_t ct0 = clock(); |
| 262 |
iter->iterate(Options.getUnsigned("Iterations"), Options.getUnsigned("PrintFactor")); |
| 263 |
time_t t1 = time(0); |
| 264 |
clock_t ct1 = clock(); |
| 265 |
|
| 266 |
if (!Options.getBool("DoNotPrintElapsedComputeTime")) { |
| 267 |
cout << "# Wall time: " << difftime(t1, t0) << " s." << endl; |
| 268 |
cout << "# CPU time: " << (Real(ct1 - ct0) / CLOCKS_PER_SEC) << " s." << endl; |
| 269 |
} |
| 270 |
cout << "# Total acceptance ratio: " |
| 271 |
<< mcmcEnd.getAcceptanceRatio() << endl |
| 272 |
<< mcmcEnd.getAcceptanceInfo(); |
| 273 |
cout << "# Last iteration root probs: " << gsrModel.getRootProbDebugInfo() << endl; |
| 274 |
delete iter; |
| 275 |
} |
| 276 |
|
| 277 |
/************************************************************************ |
| 278 |
* Helper. Creates sequence data, trees, etc. |
| 279 |
* Deletion must be taken care of by invoking method. |
| 280 |
************************************************************************/ |
| 281 |
void createUnderlyingObjects( |
| 282 |
beep::MatrixTransitionHandler*& Q, |
| 283 |
beep::SequenceData*& D, |
| 284 |
beep::Tree*& S, |
| 285 |
beep::EdgeDiscretizer*& discretizer, |
| 286 |
beep::EdgeDiscTree*& DS, |
| 287 |
beep::Tree*& G, |
| 288 |
beep::StrStrMap*& gsMap) { |
| 289 |
using namespace std; |
| 290 |
using namespace beep; |
| 291 |
using namespace beep::option; |
| 292 |
|
| 293 |
// For practical reasons, set up the substitution matrix first. |
| 294 |
// Use user-defined matrix if such has been provided. |
| 295 |
if (Options.hasBeenParsed("UserSubstModel")) { |
| 296 |
if (Options.hasBeenParsed("SubstModel")) |
| 297 |
throw AnError("Cannot use both predefined and user-defined subst. model.", 1); |
| 298 |
UserSubstModelOption* smUsr = Options.getUserSubstModelOption("UserSubstModel"); |
| 299 |
Q = new MatrixTransitionHandler(MatrixTransitionHandler::userDefined(smUsr->type, smUsr->pi, smUsr->r)); |
| 300 |
} else { |
| 301 |
string sm = Options.getStringAlt("SubstModel"); |
| 302 |
Q = new MatrixTransitionHandler(MatrixTransitionHandler::create(sm)); |
| 303 |
} |
| 304 |
|
| 305 |
// Get sequence data. This is why Q must already exist.* |
| 306 |
D = new SequenceData(SeqIO::readSequences(ParamSeqDataFile, Q->getType())); |
| 307 |
|
| 308 |
// since Q is needed for D, and for counting base frequencies in Q, we need |
| 309 |
// D (chicken and egg problem) so, as a temporary hack, I am redefining Q |
| 310 |
// for F81 model |
| 311 |
if (Options.getStringAlt("SubstModel") == "F81") { |
| 312 |
std::map<char, double> bf = D->getBaseFrequencies(); |
| 313 |
Q = new MatrixTransitionHandler(MatrixTransitionHandler::create("F81", &bf)); |
| 314 |
} |
| 315 |
|
| 316 |
// set the base frequencies in Q |
| 317 |
|
| 318 |
//std::map<char, double> bf = D->getBaseFrequencies(); |
| 319 |
///for (map<char, double>::iterator ii = bf.begin(); ii != bf.end(); ++ii) { |
| 320 |
// cout << (*ii).first << ": " << (*ii).second << endl; |
| 321 |
//} |
| 322 |
|
| 323 |
// Create S from file. |
| 324 |
S = new Tree(TreeIO::fromFile(ParamSTreeFile).readHostTree()); |
| 325 |
if (Options.getBool("Rescale")) { |
| 326 |
Real sc = S->rootToLeafTime(); |
| 327 |
RealVector* tms = new RealVector(S->getTimes()); |
| 328 |
for (RealVector::iterator it = tms->begin(); it != tms->end(); ++it) { |
| 329 |
(*it) /= sc; |
| 330 |
} |
| 331 |
S->setTopTime(S->getTopTime() / sc); |
| 332 |
S->setTimes(*tms, true); |
| 333 |
preamble << "# Host tree root-to-leaf span was rescaled from " << sc << " to 1.0.\n"; |
| 334 |
} |
| 335 |
//cout << S->print(false,false,true,false) << endl; |
| 336 |
//cout << *S << endl; |
| 337 |
|
| 338 |
if (Options.hasBeenParsed("TopTime")) { |
| 339 |
Real tt = Options.getDouble("TopTime"); |
| 340 |
if (tt <= 0) { |
| 341 |
tt = S->rootToLeafTime(); |
| 342 |
preamble << "# Changing root edge time span to " << tt << ".\n"; |
| 343 |
} |
| 344 |
S->setTopTime(tt); |
| 345 |
} |
| 346 |
if (S->getTopTime() < 1e-8) |
| 347 |
throw AnError("Host tree top time must be greater than 0.", 1); |
| 348 |
|
| 349 |
// Create discretized tree DS based on S. |
| 350 |
Real timestep = Options.getDouble("DiscTimestep"); |
| 351 |
unsigned minIvs = Options.getUnsigned("DiscMinIvs"); |
| 352 |
unsigned ttIvs = Options.getUnsigned("TopTimeDiscIvs"); |
| 353 |
if (timestep == 0) { |
| 354 |
if (ttIvs == 0) { |
| 355 |
ttIvs = minIvs; |
| 356 |
} |
| 357 |
discretizer = new EquiSplitEdgeDiscretizer(minIvs, ttIvs); |
| 358 |
} else { |
| 359 |
if (ttIvs == 0) { |
| 360 |
ttIvs = std::ceil(S->rootToLeafTime() / timestep); |
| 361 |
} |
| 362 |
discretizer = new StepSizeEdgeDiscretizer(timestep, minIvs, ttIvs); |
| 363 |
} |
| 364 |
DS = new EdgeDiscTree(*S, discretizer); |
| 365 |
|
| 366 |
// Create random guest tree G unless file specified. |
| 367 |
// Fill G-S map. If empty (no mapping info was found in the gene tree or a |
| 368 |
// random tree was created), we have to use file passed as parameter with that info. |
| 369 |
gsMap = new StrStrMap(); |
| 370 |
TreeIO tio = TreeIO::fromFile(Options.getString("GTreeFile")); |
| 371 |
G = (Options.hasBeenParsed("GTreeFile")) ? |
| 372 |
new Tree(tio.readBeepTree(NULL, gsMap)) : |
| 373 |
new Tree(RandomTreeGenerator::generateRandomTree(D->getAllSequenceNames())); |
| 374 |
if (gsMap->size() == 0) { |
| 375 |
if (ParamGSMapFile == "") throw AnError("Missing guest-to-host leaf map.", 1); |
| 376 |
else { |
| 377 |
delete gsMap; |
| 378 |
gsMap = new StrStrMap(TreeIO::readGeneSpeciesInfo(ParamGSMapFile)); |
| 379 |
} |
| 380 |
} |
| 381 |
G->doDeleteTimes(); |
| 382 |
G->doDeleteRates(); |
| 383 |
} |
| 384 |
|
| 385 |
/************************************************************************ |
| 386 |
* Helper. Prints usage message to stderr. |
| 387 |
************************************************************************/ |
| 388 |
void showHelpMsg() { |
| 389 |
using std::cerr; |
| 390 |
using std::endl; |
| 391 |
cerr |
| 392 |
<< "===================================================================================" << endl |
| 393 |
<< "Usage: primeDLRS [<options>] <seqfile> <hostfile> [<gsfile>]" << endl |
| 394 |
<< endl |
| 395 |
<< "Description: Guest-in-host tree reconciliation tool, enabling analysis of" << endl |
| 396 |
<< "e.g. guest tree topologies, reconciliation properties and duplication-loss rates." << endl |
| 397 |
<< "Based on a Bayesian MCMC framework using the underlying GSR model:" << endl |
| 398 |
<< "1) the guest tree topology and its divergence times are modelled with a" << endl |
| 399 |
<< " duplication-loss process in accordance with the Gene Evolution Model (GEM)." << endl |
| 400 |
<< "2) sequence evolution is modelled with a user-defined substitution model." << endl |
| 401 |
<< "3) sequence evolution rate variation over guest tree edges (relaxed molecular" << endl |
| 402 |
<< " clock) are modelled with iid values from a user-selected distribution." << endl |
| 403 |
<< "4) sequence evolution rate variation over sites (positions) are modelled according" << endl |
| 404 |
<< " to a discretized Gamma distribution." << endl |
| 405 |
<< "The implementation uses a discretization of the host tree to perform its computations." << endl |
| 406 |
<< "Please review available options, as you will need to change default settings." << endl |
| 407 |
<< "Option -r may be useful to avoid numeric issues due to scaling." << endl |
| 408 |
<< endl |
| 409 |
<< "Parameters:" << endl |
| 410 |
<< " <seqfile> (string), file with aligned sequences for guest tree leaves." << endl |
| 411 |
<< " <hostfile> (string), PrIME Newick file with host tree incl. divergence times." << endl |
| 412 |
<< " Leaves must have time 0 and root have time > 0." << endl |
| 413 |
<< " <gsfile> (string), tab-delimited file relating guest tree leaves to host" << endl |
| 414 |
<< " tree leaves if info not included in <hostfile>." << endl |
| 415 |
<< endl |
| 416 |
<< "Options:" << endl |
| 417 |
<< " -h/-u/-?" << endl |
| 418 |
<< " Display help (this text)." << endl |
| 419 |
<< Options |
| 420 |
<< "===================================================================================" << endl; |
| 421 |
} |
| 422 |
|
| 423 |
/************************************************************************ |
| 424 |
* Helper. Reads program arguments (not options). |
| 425 |
************************************************************************/ |
| 426 |
void readParameters(int& argIdx, int argc, char **argv) { |
| 427 |
if (argc - argIdx < NO_OF_PARAMS) { |
| 428 |
throw beep::AnError("Too few input parameters!", 1); |
| 429 |
} |
| 430 |
ParamSeqDataFile = argv[argIdx++]; |
| 431 |
ParamSTreeFile = argv[argIdx++]; |
| 432 |
if (argIdx < argc) { |
| 433 |
ParamGSMapFile = argv[argIdx++]; |
| 434 |
} |
| 435 |
}; |
| 436 |
|
| 437 |
/************************************************************************ |
| 438 |
* Helper. Creates a 2-parameter density function from its string ID. |
| 439 |
************************************************************************/ |
| 440 |
beep::Density2P* createDensity2P(std::string id, double mean, double var) { |
| 441 |
using namespace beep; |
| 442 |
Density2P* df = NULL; |
| 443 |
if (id == "INVG") { |
| 444 |
df = new InvGaussDensity(mean, var); |
| 445 |
}// else if (id == "DISCGAMMA") { df = new DiscreteGammaDensity(mean, var, 200); } |
| 446 |
else if (id == "LOGN") { |
| 447 |
df = new LogNormDensity(mean, var); |
| 448 |
} else if (id == "GAMMA") { |
| 449 |
df = new GammaDensity(mean, var); |
| 450 |
} else if (id == "UNIFORM") { |
| 451 |
df = new UniformDensity(mean, var, true); |
| 452 |
} else { |
| 453 |
throw AnError("Unknown Density2P identifier: " + id + '.', 1); |
| 454 |
} |
| 455 |
return df; |
| 456 |
}; |
| 457 |
|
| 458 |
/************************************************************************ |
| 459 |
* Helper. Creates default values corresponding to options and stores |
| 460 |
* them in global map. |
| 461 |
************************************************************************/ |
| 462 |
void createDefaultOptions() { |
| 463 |
using namespace std; |
| 464 |
using namespace beep::option; |
| 465 |
Options.addStringOption("Outfile", "o", "", |
| 466 |
" -o <string>\n" |
| 467 |
" Output filename. Defaults to stderr.\n"); |
| 468 |
Options.addUnsignedOption("Seed", "s", 0, |
| 469 |
" -s <unsigned int>\n" |
| 470 |
" Seed for pseudo-random number generator. Defaults to random seed.\n"); |
| 471 |
|
| 472 |
// The conf_value_from_cmake_* values are set in CMakeLists.txt |
| 473 |
Options.addUnsignedOption("Iterations", "i", conf_value_from_cmake_Iterations, |
| 474 |
" -i <unsigned int>\n" |
| 475 |
" Number of iterations. Defaults to " conf_value_from_cmake_Iterations_string ".\n"); |
| 476 |
Options.addUnsignedOption("Thinning", "t", conf_value_from_cmake_Thinning, |
| 477 |
" -t <unsigned int>\n" |
| 478 |
" Thinning, i.e. sample every <value>-th iteration. Defaults to " conf_value_from_cmake_Thinning_string ".\n"); |
| 479 |
Options.addUnsignedOption("PrintFactor", "w", conf_value_from_cmake_PrintFactor, |
| 480 |
" -w <unsigned int>\n" |
| 481 |
" Output diagnostics to stderr every <value>-th sample. Defaults to " conf_value_from_cmake_PrintFactor_string ".\n"); |
| 482 |
Options.addBoolOption("Quiet", "q", false, |
| 483 |
" -q \n" |
| 484 |
" Do not output diagnostics. Non-quiet by default.\n"); |
| 485 |
Options.addStringAltOption("RunType", "m", conf_value_from_cmake_RunType_string, "MCMC,PDHC,PD", |
| 486 |
" -m <'MCMC'/'PDHC'/'PD'>\n" |
| 487 |
" Execution type (MCMC, posterior density hill-climbing from initial\n" |
| 488 |
" values, or just initial posterior density). Defaults to " conf_value_from_cmake_RunType_string ".\n", |
| 489 |
UPPER); |
| 490 |
Options.addStringAltOption("SubstModel", "Sm", conf_value_from_cmake_SubstModel_string, "UniformAA,JC69,F81,JTT,UniformCodon,ArveCodon", |
| 491 |
" -Sm <'UniformAA'/'JC69'/'JTT'/'F81'/'UniformCodon'/'ArveCodon'>\n" |
| 492 |
" Substitution model. " conf_value_from_cmake_SubstModel_string " by default.\n", |
| 493 |
UPPER); |
| 494 |
Options.addUserSubstModelOption("UserSubstModel", "Su", |
| 495 |
" -Su <'DNA'/'AminoAcid'/'Codon'> <Pi=float1 float2 ... floatn> <R=float1 float2 ...float(n*(n-1)/2)>\n" |
| 496 |
" User-defined substitution model. The size of Pi and R must fit data type \n" |
| 497 |
" (DNA: n=4, AminoAcid: n=20, Codon: n=62). R is given as a flattened\n" |
| 498 |
" upper triangular matrix. Don't use both option -Su and -Sm.\n"); |
| 499 |
Options.addUnsignedOption("SiteRateCats", "Sn", conf_value_from_cmake_SiteRateCats, |
| 500 |
" -Sn <unsigned int>\n" |
| 501 |
" Number of steps of discretized Gamma-distribution for sequence\n" |
| 502 |
" evolution rate variation over sites. Defaults to " conf_value_from_cmake_SiteRateCats_string " (no variation).\n"); |
| 503 |
Options.addStringAltOption("EdgeRateDistr", "Ed", conf_value_from_cmake_EdgeRateDistr_string, "Gamma,InvG,LogN,Uniform", |
| 504 |
" -Ed <'Gamma'/'InvG'/'LogN'/'Uniform'>\n" |
| 505 |
" Distribution for iid sequence evolution rate variation over guest\n" |
| 506 |
" tree edges. Defaults to " conf_value_from_cmake_EdgeRateDistr_string " (not to confuse with -Sn).\n", |
| 507 |
UPPER); |
| 508 |
Options.addDoubleX2Option("EdgeRateParams", "Ep", pair<double, double>(1.0, 1.0), |
| 509 |
" -Ep <float> <float>\n" |
| 510 |
" Initial mean and variance of sequence evolution rate.\n" |
| 511 |
" Defaults to simple rule-of-thumb based on host tree times.\n"); |
| 512 |
Options.addBoolOption("EdgeRateFixed", "Ef", false, |
| 513 |
" -Ef \n" |
| 514 |
" Fix mean and variance of sequence evolution rate. Non-fixed by default.\n"); |
| 515 |
Options.addStringOption("GTreeFile", "Gi", "", |
| 516 |
" -Gi <string>\n" |
| 517 |
" Filename with initial guest tree topology.\n"); |
| 518 |
Options.addBoolOption("GTreeFixed", "Gg", false, |
| 519 |
" -Gg \n" |
| 520 |
" Fix initial guest tree topology, i.e. perform no branch-swapping.\n" |
| 521 |
" Non-fixed by default.\n"); |
| 522 |
Options.addDoubleX2Option("BDRates", "Bp", pair<double, double>(conf_value_from_cmake_BDRates_first, conf_value_from_cmake_BDRates_second), |
| 523 |
" -Bp <float> <float>\n" |
| 524 |
" Initial duplication and loss rates. Defaults to " conf_value_from_cmake_BDRates_first_string " and " conf_value_from_cmake_BDRates_second_string ".\n"); |
| 525 |
Options.addBoolOption("BDRatesFixed", "Bf", false, |
| 526 |
" -Bf \n" |
| 527 |
" Fix initial duplication and loss rates. Non-fixed by default.\n"); |
| 528 |
Options.addDoubleOption("TopTime", "Bt", 0.0, |
| 529 |
" -Bt <float>\n" |
| 530 |
" Override time span of edge above root in host tree. If the value is <=0, the span\n" |
| 531 |
" will be set to equal the root-to-leaf time. Defaults to value in host tree file.\n" |
| 532 |
" See also option -Dtt.\n"); |
| 533 |
Options.addDoubleOption("DiscTimestep", "Dt", conf_value_from_cmake_DiscTimestep, |
| 534 |
" -Dt <float>\n" |
| 535 |
" Approximate discretization timestep. Set to 0 to divide every edge in equally\n" |
| 536 |
" many parts (see -Di). Defaults to " conf_value_from_cmake_DiscTimestep_string ". See -Dtt for edge above root.\n"); |
| 537 |
Options.addUnsignedOption("DiscMinIvs", "Di", conf_value_from_cmake_DiscMinIvs, |
| 538 |
" -Di <unsigned int>\n" |
| 539 |
" Minimum number of parts to slice each edge in. If -Dt is set to 0, this becomes\n" |
| 540 |
" the exact number of parts. Minimum 2. Defaults to " conf_value_from_cmake_DiscMinIvs_string ". See -Dtt for edge above root.\n"); |
| 541 |
Options.addUnsignedOption("TopTimeDiscIvs", "Dtt", 0, |
| 542 |
" -Dtt <unsigned int>\n" |
| 543 |
" Override number of discretization points for edge above root in host tree.\n" |
| 544 |
" By default, irrespective of time span, this is set to the number\n" |
| 545 |
" of points for a (hypothetical) root-to-leaf edge.\n"); |
| 546 |
Options.addBoolOption("Rescale", "r", false, |
| 547 |
" -r \n" |
| 548 |
" Rescale the host tree so that the root-to-leaf time equals 1.0. All\n" |
| 549 |
" inferred parameters will refer to the new scale. Off by default.\n" |
| 550 |
" Note that discretization parameters are NOT rescaled.\n"); |
| 551 |
Options.addBoolOption("DoNotPrintElapsedComputeTime", "Z", false, |
| 552 |
" -Z \n" |
| 553 |
" Do not print elapsed wall time and CPU time\n"); |
| 554 |
Options.addBoolOption("DoNotPrintRunInfo", "W", false, |
| 555 |
" -W \n" |
| 556 |
" Do not print the command line\n"); |
| 557 |
Options.addBoolOption("DebugInfo", "debuginfo", false, |
| 558 |
" -debuginfo \n" |
| 559 |
" Show misc. info to stderr before iterating. Not shown by default.\n"); |
| 560 |
}; |