Skip to content

Commit c1c35aa

Browse files
author
Thu-Hien To
committed
fix bug set minblen=-1 in relative date case, and do not remove outgroup
1 parent c5d4925 commit c1c35aa

File tree

7 files changed

+59
-22
lines changed

7 files changed

+59
-22
lines changed

bin/lsd2_mac

240 Bytes
Binary file not shown.

bin/lsd2_unix

72 Bytes
Binary file not shown.

src/lsd.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ int lsd::buildTimeTree( int argc, char** argv, InputOutputStream *inputOutput)
4646
if (io->inOutgroup){
4747
extrait_outgroup(io, opt);
4848
}
49-
ifstream gr(opt->rate.c_str());
5049
*(io->outTree1)<<"#NEXUS\n";
5150
*(io->outTree2)<<"#NEXUS\n";
5251
bool constraintConsistent=true;
@@ -100,7 +99,7 @@ int lsd::buildTimeTree( int argc, char** argv, InputOutputStream *inputOutput)
10099
double br=0;
101100
if (opt->givenRate[0]){
102101
string line;
103-
if( getline(gr, line)) {
102+
if( getline(*(io->inRate), line)) {
104103
vector<double> all_rates = read_double_from_line(line);
105104
opt->rho = all_rates[0];
106105
if (all_rates.size() > 1){
@@ -254,7 +253,6 @@ int lsd::buildTimeTree( int argc, char** argv, InputOutputStream *inputOutput)
254253
*(io->outTree1)<<"End;\n";
255254
*(io->outTree2)<<"End;\n";
256255
cout<<"\nTOTAL ELAPSED TIME: "<<elapsed_time<<" seconds"<<endl;
257-
gr.close();
258256
if (!inputOutput)
259257
delete io;
260258
return EXIT_SUCCESS;

src/lsd.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class InputOutputStream {
2626
/** input partition stream */
2727
istream *inPartition;
2828

29+
/** input rate stream */
30+
istream *inRate;
31+
2932
/** output result stream */
3033
ostream *outResult;
3134

@@ -47,7 +50,7 @@ class InputOutputStream {
4750
@param outgroup outgroup string
4851
@param date date string
4952
*/
50-
InputOutputStream(string tree, string outgroup, string date,string partition);
53+
InputOutputStream(string tree, string outgroup, string date,string rate,string partition);
5154

5255
/** destructor */
5356
virtual ~InputOutputStream();
@@ -66,16 +69,22 @@ class InputOutputStream {
6669
virtual void setOutgroup(string str);
6770

6871
/**
69-
set the content of the outgroup stream
72+
set the content of the date stream
7073
@param str a string
7174
*/
7275
virtual void setDate(string str);
7376

7477
/**
75-
set the content of the outgroup stream
78+
set the content of the partition stream
7679
@param str a string
7780
*/
7881
virtual void setPartition(string str);
82+
83+
/**
84+
set the content of the rate stream
85+
@param str a string
86+
*/
87+
virtual void setRate(string str);
7988
};
8089

8190
/**

src/options.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Pr* getOptions( int argc, char** argv )
2525

2626
Pr* getCommandLine( int argc, char** argv)
2727
{
28-
const string VERSION="v1.7";
28+
const string VERSION="v1.7.1";
2929
Pr* opt = new Pr();
3030
int c;
3131
string s;
@@ -362,7 +362,7 @@ Pr* getInterface()
362362

363363
void printInterface(ostream& in, Pr* opt)
364364
{
365-
const string VERSION = "v1.7";
365+
const string VERSION = "v1.7.1";
366366

367367
in<<"\nLEAST-SQUARE METHODS TO ESTIMATE RATES AND DATES - "<<VERSION<<" \n\n";
368368
in<<"\nInput files:\n";
@@ -505,7 +505,7 @@ void printHelp( void )
505505
const string BOLD = "\033[00;01m";
506506
const string LINE = "\033[00;04m";
507507
const string FLAT = "\033[00;00m";
508-
const string VERSION = "v1.7";
508+
const string VERSION = "v1.7.1";
509509

510510
cout<<BOLD<<"LSD: LEAST-SQUARES METHODS TO ESTIMATE RATES AND DATES - "<<VERSION<<"\n\n";
511511
cout<<BOLD<<"DESCRIPTION\n"

src/readData.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ void extrait_outgroup(InputOutputStream *io, Pr* pr){
418418
list<string> outgroups = getOutgroup(*(io->inOutgroup), pr->fnOutgroup);
419419
ostringstream w;
420420
for (int y=0;y<pr->nbData;y++){
421-
cout<<"Removing outgroups of tree "<<y+1<<" ...\n";
421+
if (pr->keepOutgroup) cout<<"Reroot the tree "<<y+1<<" using given outgroups ...\n";
422+
else cout<<"Removing outgroups of tree "<<y+1<<" ...\n";
422423
Node** nodes = tree2data(*(io->inTree),pr,s);
423424
if (!pr->rooted) {
424425
nodes=unrooted2rootedS(pr, nodes, s);
@@ -432,23 +433,22 @@ void extrait_outgroup(InputOutputStream *io, Pr* pr){
432433
Node** nodes_new = cloneLeaves(pr,nodes,0);
433434
int p_r=reroot_rootedtree(r, pr, nodes, nodes_new);
434435
computeSuc_polytomy(pr, nodes_new);
435-
if (pr->keepOutgroup) {
436-
w << newick(0,0,pr,nodes_new,nbTips);
436+
if (keepBelow) {
437+
w << newick(r, r, pr, nodes_new,nbTips);
437438
}
438439
else{
439-
if (keepBelow) {
440-
w << newick(r, r, pr, nodes_new,nbTips);
441-
}
442-
else{
443-
w << newick(p_r, p_r,pr, nodes_new,nbTips).c_str();
444-
}
440+
w << newick(p_r, p_r,pr, nodes_new,nbTips).c_str();
445441
}
446-
for (int i=0;i<=pr->nbBranches;i++) delete nodes_new[i];
447-
delete[] nodes_new;
448442
if ((nbTips+outgroups.size()) != (pr->nbBranches+1 - pr->nbINodes)){
449443
cerr<<"Error: The outgroups do not form a monophyletic in the input tree."<<endl;
450444
exit(EXIT_FAILURE);
451445
}
446+
if (pr->keepOutgroup) {
447+
w.str("");
448+
w << newick(0,0,pr,nodes_new,nbTips);
449+
}
450+
for (int i=0;i<=pr->nbBranches;i++) delete nodes_new[i];
451+
delete[] nodes_new;
452452
}
453453
else{
454454
cout<<"The outgroups are not in the tree "<<y+1<<endl;

src/utils.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,24 @@ InputOutputStream::InputOutputStream () {
2121
inTree = nullptr;
2222
inOutgroup = nullptr;
2323
inDate = nullptr;
24+
inRate = nullptr;
2425
inPartition = nullptr;
2526
outResult = nullptr;
2627
outTree1 = nullptr;
2728
outTree2 = nullptr;
2829
outTree3 = nullptr;
2930
}
3031

31-
InputOutputStream::InputOutputStream(string tree, string outgroup, string date, string partition) {
32+
InputOutputStream::InputOutputStream(string tree, string outgroup, string date, string rate, string partition) {
3233
inTree = nullptr;
3334
inOutgroup = nullptr;
3435
inDate = nullptr;
36+
inRate = nullptr;
3537
inPartition = nullptr;
3638
setTree(tree);
3739
setOutgroup(outgroup);
3840
setDate(date);
41+
setRate(rate);
3942
setPartition(partition);
4043
outResult = new ostringstream;
4144
outTree1 = new ostringstream;
@@ -60,6 +63,10 @@ InputOutputStream::~InputOutputStream() {
6063
delete inPartition;
6164
inPartition = nullptr;
6265
}
66+
if (inRate) {
67+
delete inRate;
68+
inRate = nullptr;
69+
}
6370
if (outResult) {
6471
delete outResult;
6572
outResult = nullptr;
@@ -108,6 +115,14 @@ void InputOutputStream::setPartition(string str) {
108115
inPartition = new istringstream(str);
109116
}
110117

118+
void InputOutputStream::setRate(string str) {
119+
if (str.empty())
120+
return;
121+
if (inRate)
122+
delete inRate;
123+
inRate = new istringstream(str);
124+
}
125+
111126
InputOutputFile::InputOutputFile(Pr *opt) : InputOutputStream() {
112127
treeIsFile = true;
113128
// open the tree file
@@ -138,7 +153,7 @@ InputOutputFile::InputOutputFile(Pr *opt) : InputOutputStream() {
138153
}
139154
}
140155

141-
// open date file
156+
// open partition file
142157
if (opt->partitionFile != "") {
143158
ifstream *part_file = new ifstream(opt->partitionFile);
144159
inPartition = part_file;
@@ -148,6 +163,17 @@ InputOutputFile::InputOutputFile(Pr *opt) : InputOutputStream() {
148163
}
149164
}
150165

166+
// open given rate file
167+
if (opt->rate != "") {
168+
ifstream *rate_file = new ifstream(opt->rate);
169+
inRate = rate_file;
170+
if (!rate_file->is_open()) {
171+
cerr << "Error: cannot open rate file " << opt->rate << endl;
172+
exit(EXIT_FAILURE);
173+
}
174+
}
175+
176+
151177
// open the result file
152178
ofstream *result_file = new ofstream(opt->outFile);
153179
outResult = result_file;
@@ -191,6 +217,9 @@ InputOutputFile::~InputOutputFile() {
191217
if (inPartition) {
192218
((ifstream*)inPartition)->close();
193219
}
220+
if (inRate) {
221+
((ifstream*)inRate)->close();
222+
}
194223
if (outResult) {
195224
((ofstream*)outResult)->close();
196225
}
@@ -2835,6 +2864,7 @@ void imposeMinBlen(ostream& file,Pr* pr, Node** nodes, double median_rate,bool m
28352864
}
28362865
}
28372866
else {
2867+
minblen = m;
28382868
if (pr->minblenL < 0){
28392869
cout<<"Minimum branch length of time scaled tree (settable via option -u and -U): "<<m<<endl;
28402870
file<<"Minimum branch length of time scaled tree (settable via option -u and -U): "<<m<<"\n";

0 commit comments

Comments
 (0)