Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0edccf4
first implementation
trongnhanuit Nov 19, 2024
8238135
To reconstruct extant (or ancestral) sequences, we must use the Non-r…
trongnhanuit Nov 19, 2024
38468bd
Extend ESR to partition models
trongnhanuit Nov 21, 2024
9929279
remove redundant/duplicate code
trongnhanuit Nov 21, 2024
6859aa6
Minor update: changing the filename in the comment to reflect the cor…
trongnhanuit Dec 8, 2024
1042a69
Reimplement ESR
trongnhanuit Dec 12, 2024
dc78828
Bug fixed for ESR with Rate heterogeneity models
trongnhanuit Dec 13, 2024
530e188
Bug fixed: forgot returning the likelihood value
trongnhanuit Dec 13, 2024
3f35d99
bug fixed: avoid data race by not sharing transposed_trans_mat_ptr ac…
trongnhanuit Jan 29, 2025
2bb6952
Avoid warnings from compilers
trongnhanuit Feb 19, 2025
cf230d4
fix crashes due to unsafe use of the partial lh buffer
trongnhanuit Feb 19, 2025
7e231f0
introduce --gap-asr and --gap-esr
trongnhanuit May 5, 2025
5ee7a7f
Convert original alignment into binary (gap/non-gap) alignment
trongnhanuit May 6, 2025
4f7ac7e
run ESR/ASR on the faked binary data
trongnhanuit May 6, 2025
e390f97
first implementation of gap-esr/asr that works for the simplest use c…
trongnhanuit May 6, 2025
04a1e23
overwrite the predicted character if p_gap > p_non_gap
trongnhanuit May 6, 2025
f11ac01
remove the 'p_non_gap' column; and normalized the probabilities
trongnhanuit May 7, 2025
c267a5f
allow IQ-TREE to re-estimate branch lengths when reconstruct gapped s…
trongnhanuit May 7, 2025
e6d5896
fix the model for binary data (when reconstruct gapped sequences): GT…
trongnhanuit May 7, 2025
e4c2e7f
load a fixed tree topology when reconstruct gapped sequences
trongnhanuit May 8, 2025
3f7be1f
convert SuperAlignment to binary data
trongnhanuit May 8, 2025
dfaaf54
init SuperAlignment-specific variables after being converted to binar…
trongnhanuit May 8, 2025
c10307b
Bug fixed: delay deleting the "first_insertion" pointer
trongnhanuit May 9, 2025
0112e4f
print gapped sequence reconstruction for partition models.
trongnhanuit May 9, 2025
4543773
fix a crashing issue due to accessing to deallocated pointer
trongnhanuit May 13, 2025
cf1fb1d
output binary data for debugging
trongnhanuit May 13, 2025
f9a4fed
Show a warning if users specify "-blfix" together with "-gap-asr"/"-g…
trongnhanuit May 14, 2025
4db9909
let ModelFinder select the rate heterogeneity model for the fake bina…
trongnhanuit May 14, 2025
9b24767
support -gap-esr/asr on (single) alignment without gaps
trongnhanuit May 14, 2025
c07635f
support -gap-esr/asr on partition alignment that all partition member…
trongnhanuit May 14, 2025
13e28ea
implement checkpoint for the binary-data run
trongnhanuit May 16, 2025
8953c79
bug fixed: re-define p_gap and p_non_gap as local variables
trongnhanuit May 16, 2025
d2aa6a3
don't support `-gap-esr` and `-gap-asr` if some partitions are gapped…
trongnhanuit May 16, 2025
9b6c549
update assertion in ModelFinder to support single-state alignments
trongnhanuit Jun 30, 2025
5404f40
consider GTR2 and JC2 for subst models and all ("AUTO") for rate models
trongnhanuit Jun 30, 2025
3f81ee7
don't support ASR/ESR if using unlinked topology (-S)
trongnhanuit Jul 2, 2025
2fe085e
first attempt to support non-reversible models for ASR/ESR
trongnhanuit Jul 4, 2025
af88499
don't allow mixing reversible and non-reversible models in partitions
trongnhanuit Jul 7, 2025
cae233b
add missing log in a special case - don't need to infer gaps in non-g…
trongnhanuit Jul 7, 2025
481b9d3
update console log
trongnhanuit Jul 8, 2025
d359577
support non-reversible models for gapped-ASR/ESR with partitions
trongnhanuit Jul 11, 2025
3fb548f
support gap-asr/esr with unlinked topology
trongnhanuit Jul 13, 2025
e0bea48
Merge master into gap_asr_esr
trongnhanuit Sep 18, 2026
5780650
Fix post-merge API mismatches in gap-ASR/ESR binary conversion
trongnhanuit Sep 18, 2026
0e845b2
exclude +ASC to avoid issues when testing binary models +ASC
trongnhanuit Feb 2, 2026
ac92478
Avoid using +ASR when perform fast likelihood tree search in ModelFin…
trongnhanuit Apr 13, 2026
6b204f6
Avoid ModelFinder from changing the topology of the binary data when …
trongnhanuit Sep 24, 2026
8ebf582
Preserve Params by clone a new instance for locally used inside gapp…
trongnhanuit Sep 24, 2026
ac021cf
fix accessing a null pointer
trongnhanuit Sep 24, 2026
9719816
avoid changing taxon name
trongnhanuit Sep 24, 2026
9fe9208
Avoid Bootstrap and other options are inherited into the binary run o…
trongnhanuit Sep 24, 2026
9f60b77
Temporarily set the global params for the binary run and then reset t…
trongnhanuit Sep 24, 2026
c6aa59e
don't support using both -gap-asr/-gap-esr and --no-treefile/--no-ou…
trongnhanuit Sep 24, 2026
87c0ef9
check special case: partitions with mixing reversible and non-reversi…
trongnhanuit Sep 24, 2026
878e0ac
minor update to avoid incorrect counting of the number of partitions
trongnhanuit Sep 25, 2026
3a204e2
minor fixes: avoid memory leaks and improve checkpointings
trongnhanuit Sep 25, 2026
9f26177
fix dead identifiers in unused INSTRSET<2 naive kernel (would not com…
trongnhanuit Sep 25, 2026
1daa873
minor updates
trongnhanuit Sep 25, 2026
2b7d582
fix unscaled per-category sum in ASR/ESR state reconstruction under s…
trongnhanuit Sep 25, 2026
e26ab8f
handle cases that runs -gap-asr/esr with -redo or -o
trongnhanuit Sep 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions alignment/alignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,27 @@ void Alignment::checkAbsentStates(string msg) {
}
}

bool Alignment::containSingleStateOnly(const int& state)
{
// the alignment contains only one single state if:
// 1. it contains only one pattern
// 2. that pattern contains only one state
if (size() == 1
&& at(0).num_chars == 1)
{
// if a specific state is specified (not -1), check if that state is the only one present in the alignment
if (state >= 0)
{
ASSERT(state < num_states);
return at(0).freqs[state] == at(0).size();
}
// otherwise, don't need to check that constraint
return true;
}

return false;
}

void Alignment::checkSeqName() {
ostringstream warn_str;
StrVector::iterator it;
Expand Down Expand Up @@ -3986,6 +4007,54 @@ Alignment *Alignment::convertCodonToDNA() const {
return aln;
}

void Alignment::convertToBin(Alignment* res, const string& new_model_name)
{
// metadata copy, matching the convention used by initAlignmentCopy()
// (see convertToCodonOrAA/convertCodonToAA/convertCodonToDNA)
res->seq_names = seq_names;
res->name = name;
res->position_spec = position_spec;
res->model_name = new_model_name; //res->model_name = model_name;
res->aln_file = aln_file;
res->sequence_type = "BIN"; //res->sequence_type = sequence_type;
res->char_partition = char_partition;
res->tree_len = tree_len;
res->seq_type = SEQ_BINARY;
res->num_states = 2;

res->computeUnknownState();

res->clear();
res->pattern_index.clear();

VerboseMode save_mode = verbose_mode;
verbose_mode = min(verbose_mode, VB_MIN); // to avoid printing gappy sites in addPattern
size_t nsite = getNSite();
size_t nseq = getNSeq();
Pattern pat;
pat.resize(nseq);

for (size_t site = 0; site < nsite; ++site)
{
for (size_t seq = 0; seq < nseq; ++seq)
{
StateType state = at(getPatternID(site))[seq];
pat[seq] = state == STATE_UNKNOWN ? 0 : 1;
}
res->addPattern(pat);
}
verbose_mode = save_mode;
res->updateConstPatterns();
res->countConstSites();
}

Alignment* Alignment::convertToBin(const string& new_model_name)
{
Alignment *res = new Alignment;
convertToBin(res, new_model_name);
return res;
}

static const char *convert_site_range(const char *str, int &lower, int &upper,
int &step) {
char *endptr;
Expand Down
21 changes: 21 additions & 0 deletions alignment/alignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,13 @@ class Alignment : public vector<Pattern>, public CharSet, public StateSpace {
*/
virtual void checkAbsentStates(string msg);

/*
check if the alignment contains only one single state
@param[in] state the state to check, if not specified, there is no constraint on the only single state
@return TRUE if the alignment contains only one single state; otherwise return FALSE
*/
bool containSingleStateOnly(const int& state = -1);

/**
check proper and undupplicated sequence names
*/
Expand Down Expand Up @@ -695,6 +702,20 @@ class Alignment : public vector<Pattern>, public CharSet, public StateSpace {
*/
Alignment *convertCodonToDNA() const;

/**
convert an alignment into binary (gap/non-gap) alignment
@param[in] model_name name of model for the new alignment
@return a pointer to a new alignment
*/
virtual Alignment* convertToBin(const string& model_name = "GTR2");

/**
convert an alignment into binary (gap/non-gap) alignment
@param[in] model_name name of model for the new alignment
@param[out] output_aln a pointer to a new alignment
*/
void convertToBin(Alignment* output_aln, const string& model_name);

/**
@param quartet ID of four taxa
@param[out] support number of sites supporting 12|34, 13|24 and 14|23
Expand Down
25 changes: 25 additions & 0 deletions alignment/superalignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1891,3 +1891,28 @@ void SuperAlignment::orderPatternByNumChars(int pat_type) {
// TODO compute pars_lower_bound (lower bound of pars score for remaining patterns)
delete [] pars_lower_bound;
}

SuperAlignment* SuperAlignment::convertToBin(const string& new_model_name)
{
SuperAlignment* new_aln = new SuperAlignment;
// convert the base alignment
Alignment::convertToBin(new_aln, new_model_name);

// convert alignment members one by one
for (vector<Alignment*>::iterator it = partitions.begin(); it != partitions.end(); it++) {
new_aln->partitions.push_back((*it)->convertToBin(new_model_name));
}

// clone SuperAlignment-specific variables
new_aln->max_num_states = 2;
new_aln->taxa_index = taxa_index;
// discard the binary gap/non-gap patterns written by Alignment::convertToBin() above:
// SuperAlignment::buildPattern() (called via init() below) builds its own
// partition-presence pattern instead, and asserts the pattern list starts empty
new_aln->clear();
new_aln->pattern_index.clear();
new_aln->site_pattern.clear();
new_aln->init();

return new_aln;
}
7 changes: 7 additions & 0 deletions alignment/superalignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ class SuperAlignment : public Alignment
/** order pattern by number of character states and return in ptn_order
*/
virtual void orderPatternByNumChars(int pat_type);

/**
convert an alignment into binary (gap/non-gap) alignment
@param[in] model_name name of model for the new alignment
@return a pointer to a new alignment
*/
virtual SuperAlignment* convertToBin(const string& model_name = "GTR2");

/**
actual partition alignments
Expand Down
36 changes: 1 addition & 35 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2259,43 +2259,9 @@ int main(int argc, char *argv[]) {
parseArg(argc, argv, Params::getInstance());

// 2015-12-05
Checkpoint *checkpoint = new Checkpoint;
string filename = (string)Params::getInstance().out_prefix +".ckp.gz";
checkpoint->setFileName(filename);

bool append_log = false;

if (!Params::getInstance().ignore_checkpoint && fileExists(filename)) {
checkpoint->load();
if (checkpoint->hasKey("finished")) {
if (checkpoint->getBool("finished")) {
if (Params::getInstance().force_unfinished) {
if (MPIHelper::getInstance().isMaster())
cout << "NOTE: Continue analysis although a previous run already finished" << endl;
} else {
delete checkpoint;
if (MPIHelper::getInstance().isMaster())
outError("Checkpoint (" + filename + ") indicates that a previous run successfully finished\n" +
"Use `-redo` option if you really want to redo the analysis and overwrite all output files.\n" +
"Use `--redo-tree` option if you want to restore ModelFinder and only redo tree search.\n" +
"Use `--undo` option if you want to continue previous run when changing/adding options."
);
else
exit(EXIT_SUCCESS);
exit(EXIT_FAILURE);
}
} else {
append_log = true;
}
} else {
if (MPIHelper::getInstance().isMaster())
outWarning("Ignore invalid checkpoint file " + filename);
checkpoint->clear();
}
}

if (MPIHelper::getInstance().isWorker())
checkpoint->setFileName("");
Checkpoint *checkpoint = initAndCheckCheckpoint(filename, Params::getInstance(), append_log);

_log_file = Params::getInstance().out_prefix;
_log_file += ".log";
Expand Down
Loading
Loading