@@ -25,6 +25,8 @@ LoadFunctionLibrary("libv3/models/codon/BS_REL.bf");
2525LoadFunctionLibrary("libv3/convenience/math.bf");
2626LoadFunctionLibrary("libv3/tasks/mpi.bf");
2727LoadFunctionLibrary("libv3/models/rate_variation.bf");
28+ LoadFunctionLibrary("libv3/tasks/ancestral.bf");
29+
2830
2931
3032
@@ -179,7 +181,14 @@ namespace relax {
179181 LoadFunctionLibrary ("modules/grid_compute.ibf");
180182}
181183
182- KeywordArgument ("output", "Write the resulting JSON to this file (default is to save to the same path as the alignment file + 'RELAX.json')", relax.codon_data_info [terms.json.json]);
184+
185+ relax.default_output = relax.codon_data_info [terms.json.json];
186+
187+ if (relax.multiple_files) {
188+ relax.default_output = (relax.codon_data_info [relax.file_list[0]])[terms.json.json];
189+ }
190+
191+ KeywordArgument ("output", "Write the resulting JSON to this file (default is to save to the same path as the alignment file + 'RELAX.json')", relax.default_output);
183192
184193relax.codon_data_info [terms.json.json] = io.PromptUserForFilePath ("Save the resulting JSON file to");
185194
@@ -1180,6 +1189,7 @@ function relax.FitMainTestPair (prompt) {
11801189 relax.stashLF = estimators.TakeLFStateSnapshot (relax.alternative_model.fit[terms.likelihood_function]);
11811190
11821191 } else {
1192+ io.ReportProgressMessageMD("RELAX", "alt-2", "> Restoring the original set of parameters (alternative optimization did not yield an improvement).");
11831193 estimators.RestoreLFStateFromSnapshot(relax.alternative_model.fit[terms.likelihood_function], relax.take1_snapshot);
11841194 }
11851195
@@ -1218,6 +1228,16 @@ function relax.FitMainTestPair (prompt) {
12181228 relax.distribution_for_json,
12191229 relax.display_orders[relax.alternative_name]
12201230 );
1231+
1232+ relax.json [^"terms.substitutions"] = {};
1233+
1234+ for (_partition_, _selection_; in; relax.selected_branches) {
1235+ relax.ancestral_info = ancestral.build (relax.alternative_model.fit[terms.likelihood_function],0+_partition_,FALSE);
1236+ (relax.json [^"terms.substitutions"] )[_partition_] = ancestral.ComputeCompressedSubstitutions (relax.ancestral_info);
1237+ DeleteObject (relax.ancestral_info);
1238+ }
1239+
1240+
12211241
12221242 selection.io.json_store_branch_attribute(relax.json, relax.alternative_name, terms.branch_length, relax.display_orders[relax.alternative_name],
12231243 0,
@@ -1231,9 +1251,15 @@ function relax.FitMainTestPair (prompt) {
12311251 relax.tree_ids = estimators.LFObjectGetTrees (relax.alternative_model.fit[terms.likelihood_function]);
12321252
12331253 estimators.RestoreLFStateFromSnapshot (relax.alternative_model.fit[terms.likelihood_function],relax.stashLF);
1254+
12341255
12351256 utility.ToggleEnvVariable ("KEEP_OPTIMAL_ORDER", TRUE);
12361257 relax.er_report.tagged_sites = {};
1258+ relax.json [terms.json.site_logl] = {};
1259+ relax.json [terms.json.evidence_ratios] = {};
1260+ (relax.json [terms.json.site_logl])[terms.json.unconstrained] = selection.ComputeSiteLikelihoods (relax.alternative_model.fit[terms.likelihood_function]);
1261+
1262+
12371263 for (_partition_, _selection_; in; relax.selected_branches) {
12381264
12391265
@@ -1254,10 +1280,8 @@ function relax.FitMainTestPair (prompt) {
12541280 relax.ll_by_branch = {};
12551281 relax.model_by_branch = {};
12561282
1257-
1283+ (relax.json [terms.json.site_logl])[_partition_] = {};
12581284 relax.altLL = relax.alternative_model.fit [terms.fit.log_likelihood];
1259- relax.json [terms.json.site_logl] = {};
1260- (relax.json [terms.json.site_logl])[terms.json.unconstrained] = selection.ComputeSiteLikelihoods (relax.alternative_model.fit[terms.likelihood_function]);
12611285
12621286 for (_b_,_ignore_; in; relax.tested_branches) {
12631287 GetString (relax._current_model, ^_b_, -5);
@@ -1272,22 +1296,21 @@ function relax.FitMainTestPair (prompt) {
12721296 SetParameter ( ^_b_ , MODEL, ^relax._current_model);
12731297 }
12741298
1275-
1276- relax.json [terms.json.evidence_ratios] = {terms.json.by_branch : relax.ll_by_branch};
1299+ (relax.json [terms.json.evidence_ratios])[_partition_] = {terms.json.by_branch : relax.ll_by_branch};
12771300
12781301 for (_b_,_ignore_; in; relax.tested_branches) {
12791302 SetParameter ( ^_b_ , MODEL, ^relax.reference_model_namespace);
12801303 }
12811304 LFCompute (^(relax.alternative_model.fit[terms.likelihood_function]),LF_START_COMPUTE);
12821305 LFCompute (^(relax.alternative_model.fit[terms.likelihood_function]),relax.ll);
12831306 LFCompute (^(relax.alternative_model.fit[terms.likelihood_function]),LF_DONE_COMPUTE);
1284- (relax.json [terms.json.site_logl])[terms.json.constrained] = selection.ComputeSiteLikelihoods (relax.alternative_model.fit[terms.likelihood_function]);
1307+ (( relax.json [terms.json.site_logl])[_partition_ ])[terms.json.constrained] = selection.ComputeSiteLikelihoods (relax.alternative_model.fit[terms.likelihood_function]);
12851308
12861309 for (_b_,_ignore_; in; relax.tested_branches) {
12871310 SetParameter ( ^_b_ , MODEL, ^(relax.model_by_branch[_b_]));
12881311 }
12891312
1290- (relax.json [terms.json.evidence_ratios ])[terms.json.constrained] = selection.EvidenceRatios ( (relax.json [terms.json.site_logl])[terms.json.unconstrained], (relax.json [terms.json.site_logl])[terms.json.constrained]);
1313+ (( relax.json [terms.json.site_logl ])[_partition_])[ terms.json.constrained] = selection.EvidenceRatios ((relax.json [terms.json.site_logl])[terms.json.unconstrained], (( relax.json [terms.json.site_logl])[_partition_ ])[terms.json.constrained]);
12911314
12921315
12931316
0 commit comments