Skip to content

Commit 6c6f978

Browse files
authored
Merge pull request #73 from StefanFlaumberg/bugfix
Allow for single-state alignments and remove misleading warnings
2 parents 28c89a5 + 67d62b3 commit 6c6f978

File tree

5 files changed

+32
-46
lines changed

5 files changed

+32
-46
lines changed

alignment/alignment.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,33 +123,37 @@ double chi2prob (int deg, double chi2)
123123
} /* chi2prob */
124124

125125

126-
int Alignment::checkAbsentStates(string msg) {
127-
double *state_freq = new double[num_states];
128-
computeStateFreq(state_freq);
129-
string absent_states, rare_states;
130-
int count = 0;
131-
// Skip check for PoMo.
126+
void Alignment::checkAbsentStates(string msg) {
127+
// skip checking for PoMo
132128
if (seq_type == SEQ_POMO)
133-
return 0;
134-
for (int i = 0; i < num_states; i++)
135-
if (state_freq[i] == 0.0) {
129+
return;
130+
string absent_states, rare_states;
131+
int absent_cnt = 0;
132+
double *state_freqs = new double[num_states];
133+
computeStateFreq(state_freqs);
134+
for (int x = 0; x < num_states; ++x) {
135+
if (state_freqs[x] == 0.0) {
136136
if (!absent_states.empty())
137137
absent_states += ", ";
138-
absent_states += convertStateBackStr(i);
139-
count++;
140-
} else if (state_freq[i] <= Params::getInstance().min_state_freq) {
138+
absent_states += convertStateBackStr(x);
139+
absent_cnt++;
140+
} else if (state_freqs[x] <= Params::getInstance().min_state_freq) {
141141
if (!rare_states.empty())
142142
rare_states += ", ";
143-
rare_states += convertStateBackStr(i);
143+
rare_states += convertStateBackStr(x);
144144
}
145-
if (count >= num_states-1 && Params::getInstance().fixed_branch_length != BRLEN_FIX)
146-
outError("Only one state is observed in " + msg);
145+
}
146+
delete [] state_freqs;
147+
if (absent_cnt == num_states)
148+
outError("Only gaps observed in " + msg);
149+
if (absent_cnt == num_states - 1)
150+
outWarning("Only one state observed in " + msg);
151+
if (absent_cnt > 0)
152+
outWarning(convertIntToString(absent_cnt) + " states (see below) not observed in " + msg);
147153
if (!absent_states.empty())
148-
cout << "NOTE: State(s) " << absent_states << " not present in " << msg << " and thus removed from Markov process to prevent numerical problems" << endl;
154+
outWarning("State(s) " + absent_states + " not present in " + msg + " and may cause numerical problems");
149155
if (!rare_states.empty())
150-
cout << "WARNING: States(s) " << rare_states << " rarely appear in " << msg << " and may cause numerical problems" << endl;
151-
delete[] state_freq;
152-
return count;
156+
outWarning("State(s) " + rare_states + " rarely appear in " + msg + " and may cause numerical problems");
153157
}
154158

155159
void Alignment::checkSeqName() {

alignment/alignment.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,10 @@ class Alignment : public vector<Pattern>, public CharSet, public StateSpace {
501501
int getMaxSeqNameLength();
502502

503503
/*
504-
check if some state is absent, which may cause numerical issues
504+
check if some states are absent, which may cause numerical issues
505505
@param msg additional message into the warning
506-
@return number of absent states in the alignment
507506
*/
508-
virtual int checkAbsentStates(string msg);
507+
virtual void checkAbsentStates(string msg);
509508

510509
/**
511510
check proper and undupplicated sequence names

alignment/superalignment.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,9 @@ Alignment *SuperAlignment::removeIdenticalSeq(string not_remove, bool keep_two,
11481148
return aln;
11491149
}
11501150

1151-
int SuperAlignment::checkAbsentStates(string msg) {
1152-
int count = 0;
1153-
for (auto it = partitions.begin(); it != partitions.end(); ++it)
1154-
count += (*it)->checkAbsentStates("partition " + convertIntToString((it-partitions.begin())+1));
1155-
return count;
1151+
void SuperAlignment::checkAbsentStates(string msg) {
1152+
for (vector<Alignment*>::iterator it = partitions.begin(); it != partitions.end(); ++it)
1153+
(*it)->checkAbsentStates("partition " + convertIntToString((it-partitions.begin())+1));
11561154
}
11571155

11581156
/*

alignment/superalignment.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,10 @@ class SuperAlignment : public Alignment
171171

172172

173173
/*
174-
check if some state is absent, which may cause numerical issues
174+
check if some states are absent, which may cause numerical issues
175175
@param msg additional message into the warning
176-
@return number of absent states in the alignment
177176
*/
178-
virtual int checkAbsentStates(string msg);
177+
virtual void checkAbsentStates(string msg);
179178

180179
/**
181180
Quit if some sequences contain only gaps or missing data

main/phyloanalysis.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,22 +3420,8 @@ bool isTreeMixture(Params& params) {
34203420

34213421
void runTreeReconstruction(Params &params, IQTree* &iqtree) {
34223422

3423-
// string dist_file;
3424-
// params.startCPUTime = getCPUTime();
3425-
// params.start_real_time = getRealTime();
3426-
3427-
int absent_states = 0;
3428-
if (iqtree->isSuperTree()) {
3429-
PhyloSuperTree *stree = (PhyloSuperTree*)iqtree;
3430-
for (auto i = stree->begin(); i != stree->end(); i++)
3431-
absent_states += (*i)->aln->checkAbsentStates("partition " + (*i)->aln->name);
3432-
} else {
3433-
absent_states = iqtree->aln->checkAbsentStates("alignment");
3434-
}
3435-
if (absent_states > 0) {
3436-
cout << "NOTE: " << absent_states << " states (see above) are not present and thus removed from Markov process to prevent numerical problems" << endl;
3437-
}
3438-
3423+
iqtree->aln->checkAbsentStates("alignment");
3424+
34393425
// Make sure that no partial likelihood of IQ-TREE is initialized when PLL is used to save memory
34403426
if (params.pll) {
34413427
iqtree->deleteAllPartialLh();

0 commit comments

Comments
 (0)