Skip to content

Commit 67d62b3

Browse files
Fix the checkAbsentStates functions
1 parent cb977a7 commit 67d62b3

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
@@ -484,11 +484,10 @@ class Alignment : public vector<Pattern>, public CharSet, public StateSpace {
484484
int getMaxSeqNameLength();
485485

486486
/*
487-
check if some state is absent, which may cause numerical issues
487+
check if some states are absent, which may cause numerical issues
488488
@param msg additional message into the warning
489-
@return number of absent states in the alignment
490489
*/
491-
virtual int checkAbsentStates(string msg);
490+
virtual void checkAbsentStates(string msg);
492491

493492
/**
494493
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
@@ -3403,22 +3403,8 @@ bool isTreeMixture(Params& params) {
34033403

34043404
void runTreeReconstruction(Params &params, IQTree* &iqtree) {
34053405

3406-
// string dist_file;
3407-
// params.startCPUTime = getCPUTime();
3408-
// params.start_real_time = getRealTime();
3409-
3410-
int absent_states = 0;
3411-
if (iqtree->isSuperTree()) {
3412-
PhyloSuperTree *stree = (PhyloSuperTree*)iqtree;
3413-
for (auto i = stree->begin(); i != stree->end(); i++)
3414-
absent_states += (*i)->aln->checkAbsentStates("partition " + (*i)->aln->name);
3415-
} else {
3416-
absent_states = iqtree->aln->checkAbsentStates("alignment");
3417-
}
3418-
if (absent_states > 0) {
3419-
cout << "NOTE: " << absent_states << " states (see above) are not present and thus removed from Markov process to prevent numerical problems" << endl;
3420-
}
3421-
3406+
iqtree->aln->checkAbsentStates("alignment");
3407+
34223408
// Make sure that no partial likelihood of IQ-TREE is initialized when PLL is used to save memory
34233409
if (params.pll) {
34243410
iqtree->deleteAllPartialLh();

0 commit comments

Comments
 (0)