From f4ce6943d881a3ba9fba263a242658bdfe50a1b5 Mon Sep 17 00:00:00 2001 From: NicolaDM Date: Mon, 7 Sep 2020 11:58:52 +0100 Subject: [PATCH 1/6] Add files via upload --- model/modelunrest.cpp | 56 ++++++++++++++++++++++++++++++++++++------- model/modelunrest.h | 1 + 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/model/modelunrest.cpp b/model/modelunrest.cpp index d33d7b44f..6e66ba251 100644 --- a/model/modelunrest.cpp +++ b/model/modelunrest.cpp @@ -6,25 +6,63 @@ */ #include "modelunrest.h" +#include +#include ModelUnrest::ModelUnrest(PhyloTree *tree, string model_params) : ModelMarkov(tree, false) { - num_params = getNumRateEntries() - 1; - //ModelMarkov::setReversible in the ModelMarkov - //constructor sets all the rates to 0.0. But... - for (int i=0; i <= num_params; i++) { - rates[i] = 1.0; - } + num_params = getNumRateEntries() - 1; + //model_parameters = new double [num_params]; + for (int i=0; i< num_params; i++) rates[i] = 1.0; + //setRates(); if (model_params != "") { - cout << "WARNING: Supplying model params to constructor not yet properly implemented -- ignored" << endl; - // TODO: parse model_params into model_parameters, then call setRates(). + int end_pos = 0; + cout << __func__ << " " << model_params << endl; + for (int i = 0; i < 12; i++) { + int new_end_pos; + try { + rates[i] = convert_double(model_params.substr(end_pos).c_str(), new_end_pos); + } catch (string &model_params) { + outError(model_params); + } + + end_pos += new_end_pos; + if (rates[i] <= 0.0) + outError("Non-positive rates found"); + if (i == 11 && end_pos < model_params.length()) + outError("String too long ", model_params); + if (i < 11 && end_pos >= model_params.length()) + outError("Unexpected end of string ", model_params); + if (end_pos < model_params.length() && model_params[end_pos] != ',') + outError("Comma to separate rates not found in ", model_params); + end_pos++; + } + num_params = 0; + writeInfo(cout); } name = "UNREST"; full_name = "Unrestricted model (non-reversible)"; ModelMarkov::init(FREQ_ESTIMATE); } +void ModelUnrest::writeInfo(ostream &out) { + out << "UNREST rate values:"; + out << " A-C: " << rates[0]; + out << " A-G: " << rates[1]; + out << " A-T: " << rates[2]; + out << " C-A: " << rates[3]; + out << " C-G: " << rates[4]; + out << " C-T: " << rates[5]; + out << " G-A: " << rates[6]; + out << " G-C: " << rates[7]; + out << " G-T: " << rates[8]; + out << " T-A: " << rates[9]; + out << " T-C: " << rates[10]; + out << " T-G: " << rates[11]; + out << endl; +} + /* static */ bool ModelUnrest::validModelName(string model_name) { return (model_name == "UNREST"); } @@ -39,6 +77,8 @@ void ModelUnrest::setBounds(double *lower_bound, double *upper_bound, bool *boun } } + + /* void ModelUnrest::setRates() { // For UNREST, parameters are simply the off-diagonal rate matrix entries diff --git a/model/modelunrest.h b/model/modelunrest.h index 01aeb07eb..fc1b660b1 100644 --- a/model/modelunrest.h +++ b/model/modelunrest.h @@ -48,6 +48,7 @@ class ModelUnrest: public ModelMarkov { virtual void restoreCheckpoint(); protected: + void writeInfo(ostream &out); }; #endif /* MODELUNREST_H_ */ From 957241e275a04ed1a1e6b577ad985ffdd3eebc98 Mon Sep 17 00:00:00 2001 From: NicolaDM Date: Mon, 7 Sep 2020 12:01:43 +0100 Subject: [PATCH 2/6] file needed for compilation --- utils/decentTree.cpp | 127 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 utils/decentTree.cpp diff --git a/utils/decentTree.cpp b/utils/decentTree.cpp new file mode 100644 index 000000000..a1221c175 --- /dev/null +++ b/utils/decentTree.cpp @@ -0,0 +1,127 @@ +// +// DecentTree.cpp +// +// Copyright (C) 2020, James Barbetti. +// +// LICENSE: +//* This program is free software; you can redistribute it and/or modify +//* it under the terms of the GNU General Public License as published by +//* the Free Software Foundation; either version 2 of the License, or +//* (at your option) any later version. +//* +//* This program is distributed in the hope that it will be useful, +//* but WITHOUT ANY WARRANTY; without even the implied warranty of +//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//* GNU General Public License for more details. +//* +//* You should have received a copy of the GNU General Public License +//* along with this program; if not, write to the +//* Free Software Foundation, Inc., +//* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// + +#include //for std::string +#include //for std::cout +#include "progress.h" //for progress_display::setProgressDisplay() +#include "starttree.h" //for StartTree::Factory +#include "operatingsystem.h" //for getOSName + +#define PROBLEM(x) if (1) problems = problems + x + ".\n"; else 0 + +namespace { + bool endsWith(const std::string s, const char* suffix) { + auto suffixLen = strlen(suffix); + if (s.length() < suffixLen) { + return false; + } + return s.substr(s.length()-suffixLen, suffixLen) == suffix; + } +}; + +void showBanner() { + std::cout << "\nDecentTree for " << getOSName() << "\n"; + std::cout << "Based on algorithms (UPGMA, NJ, BIONJ) proposed by Sokal & Michener [1958], Saitou & Nei [1987], Gascuel [2009]\n"; + std::cout << "Incorporating (in NJ-R and BIONJ-R) techniques proposed by Simonson, Mailund, and Pedersen [2011]\n"; + std::cout << "Developed by Olivier Gascuel [2009], Hoa Sien Cuong [2009], James Barbetti [2020]\n"; + std::cout << "(To suppress this banner pass -no-banner)\n"; +} + +void showUsage() { + std::cout << "\nUsage: DecentTree -in [mldist] -out [newick] -t [algorithm] (-gz) (-no-banner)\n"; + std::cout << "[mldist] is the path of a distance matrix file (which may be in .gz format)\n"; + std::cout << "[newick] is the path to write the newick tree file to (if it ends in .gz it will be compressed)\n"; + std::cout << "[algorithm] is one of the following, supported, distance matrix algorithms:\n"; + std::cout << StartTree::Factory::getInstance().getListOfTreeBuilders(); +} + +int main(int argc, char* argv[]) { + std::string problems; + progress_display::setProgressDisplay(true); //Displaying progress bars + std::string algorithmName = StartTree::Factory::getNameOfDefaultTreeBuilder(); + std::string inputFilePath; + std::string outputFilePath; + bool isOutputZipped = false; + bool isBannerSuppressed = false; + for (int argNum=1; argNumsetZippedOutput(isOutputZipped || endsWith(outputFilePath,".gz")); + if (!algorithm->constructTree(inputFilePath, outputFilePath)) { + std::cerr << "Tree construction failed."; + return 1; + } + return 0; +} From 25e8b83155ce73a635c63e484f920931ce5414ca Mon Sep 17 00:00:00 2001 From: NicolaDM Date: Mon, 7 Sep 2020 12:02:33 +0100 Subject: [PATCH 3/6] deleted DecentTree.cpp --- utils/DecentTree.cpp | 127 ------------------------------------------- 1 file changed, 127 deletions(-) delete mode 100644 utils/DecentTree.cpp diff --git a/utils/DecentTree.cpp b/utils/DecentTree.cpp deleted file mode 100644 index a1221c175..000000000 --- a/utils/DecentTree.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// -// DecentTree.cpp -// -// Copyright (C) 2020, James Barbetti. -// -// LICENSE: -//* This program is free software; you can redistribute it and/or modify -//* it under the terms of the GNU General Public License as published by -//* the Free Software Foundation; either version 2 of the License, or -//* (at your option) any later version. -//* -//* This program is distributed in the hope that it will be useful, -//* but WITHOUT ANY WARRANTY; without even the implied warranty of -//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -//* GNU General Public License for more details. -//* -//* You should have received a copy of the GNU General Public License -//* along with this program; if not, write to the -//* Free Software Foundation, Inc., -//* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// - -#include //for std::string -#include //for std::cout -#include "progress.h" //for progress_display::setProgressDisplay() -#include "starttree.h" //for StartTree::Factory -#include "operatingsystem.h" //for getOSName - -#define PROBLEM(x) if (1) problems = problems + x + ".\n"; else 0 - -namespace { - bool endsWith(const std::string s, const char* suffix) { - auto suffixLen = strlen(suffix); - if (s.length() < suffixLen) { - return false; - } - return s.substr(s.length()-suffixLen, suffixLen) == suffix; - } -}; - -void showBanner() { - std::cout << "\nDecentTree for " << getOSName() << "\n"; - std::cout << "Based on algorithms (UPGMA, NJ, BIONJ) proposed by Sokal & Michener [1958], Saitou & Nei [1987], Gascuel [2009]\n"; - std::cout << "Incorporating (in NJ-R and BIONJ-R) techniques proposed by Simonson, Mailund, and Pedersen [2011]\n"; - std::cout << "Developed by Olivier Gascuel [2009], Hoa Sien Cuong [2009], James Barbetti [2020]\n"; - std::cout << "(To suppress this banner pass -no-banner)\n"; -} - -void showUsage() { - std::cout << "\nUsage: DecentTree -in [mldist] -out [newick] -t [algorithm] (-gz) (-no-banner)\n"; - std::cout << "[mldist] is the path of a distance matrix file (which may be in .gz format)\n"; - std::cout << "[newick] is the path to write the newick tree file to (if it ends in .gz it will be compressed)\n"; - std::cout << "[algorithm] is one of the following, supported, distance matrix algorithms:\n"; - std::cout << StartTree::Factory::getInstance().getListOfTreeBuilders(); -} - -int main(int argc, char* argv[]) { - std::string problems; - progress_display::setProgressDisplay(true); //Displaying progress bars - std::string algorithmName = StartTree::Factory::getNameOfDefaultTreeBuilder(); - std::string inputFilePath; - std::string outputFilePath; - bool isOutputZipped = false; - bool isBannerSuppressed = false; - for (int argNum=1; argNumsetZippedOutput(isOutputZipped || endsWith(outputFilePath,".gz")); - if (!algorithm->constructTree(inputFilePath, outputFilePath)) { - std::cerr << "Tree construction failed."; - return 1; - } - return 0; -} From e375f23782e2982df96e000255c32973e0f84dfd Mon Sep 17 00:00:00 2001 From: NicolaDM Date: Fri, 11 Sep 2020 14:02:13 +0100 Subject: [PATCH 4/6] renamed decenttree as currently in master --- utils/decenttree.cpp | 127 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 utils/decenttree.cpp diff --git a/utils/decenttree.cpp b/utils/decenttree.cpp new file mode 100644 index 000000000..a1221c175 --- /dev/null +++ b/utils/decenttree.cpp @@ -0,0 +1,127 @@ +// +// DecentTree.cpp +// +// Copyright (C) 2020, James Barbetti. +// +// LICENSE: +//* This program is free software; you can redistribute it and/or modify +//* it under the terms of the GNU General Public License as published by +//* the Free Software Foundation; either version 2 of the License, or +//* (at your option) any later version. +//* +//* This program is distributed in the hope that it will be useful, +//* but WITHOUT ANY WARRANTY; without even the implied warranty of +//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//* GNU General Public License for more details. +//* +//* You should have received a copy of the GNU General Public License +//* along with this program; if not, write to the +//* Free Software Foundation, Inc., +//* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// + +#include //for std::string +#include //for std::cout +#include "progress.h" //for progress_display::setProgressDisplay() +#include "starttree.h" //for StartTree::Factory +#include "operatingsystem.h" //for getOSName + +#define PROBLEM(x) if (1) problems = problems + x + ".\n"; else 0 + +namespace { + bool endsWith(const std::string s, const char* suffix) { + auto suffixLen = strlen(suffix); + if (s.length() < suffixLen) { + return false; + } + return s.substr(s.length()-suffixLen, suffixLen) == suffix; + } +}; + +void showBanner() { + std::cout << "\nDecentTree for " << getOSName() << "\n"; + std::cout << "Based on algorithms (UPGMA, NJ, BIONJ) proposed by Sokal & Michener [1958], Saitou & Nei [1987], Gascuel [2009]\n"; + std::cout << "Incorporating (in NJ-R and BIONJ-R) techniques proposed by Simonson, Mailund, and Pedersen [2011]\n"; + std::cout << "Developed by Olivier Gascuel [2009], Hoa Sien Cuong [2009], James Barbetti [2020]\n"; + std::cout << "(To suppress this banner pass -no-banner)\n"; +} + +void showUsage() { + std::cout << "\nUsage: DecentTree -in [mldist] -out [newick] -t [algorithm] (-gz) (-no-banner)\n"; + std::cout << "[mldist] is the path of a distance matrix file (which may be in .gz format)\n"; + std::cout << "[newick] is the path to write the newick tree file to (if it ends in .gz it will be compressed)\n"; + std::cout << "[algorithm] is one of the following, supported, distance matrix algorithms:\n"; + std::cout << StartTree::Factory::getInstance().getListOfTreeBuilders(); +} + +int main(int argc, char* argv[]) { + std::string problems; + progress_display::setProgressDisplay(true); //Displaying progress bars + std::string algorithmName = StartTree::Factory::getNameOfDefaultTreeBuilder(); + std::string inputFilePath; + std::string outputFilePath; + bool isOutputZipped = false; + bool isBannerSuppressed = false; + for (int argNum=1; argNumsetZippedOutput(isOutputZipped || endsWith(outputFilePath,".gz")); + if (!algorithm->constructTree(inputFilePath, outputFilePath)) { + std::cerr << "Tree construction failed."; + return 1; + } + return 0; +} From ca82c1e7ec0a7477c92ba58f9149f644948d8498 Mon Sep 17 00:00:00 2001 From: NicolaDM Date: Fri, 11 Sep 2020 14:02:41 +0100 Subject: [PATCH 5/6] Delete decentTree.cpp --- utils/decentTree.cpp | 127 ------------------------------------------- 1 file changed, 127 deletions(-) delete mode 100644 utils/decentTree.cpp diff --git a/utils/decentTree.cpp b/utils/decentTree.cpp deleted file mode 100644 index a1221c175..000000000 --- a/utils/decentTree.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// -// DecentTree.cpp -// -// Copyright (C) 2020, James Barbetti. -// -// LICENSE: -//* This program is free software; you can redistribute it and/or modify -//* it under the terms of the GNU General Public License as published by -//* the Free Software Foundation; either version 2 of the License, or -//* (at your option) any later version. -//* -//* This program is distributed in the hope that it will be useful, -//* but WITHOUT ANY WARRANTY; without even the implied warranty of -//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -//* GNU General Public License for more details. -//* -//* You should have received a copy of the GNU General Public License -//* along with this program; if not, write to the -//* Free Software Foundation, Inc., -//* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// - -#include //for std::string -#include //for std::cout -#include "progress.h" //for progress_display::setProgressDisplay() -#include "starttree.h" //for StartTree::Factory -#include "operatingsystem.h" //for getOSName - -#define PROBLEM(x) if (1) problems = problems + x + ".\n"; else 0 - -namespace { - bool endsWith(const std::string s, const char* suffix) { - auto suffixLen = strlen(suffix); - if (s.length() < suffixLen) { - return false; - } - return s.substr(s.length()-suffixLen, suffixLen) == suffix; - } -}; - -void showBanner() { - std::cout << "\nDecentTree for " << getOSName() << "\n"; - std::cout << "Based on algorithms (UPGMA, NJ, BIONJ) proposed by Sokal & Michener [1958], Saitou & Nei [1987], Gascuel [2009]\n"; - std::cout << "Incorporating (in NJ-R and BIONJ-R) techniques proposed by Simonson, Mailund, and Pedersen [2011]\n"; - std::cout << "Developed by Olivier Gascuel [2009], Hoa Sien Cuong [2009], James Barbetti [2020]\n"; - std::cout << "(To suppress this banner pass -no-banner)\n"; -} - -void showUsage() { - std::cout << "\nUsage: DecentTree -in [mldist] -out [newick] -t [algorithm] (-gz) (-no-banner)\n"; - std::cout << "[mldist] is the path of a distance matrix file (which may be in .gz format)\n"; - std::cout << "[newick] is the path to write the newick tree file to (if it ends in .gz it will be compressed)\n"; - std::cout << "[algorithm] is one of the following, supported, distance matrix algorithms:\n"; - std::cout << StartTree::Factory::getInstance().getListOfTreeBuilders(); -} - -int main(int argc, char* argv[]) { - std::string problems; - progress_display::setProgressDisplay(true); //Displaying progress bars - std::string algorithmName = StartTree::Factory::getNameOfDefaultTreeBuilder(); - std::string inputFilePath; - std::string outputFilePath; - bool isOutputZipped = false; - bool isBannerSuppressed = false; - for (int argNum=1; argNumsetZippedOutput(isOutputZipped || endsWith(outputFilePath,".gz")); - if (!algorithm->constructTree(inputFilePath, outputFilePath)) { - std::cerr << "Tree construction failed."; - return 1; - } - return 0; -} From ca6f98be1f355c025fe1b18f54b6aff46f35c382 Mon Sep 17 00:00:00 2001 From: Bui Quang Minh Date: Tue, 7 May 2024 12:44:39 +1000 Subject: [PATCH 6/6] revert initialisation in modelunrest.cpp --- model/modelunrest.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/model/modelunrest.cpp b/model/modelunrest.cpp index 1b9c3d8c7..cd181f959 100644 --- a/model/modelunrest.cpp +++ b/model/modelunrest.cpp @@ -12,10 +12,13 @@ ModelUnrest::ModelUnrest(PhyloTree *tree, string model_params, StateFreqType freq_type, string freq_params) : ModelMarkov(tree, false) { - num_params = getNumRateEntries() - 1; - //model_parameters = new double [num_params]; - for (int i=0; i< num_params; i++) rates[i] = 1.0; - //setRates(); + num_params = getNumRateEntries() - 1; + //ModelMarkov::setReversible in the ModelMarkov + //constructor sets all the rates to 0.0. But... + for (int i=0; i <= num_params; i++) { + rates[i] = 1.0; + } + if (model_params != "") { //cout << "WARNING: Supplying model params to constructor not yet properly implemented -- ignored" << endl; // TODO: parse model_params into model_parameters, then call setRates().