Skip to content

Commit 57916f1

Browse files
James BarbettiJames Barbetti
James Barbetti
authored and
James Barbetti
committed
Merging changes from iqtree.
1. Corrected a couple of problems (with visibility of prepareToConstructTree() implementations). 2. utils/stringfunctions.cpp and utils/stringfunctions.h now included in decenttree (and various examples).
1 parent f23115f commit 57916f1

11 files changed

+605
-24
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ add_executable(decenttree
601601
utils/gzstream.cpp utils/gzstream.h
602602
utils/progress.cpp utils/progress.h
603603
utils/operatingsystem.cpp utils/operatingsystem.h
604+
utils/stringfunctions.cpp utils/stringfunctions.h
604605
utils/vectortypes.cpp utils/vectortypes.h)
605606

606607
if(ZLIB_FOUND)

decenttree.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
#include <string> //for std::string
2424
#include <iostream> //for std::cout
2525
#include <math.h> //for log
26+
#include <utils/argument.h> //for Argument, ArgumentMap, et al.
2627
#include <utils/progress.h> //for progress_display::setProgressDisplay()
2728
#include <utils/operatingsystem.h> //for getOSName
2829
#include <utils/hammingdistance.h> //for hammingDistance
29-
#include <utils/argument.h> //for Argument, ArgumentMap, et al.
30+
#include <utils/stringfunctions.h> //for contains
3031
#include "starttree.h" //for StartTree::Factory
3132
#include "flatmatrix.h" //for FlatMatrix
3233
#include "distancematrix.h" //for loadDistanceMatrixInto
@@ -38,20 +39,6 @@
3839
#define PROBLEM(x) if (1) problems << x << ".\n"; else 0
3940

4041
namespace {
41-
bool endsWith(const std::string& s, const char* suffix) {
42-
auto suffixLen = strlen(suffix);
43-
if (s.length() < suffixLen) {
44-
return false;
45-
}
46-
return s.substr(s.length()-suffixLen, suffixLen) == suffix;
47-
}
48-
49-
std::string string_to_lower(const std::string& input_string) {
50-
std::string answer = input_string;
51-
std::transform(answer.begin(), answer.end(), answer.begin(),
52-
[]( char c){ return std::tolower(c); });
53-
return answer;
54-
}
5542

5643
bool correcting_distances = true;
5744
bool is_DNA = true;
@@ -399,8 +386,7 @@ class DecentTreeOptions {
399386
range_restrict(0, 9, compression_level );
400387
range_restrict(1, 15, precision );
401388
format = string_to_lower(format);
402-
if (isOutputZipped &&
403-
format.find(".gz") == std::string::npos) {
389+
if (isOutputZipped && !contains(format, ".gz")) {
404390
//Ensure that distance file will be compressed
405391
format += ".gz";
406392
}

decenttree_update.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ cp timeutil.h my_assert.h safe_io.h ../../decenttree/utils
2424
cp parallel_mergesort.h parallel_sort.h ../../decenttree/utils
2525
cp vectortypes.cpp vectortypes.h ../../decenttree/utils
2626
cp hammingdistance.h ../../decenttree/utils
27+
cp stringfunctions.h stringfunctions.cpp ../../decenttree/utils
2728
cd ..
2829
cp -R zlib-1.2.7 ../decenttree
2930
cp -R lib ../decenttree

fancyrapidnj.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ template <class T=NJFloat> class FancyNJMatrix {
251251

252252
return true;
253253
}
254+
virtual bool prepareToConstructTree() {
255+
}
254256
virtual bool constructTree() {
257+
prepareToConstructTree();
255258
if (original_rank<3) {
256259
return false;
257260
}

flatmatrix.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
//
3030

3131
#include "flatmatrix.h"
32-
#include "utils/progress.h"
32+
#include <utils/progress.h>
33+
#include <utils/stringfunctions.h> //for contains
3334
#include <math.h> //for log10
3435
#include <iostream> //for std::fstream
3536
#include <sstream> //for std::stringstream
@@ -113,8 +114,8 @@ bool FlatMatrix::writeToDistanceFile(const std::string& format,
113114
const std::string& file_name) const {
114115
#if USE_PROGRESS_DISPLAY
115116
double rows = static_cast<double>(getSize());
116-
bool isTriangle = format.find("lower") != std::string::npos ||
117-
format.find("upper") != std::string::npos;
117+
bool isTriangle = contains(format,"lower") ||
118+
contains(format,"upper");
118119
double halfIfTriangle = isTriangle ? 0.5 : 1.0;
119120

120121
double calculations = rows * rows * halfIfTriangle;
@@ -125,7 +126,7 @@ bool FlatMatrix::writeToDistanceFile(const std::string& format,
125126
#endif
126127

127128
try {
128-
if (format.find(".gz") == std::string::npos) {
129+
if (!contains(format,".gz")) {
129130
std::ofstream out;
130131
out.exceptions(std::ios::failbit | std::ios::badbit);
131132
out.open(file_name.c_str());

sequence.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <utils/hammingdistance.h> //for vectorHamingDistance()
3232
#include <utils/gzstream.h> //for pigzstream class
3333
#include <utils/safe_io.h> //for safeGetLine()
34+
#include <utils/stringfunctions.h> //for contains()
3435

3536
bool isNucleotideOrMissing(const char c) {
3637
return isalnum(c) || c == '-' || c == '?'||
@@ -633,8 +634,8 @@ bool SequenceLoader::writeDistanceMatrixToFile(bool numbered_names,
633634
getNumberOfStates();
634635

635636
#if USE_PROGRESS_DISPLAY
636-
bool isTriangle = output_format.find("lower") != std::string::npos ||
637-
output_format.find("upper") != std::string::npos;
637+
bool isTriangle = contains(output_format,"lower") ||
638+
contains(output_format,"upper");
638639
double halfIfTriangle = isTriangle ? 0.5 : 1.0;
639640
double calculations = static_cast<double>(rank)
640641
* static_cast<double>(rank) * halfIfTriangle;

stitchup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ template < class T=double> class StitchupMatrix: public SquareMatrix<T> {
486486
virtual void beSilent() {
487487
silent = true;
488488
}
489+
virtual void prepareToConstructTree() {
490+
}
489491
virtual bool constructTree() {
490492
prepareToConstructTree();
491493
if (row_count<3) {
@@ -575,6 +577,7 @@ class NearestTaxonClusterJoiningMatrix: public S {
575577
using super::clusters;
576578
using super::rowTotals;
577579
//member functions from super-class
580+
using super::prepareToConstructTree;
578581
using super::cluster;
579582
using super::finishClustering;
580583

@@ -633,7 +636,6 @@ class NearestTaxonClusterJoiningMatrix: public S {
633636
progress += (taxon_count-row_count);
634637
}
635638
finishClustering();
636-
637639
}
638640

639641
virtual bool constructTree() override {

0 commit comments

Comments
 (0)