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

Commit 714d6cb

Browse files
committed
Fix NONREV protein model initialisation unintentionally converting rooted input tree (reported by Suha Naser)
1 parent a37ba62 commit 714d6cb

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

model/modelmarkov.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ void ModelMarkov::readStateFreq(string str) throw(const char*) {
15261526
state_freq[i] *= sum;
15271527
}
15281528

1529-
void ModelMarkov::readParameters(const char *file_name) {
1529+
void ModelMarkov::readParameters(const char *file_name, bool adapt_tree) {
15301530
if (!fileExists(file_name))
15311531
outError("File not found ", file_name);
15321532

@@ -1538,9 +1538,9 @@ void ModelMarkov::readParameters(const char *file_name) {
15381538
double d;
15391539
in >> d;
15401540
if (d < 0) {
1541-
setReversible(false);
1541+
setReversible(false, adapt_tree);
15421542
} else
1543-
setReversible(true);
1543+
setReversible(true, adapt_tree);
15441544
in.close();
15451545
}
15461546
catch (...) {
@@ -1574,16 +1574,16 @@ void ModelMarkov::readParameters(const char *file_name) {
15741574
}
15751575
}
15761576

1577-
void ModelMarkov::readParametersString(string &model_str) {
1577+
void ModelMarkov::readParametersString(string &model_str, bool adapt_tree) {
15781578

15791579
// if detect if reading full matrix or half matrix by the first entry
15801580
int end_pos;
15811581
double d = 0.0;
15821582
d = convert_double(model_str.c_str(), end_pos);
15831583
if (d < 0) {
1584-
setReversible(false);
1584+
setReversible(false, adapt_tree);
15851585
} else
1586-
setReversible(true);
1586+
setReversible(true, adapt_tree);
15871587

15881588
try {
15891589
stringstream in(model_str);

model/modelmarkov.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ class ModelMarkov : public ModelSubst, public EigenDecomposition
170170
read model parameters from a file
171171
@param file_name file containing rate matrix and state frequencies
172172
*/
173-
void readParameters(const char *file_name);
173+
void readParameters(const char *file_name, bool adapt_tree = true);
174174

175175
/**
176176
read model parameters from a string
177177
@param model_str string containing rate matrix and state frequencies
178178
*/
179-
void readParametersString(string &model_str);
179+
void readParametersString(string &model_str, bool adapt_tree = true);
180180

181181
/**
182182
compute the transition probability matrix.

model/modelprotein.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,10 @@ void ModelProtein::init(const char *model_name, string model_params, StateFreqTy
780780
if (Params::getInstance().model_name_init) {
781781
nxs_model = models_block->findModel(Params::getInstance().model_name_init);
782782
if (nxs_model) {
783-
readParametersString(nxs_model->description);
783+
readParametersString(nxs_model->description, false);
784784
} else {
785785
// initialize with custom model file
786-
readParameters(Params::getInstance().model_name_init);
786+
readParameters(Params::getInstance().model_name_init, false);
787787
}
788788
rescaleRates(rates, getNumRateEntries());
789789
if (!isReversible())
@@ -792,7 +792,7 @@ void ModelProtein::init(const char *model_name, string model_params, StateFreqTy
792792
// initialize rate matrix with LG
793793
nxs_model = models_block->findModel("LG");
794794
ASSERT(nxs_model);
795-
readParametersString(nxs_model->description);
795+
readParametersString(nxs_model->description, false);
796796
rescaleRates(rates, getNumRateEntries());
797797
}
798798
// 2018-05-08 bug fix: GTR20 rates are not optimized
@@ -807,10 +807,10 @@ void ModelProtein::init(const char *model_name, string model_params, StateFreqTy
807807
if (Params::getInstance().model_name_init) {
808808
nxs_model = models_block->findModel(Params::getInstance().model_name_init);
809809
if (nxs_model) {
810-
readParametersString(nxs_model->description);
810+
readParametersString(nxs_model->description, false);
811811
} else {
812812
// initialize with custom model file
813-
readParameters(Params::getInstance().model_name_init);
813+
readParameters(Params::getInstance().model_name_init, false);
814814
}
815815
rescaleRates(rates, getNumRateEntries());
816816
if (isReversible())
@@ -819,7 +819,7 @@ void ModelProtein::init(const char *model_name, string model_params, StateFreqTy
819819
// initialize rate matrix with LG
820820
nxs_model = models_block->findModel("LG");
821821
ASSERT(nxs_model);
822-
readParametersString(nxs_model->description);
822+
readParametersString(nxs_model->description, false);
823823
rescaleRates(rates, getNumRateEntries());
824824
setReversible(false);
825825
}

0 commit comments

Comments
 (0)