Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
refactor partition_type to BRLEN_*. Checkpoint partition_type to prev…
Browse files Browse the repository at this point in the history
…ent mixing edge-linked and edge-unlinked partition finding
  • Loading branch information
bqminh committed Dec 21, 2017
1 parent 0d2cc01 commit cb49148
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
29 changes: 20 additions & 9 deletions main/phyloanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void reportTree(ofstream &out, Params &params, PhyloTree &tree, double tree_lh,
else
out << "NOTE: Tree is UNROOTED although outgroup taxon '" << tree.root->name << "' is drawn at root" << endl;

if (tree.isSuperTree() && params.partition_type == 0)
if (tree.isSuperTree() && params.partition_type == BRLEN_OPTIMIZE)
out << "NOTE: Branch lengths are weighted average over all partitions" << endl
<< " (weighted by the number of sites in the partitions)" << endl;
if (tree.isMixlen())
Expand Down Expand Up @@ -928,14 +928,16 @@ void reportPhyloAnalysis(Params &params, string &original_model,
out << "SUBSTITUTION PROCESS" << endl << "--------------------" << endl
<< endl;
if (tree.isSuperTree()) {
if(params.partition_type)
out << "Proportional partition model with joint branch lengths and separate models between partitions" << endl << endl;
if(params.partition_type == BRLEN_SCALE)
out << "Edge-linked-proportional partition model but separate models between partitions" << endl << endl;
else if(params.partition_type == BRLEN_FIX)
out << "Edge-linked-equal partition model but separate models between partitions" << endl << endl;
else
out << "Full partition model with separate branch lengths and models between partitions" << endl << endl;
out << "Edge-unlinked partition model and separate models between partitions" << endl << endl;
PhyloSuperTree *stree = (PhyloSuperTree*) &tree;
PhyloSuperTree::iterator it;
int part;
if(params.partition_type)
if(params.partition_type != BRLEN_OPTIMIZE)
out << " ID Model Speed Parameters" << endl;
else
out << " ID Model TreeLen Parameters" << endl;
Expand All @@ -944,7 +946,7 @@ void reportPhyloAnalysis(Params &params, string &original_model,
out.width(4);
out << right << (part+1) << " ";
out.width(14);
if(params.partition_type)
if(params.partition_type != BRLEN_OPTIMIZE)
out << left << (*it)->getModelName() << " " << stree->part_info[part].part_rate << " " << (*it)->getModelNameParams() << endl;
else
out << left << (*it)->getModelName() << " " << (*it)->treeLength() << " " << (*it)->getModelNameParams() << endl;
Expand Down Expand Up @@ -1549,6 +1551,15 @@ void initializeParams(Params &params, IQTree &iqtree, ModelCheckpoint &model_inf
Checkpoint *orig_checkpoint = iqtree.getCheckpoint();
iqtree.setCheckpoint(&model_info);

int partition_type;
if (CKP_RESTORE2((&model_info), partition_type)) {
if (partition_type != params.partition_type)
outError("Mismatch partition type between checkpoint and partition file command option");
} else {
partition_type = params.partition_type;
CKP_SAVE2((&model_info), partition_type);
}

// compute initial tree
iqtree.computeInitialTree(dist_file, params.SSE);

Expand Down Expand Up @@ -2734,7 +2745,7 @@ void runStandardBootstrap(Params &params, string &original_model, Alignment *ali
}
IQTree *boot_tree;
if (alignment->isSuperAlignment()){
if(params.partition_type){
if(params.partition_type != BRLEN_OPTIMIZE){
boot_tree = new PhyloSuperTreePlen((SuperAlignment*) bootstrap_alignment, (PhyloSuperTree*) tree);
} else {
boot_tree = new PhyloSuperTree((SuperAlignment*) bootstrap_alignment, (PhyloSuperTree*) tree);
Expand Down Expand Up @@ -2997,7 +3008,7 @@ void runPhyloAnalysis(Params &params, Checkpoint *checkpoint) {
/****************** read in alignment **********************/
if (params.partition_file) {
// Partition model analysis
if(params.partition_type){
if(params.partition_type != BRLEN_OPTIMIZE){
// since nni5 does not work yet, stop the programm
/* if(params.nni5)
outError("-nni5 option is unsupported yet for proportitional partition model. please use -nni1 option");*/
Expand Down Expand Up @@ -3203,7 +3214,7 @@ void runPhyloAnalysis(Params &params, Checkpoint *checkpoint) {
// }

if(verbose_mode >= VB_MED){
if(tree->isSuperTree() && params.partition_type){
if(tree->isSuperTree() && params.partition_type != BRLEN_OPTIMIZE){
((PhyloSuperTreePlen*) tree)->printNNIcasesNUM();
}
}
Expand Down
12 changes: 5 additions & 7 deletions main/phylotesting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,9 +1455,9 @@ void testPartitionModel(Params &params, PhyloSuperTree* in_tree, ModelCheckpoint
DoubleVector lenvec; // tree length for each partition
double lhsum = 0.0;
int dfsum = 0;
if (params.partition_type) {
if (params.partition_type != BRLEN_OPTIMIZE) {
dfsum = in_tree->getNBranchParameters(BRLEN_OPTIMIZE);
if (params.partition_type == 'p')
if (params.partition_type == BRLEN_SCALE)
dfsum -= 1;
}
int ssize = in_tree->getAlnNSite();
Expand Down Expand Up @@ -1517,7 +1517,7 @@ void testPartitionModel(Params &params, PhyloSuperTree* in_tree, ModelCheckpoint


// read tree with branch lengths for linked partition model
if (params.partition_type && !concat_tree.empty()) {
if (params.partition_type != BRLEN_OPTIMIZE && !concat_tree.empty()) {
in_tree->readTreeString(concat_tree);
int part = 0;
for (auto it = in_tree->begin(); it != in_tree->end(); it++, part++) {
Expand Down Expand Up @@ -1564,8 +1564,6 @@ void testPartitionModel(Params &params, PhyloSuperTree* in_tree, ModelCheckpoint
}

bool parallel_over_partitions = false;
int brlen_type = (params.partition_type == 0) ? BRLEN_OPTIMIZE :
((params.partition_type == 'p') ? BRLEN_SCALE : BRLEN_FIX);

#ifdef _OPENMP
parallel_over_partitions = !params.model_test_and_tree && (in_tree->size() >= num_threads);
Expand All @@ -1582,7 +1580,7 @@ void testPartitionModel(Params &params, PhyloSuperTree* in_tree, ModelCheckpoint
if (params.model_name.empty())
part_model_name = in_tree->part_info[i].model_name;
ModelInfo best_model;
best_model.name = testModel(params, this_tree, part_model_info, models_block, (parallel_over_partitions ? 1 : num_threads), brlen_type, in_tree->part_info[i].name, false, part_model_name);
best_model.name = testModel(params, this_tree, part_model_info, models_block, (parallel_over_partitions ? 1 : num_threads), params.partition_type, in_tree->part_info[i].name, false, part_model_name);

ASSERT(best_model.restoreCheckpoint(&part_model_info));

Expand Down Expand Up @@ -1732,7 +1730,7 @@ void testPartitionModel(Params &params, PhyloSuperTree* in_tree, ModelCheckpoint
tree->saveCheckpoint();
}
best_model.name = testModel(params, tree, part_model_info, models_block,
params.model_test_and_tree ? num_threads : 1, brlen_type, cur_pair.set_name);
params.model_test_and_tree ? num_threads : 1, params.partition_type, cur_pair.set_name);
best_model.restoreCheckpoint(&part_model_info);
if (params.model_test_and_tree) {
delete tree->getCheckpoint();
Expand Down
4 changes: 2 additions & 2 deletions tree/iqtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ void IQTree::initializeModel(Params &params, string &model_name, ModelsBlock *mo
try {
if (!getModelFactory()) {
if (isSuperTree()) {
if (params.partition_type) {
if (params.partition_type != BRLEN_OPTIMIZE) {
setModelFactory(new PartitionModelPlen(params, (PhyloSuperTreePlen*) this, models_block));
} else
setModelFactory(new PartitionModel(params, (PhyloSuperTree*) this, models_block));
Expand Down Expand Up @@ -2746,7 +2746,7 @@ void IQTree::refineBootTrees() {
// create bootstrap tree
IQTree *boot_tree;
if (aln->isSuperAlignment()){
if(params->partition_type){
if(params->partition_type != BRLEN_OPTIMIZE){
boot_tree = new PhyloSuperTreePlen((SuperAlignment*) bootstrap_alignment, (PhyloSuperTree*) this);
} else {
boot_tree = new PhyloSuperTree((SuperAlignment*) bootstrap_alignment, (PhyloSuperTree*) this);
Expand Down
2 changes: 1 addition & 1 deletion tree/phylosupertreeplen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PhyloSuperTreePlen::PhyloSuperTreePlen(Params &params)
: PhyloSuperTree(params)
{
memset(allNNIcases_computed, 0, 5*sizeof(int));
fixed_rates = (params.partition_type == 'j') ? true : false;
fixed_rates = (params.partition_type == BRLEN_FIX) ? true : false;
int part = 0;
for (iterator it = begin(); it != end(); it++, part++) {
part_info[part].part_rate = 1.0;
Expand Down
15 changes: 9 additions & 6 deletions utils/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ void parseArg(int argc, char *argv[], Params &params) {
params.do_au_test = false;
params.siteLL_file = NULL; //added by MA
params.partition_file = NULL;
params.partition_type = 0;
params.partition_type = BRLEN_OPTIMIZE;
params.partfinder_rcluster = 100;
params.partfinder_rcluster_max = 0;
params.partfinder_rcluster_fast = false;
Expand Down Expand Up @@ -1648,7 +1648,7 @@ void parseArg(int argc, char *argv[], Params &params) {
if (cnt >= argc)
throw "Use -spp <type of partition model>";
params.partition_file = argv[cnt];
params.partition_type = 'p';
params.partition_type = BRLEN_SCALE;
params.opt_gammai = false;
continue;
}
Expand All @@ -1657,13 +1657,13 @@ void parseArg(int argc, char *argv[], Params &params) {
if (cnt >= argc)
throw "Use -q <type of partition model>";
params.partition_file = argv[cnt];
params.partition_type = 'j';
params.partition_type = BRLEN_FIX;
params.optimize_alg_gammai = "Brent";
params.opt_gammai = false;
continue;
}
if (strcmp(argv[cnt], "-M") == 0) {
params.partition_type = 0;
params.partition_type = BRLEN_OPTIMIZE;
continue;
}
if (strcmp(argv[cnt], "-rcluster") == 0) {
Expand Down Expand Up @@ -3427,9 +3427,12 @@ void parseArg(int argc, char *argv[], Params &params) {
usage(argv, false);
#endif
}


if (params.model_test_and_tree && params.partition_type != BRLEN_OPTIMIZE)
outError("-mtree not allowed with edge-linked partition model (-spp or -q)");

if (params.do_au_test && params.topotest_replicates == 0)
outError("For AU test please please specify number of bootstrap replicates via -zb option");
outError("For AU test please specify number of bootstrap replicates via -zb option");

if (params.lh_mem_save == LM_MEM_SAVE && params.partition_file)
outError("-mem option does not work with partition models yet");
Expand Down
9 changes: 5 additions & 4 deletions utils/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -825,12 +825,13 @@ class Params {
char *partition_file;

/**
* IMPORTANT (2012-12-21): refactor this variable as below
* defines the relation between edge lengths in supertree and subtrees
* 0 (NULL) for separate edge length (default)
* 'p' for proportional edge length
* 'j' for joint edge length
* BRLEN_OPTIMIZE (0) for separate edge length (default)
* BRLEN_FIX (1) for joint edge length
* BRLEN_SCALE (2) for proportional edge length
*/
char partition_type;
int partition_type;

/** percentage for rcluster algorithm like PartitionFinder */
double partfinder_rcluster;
Expand Down

0 comments on commit cb49148

Please sign in to comment.