From 48091351fd4f4fc5f5bc2b3f390458d2df9ba8be Mon Sep 17 00:00:00 2001 From: Segei L Kosakovsky Pond Date: Fri, 21 Feb 2020 17:08:58 -0500 Subject: [PATCH 1/3] Resolve issue #1089 --- res/TemplateBatchFiles/libv3/tasks/ancestral.bf | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/res/TemplateBatchFiles/libv3/tasks/ancestral.bf b/res/TemplateBatchFiles/libv3/tasks/ancestral.bf index c6a39f9b7..8ce0bab8d 100644 --- a/res/TemplateBatchFiles/libv3/tasks/ancestral.bf +++ b/res/TemplateBatchFiles/libv3/tasks/ancestral.bf @@ -198,7 +198,12 @@ lfunction ancestral._buildAncestralCacheInternal(_lfID, _lfComponentID, doSample _bacTreeAVLOrder = {}; for (_bacCounter = 1; _bacCounter <= _bacBranchCount; _bacCounter += 1) { - _bacTreeAVLOrder[(_bac_tree_avl[_bacCounter])["Name"] && 1] = _bacCounter; + _bacNodeName = (_bac_tree_avl[_bacCounter])["Name"]; + + if (Abs ((_bac_tree_avl[_bacCounter])["Children"]) == 0) { + _bacNodeName = _bacNodeName && 1; + } + _bacTreeAVLOrder[_bacNodeName] = _bacCounter; } @@ -207,13 +212,10 @@ lfunction ancestral._buildAncestralCacheInternal(_lfID, _lfComponentID, doSample _bacMapTreeNodeToDF[_bacTreeAVLOrder[_bacSequenceNames[_bacCounter] && 1] - 1] = _bacCounter; } - for (_bacCounter = 0; _bacCounter < Columns(_bacAncestralNames); _bacCounter += 1) { - _bacMapTreeNodeToDF[_bacTreeAVLOrder[_bacAncestralNames[_bacCounter] && 1] - 1] = _bacCounter + _bacFilterSequenceCount; + _bacMapTreeNodeToDF[_bacTreeAVLOrder[_bacAncestralNames[_bacCounter]] - 1] = _bacCounter + _bacFilterSequenceCount; } - - /* make some auxiliary variables */ _bacUnitRow = { From ea3be92e0c9fa97b815aa1790d996d8c8fb4d8fc Mon Sep 17 00:00:00 2001 From: Segei L Kosakovsky Pond Date: Tue, 25 Feb 2020 15:56:12 -0500 Subject: [PATCH 2/3] Multiple speed enhancements by reducing the number of heap allocations; also resolves issues #1087, #1074, #1089, #1091 --- CMakeLists.txt | 4 +- .../SelectionAnalyses/MEME.bf | 19 +- .../libv3/tasks/estimators.bf | 7 +- src/core/associative_list.cpp | 16 +- src/core/avllist.cpp | 4 +- src/core/batchlan.cpp | 58 +- src/core/batchlanruntime.cpp | 7 +- src/core/calcnode.cpp | 36 +- src/core/dataset.cpp | 2 +- src/core/formula.cpp | 28 +- src/core/global_things.cpp | 7 +- src/core/include/batchlan.h | 7 +- src/core/include/calcnode.h | 10 +- src/core/include/formula.h | 2 + src/core/include/function_templates.h | 4 +- src/core/include/hy_string_buffer.h | 16 +- src/core/include/hy_strings.h | 29 +- src/core/include/likefunc.h | 13 +- src/core/include/matrix.h | 5 +- src/core/include/parser.h | 16 +- src/core/include/simplelist.h | 4 + src/core/include/variable.h | 4 +- src/core/include/variablecontainer.h | 1 + src/core/likefunc.cpp | 90 ++- src/core/likefunc2.cpp | 11 +- src/core/matrix.cpp | 164 ++--- src/core/nexus.cpp | 2 +- src/core/parser.cpp | 151 ++++- src/core/simplelist.cpp | 8 + src/core/string_buffer.cpp | 36 +- src/core/strings.cpp | 24 +- src/core/tree.cpp | 18 +- src/core/variable.cpp | 102 +++- src/core/variablecontainer.cpp | 39 +- src/mains/unix.cpp | 9 +- tests/hbltests/Results/HIVSweden.out | 576 +++++++++--------- .../Results/HIVSweden.out_MODEL_-1.nex | 55 +- .../Results/HIVSweden.out_MODEL_0.nex | 57 +- .../Results/HIVSweden.out_MODEL_1.nex | 61 +- tests/hbltests/UnitTests/HBLCommands/Gamma.bf | 2 +- tests/hbltests/UnitTests/HBLCommands/IBeta.bf | 2 +- .../hbltests/UnitTests/HBLCommands/LnGamma.bf | 2 +- tests/hbltests/UnitTests/HBLCommands/Sin.bf | 2 +- tests/hbltests/UnitTests/HBLCommands/Sqrt.bf | 2 +- tests/hbltests/UnitTests/HBLCommands/Tan.bf | 2 +- tests/hbltests/UnitTests/HBLCommands/Tree.bf | 2 +- tests/hbltests/UnitTests/HBLCommands/ZCDF.bf | 2 +- tests/hbltests/libv3/MEME-partitioned.wbf | 2 +- 48 files changed, 1079 insertions(+), 641 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 412fa6d61..97883387c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -417,10 +417,10 @@ if(${MPI_FOUND}) HYPHYMPI PROPERTIES if(${OPENMP_FOUND}) - COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS} ${DEFAULT_WARNING_FLAGS} ${MPI_COMPILE_FLAGS} ${OpenMP_CXX_FLAGS} " + COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS} ${DEFAULT_WARNING_FLAGS} ${MPI_COMPILE_FLAGS} ${OpenMP_CXX_FLAGS} -g " LINK_FLAGS "${DEFAULT_LINK_FLAGS} ${MPI_LINK_FLAGS} ${OpenMP_CXX_FLAGS} -g " else(${OPENMP_FOUND}) - COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS} ${DEFAULT_WARNING_FLAGS} ${MPI_COMPILE_FLAGS} " + COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS} ${DEFAULT_WARNING_FLAGS} ${MPI_COMPILE_FLAGS} -g " LINK_FLAGS "${DEFAULT_LINK_FLAGS} ${MPI_LINK_FLAGS}" endif(${OPENMP_FOUND}) ) diff --git a/res/TemplateBatchFiles/SelectionAnalyses/MEME.bf b/res/TemplateBatchFiles/SelectionAnalyses/MEME.bf index 76998c3ba..ca955650d 100644 --- a/res/TemplateBatchFiles/SelectionAnalyses/MEME.bf +++ b/res/TemplateBatchFiles/SelectionAnalyses/MEME.bf @@ -490,14 +490,25 @@ lfunction meme.handle_a_site (lf_fel, lf_bsrel, filter_data, partition_index, pa ^"meme.site_mixture_weight" = 0.75; if (^"meme.site_alpha" > 0) { ^"meme.site_omega_minus" = 1; + ^"meme.site_beta_plus" = ^"meme.site_alpha" * 1.5; } else { ^"meme.site_omega_minus" = ^"meme.site_beta_plus" / Max (^"meme.site_alpha", 1e-6); + ^"meme.site_beta_plus" = 0.1; /* avoid 0/0 by making the denominator non-zero*/ } - - //console.log ("Optimizing MEME for pattern " + pattern_info); - //utility.SetEnvVariable ("LF_NEXUS_EXPORT_EXTRA", "Optimize (res,`lf_bsrel`);"); - //io.SpoolLF (lf_bsrel, "/tmp/meme.debug" + ^"MPI_NODE_ID", "MEME"); + + + /* + console.log (pattern_info); + console.log (^"meme.site_alpha"); + console.log (^"meme.site_omega_minus"); + console.log (^"meme.site_beta_plus"); + + console.log ("Optimizing MEME for pattern " + pattern_info); + utility.SetEnvVariable ("LF_NEXUS_EXPORT_EXTRA", "Optimize (res,`lf_bsrel`);"); + io.SpoolLF (lf_bsrel, "/tmp/meme.debug" + (pattern_info['sites'])[0], "MEME"); + */ + Optimize (results, ^lf_bsrel); //console.log (results[1][0]); diff --git a/res/TemplateBatchFiles/libv3/tasks/estimators.bf b/res/TemplateBatchFiles/libv3/tasks/estimators.bf index 5c967b476..7974f784c 100644 --- a/res/TemplateBatchFiles/libv3/tasks/estimators.bf +++ b/res/TemplateBatchFiles/libv3/tasks/estimators.bf @@ -978,13 +978,14 @@ lfunction estimators.FitCodonModel(codon_data, tree, generator, genetic_code, op //TODO: Where is data_filter being set? if (Type(data_filter) == "String") { - return estimators.FitMGREV({ + return estimators.FitCodonModel({ { codon_data__ } }, { "0": tree }, + generator, genetic_code, option, initial_values) @@ -1033,7 +1034,7 @@ lfunction estimators.FitCodonModel(codon_data, tree, generator, genetic_code, op lf_components[2 * i + 1] = "tree_" + i; model.ApplyModelToTree(Eval("&`lf_components[2*i + 1]`"), tree[i], model_assignment, None); } - + partition_omega = {}; @@ -1047,7 +1048,7 @@ lfunction estimators.FitCodonModel(codon_data, tree, generator, genetic_code, op if (Abs(partition_omega)) { - + /** declare the global ratios for each branch set and add them to the model parameter set diff --git a/src/core/associative_list.cpp b/src/core/associative_list.cpp index 2906bfd63..066d6f0c5 100644 --- a/src/core/associative_list.cpp +++ b/src/core/associative_list.cpp @@ -110,11 +110,19 @@ bool _AssociativeList::ParseStringRepresentation (_String& serialized_form, _For key = *(_String*)key_value_pair(0); } - _Formula value (*(_String*)key_value_pair(1),theP, doErrors?nil :fpc.errMsg()); - HBLObjectRef valueC = compute_keys_values ? value.Compute() : new _MathObject; - + HBLObjectRef valueC = nil; + if (compute_keys_values) { + _Formula value (*(_String*)key_value_pair(1),theP, doErrors?nil :fpc.errMsg()); + valueC = value.Compute(); + if (valueC) { + valueC->AddAReference(); + } + } else { + valueC = new _MathObject; + } + if (valueC) { - MStore (key, valueC, compute_keys_values); + MStore (key, valueC, false); } else { throw (((_String*)key_value_pair(1))->Enquote() & " could not be evaluated"); diff --git a/src/core/avllist.cpp b/src/core/avllist.cpp index bbaf3d5a8..453274083 100644 --- a/src/core/avllist.cpp +++ b/src/core/avllist.cpp @@ -279,8 +279,7 @@ bool _AVLList::IsValidIndex(long index) const { //______________________________________________________________ -long _AVLList::GetByIndex (const long theIndex) -{ +long _AVLList::GetByIndex (const long theIndex) { if (theIndex == 0) { return First(); } @@ -475,7 +474,6 @@ const _List _AVLList::Keys (void) const { cn = Traverser (hist,ls,root); - bool first = true; while (cn>=0) { keys << Retrieve (cn); cn = Traverser (hist,ls); diff --git a/src/core/batchlan.cpp b/src/core/batchlan.cpp index 8dbd4974e..3a0cbad36 100644 --- a/src/core/batchlan.cpp +++ b/src/core/batchlan.cpp @@ -595,7 +595,7 @@ void ClearBFFunctionLists (long start_here) { _SimpleList delete_me (batchLanguageFunctionNames.countitems()-start_here, start_here, 1L); for (unsigned long k = 0UL; k < delete_me.countitems(); k++) { - batchLanguageFunctionNamesIndexed.Delete (batchLanguageFunctionNames.GetItem (delete_me.get (k))); + batchLanguageFunctionNamesIndexed.Delete (batchLanguageFunctionNames.GetItem (delete_me.get (k)), true); } batchLanguageFunctionNames.DeleteList (delete_me); @@ -610,6 +610,7 @@ void ClearBFFunctionLists (long start_here) { batchLanguageFunctionClassification.Clear (); batchLanguageFunctionParameterLists.Clear (); batchLanguageFunctionParameterTypes.Clear (); + batchLanguageFunctionNamesIndexed.Clear (true); } } } @@ -1842,13 +1843,13 @@ bool _ExecutionList::BuildList (_String& s, _SimpleList* bc, bool proce //char const * savePointer = s.get_str(); - _SimpleList triePath; _List local_object_manager; + _StringBuffer currentLine (128UL); try { while (s.nonempty ()) { // repeat while there is stuff left in the buffer - _String currentLine (_ElementaryCommand::FindNextCommand (s)); + _ElementaryCommand::FindNextCommand (s,currentLine); if (currentLine.get_char(0)=='}') { currentLine.Trim(1,kStringEnd); @@ -1858,8 +1859,7 @@ bool _ExecutionList::BuildList (_String& s, _SimpleList* bc, bool proce continue; } - triePath.Clear(false); - long prefixTreeCode = _HY_ValidHBLExpressions.FindKey (currentLine, &triePath, true); + long prefixTreeCode = _HY_ValidHBLExpressions.FindKey (currentLine, nil, true); _List *pieces = nil; _HBLCommandExtras *commandExtraInfo = nil; @@ -2051,7 +2051,9 @@ bool _ExecutionList::BuildList (_String& s, _SimpleList* bc, bool proce // plain ol' formula - parse it as such! else { _String checker (currentLine); - if (_ElementaryCommand::FindNextCommand (checker).length ()==currentLine.length()) { + _StringBuffer next_command; + _ElementaryCommand::FindNextCommand (checker,next_command); + if (next_command.length ()==currentLine.length()) { if (currentLine.length()>1) while (currentLine (-1L) ==';') { currentLine.Trim (0,currentLine.length()-2); @@ -2065,8 +2067,8 @@ bool _ExecutionList::BuildList (_String& s, _SimpleList* bc, bool proce AppendNewInstance (oddCommand); } else { while (currentLine.nonempty()) { - _String part (_ElementaryCommand::FindNextCommand (currentLine)); - BuildList (part,bc,processed); + _ElementaryCommand::FindNextCommand (currentLine,next_command); + BuildList (next_command,bc,processed); } } } @@ -2269,6 +2271,7 @@ BaseRef _ElementaryCommand::toStr (unsigned long) { case HY_HBL_COMMAND_CHOICE_LIST: case HY_HBL_COMMAND_SELECT_TEMPLATE_MODEL: case HY_HBL_COMMAND_KEYWORD_ARGUMENT: + case HY_HBL_COMMAND_GET_INFORMATION: case HY_HBL_COMMAND_SIMULATE_DATA_SET: { (*string_form) << procedure (code); } @@ -3234,16 +3237,16 @@ bool _ElementaryCommand::Execute (_ExecutionList& chain) { SetStatusLine (_String("Constructing Tree ")&treeIdent); long varID = LocateVarByName (treeIdent); - hyFloat rtv = 0.0; // mod 11/19/2003 - checkParameter (replaceTreeStructure, rtv, 0.0); // mod 11/19/2003 + + bool replace_tree_structure = hy_env::EnvVariableTrue(replaceTreeStructure); _SimpleList leftOverVars; // mod 02/03/2003 if (varID>=0) if (FetchVar(varID)->ObjectClass()==TREE) { - if (rtv>0.5) { + if (replace_tree_structure) { DeleteVariable(*FetchVar(varID)->GetName()); // mod 11/19/2003 } else { - DeleteTreeVariable(*FetchVar(varID)->GetName(),leftOverVars,true); // mod 02/03/2003 + DeleteTreeVariable(varID,leftOverVars); // mod 02/03/2003 } } @@ -3260,7 +3263,7 @@ bool _ElementaryCommand::Execute (_ExecutionList& chain) { tr = new _TheTree (treeIdent,(_TreeTopology*)formRes); } else if (formRes->ObjectClass () == TREE) { for (unsigned long i = 0; i < leftOverVars.lLength; i++) { - //printf ("%s\n", LocateVar(leftOverVars.list_data[i])->GetName()->sData); + //rintf ("%s\n", LocateVar(leftOverVars.list_data[i])->GetName()->get_str()); DeleteVariable(leftOverVars.list_data[i], true); } leftOverVars.Clear(); @@ -3674,12 +3677,13 @@ bool _ElementaryCommand::Execute (_ExecutionList& chain) { //____________________________________________________________________________________ -const _String _ElementaryCommand::FindNextCommand (_String& input) { +void _ElementaryCommand::FindNextCommand (_String& input, _StringBuffer &result) { long index = input.length(); + result.Reset(); if (index == 0L) { - return kEmptyString; + return; } bool skipping = false; @@ -3705,7 +3709,6 @@ const _String _ElementaryCommand::FindNextCommand (_String& input) { _SimpleList is_DoWhileLoop; - _StringBuffer result (128L); char last_char = '\0'; // a look back character @@ -3847,7 +3850,8 @@ const _String _ElementaryCommand::FindNextCommand (_String& input) { if (parentheses_depth < 0L) { HandleApplicationError (_String("Too many closing ')' near '") & input.Cut (MAX(0,index-32),index) & "'."); input.Clear(); - return kEmptyString; + result.Reset(); + return ; } last_char = '\0'; continue; @@ -3864,7 +3868,8 @@ const _String _ElementaryCommand::FindNextCommand (_String& input) { if (bracket_depth < 0L) { HandleApplicationError (_String("Too many closing ']' near '") & input.Cut (MAX(0,index-32),index) & "'."); input.Clear(); - return kEmptyString; + result.Reset(); + return ; } last_char = '\0'; continue; @@ -3921,9 +3926,10 @@ const _String _ElementaryCommand::FindNextCommand (_String& input) { & (literal_state == single_quote?" In a '' literal. ":kEmptyString) & (comment_state == slash_star ? " In a /* */ comment ":kEmptyString) & '\n' & input); input.Clear(); - return kEmptyString; + result.Reset(); + return ; } else { - result = kEmptyString; + result.Reset(); } } @@ -3953,9 +3959,6 @@ const _String _ElementaryCommand::FindNextCommand (_String& input) { input.Clear(); } - - - return result; } //____________________________________________________________________________________ @@ -4187,7 +4190,8 @@ bool _ElementaryCommand::BuildIfThenElse (_String&source, _ExecutionList&targ source.Trim (upto,-1); target.AppendNewInstance (new _ElementaryCommand); - _String nextCommand (FindNextCommand(source)); + _StringBuffer nextCommand; + _ElementaryCommand::FindNextCommand(source,nextCommand); success *= target.BuildList (nextCommand, bc, true); } @@ -4414,10 +4418,10 @@ bool _ElementaryCommand::ConstructCategory (_String&source, _ExecutionList&ta if (mark1!=-1) { mark2 = source.FindBackwards(')',mark1+1,-1); if (mark2!=-1) { - source = source.Cut (mark1+1,mark2-1); + _String definition (source,mark1+1,mark2-1); _List args; - ExtractConditions (source,0,args,','); - if (args.lLength>=7UL) { + ExtractConditions (definition,0,args,','); + if (args.countitems()>=7UL) { _ElementaryCommand * cv = new _ElementaryCommand (20); cv->parameters&&(&catID); cv->addAndClean(target,&args,0); diff --git a/src/core/batchlanruntime.cpp b/src/core/batchlanruntime.cpp index 1b15fa6ca..984c8bfaa 100644 --- a/src/core/batchlanruntime.cpp +++ b/src/core/batchlanruntime.cpp @@ -3055,10 +3055,11 @@ bool _ElementaryCommand::HandleGetString (_ExecutionList& current_program) } // next, handle lookup of HBL objects + const _String source_name = AppendContainerName (*GetIthParameter(1), current_program.nameSpacePrefix); long object_type = HY_BL_ANY, object_index; - + BaseRefConst source_object = nil; try { source_object = _GetHBLObjectByTypeMutable (source_name, object_type, &object_index); @@ -3997,7 +3998,9 @@ void _ElementaryCommand::ExecuteCase31 (_ExecutionList& chain) { // and that it is a valid transition matrix isExpressionBased = new _Formula; _FormulaParsingContext fpc (nil, chain.nameSpacePrefix); - matrixExpression = _ElementaryCommand::FindNextCommand (matrixExpression); + _StringBuffer trimmed_expression; + _ElementaryCommand::FindNextCommand (matrixExpression,trimmed_expression); + matrixExpression = trimmed_expression; long parseCode = Parse(isExpressionBased,matrixExpression,fpc, nil); if (parseCode != HY_FORMULA_EXPRESSION || isExpressionBased->ObjectClass()!= MATRIX ) { throw (defErrMsg & " parse code = " & parseCode & " " & (parseCode == HY_FORMULA_EXPRESSION ? (_String(", object type code ") & _String((long) isExpressionBased->ObjectClass())) : kEmptyString )); diff --git a/src/core/calcnode.cpp b/src/core/calcnode.cpp index 49900f607..d9539c188 100644 --- a/src/core/calcnode.cpp +++ b/src/core/calcnode.cpp @@ -60,6 +60,8 @@ _CalcNode::_CalcNode () { theProbs = nil; // default constructor, doesn't do much compExp = nil; matrixCache = nil; + flags = 0; + cBase = 0; } //_______________________________________________________________________________________________ @@ -84,6 +86,7 @@ void _CalcNode::InitializeCN ( _String const& parms, int, _VariableContai if (theIndex < 0) return; cBase = 0; + flags = 0; theProbs = nil; compExp = nil; matrixCache = nil; @@ -166,6 +169,7 @@ long _CalcNode::SetDependance (long var_index) { it needs to be marked as such in this CalcNode */ + PopulateAndSort ([&] (_AVLList& avl) -> void { LocateVar (var_index)->ScanForVariables (avl,true); }).Each ( [&] (long var_index, unsigned long idx) -> void { @@ -499,11 +503,14 @@ bool _CalcNode::RecomputeMatrix (long categID, long totalCategs, _Matrix #ifdef _UBER_VERBOSE_MX_UPDATE_DUMP fprintf (stderr, "[_CalcNode::RecomputeMatrix] Deleting category %ld for node %s at %p\n", categID, GetName()->sData, GetCompExp(categID)); #endif - DeleteObject(GetCompExp(categID, true)); - + if (clear_exponentials()) { + DeleteObject(GetCompExp(categID, true)); + } } else { if (compExp) { - DeleteAndZeroObject(compExp); + if (clear_exponentials ()) { + DeleteAndZeroObject(compExp); + } } } } @@ -580,14 +587,26 @@ bool _CalcNode::RecomputeMatrix (long categID, long totalCategs, _Matrix } //_______________________________________________________________________________________________ -void _CalcNode::SetCompExp (_Matrix* m, long catID) { - compExp = m; +void _CalcNode::SetCompExp (_Matrix* m, long catID, bool do_exponentiation) { + + _Matrix ** store_exp_here; + if (catID >= 0 && matrixCache) { if (remapMyCategories.lLength) { catID = remapMyCategories.list_data[catID*(categoryVariables.lLength+1)]; } - matrixCache[catID] = compExp; + store_exp_here = &(matrixCache[catID]); + } else { + store_exp_here = &compExp; + } + + if (do_exponentiation) { + compExp = m->Exponentiate(1., true, *store_exp_here); + reuse_exponentials (); + } else { + compExp = m; } + *store_exp_here = compExp; } //_______________________________________________________________________________________________ _Matrix* _CalcNode::ComputeModelMatrix (bool) { @@ -619,7 +638,9 @@ _Matrix* _CalcNode::GetCompExp (long catID, bool doClear) const { _Matrix* ret = matrixCache?matrixCache[catID]:compExp; if (doClear && matrixCache) { - matrixCache[catID] = nil; + if (matrixCache[catID] && matrixCache[catID]->CanFreeMe()) { + matrixCache[catID] = nil; + } } return ret; } @@ -634,6 +655,7 @@ BaseRef _CalcNode::makeDynamic(void) const { res->categoryIndexVars.Duplicate (&categoryIndexVars); res->theValue = theValue; res->cBase = cBase; + res->flags = flags; if (cBase) { res->theProbs = new hyFloat [cBase]; CopyArray(res->theProbs, theProbs, cBase); diff --git a/src/core/dataset.cpp b/src/core/dataset.cpp index e5f00ada5..094736426 100644 --- a/src/core/dataset.cpp +++ b/src/core/dataset.cpp @@ -700,7 +700,7 @@ void _DataSet::MatchIndices(_Formula &f, _SimpleList &receptacle, bool isVert, receptacle << i; } } - v->SetValue(new _Constant(0.0), nil); + v->SetValue(new _Constant(0.0), false); } //_________________________________________________________ diff --git a/src/core/formula.cpp b/src/core/formula.cpp index 390c2ebf8..0400f78ce 100644 --- a/src/core/formula.cpp +++ b/src/core/formula.cpp @@ -2580,9 +2580,7 @@ bool _Formula::CheckFForDependence (long varID, bool checkAll) { return true; } if (checkAll) { - _Variable * v = LocateVar(f); - if (!v->IsIndependent()) - if (v->CheckFForDependence(varID)) { + if (LocateVar(f)->CheckFForDependence(varID)) { return true; } } @@ -2592,6 +2590,30 @@ bool _Formula::CheckFForDependence (long varID, bool checkAll) { return false; } +//__________________________________________________________________________________ +bool _Formula::CheckFForDependence (_AVLList const& indices, bool checkAll) { + unsigned long const upper_bound = NumberOperations(); + + for (unsigned long i=0UL; iIsAVariable()) { + long f = this_op->GetAVariable(); + if (f>=0) { + if (indices.FindLong (f)) { + return true; + } + if (checkAll) { + if (LocateVar(f)->CheckFForDependence(indices)) { + return true; + } + } + } + } + } + return false; +} + + //__________________________________________________________________________________ void _Formula::LocalizeFormula (_Formula& ref, _String& parentName, _SimpleList& iv, _SimpleList& iiv, _SimpleList& dv, _SimpleList& idv) { unsigned long const upper_bound = ref.NumberOperations(); diff --git a/src/core/global_things.cpp b/src/core/global_things.cpp index 0862bc1d9..5a76a22fb 100644 --- a/src/core/global_things.cpp +++ b/src/core/global_things.cpp @@ -92,8 +92,8 @@ namespace hy_global { has_terminal_stderr = true, ignore_kw_defaults = false; - FILE *hy_error_log_file, - *hy_message_log_file; + FILE *hy_error_log_file = NULL, + *hy_message_log_file = NULL; hyTreeDefinitionPhase isDefiningATree = kTreeNotBeingDefined; @@ -131,7 +131,7 @@ namespace hy_global { hy_standard_library_directory ("TemplateBatchFiles"), hy_standard_model_directory ("TemplateModels"), hy_error_log_name ("errors.log"), - hy_messages_log_name ("messages.log"); + hy_messages_log_name ; // 20200222 : DISABLE MESSAGES BY DEFAULT _List _hy_application_globals_aux, @@ -392,6 +392,7 @@ namespace hy_global { for (long file_index = 0; file_index < 2; file_index++) { long p = 1L; + if (prefix[file_index]->empty()) continue; #ifndef __HYPHYMPI__ _String file_name (*prefix[file_index]); #if defined __MINGW32__ diff --git a/src/core/include/batchlan.h b/src/core/include/batchlan.h index 5e8fdce98..27859e25e 100644 --- a/src/core/include/batchlan.h +++ b/src/core/include/batchlan.h @@ -47,6 +47,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "dataset.h" #include "trie.h" #include "associative_list.h" +#include "hy_string_buffer.h" #include @@ -289,8 +290,8 @@ class _ElementaryCommand: public _String // string contains the literal for th long get_code (void) const { return code; }; unsigned long parameter_count (void) const { return parameters.countitems();} - static const _String FindNextCommand (_String&); - // finds & returns the next command block in input + static void FindNextCommand (_String&, _StringBuffer&); + // finds & stores the next command from _String into _StringBuffer // chops the input to remove the newly found line static long ExtractConditions (_String const& , long , _List&, char delimeter = ';', bool includeEmptyConditions = true); @@ -424,7 +425,7 @@ class _ElementaryCommand: public _String // string contains the literal for th friend class _ExecutionList; friend void DeleteVariable (long, bool); friend void UpdateChangingFlas (long); - friend void UpdateChangingFlas (_SimpleList&); + friend void UpdateChangingFlas (_SimpleList const&); private: diff --git a/src/core/include/calcnode.h b/src/core/include/calcnode.h index 62bd6c266..663f65b71 100644 --- a/src/core/include/calcnode.h +++ b/src/core/include/calcnode.h @@ -50,7 +50,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define ROOTED_RIGHT 2 #define HY_REPLACE_BAD_BRANCH_LENGTH_WITH_THIS 0.000000001 - +#define fReusePreviouslyAllocatedMatrixExponentials 0x01 //_______________________________________________________________________________________________ @@ -116,7 +116,10 @@ class _CalcNode: public _VariableContainer { return theProbs; } - void SetCompExp (_Matrix*, long = -1); + bool clear_exponentials (void) const { return (flags & fReusePreviouslyAllocatedMatrixExponentials) == 0;} + void reuse_exponentials (void) { flags = flags | fReusePreviouslyAllocatedMatrixExponentials;} + + void SetCompExp (_Matrix*, long = -1, bool do_exponentiation = false); void SetCompMatrix (long); _Matrix* GetCompExp (long catID = -1, bool = false) const; @@ -213,7 +216,8 @@ class _CalcNode: public _VariableContainer { _Matrix ** matrixCache; // only meaningful for category computations long cBase, // dimension of theProbs - lastState; + flags; + /*nodeIndex, referenceNode, slaveNodes;*/ diff --git a/src/core/include/formula.h b/src/core/include/formula.h index 104916021..a44a531c3 100644 --- a/src/core/include/formula.h +++ b/src/core/include/formula.h @@ -146,6 +146,8 @@ class _Formula { */ virtual bool CheckFForDependence (long, bool checkAll = false); + virtual bool CheckFForDependence (_AVLList const & indices, bool checkAll = false); + _List& GetList (void) { return theFormula; } diff --git a/src/core/include/function_templates.h b/src/core/include/function_templates.h index a7dd31f02..b525a4b80 100644 --- a/src/core/include/function_templates.h +++ b/src/core/include/function_templates.h @@ -226,8 +226,8 @@ template void DeleteAndZeroObject(ARG_TYPE &object) { If the object was deleted, set the pointer to NULL */ - DeleteObject(object); - object = NULL; + DeleteObject(object); + object = NULL; } template diff --git a/src/core/include/hy_string_buffer.h b/src/core/include/hy_string_buffer.h index 6ed6c86a5..a7459b479 100644 --- a/src/core/include/hy_string_buffer.h +++ b/src/core/include/hy_string_buffer.h @@ -51,7 +51,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define kAppendAnAssignmentToBufferAssignment 0x04 #define kAppendAnAssignmentToBufferGlobal 0x08 -#define _HY_STRING_BUFFER_PREALLOCATE_SLOTS 256 +#define _HY_STRING_BUFFER_PREALLOCATE_SLOTS 1024 class _StringBuffer : public _String { @@ -175,6 +175,14 @@ class _StringBuffer : public _String { */ virtual void Clear(); + /** + * Empties this object without clearing the memory + * Revision history + - SLKP 20200224 Initial Implementation + */ + + virtual void Reset(); + /** * Standard destructor * Revision history @@ -202,6 +210,9 @@ class _StringBuffer : public _String { void Duplicate (BaseRefConst); + virtual void Trim(long, long); + + /** * Move semantics for buffer assignment * @param rhs A pointer to the _StringBuffer to be moved from @@ -266,7 +277,8 @@ class _StringBuffer : public _String { [CHANGE-NOTE SLKP 20170614 return *this for chaining] */ _StringBuffer& AppendNCopies (_String const& value, unsigned long copies); - + + /** * Append a substring of the source string to this buffer * @param source the string to copy from diff --git a/src/core/include/hy_strings.h b/src/core/include/hy_strings.h index e3e56b473..29d0343a6 100644 --- a/src/core/include/hy_strings.h +++ b/src/core/include/hy_strings.h @@ -672,7 +672,7 @@ class _String : public BaseObj { [CHANGE-NOTE SLKP 20170519 remove the bool argument for memory handling] */ - void Trim(long, long); + virtual void Trim(long, long); /** * Converts string to a particular case @@ -686,6 +686,7 @@ class _String : public BaseObj { ] */ const _String ChangeCase(hy_string_case conversion_type) const; + void ChangeCaseInPlace(hy_string_case conversion_type); /** * Returns a list from a string split by a substr @@ -1453,6 +1454,19 @@ class _String : public BaseObj { _SimpleList const RegExpAllMatches(_String const &pattern, bool case_sensitive, bool handle_errors) const; + /** given coordinates start and end, converts then to valid string indices + if called on an empty string, returns 0 and does not change start and end + if start < 0 it is reset to 0 + if end < 0 or >= string length it is reset to (string length) - 1 + + @param start: start of the range (0-based) + @param end : end of the range + @return : the length of the range + + * Revision history + - SLKP 20170517 porting from v3 branch + */ + long NormalizeRange(long &start, long &end) const; private: @@ -1522,19 +1536,6 @@ class _String : public BaseObj { inline void AllocateAndCopyString(const char *source_string, unsigned long length); - /** given coordinates start and end, converts then to valid string indices - if called on an empty string, returns 0 and does not change start and end - if start < 0 it is reset to 0 - if end < 0 or >= string length it is reset to (string length) - 1 - - @param start: start of the range (0-based) - @param end : end of the range - @return : the length of the range - - * Revision history - - SLKP 20170517 porting from v3 branch - */ - long NormalizeRange(long &start, long &end) const; /** Factored out core of RegExpMatch and RegExpAllMatches * Revision history diff --git a/src/core/include/likefunc.h b/src/core/include/likefunc.h index 1d044329e..4c7c813af 100644 --- a/src/core/include/likefunc.h +++ b/src/core/include/likefunc.h @@ -190,7 +190,8 @@ class _LikelihoodFunction: public BaseObj void UpdateIndependent (long,bool,_SimpleList* = nil,_SimpleList* = nil); void UpdateDependent (long); - + void UpdateDependent (_AVLList const &); + bool PreCompute (void); void PostCompute (void); virtual @@ -767,6 +768,16 @@ void StateCounterResultHandler (_Formula&, _SimpleList*,long&,long&,long,_M _LikelihoodFunction* FindLikeFuncByName (_String&); +template +void DoForEachLikelihoodFunction (ACTION cb) { + for (long i = 0; i < likeFuncNamesList.lLength; i++) { + if (((_String*)likeFuncNamesList.GetItem(i))->nonempty()) { + cb ((_LikelihoodFunction*)likeFuncList.GetItem (i), i); + } + } +} + + extern bool usedCachedResults; extern hyFloat _lfScalerUpwards, diff --git a/src/core/include/matrix.h b/src/core/include/matrix.h index 321d8f000..1f337e5fc 100644 --- a/src/core/include/matrix.h +++ b/src/core/include/matrix.h @@ -180,6 +180,7 @@ class _Matrix: public _MathObject { ~_Matrix (void); //destructor virtual void Clear (void); //deletes all the entries w/o destroying the matrix + virtual void ZeroNumericMatrix (void); //deletes all the entries w/o destroying the matrix void Initialize (bool = false); // zeros all matrix structures @@ -308,7 +309,7 @@ class _Matrix: public _MathObject { // square the matrix by Strassen's Multiplication - _Matrix* Exponentiate (hyFloat scale_to = 1.0, bool check_transition = false); // exponent of a matrix + _Matrix* Exponentiate (hyFloat scale_to = 1.0, bool check_transition = false, _Matrix * write_here = nil); // exponent of a matrix void Transpose (void); // transpose a matrix _Matrix Gauss (void); // Gaussian Triangularization process HBLObjectRef LUDecompose (void) const; @@ -438,7 +439,7 @@ class _Matrix: public _MathObject { _Formula* GetFormula (long, long) const; HBLObjectRef MultByFreqs (long); - HBLObjectRef EvaluateSimple (void); + HBLObjectRef EvaluateSimple (_Matrix* existing_receptacle = nil); HBLObjectRef SortMatrixOnColumn (HBLObjectRef); HBLObjectRef K_Means (HBLObjectRef); HBLObjectRef pFDR (HBLObjectRef); // positive false discovery rate diff --git a/src/core/include/parser.h b/src/core/include/parser.h index 62051bc02..0ed76c7a9 100644 --- a/src/core/include/parser.h +++ b/src/core/include/parser.h @@ -113,9 +113,19 @@ _String* FetchMathObjectNameOfTypeByIndex (const unsigned long objectClass, c void DeleteVariable (_String const&, bool deleteself = true); void DeleteVariable (long, bool deleteself, bool do_checks = true); -void DeleteTreeVariable -(_String&, _SimpleList&,bool); - +void SetVariablesToOwnValues (_AVLList const & indices); + +void DeleteTreeVariable (long, _SimpleList&); + +template +void DoForEachVariable(ACTION do_this) { + for (long i = 0; i < variablePtrs.lLength; i++) { + _Variable * ith_var = (_Variable *)variablePtrs.GetItem (i); + if (ith_var) { + do_this (ith_var, i); + } + } +} void stashParameter (_String const& name, hyFloat newVal, bool); diff --git a/src/core/include/simplelist.h b/src/core/include/simplelist.h index e0b78e7b4..a10a29cd7 100644 --- a/src/core/include/simplelist.h +++ b/src/core/include/simplelist.h @@ -78,6 +78,10 @@ class _SimpleList:public BaseObj { //length constructor _SimpleList(unsigned long); + //length constructor with storage already preallocated somewhere else + //e.g. using `alloca` + _SimpleList(unsigned long, long* preallocated_storage); + // stack copy contructor _SimpleList(_SimpleList const&,long=0,long=-1); diff --git a/src/core/include/variable.h b/src/core/include/variable.h index 9e96376f6..9d0d3ed15 100644 --- a/src/core/include/variable.h +++ b/src/core/include/variable.h @@ -78,7 +78,7 @@ class _Variable : public _Constant { (varValue?varValue->IsIndependent():true); } virtual bool IsConstant (void); - void SetValue (HBLObjectRef, bool = true); // set the value of the variable + void SetValue (HBLObjectRef, bool = true, bool = true); // set the value of the variable void SetValue (hyFloat); // set the value of the variable void SetNumericValue (hyFloat); void CheckAndSet (hyFloat, bool = false); @@ -135,10 +135,12 @@ class _Variable : public _Constant { virtual void ClearConstraints (void); virtual bool CheckFForDependence (long, bool = false); + virtual bool CheckFForDependence (_AVLList const&, bool = false); virtual bool HasBeenInitialized (void) const {return !(varFlags & HY_VARIABLE_NOTSET);} virtual void MarkModified (void) {varFlags = varFlags | HY_VARIABLE_CHANGED;} _String const ContextFreeName (void) const; + _StringBuffer& ContextFreeName (_StringBuffer&) const; _String const ParentObjectName (void) const; _String* GetName (void) const{ diff --git a/src/core/include/variablecontainer.h b/src/core/include/variablecontainer.h index 22a223dc4..91cf6c130 100644 --- a/src/core/include/variablecontainer.h +++ b/src/core/include/variablecontainer.h @@ -96,6 +96,7 @@ class _VariableContainer: public _Variable { bool HasLocals (void); virtual bool RemoveDependance (long); + virtual void RemoveDependance (_AVLList const&); virtual long SetDependance (long); bool SetMDependance (_SimpleList const&); diff --git a/src/core/likefunc.cpp b/src/core/likefunc.cpp index 2d48f1123..fab94c46f 100644 --- a/src/core/likefunc.cpp +++ b/src/core/likefunc.cpp @@ -2574,14 +2574,30 @@ void _LikelihoodFunction::CheckDependentBounds (void) { for (index = 0; indexcurrentValues[j]) { - dependancies.Store(j,index,1.0); - } else if (temp1currentValues[j]) { + dependancies.Store(j,index,1.0); + } else if (temp1 GetIthIndependentBound(index, true)) { + SetIthIndependent (index,temp*0.9999999999999); + for (j=0; j < indexDep.lLength; j++) { + hyFloat temp1 = GetIthDependent(j); + if (temp1>currentValues[j]) { + dependancies.Store(j,index,-1.0); + } else if (temp1 %g\n", j, correlation); + //fprintf (stderr, "## %d -> %g\n", j, correlation); for (i=0; i long { + _SimpleList deleted_indices, + deleted_vars; + + dl->Each ([&l, &deleted_indices, &deleted_vars] (long v, unsigned long i) -> void { + if (l.FindLong (v) >= 0) { + deleted_indices << i; + deleted_vars << v; + } + }); + + if (deleted_vars.nonempty()) { + dl->DeleteList(deleted_indices); + (*il) << deleted_vars; + } + + return deleted_vars.countitems(); + }; + + long deleted_overall = handle_list(list, &indexDep, &indexInd); + + if (deleted_overall) { + for (unsigned long k = 0; k=0) { @@ -7757,6 +7807,20 @@ void _LikelihoodFunction::Setup (bool check_reversibility) alreadyDone = IsModelReversible (treeModels.list_data[m]); alreadyDoneModels.Insert ((BaseRef)treeModels.list_data[m], alreadyDone); } + if (alreadyDone) { + _Variable *q = nil, + *f = nil; + bool mbf; + RetrieveModelComponents (treeModels.list_data[m], q, f, mbf); + if (!base_frequencies) { + base_frequencies = (_Matrix*)f->GetValue(); + } else { + _Matrix * my_freqs = (_Matrix*)f->GetValue(); + if (!my_freqs->Equal (base_frequencies)) { + isReversiblePartition = false; + } + } + } isReversiblePartition = isReversiblePartition && alreadyDone; } ReportWarning (_String ("Partition ") & (long)i & " reversible model flag computed as " & (long)isReversiblePartition); @@ -7867,8 +7931,8 @@ hyFloat _LikelihoodFunction::ComputeBlock (long index, hyFloat* siteRes, long c if (nodeID == 1) { if (matrices->lLength == 2) { - branches->Clear(); - matrices->Clear(); + branches->Clear(false); + matrices->Clear(false); snID = t->DetermineNodesForUpdate (*branches, matrices,catID,*cbid,canClear); } diff --git a/src/core/likefunc2.cpp b/src/core/likefunc2.cpp index 5134cd318..3d65bb0fb 100644 --- a/src/core/likefunc2.cpp +++ b/src/core/likefunc2.cpp @@ -540,6 +540,9 @@ void _LikelihoodFunction::PopulateConditionalProbabilities (long in catVariable->SetIntervalValue(0,true); if (runMode == _hyphyLFConditionProbsWeightedSum || runMode == _hyphyLFConditionMPIIterate || runMode == _hyphyLFConditionProbsClassWeights) { (*catWeigths) << catVariable->GetWeights(); + catVariable->SetIntervalValue(0,false); + } else { + catVariable->SetIntervalValue(0,true); } } @@ -571,21 +574,21 @@ void _LikelihoodFunction::PopulateConditionalProbabilities (long in if (currentRateCombo && remainder == 0) { categoryValues.list_data[catCount] = 0; - (((_CategoryVariable**)(variables->list_data))[catCount])->SetIntervalValue(0); + (((_CategoryVariable**)(variables->list_data))[catCount])->SetIntervalValue(0,false); for (long uptick = catCount-1; uptick >= 0; uptick --) { categoryValues.list_data[uptick]++; if (categoryValues.list_data[uptick] == categoryCounts->list_data[uptick]) { categoryValues.list_data[uptick] = 0; - (((_CategoryVariable**)(variables->list_data))[uptick])->SetIntervalValue(0); + (((_CategoryVariable**)(variables->list_data))[uptick])->SetIntervalValue(0,false); } else { - (((_CategoryVariable**)(variables->list_data))[uptick])->SetIntervalValue(categoryValues.list_data[uptick]); + (((_CategoryVariable**)(variables->list_data))[uptick])->SetIntervalValue(categoryValues.list_data[uptick],false); break; } } } else { if (currentRateCombo) { categoryValues.list_data[catCount]++; - (((_CategoryVariable**)(variables->list_data))[catCount])->SetIntervalValue(remainder); + (((_CategoryVariable**)(variables->list_data))[catCount])->SetIntervalValue(remainder, false); } } } diff --git a/src/core/matrix.cpp b/src/core/matrix.cpp index 3914d6402..5105444c4 100644 --- a/src/core/matrix.cpp +++ b/src/core/matrix.cpp @@ -1476,14 +1476,15 @@ HBLObjectRef _Matrix::MultByFreqs (long freqID) { if (theIndex) { _Matrix* vm = (_Matrix*) value; hyFloat *dp = vm ->theData; - hyFloat *tempDiags = new hyFloat [hDim] {0.0}; + hyFloat *tempDiags = (hyFloat*) alloca (sizeof(hyFloat) * hDim); + InitializeArray(tempDiags, hDim, 0.0); if (freq_matrix) { for (long i=0; itheData[p]); } @@ -1495,7 +1496,7 @@ HBLObjectRef _Matrix::MultByFreqs (long freqID) { long p = theIndex[i]; if (p != -1) { long h = p/vDim; - p %= vDim; + p -= h*vDim; if (h!=p) { tempDiags[h] += dp[i]; } @@ -1507,7 +1508,6 @@ HBLObjectRef _Matrix::MultByFreqs (long freqID) { vm->Store (j,j,-tempDiags[j]); } - delete [] tempDiags; } else { hyFloat * theMatrix = ((_Matrix*)value)->theData; @@ -1567,7 +1567,7 @@ HBLObjectRef _Matrix::Compute (void) { } if (storageType != _SIMPLE_FORMULA_TYPE) { - theValue = Evaluate(false); + theValue = Evaluate(false); } else { theValue = EvaluateSimple (); } @@ -1582,15 +1582,20 @@ HBLObjectRef _Matrix::ComputeNumeric (bool copy) { if (storageType == 0 && ANALYTIC_COMPUTATION_FLAG) { return this; } - - if (theValue) { - DeleteObject (theValue); - } - if (storageType != _SIMPLE_FORMULA_TYPE) { + if (theValue) { + DeleteObject (theValue); + } theValue = Evaluate(false); } else { - theValue = EvaluateSimple (); + if (copy) { + if (theValue) { + DeleteObject (theValue); + } + theValue = EvaluateSimple(); + } else { + theValue = EvaluateSimple((_Matrix*)theValue); + } } return theValue; } @@ -1598,9 +1603,7 @@ HBLObjectRef _Matrix::ComputeNumeric (bool copy) { if (theValue) { DeleteObject (theValue); } - - theValue = (_Matrix*)makeDynamic(); - return theValue; + return (theValue = (_Matrix*)makeDynamic()); } return this; } @@ -2744,9 +2747,19 @@ void _Matrix::FillInList (_List& fillMe, bool convert_numbers) const { } //_____________________________________________________________________________________________ -HBLObjectRef _Matrix::EvaluateSimple (void) { +HBLObjectRef _Matrix::EvaluateSimple (_Matrix* existing_storage) { // evaluate the matrix overwriting the old one - _Matrix * result = new _Matrix (hDim, vDim, bool (theIndex), true); + _Matrix * result; + + if (existing_storage && existing_storage->hDim == hDim && existing_storage->vDim == vDim && existing_storage->is_numeric() && ((bool)existing_storage->theIndex == (bool)theIndex)) { + existing_storage->ZeroNumericMatrix(); + result = existing_storage; + } else { + if (existing_storage) { + DeleteObject (existing_storage); + } + result = new _Matrix (hDim, vDim, bool (theIndex), true); + } if (cmd->varIndex.lLength) { @@ -2767,29 +2780,19 @@ HBLObjectRef _Matrix::EvaluateSimple (void) { for (long f = 0; f < cmd->formulasToEval.lLength; f++) { cmd->formulaValues [f] = ((_Formula*)cmd->formulasToEval.list_data[f])->ComputeSimple(cmd->theStack, cmd->varValues); - /*if (terminate_execution) - { - ((_Formula*)cmd->formulasToEval.list_data[f])->ConvertFromSimple(cmd->varIndex); - _String * s = (_String*)((_Formula*)cmd->formulasToEval.list_data[f])->toStr(); - WarnError (*s); - DeleteObject (s); - return result; - }*/ } long * fidx = cmd->formulaRefs; if (theIndex) { - result->lDim = lDim; + if (result->lDim != lDim) { + result->lDim = lDim; + result->theIndex = (long*)MemReallocate((hyPointer)result->theIndex,sizeof(long)*lDim); + result->theData = (hyFloat*)MemReallocate ((hyPointer)result->theData,sizeof(hyFloat)*lDim); + } result->bufferPerRow = bufferPerRow; result->overflowBuffer = overflowBuffer; result->allocationBlock = allocationBlock; - result->theIndex = (long*)MemReallocate((hyPointer)result->theIndex,sizeof(long)*lDim); - result->theData = (hyFloat*)MemReallocate ((hyPointer)result->theData,sizeof(hyFloat)*lDim); - - /*memcpy (result->theIndex,theIndex,sizeof(long)*lDim);*/ - - for (long i = 0; itheIndex[i] = idx; } - /*for (long i = 0; iComputeSimple(cmd->theStack, cmd->varValues); - result.theData[i] = formValue; - } - } */ if (hDim==vDim) { - hyFloat* diagStorage = new hyFloat [hDim]; - { - for (long i = 0; itheIndex[i]; if (k!=-1) { - diagStorage[k/hDim] -= result->theData[i]; + diagStorage[k/hDim] += result->theData[i]; } } - { - for (long i = 0; iComputeSimple(cmd->theStack,cmd->varValues); - result.theData[i] = formValue; - //break; - } - } */ for (long i = 0; i= 0) { @@ -2850,21 +2828,23 @@ HBLObjectRef _Matrix::EvaluateSimple (void) { } if (hDim==vDim) - for (long i = 0; iIsEmpty()) //{ - hyFloat st = 0; - long k = i/vDim,j; - for (j = k*vDim; jtheData[j]; + + hyFloat st = 0.; + long j; + + for (j = r*vDim; jtheData[j]; } - for (j = k*vDim+k+1; j<(k+1)*vDim; j++) { - st-=result->theData[j]; + for (j = r*vDim+r+1; j<(r+1)*vDim; j++) { + st += result->theData[j]; } - result->theData[i] = st; + result->theData[i] = -st; //} } } @@ -2910,8 +2890,7 @@ void _Matrix::ClearObjects (void) //_____________________________________________________________________________________________ -void _Matrix::Clear (void) -{ +void _Matrix::Clear (void) { DeleteObject (theValue); if (storageType == 2) { // has formulas in it - must delete ClearFormulae(); @@ -2933,6 +2912,17 @@ void _Matrix::Clear (void) //_____________________________________________________________________________________________ +void _Matrix::ZeroNumericMatrix (void) { + if (is_numeric()) { + InitializeArray (theData, lDim, 0.0); + if (!is_dense()) { + InitializeArray (theIndex, lDim, -1L); + } + } +} + +//_____________________________________________________________________________________________ + void _Matrix::Resize (long newH) { if (newH >= 0 && newH != hDim && storageType == 1 && theIndex == nil) { @@ -4333,10 +4323,9 @@ void _Matrix::Transpose (void) void _Matrix::CompressSparseMatrix (bool transpose, hyFloat * stash) { if (theIndex) { - _SimpleList sortedIndex ((unsigned long)lDim) - ,sortedIndex3 ((unsigned long)lDim) - ,sortedIndex2 - ; + _SimpleList sortedIndex ((unsigned long)lDim, (long*)alloca (lDim * sizeof (long))), + sortedIndex3 ((unsigned long)lDim, (long*)alloca (lDim * sizeof (long))), + sortedIndex2; long blockChunk = 32, @@ -4380,7 +4369,7 @@ void _Matrix::CompressSparseMatrix (bool transpose, hyFloat * stash) //_____________________________________________________________________________________________ -_Matrix* _Matrix::Exponentiate (hyFloat scale_to, bool check_transition) { +_Matrix* _Matrix::Exponentiate (hyFloat scale_to, bool check_transition, _Matrix * existing_storage) { // find the maximal elements of the matrix @@ -4421,9 +4410,16 @@ _Matrix* _Matrix::Exponentiate (hyFloat scale_to, bool check_transition) { } else { max = 1.; } + + _Matrix *result; - _Matrix *result = new _Matrix(hDim, vDim , is_polynomial(), !is_polynomial()), - temp (*this); + if (!is_polynomial() && existing_storage && existing_storage->hDim == hDim && existing_storage->vDim == vDim && existing_storage->is_numeric() && existing_storage->is_dense()) { + result = existing_storage; + InitializeArray(result->theData, result->lDim, 0.0); + } else { + result = new _Matrix(hDim, vDim , is_polynomial(), !is_polynomial()); + } + // put ones on the diagonal @@ -4447,6 +4443,8 @@ _Matrix* _Matrix::Exponentiate (hyFloat scale_to, bool check_transition) { i = 2; if (precisionArg || is_polynomial()) { + _Matrix temp (*this); + if (!is_polynomial()) { for (; i<=precisionArg; i++) { temp *= (*this); @@ -4474,7 +4472,15 @@ _Matrix* _Matrix::Exponentiate (hyFloat scale_to, bool check_transition) { i=2; + if (is_dense()) { // avoid matrix allocation + _Matrix temp ; + temp.hDim = hDim; + temp.vDim = vDim; + temp.lDim = lDim; + temp.theData = (hyFloat*)alloca(sizeof (hyFloat) * hDim*vDim); + memcpy (temp.theData, theData, sizeof (hyFloat) * hDim*vDim); + _Matrix tempS; tempS.hDim = hDim; tempS.vDim = vDim; @@ -4499,8 +4505,10 @@ _Matrix* _Matrix::Exponentiate (hyFloat scale_to, bool check_transition) { memcpy (temp.theData, tempS.theData, lDim * sizeof (hyFloat)); } tempS.theData = nil; + temp.theData = nil; } else { + _Matrix temp (*this); _Matrix tempS (hDim, vDim, false, temp.storageType); do { temp.MultbyS (*this,theIndex!=nil, &tempS, stash); diff --git a/src/core/nexus.cpp b/src/core/nexus.cpp index ead89ba9b..08eb630e9 100644 --- a/src/core/nexus.cpp +++ b/src/core/nexus.cpp @@ -216,7 +216,7 @@ bool ReadNextNexusStatement (FileState& fState, FILE* f, _String& CurrentLine, l } // TODO 20170821: SLKP, this needs to be case sensitive - blank = blank.ChangeCase(kStringUpperCase); + blank.ChangeCaseInPlace(kStringUpperCase); if (newPos=0) { - _String *name = (_String*)variableNames.Retrieve (dv); - _String myName = *name&"."; - long vidx = variableNames.GetXtra (dv); +void DeleteTreeVariable (long tree_variable_index, _SimpleList & parms) { + if (tree_variable_index>=0) { + + /* + 1. Indentify all the variables that are in the tree.* and tree.*.* domain + 2. Scan all the variables that are dependend on the list here and "batch" unconstrain them + 3. Delete the tree and tree nodes; store the remainign variables in parms + */ + + + _String const *tree_name = (_String const*)variableNames.Retrieve (tree_variable_index), + kDot = ".", + tree_prefix = *tree_name&kDot; + + _SimpleList traversal_stack, + indices_to_delete, + all_subdomain_indices; + + _AVLList indices_to_delete_avl (&indices_to_delete), + all_subdomain_indices_avl (&all_subdomain_indices), + will_keep_these (&parms); + + + long tree_array_index = tree_variable_index; + variableNames.Find (tree_name,traversal_stack); + + while (long next_var = variableNames.Next (tree_array_index,traversal_stack)) { + if (next_var < 0) { + break; + } + _String const * next_var_name = (_String const *)variableNames.Retrieve(next_var); + if (next_var_name->BeginsWith(tree_prefix)) { + all_subdomain_indices_avl.InsertNumber(next_var); + + _Variable * secondary_variable = FetchVar (next_var); + + if (next_var_name->FindBackwards(kDot, tree_prefix.length() + 1, kStringEnd) != kNotFound && !secondary_variable->IsContainer()) { + // 20200220: deleting all containers here; only "plain" variables will be kept + // subnode level + will_keep_these.InsertNumber(next_var); + } else { + indices_to_delete_avl.InsertNumber (next_var); + } + } else { + break; + } + tree_array_index = next_var; + } + + //if ((nvid = variableNames.Next (dv,recCache))>=0) + + all_subdomain_indices_avl.ReorderList(); + indices_to_delete_avl.ReorderList(); + will_keep_these.ReorderList(); + + _SimpleList _touched_dependent_variables, + touched_containers; + + _AVLList touched_dependent_variables (&_touched_dependent_variables); + + DoForEachVariable([&touched_dependent_variables, &indices_to_delete_avl, &all_subdomain_indices_avl] (_Variable* v, long idx) -> void { + // only care about variables that are not going in the subdomain + if (all_subdomain_indices_avl.FindLong(idx) < 0) { + if (v->IsContainer()) { + //_VariableContainer * vc = (_VariableContainer*)vc; + /* TODO, it is theoretically possible that a node / tree variable is a template variable + in another container, but there are no use cases of this; + need to check, but later + */ + } else { + if (v->CheckFForDependence(indices_to_delete_avl)) { + //printf ("Touched dependent variable %s\n" , v->GetName()->get_str()); + touched_dependent_variables.InsertNumber(v->get_index()); + } + } + } + }); + - UpdateChangingFlas (vidx); + + //SetVariableToOwn + + UpdateChangingFlas(all_subdomain_indices); + // reset compiled formulas that may contain variable indices being deleted + + SetVariablesToOwnValues (will_keep_these); + if (touched_dependent_variables.countitems()) { + SetVariablesToOwnValues (touched_dependent_variables); + } + + + indices_to_delete.Each ([] (long var_idx, unsigned long) -> void { + _Variable * delvar = LocateVar (var_idx); + //printf ("Deleting variable %s\n" , delvar->GetName()->get_str()); + if (delvar->ObjectClass() != TREE) { + variableNames.Delete (delvar->GetName(),true); + (*((_SimpleList*)&variablePtrs))[delvar->get_index()]=0; + freeSlots<get_index(); + DeleteObject (delvar); + } else { + ((_VariableContainer*)delvar)->Clear(); + } + }); + + + return; + + /*_String const *tree_name = (_String const*)variableNames.Retrieve (dv), + tree_prefix = *tree_name&"."; + + long variable_index = variableNames.GetXtra (dv); + + UpdateChangingFlas (variable_index); _SimpleList recCache; - variableNames.Find (name,recCache); + variableNames.Find (tree_name,recCache); _String nextVarID; long nvid; if ((nvid = variableNames.Next (dv,recCache))>=0) { @@ -464,6 +565,7 @@ void DeleteTreeVariable (long dv, _SimpleList & parms, bool doDeps) } + { _SimpleList tcache; long iv, @@ -472,11 +574,11 @@ void DeleteTreeVariable (long dv, _SimpleList & parms, bool doDeps) for (; k>=0; k = variableNames.Traverser (tcache, iv)) { _Variable * thisVar = FetchVar(k); - if (thisVar->CheckFForDependence (vidx,false)) { + if (thisVar->CheckFForDependence (variable_index,false)) { HBLObjectRef curValue = thisVar->Compute(); curValue->AddAReference(); - thisVar->SetValue (curValue); - DeleteObject (curValue); + thisVar->SetValue (curValue, false); + //DeleteObject (curValue); } } } @@ -484,8 +586,8 @@ void DeleteTreeVariable (long dv, _SimpleList & parms, bool doDeps) _Variable* delvar = (FetchVar(dv)); if (delvar->ObjectClass() != TREE) { variableNames.Delete (variableNames.Retrieve(dv),true); - (*((_SimpleList*)&variablePtrs))[vidx]=0; - freeSlots<Clear(); @@ -496,8 +598,8 @@ void DeleteTreeVariable (long dv, _SimpleList & parms, bool doDeps) long nextVar = variableNames.Find (&nextVarID,recCache); for (; nextVar>=0; nextVar = variableNames.Next (nextVar, recCache)) { _String dependent = *(_String*)variableNames.Retrieve (nextVar); - if (dependent.BeginsWith(myName)) { - if (dependent.Find ('.', myName.length()+1, -1)>=0) { + if (dependent.BeginsWith(tree_prefix)) { + if (dependent.Find ('.', tree_prefix.length()+1, -1)>=0) { _Variable * checkDep = FetchVar (nextVar); if (!checkDep->IsIndependent()) { HBLObjectRef curValue = checkDep->Compute(); @@ -517,9 +619,9 @@ void DeleteTreeVariable (long dv, _SimpleList & parms, bool doDeps) for (unsigned long k=0; k 0L) { + for (long i = start; i <= end; i++) { + (*this) << source.char_at(i); + } + } return (*this); } +//============================================================= + +void _StringBuffer::Trim(long start, long end) { + + long resulting_length = NormalizeRange(start, end); + + if (resulting_length > 0L) { + if (start > 0L) { + memmove(s_data, s_data + start, resulting_length); + } + if (s_length != resulting_length) { + s_length = resulting_length; + s_data[resulting_length] = '\0'; + } + } else { + s_length = 0UL; + s_data[0] = '\0'; + } +} //============================================================= diff --git a/src/core/strings.cpp b/src/core/strings.cpp index 9d86c2405..63e6d40cc 100644 --- a/src/core/strings.cpp +++ b/src/core/strings.cpp @@ -817,6 +817,18 @@ const _String _String::ChangeCase (hy_string_case conversion_type) const { //============================================================= +void _String::ChangeCaseInPlace (hy_string_case conversion_type) { + + auto conversion_function = conversion_type == kStringUpperCase ? toupper : tolower; + + for (unsigned long i = 0UL; iget_str().ProcessVariableReferenceCases (referenced_object) == kStringDirectReference) { if (!is_global_ref && context) { - referenced_object = *context & '.' & referenced_object; + referenced_object = (_StringBuffer (context->length() + 1UL + referenced_object.length()) << *context << '.' << referenced_object); } return is_global_ref?kStringGlobalDeference:kStringLocalDeference; } @@ -1330,7 +1345,8 @@ hy_reference_type _String::ProcessVariableReferenceCases (_String& referenced_ob } if (try_as_expression.ProcessVariableReferenceCases (referenced_object) == kStringDirectReference) { if (!is_global_ref && context) { - referenced_object = *context & '.' & try_as_expression; + //referenced_object = *context & '.' & try_as_expression; + referenced_object = (_StringBuffer (context->length() + 1UL + try_as_expression.length()) << *context << '.' << try_as_expression); } return is_global_ref?kStringGlobalDeference:kStringLocalDeference; diff --git a/src/core/tree.cpp b/src/core/tree.cpp index f7b3f1322..5722d3ff1 100644 --- a/src/core/tree.cpp +++ b/src/core/tree.cpp @@ -603,7 +603,7 @@ _String _TheTree::FinalizeNode (node* nodie, long number , _String node } if (node_parameters.nonempty()) { - ReportWarning ((_String("Model ")&node_parameters.Enquote() &_String(" assigned to ")& nodeName.Enquote())); + ReportWarning (_StringBuffer (128UL) << "Model " << '"' << node_parameters << '"' << " assigned to \"" << nodeName << '"'); } else { ReportWarning (_String("No nodel was assigned to ")& nodeName.Enquote()); } @@ -659,7 +659,7 @@ _String _TheTree::FinalizeNode (node* nodie, long number , _String node ReportWarning (_String("Branch parameter of ") & nodeName&" set to " & nodeValue); } } else { - ReportWarning (nodeName&" has "& _String((long)(cNt.iVariables?cNt.iVariables->lLength/2:0)) & " parameters - branch length not assigned"); + ReportWarning (_StringBuffer (128) << nodeName << " has " << _String ((long)(cNt.iVariables?cNt.iVariables->lLength/2:0)) << " parameters - branch length not assigned"); } } @@ -2190,7 +2190,7 @@ void _TheTree::CleanUpMatrices (void) { iterator->ConvertFromSimpleMatrix(); for (long i=0; imatrixCache[i]); + DeleteAndZeroObject(iterator->matrixCache[i]); } delete [] iterator->matrixCache; @@ -2749,7 +2749,7 @@ void _TheTree::AddNodeNamesToDS (_DataSet* ds, bool doTips, bool doInternals void _TheTree::ExponentiateMatrices (_List& expNodes, long tc, long catID) { _List matrixQueue, nodesToDo; - _SimpleList isExplicitForm; + _SimpleList isExplicitForm ((unsigned long)expNodes.countitems()); bool hasExpForm = false; for (unsigned long nodeID = 0; nodeID < expNodes.lLength; nodeID++) { @@ -2791,7 +2791,7 @@ void _TheTree::ExponentiateMatrices (_List& expNodes, long tc, long catI #endif for (matrixID = 0; matrixID < matrixQueue.lLength; matrixID++) { if (isExplicitForm.list_data[matrixID] == 0 || !hasExpForm) { // normal matrix to exponentiate - ((_CalcNode*) nodesToDo(matrixID))->SetCompExp (((_Matrix*)matrixQueue(matrixID))->Exponentiate(1., true), catID); + ((_CalcNode*) nodesToDo(matrixID))->SetCompExp ((_Matrix*)matrixQueue(matrixID), catID, true); } else { (*computedExponentials) [matrixID] = ((_Matrix*)matrixQueue(matrixID))->Exponentiate(1., true); } @@ -2982,7 +2982,9 @@ hyFloat _TheTree::ComputeTreeBlockByBranch ( _SimpleList { // process the leaves first - _SimpleList taggedInternals (flatNodes.lLength, 0, 0); + long * storage = (long*)alloca (sizeof (long) * flatNodes.lLength); + InitializeArray(storage, flatNodes.lLength, 0L); + _SimpleList taggedInternals (flatNodes.lLength, storage); unsigned long const alphabetDimension = theFilter->GetDimension(), siteCount = theFilter->GetPatternCount(), alphabetDimensionmod4 = (alphabetDimension >> 2) << 2; @@ -3578,8 +3580,8 @@ void _TheTree::ComputeBranchCache ( //printf ("ComputeBranchCache\n"); _SimpleList taggedNodes (flatLeaves.lLength + flatNodes.lLength, 0, 0), - nodesToProcess, - rootPath; + nodesToProcess, + rootPath; long myParent = brID -flatLeaves.lLength; diff --git a/src/core/variable.cpp b/src/core/variable.cpp index 9cf2f8c18..dd9e289ce 100644 --- a/src/core/variable.cpp +++ b/src/core/variable.cpp @@ -138,12 +138,18 @@ unsigned long _Variable::ObjectClass (void) const { } //__________________________________________________________________________________ -bool _Variable::CheckFForDependence (long idx, bool opt) -{ +bool _Variable::CheckFForDependence (long idx, bool opt) { if (varFormula) { return varFormula->CheckFForDependence (idx, opt); } + return false; +} +//__________________________________________________________________________________ +bool _Variable::CheckFForDependence (_AVLList const& indices, bool opt) { + if (varFormula) { + return varFormula->CheckFForDependence (indices, opt); + } return false; } @@ -336,11 +342,51 @@ void _Variable::SetValue (hyFloat new_value) { } //__________________________________________________________________________________ -void _Variable::SetValue (HBLObjectRef theP, bool dup) // set the value of the var -{ +void SetVariablesToOwnValues (_AVLList const & indices) { + /* compute current variable values*/ + _SimpleList hist; + long ls = -1L, cn; + + cn = indices.Traverser (hist,ls,indices.GetRoot()); + + _SimpleList _index2value; + _AVLList index2value (&_index2value); + + while (cn>=0) { + _Variable* this_var = LocateVar (indices.RetrieveLong(cn)); + if (this_var->IsIndependent()) { + // do nothing + } else { + HBLObjectRef curValue = this_var->Compute(); + curValue->AddAReference(); + index2value.InsertNumber(this_var->get_index()); + this_var->SetValue(curValue, false, false); + //printf ("SetVariablesToOwnValues : Set own value for %s\n", this_var->GetName()->get_str()); + } + cn = indices.Traverser (hist,ls); + } + + // now clean up variable containers that may have had these as dependent template variables + + DoForEachVariable([&index2value] (_Variable* v, long v_idx) -> void { + if (v->IsContainer()) { + ((_VariableContainer*)v)->RemoveDependance (index2value); + } + }); + + DoForEachLikelihoodFunction ([&index2value] (_LikelihoodFunction *lf, long idx) -> void { + lf->UpdateDependent(index2value); + }); + + // update likelihood functions that may have had these as dependent variables + +} + +//__________________________________________________________________________________ +void _Variable::SetValue (HBLObjectRef theP, bool dup, bool do_checks) { // set the value of the var //hasBeenChanged = true; if (varFlags & HY_VARIABLE_COMPUTING) { - HandleApplicationError (_String ("A recursive dependency error in _Variable::SetValue; this is an HBL implementation bug; offending variable is '") & *GetName() & "'"); + HandleApplicationError (_String ("A recursive dependency error in _Variable::SetValue; this is an HBL implementation bug; offending variable is ") & GetName()->Enquote()); return ; } @@ -349,44 +395,33 @@ void _Variable::SetValue (HBLObjectRef theP, bool dup) // set the value of the long valueClass = theP->ObjectClass(); - /*bool doPrint = (*theName) == _String("_pattern_info_"); - if (doPrint) { - printf ("Setting %s to %s\n", theName->get_str(), _String((_String*)theP->toStr()).get_str()); - }*/ - if (valueClass==NUMBER) { - - if (varFormula) { + if (varFormula && do_checks) { // also update the fact that this variable is no longer dependent in all declared // variable containers which contain references to this variable - for (unsigned long i = 0UL; i=0) { - continue; - } - _Variable* theV = (_Variable*)variablePtrs(i); - if (theV->IsContainer()) { - _VariableContainer* theVC = (_VariableContainer*)theV; - if (!theVC->RemoveDependance (theIndex)) { - ReportWarning ((_String("Can't make variable ")&*GetName()&" independent in the context of "&*theVC->GetName()&" because its template variable is not independent.")); - continue; + DoForEachVariable([this] (_Variable* v, long v_idx) -> void { + if (v->IsContainer()) { + if (!((_VariableContainer*)v)->RemoveDependance (this->theIndex)) { + ReportWarning ((_String("Can't make variable ")&GetName()->Enquote()&" independent in the context of "&*v->GetName()&" because its template variable is not independent.")); } } - } + }); + for (unsigned long i = 0UL; inonempty()) { ((_LikelihoodFunction*)likeFuncList(i))->UpdateDependent(theIndex); } //_Formula::Clear(); - delete varFormula; - varFormula = nil; } + + delete varFormula; + varFormula = nil; if (varValue) { - DeleteObject (varValue); - varValue=nil; + DeleteAndZeroObject (varValue); } theValue = theP->Value(); @@ -729,6 +764,19 @@ _String const _Variable::ContextFreeName(void) const { return *theName; } +//__________________________________________________________________________________ +_StringBuffer& _Variable::ContextFreeName(_StringBuffer & storage) const { + static const _String kDot ("."); + + long location = theName->FindBackwards (kDot, 0L, kStringEnd); + if (location > 0L) { + return storage.AppendSubstring(*theName,location+1L,kStringEnd); + } else { + storage << *theName; + } + return storage; +} + //__________________________________________________________________________________ _String const _Variable::ParentObjectName(void) const { static const _String kDot ("."); diff --git a/src/core/variablecontainer.cpp b/src/core/variablecontainer.cpp index ac2a04466..5b4b15df9 100644 --- a/src/core/variablecontainer.cpp +++ b/src/core/variablecontainer.cpp @@ -253,7 +253,6 @@ _Matrix* _VariableContainer::GetFreqMatrix (void) const { void _VariableContainer::ScanModelBasedVariables (_String const & fullName, _AVLListXL* varCache) { if (theModel!= HY_NO_MODEL) { // build the matrix variables _SimpleList mVars; - _String varName; { @@ -286,8 +285,11 @@ void _VariableContainer::ScanModelBasedVariables (_String const & fullName, _ if (aVar->IsGlobal()) { PushGlobalVariable(aVar->get_index()); } else { - varName = fullName&'.'&aVar->ContextFreeName(); - _Variable * spawnedVar = CheckReceptacle(&varName, kEmptyString, false, false); + _StringBuffer var_name (fullName.length() + 1UL + aVar->GetName()->length()); + var_name << fullName << '.'; + aVar->ContextFreeName(var_name); + //_String var_name = fullName&'.'&aVar->ContextFreeName(); + _Variable * spawnedVar = CheckReceptacle(&var_name, kEmptyString, false, false); spawnedVar->SetBounds (aVar->GetLowerBound(), aVar->GetUpperBound()); if (aVar->IsIndependent()) { @@ -348,7 +350,7 @@ void _VariableContainer::ScanAndAttachVariables (void) { long f = variableNames.Find (theName,travcache); if (f >= 0L) { - _String theNameAndADot = *theName & '.'; + _StringBuffer theNameAndADot = (_StringBuffer (theName->length() + 1L) << *theName << '.'); for (f = variableNames.Next (f, travcache); f>=0; f = variableNames.Next (f, travcache)) { var = FetchVar (f); @@ -571,7 +573,7 @@ bool _VariableContainer::RemoveDependance (long varIndex) { if (dVariables) { long array_index = dVariables->FindStepping(varIndex,2L); - if (array_index >= 0) { + if (array_index >= 0L) { InsertVariableInSortedList(iVariables, *LocateVar (dVariables->list_data[array_index])->GetName(), @@ -583,6 +585,33 @@ bool _VariableContainer::RemoveDependance (long varIndex) { return true; } +//__________________________________________________________________________________ +void _VariableContainer::RemoveDependance (_AVLList const & list) { + if (dVariables) { + + _SimpleList removed; + + ForEachLocalVariable(dVariables, [&list, &removed, this] (long self, long template_var, unsigned long array_idx) -> void { + if (list.FindLong(self) >= 0L) { + InsertVariableInSortedList(this->iVariables, + *LocateVar (self)->GetName(), + self, + template_var); + removed << array_idx; + + } + }); + + removed.Sort(); + removed.Flip(); + + removed.Each([this] (long idx, unsigned long) -> void { + this->RemoveLocalVariable (this->dVariables, idx); + }); + + } +} + //__________________________________________________________________________________ long _VariableContainer::CheckAndAddUserExpression (_String& parameter_name, long start_with) { _String localized_name = WrapInNamespace (parameter_name, theName), diff --git a/src/mains/unix.cpp b/src/mains/unix.cpp index 4acc3e391..18baac5a0 100644 --- a/src/mains/unix.cpp +++ b/src/mains/unix.cpp @@ -606,7 +606,14 @@ void ProcessConfigStr (_String const & conf) { logInputMode = true; break; } - default: { + + case 'm': + case 'M': { + hy_messages_log_name = "messages.log"; + break; + } + + default: { ReportWarning (_String ("Option" ) & _String (c).Enquote() & " is not valid command line option and will be ignored"); } } diff --git a/tests/hbltests/Results/HIVSweden.out b/tests/hbltests/Results/HIVSweden.out index 558bbcba3..aa5076ebb 100644 --- a/tests/hbltests/Results/HIVSweden.out +++ b/tests/hbltests/Results/HIVSweden.out @@ -4,26 +4,26 @@ >Done in 2 seconds --1137.68878740196 +-1137.68956410902 ----------------------------------- -dN/dS = 0.9081653126969932 +dN/dS = 0.911942160103597 *** RUNNING MODEL 1 (Neutral) *** ###################################### ->Done in 2 seconds +>Done in 1 seconds --1114.64193668141 +-1114.64193743151 ------------------------------------------------ -dN/dS = 0.5549821538271208 (sample variance = 0.2120623763397643) +dN/dS = 0.5547174896006717 (sample variance = 0.2119990101724308) -Rate[1]= 0.07845660 (weight=0.4829049) -Rate[2]= 1.00000000 (weight=0.5170951) +Rate[1]= 0.07861747 (weight=0.4832765) +Rate[2]= 1.00000000 (weight=0.5167235) ------------------------------------------------ @@ -37,215 +37,215 @@ Import the following part into a data processing program for further analysis -Rate/Site Rate=0.07845659836123289 Rate=1 -1 0.0004134313246124715 0.9995865686753876 -2 0.9494986195186943 0.05050138048130562 -3 0.8526860373505952 0.1473139626494049 -4 0.9773065431018468 0.02269345689815316 -5 0.7088337785303482 0.2911662214696517 -6 0.9706214135555877 0.02937858644441215 -7 0.841083663701518 0.158916336298482 -8 0.644722439731872 0.355277560268128 -9 0.009002701160599442 0.9909972988394006 -10 0.2512688017144757 0.7487311982855243 -11 0.9362669941752089 0.06373300582479108 -12 0.803985398463233 0.196014601536767 -13 0.9592960641257104 0.04070393587428957 -14 0.6830555758391128 0.3169444241608872 -15 0.9686881643150316 0.03131183568496831 -16 0.9686881643150316 0.03131183568496831 -17 0.9494986195186943 0.05050138048130562 -18 0.09613438331131358 0.9038656166886864 -19 0.8045329731000239 0.1954670268999761 -20 0.4250983858706371 0.5749016141293629 -21 0.001157237075012295 0.9988427629249876 -22 0.001176312993035658 0.9988236870069644 -23 0.9494986195186943 0.05050138048130562 -24 7.027319386016872e-05 0.9999297268061399 -25 0.8600077678633851 0.139992232136615 -26 2.227705823559341e-05 0.9999777229417643 -27 0.7157077537764379 0.2842922462235621 -28 1.809741839578053e-08 0.9999999819025817 -29 0.9785935897081866 0.02140641029181342 -30 0.5822761154218885 0.4177238845781116 -31 0.002370165703518205 0.9976298342964818 -32 0.841083663701518 0.158916336298482 -33 0.9362669941752089 0.06373300582479108 -34 0.6977825772443407 0.3022174227556594 -35 0.7782908395879082 0.2217091604120917 -36 0.01416776076429902 0.9858322392357011 -37 0.06323902592252105 0.9367609740774788 -38 0.691073327987713 0.3089266720122871 -39 0.001912656476250792 0.9980873435237492 -40 0.003947386658983694 0.9960526133410164 -41 0.5293095617222775 0.4706904382777225 -42 0.8383200423653646 0.1616799576346353 -43 0.5921034700109731 0.4078965299890269 -44 0.2079167971176542 0.7920832028823458 -45 0.4810475092660724 0.5189524907339277 -46 0.01849904543412337 0.9815009545658766 -47 0.7637328241345798 0.2362671758654202 -48 0.1400437601786194 0.8599562398213805 -49 0.07638145838926107 0.923618541610739 -50 0.5563915330205015 0.4436084669794985 -51 4.374694250270806e-06 0.9999956253057498 -52 0.9686881643150316 0.03131183568496831 -53 0.9338323266082872 0.06616767339171271 -54 0.05701403403912244 0.9429859659608776 -55 0.6731492091330815 0.3268507908669185 -56 0.9785935897081866 0.02140641029181342 -57 0.03628221798165897 0.9637177820183411 -58 0.9366190715615527 0.06338092843844724 -59 0.02356797689294177 0.9764320231070582 -60 0.7157077537764379 0.2842922462235621 -61 0.2737142214547928 0.7262857785452073 -62 0.1718403585681014 0.8281596414318986 -63 0.06681709852445417 0.9331829014755458 -64 0.1587872286486478 0.8412127713513522 -65 0.1369215363202921 0.863078463679708 -66 2.81592588896611e-08 0.9999999718407411 -67 0.5389173626602737 0.4610826373397264 -68 0.0006597117100337049 0.9993402882899663 -69 2.857125884890865e-05 0.9999714287411511 -70 0.3232101345206682 0.6767898654793318 -71 0.2246226459153385 0.7753773540846616 -72 0.1616308408528564 0.8383691591471436 -73 0.1392644687864736 0.8607355312135264 -74 0.9494986195186943 0.05050138048130562 -75 0.02453009359779407 0.975469906402206 -76 6.379361230679482e-05 0.9999362063876932 -77 0.9715477961072897 0.02845220389271028 -78 0.7861650490385286 0.2138349509614714 -79 0.7327102952907434 0.2672897047092566 -80 0.9706214135555877 0.02937858644441215 -81 0.8610526021413432 0.1389473978586568 -82 0.7667165606100446 0.2332834393899555 -83 5.642631612118673e-05 0.9999435736838789 -84 0.006711572759235804 0.9932884272407642 -85 0.9683698202383987 0.03163017976160129 -86 0.9686881643150316 0.03131183568496831 -87 1.524961505130713e-05 0.9999847503849486 -88 0.7667165606100446 0.2332834393899555 -89 0.9315811679750052 0.06841883202499471 -90 0.03850185702329238 0.9614981429767077 -91 0.5870989093058979 0.4129010906941022 +Rate/Site Rate=0.07861747394474425 Rate=1 +1 0.0004171756387820546 0.9995828243612179 +2 0.949611180423643 0.05038881957635705 +3 0.8529582665262366 0.1470417334737633 +4 0.9773633760259754 0.02263662397402449 +5 0.7092394317199029 0.2907605682800972 +6 0.9706897558751614 0.02931024412483861 +7 0.8414164703263 0.1585835296737001 +8 0.6451559578781774 0.3548440421218226 +9 0.009053093997565813 0.9909469060024342 +10 0.2520815880881419 0.747918411911858 +11 0.9364333332734404 0.06356666672655968 +12 0.8042918335986166 0.1957081664013834 +13 0.95939640123464 0.04060359876536005 +14 0.6834467195021842 0.3165532804978159 +15 0.9687681772026803 0.0312318227973196 +16 0.9687681772026803 0.0312318227973196 +17 0.949611180423643 0.05038881957635705 +18 0.09646765254675914 0.9035323474532408 +19 0.8049164583959884 0.1950835416040116 +20 0.4262277110914361 0.573772288908564 +21 0.00117010716164424 0.9988298928383559 +22 0.001185885671369777 0.9988141143286303 +23 0.949611180423643 0.05038881957635705 +24 7.114291691814195e-05 0.9999288570830819 +25 0.8602756841775846 0.1397243158224154 +26 2.254023116609902e-05 0.999977459768834 +27 0.7161023719541011 0.283897628045899 +28 1.841502917909819e-08 0.9999999815849708 +29 0.9786485364590117 0.02135146354098819 +30 0.582686436699258 0.417313563300742 +31 0.002390526277210891 0.9976094737227892 +32 0.8414164703263 0.1585835296737001 +33 0.9364333332734404 0.06356666672655968 +34 0.6987750467418727 0.3012249532581273 +35 0.7790944916468581 0.2209055083531419 +36 0.01429371172876378 0.9857062882712362 +37 0.06361880439585066 0.9363811956041493 +38 0.6920562631865748 0.3079437368134252 +39 0.001928852282323563 0.9980711477176765 +40 0.003983409392734671 0.9960165906072653 +41 0.5303647162053932 0.4696352837946067 +42 0.8386350866813885 0.1613649133186115 +43 0.5925778177481617 0.4074221822518382 +44 0.2090344698105323 0.7909655301894677 +45 0.4821621443281067 0.5178378556718933 +46 0.0186132834313224 0.9813867165686775 +47 0.7641182996309834 0.2358817003690167 +48 0.1408545442834629 0.8591454557165371 +49 0.07692057903640417 0.9230794209635959 +50 0.5574343005631943 0.4425656994368057 +51 4.43894305142888e-06 0.9999955610569485 +52 0.9687681772026803 0.0312318227973196 +53 0.9339651771078613 0.06603482289213859 +54 0.05736048090793156 0.9426395190920684 +55 0.6742031250765356 0.3257968749234645 +56 0.9786485364590117 0.02135146354098819 +57 0.03651732125304075 0.9634826787469593 +58 0.9367559323807118 0.06324406761928837 +59 0.02371625697620915 0.9762837430237908 +60 0.7161023719541011 0.283897628045899 +61 0.2746100472926215 0.7253899527073786 +62 0.1724226760582058 0.8275773239417942 +63 0.06723211289807503 0.932767887101925 +64 0.1596925722997463 0.8403074277002537 +65 0.137719193721605 0.862280806278395 +66 2.859979909597426e-08 0.9999999714002009 +67 0.5393261114055373 0.4606738885944627 +68 0.0006659882940167302 0.9993340117059832 +69 2.893625055714912e-05 0.9999710637494429 +70 0.3241355652436183 0.6758644347563817 +71 0.2253810959593394 0.7746189040406605 +72 0.1625994437141345 0.8374005562858655 +73 0.1397520405558187 0.8602479594441813 +74 0.949611180423643 0.05038881957635705 +75 0.02467516020300521 0.9753248397969949 +76 6.461014423877886e-05 0.9999353898557611 +77 0.9716211799621152 0.02837882003788475 +78 0.7865525944924113 0.2134474055075888 +79 0.7335964702945454 0.2664035297054545 +80 0.9706897558751614 0.02931024412483861 +81 0.8613830849212658 0.1386169150787341 +82 0.7671107376950946 0.2328892623049054 +83 5.70998409009067e-05 0.9999429001590991 +84 0.006758971772704963 0.993241028227295 +85 0.9684512653381456 0.03154873466185435 +86 0.9687681772026803 0.0312318227973196 +87 1.538636892488436e-05 0.999984613631075 +88 0.7671107376950946 0.2328892623049054 +89 0.9317446770502245 0.06825532294977553 +90 0.03875792645356601 0.961242073546434 +91 0.5875108306075472 0.4124891693924528 *** RUNNING MODEL 2 (Selection) *** ###################################### ->Done in 9 seconds +>Done in 6 seconds --1106.44539895434 +-1106.44530886821 ------------------------------------------------ -dN/dS = 1.127340287204478 (sample variance = 1.58436948497131) +dN/dS = 1.12766514584006 (sample variance = 1.581198405980767) -Rate[1]= 0.05821071 (weight=0.3745168) -Rate[2]= 1.00000000 (weight=0.4437946) -Rate[3]= 3.64219246 (weight=0.1816886) +Rate[1]= 0.05908674 (weight=0.3752705) +Rate[2]= 1.00000000 (weight=0.4420542) +Rate[3]= 3.63178596 (weight=0.1826753) ------------------------------------------------ Sites with dN/dS>1 (Posterior cutoff = 0.9) -26 (0.9063738698527198) -28 (0.9991953848651767) -66 (0.9984704623342976) -87 (0.9855420922437026) +26 (0.9068529264412361) +28 (0.999194331685321) +66 (0.9984647844038979) +87 (0.9855377532726842) ------------------------------------------------ Sites with dN/dS<=1 (Posterior cutoff = 0.9) -1 (0.5025745641418347) -2 (0.0004541428605471889) -3 (0.005866050463654438) -4 (9.54200156090392e-05) -5 (0.03151157777417133) -6 (0.0001493070987347658) -7 (0.00688598519260396) -8 (0.05639261114774863) -9 (0.7213080114167497) -10 (0.0957831671656687) -11 (0.0009113197141057725) -12 (0.01055352361960661) -13 (0.0004882563383190259) -14 (0.03965335786634457) -15 (0.0002199913596497756) -16 (0.0002199913596497756) -17 (0.0004541428605471889) -18 (0.4314386408780044) -19 (0.01152202920294278) -20 (0.03338768826211628) -21 (0.2453512890354509) -22 (0.7972640860509772) -23 (0.0004541428605471889) -24 (0.5816335758297388) -25 (0.005128041544654446) -27 (0.02920045323827476) -29 (7.850142576752661e-05) -30 (0.09096315480882591) -31 (0.5677751557201599) -32 (0.00688598519260396) -33 (0.0009113197141057725) -34 (0.004469345511802118) -35 (0.002028614924076141) -36 (0.1042110362880712) -37 (0.08520242992547368) -38 (0.005346573047827193) -39 (0.6421357241955872) -40 (0.453384833828765) -41 (0.01173323849667157) -42 (0.006800071503757644) -43 (0.0832203669176092) -44 (0.01169451308373057) -45 (0.01734193546293329) -46 (0.4274281329493518) -47 (0.01824234121894671) -48 (0.02506914377220041) -49 (0.07048185891380006) -50 (0.01052820134563541) -51 (0.8851289361689126) -52 (0.0002199913596497756) -53 (0.0007599225412283629) -54 (0.09744338376102905) -55 (0.006278620375131812) -56 (7.850142576752661e-05) -57 (0.2035906999469696) -58 (0.0007195817628559127) -59 (0.3295595928333391) -60 (0.02920045323827476) -61 (0.08137211102185149) -62 (0.1924781396997199) -63 (0.07650875418480947) -64 (0.02123046879793863) -65 (0.02714955864845278) -67 (0.1255524548652049) -68 (0.6033318939894048) -69 (0.8321570523529694) -70 (0.05488694102002962) -71 (0.1219221800538113) -72 (0.02087278125101135) -73 (0.2761848819699247) -74 (0.0004541428605471889) -75 (0.3054732689829193) -76 (0.6736174770103036) -77 (0.0002279429764176589) -78 (0.01488093788513198) -79 (0.003192091600849912) -80 (0.0001493070987347658) -81 (0.005129925089737361) -82 (0.01763902881268067) -83 (0.8128727096598041) -84 (0.2757158795908484) -85 (0.0001941503812406847) -86 (0.0002199913596497756) -88 (0.01763902881268067) -89 (0.001161431797388906) -90 (0.1850341663559807) -91 (0.08779945638248213) +1 (0.50564337965482) +2 (0.0004635313656910933) +3 (0.005952924670428214) +4 (9.765520936665395e-05) +5 (0.03185639802201144) +6 (0.0001527036074198602) +7 (0.006988328973977571) +8 (0.05691838485498499) +9 (0.722460409856472) +10 (0.09688440510634511) +11 (0.0009287285296281832) +12 (0.01069736214711896) +13 (0.0004973370958702279) +14 (0.04005882941786322) +15 (0.0002246784862725794) +16 (0.0002246784862725794) +17 (0.0004635313656910933) +18 (0.4332343157975523) +19 (0.01167949265469138) +20 (0.03384753927105891) +21 (0.2479756329867343) +22 (0.7982428690533777) +23 (0.0004635313656910933) +24 (0.5844033633588168) +25 (0.005205692967830134) +27 (0.02952562655116002) +29 (8.039617605020493e-05) +30 (0.09167391664016496) +31 (0.5701540447371458) +32 (0.006988328973977571) +33 (0.0009287285296281832) +34 (0.004546839549977139) +35 (0.002065933241988426) +36 (0.1057174173012827) +37 (0.08647336407219176) +38 (0.005434386251906796) +39 (0.6441266380502984) +40 (0.4560125192796046) +41 (0.01192987412049621) +42 (0.006901310060365195) +43 (0.08387444264076313) +44 (0.01194443277172324) +45 (0.01761827801744891) +46 (0.4298714790053914) +47 (0.01846889590230068) +48 (0.02554544683407915) +49 (0.07154175132591806) +50 (0.0107029203838912) +51 (0.8858603694200771) +52 (0.0002246784862725794) +53 (0.0007748945705673779) +54 (0.0988422206847205) +55 (0.006380301274219317) +56 (8.039617605020493e-05) +57 (0.20577167242759) +58 (0.0007338575862225675) +59 (0.3320773710077579) +60 (0.02952562655116002) +61 (0.08234699554217713) +62 (0.1941175629581477) +63 (0.0776913356655021) +64 (0.02165309774542632) +65 (0.02766032216077592) +67 (0.1264014317341611) +68 (0.6057754917125372) +69 (0.8332313777881661) +70 (0.05559821369914605) +71 (0.1232048666936457) +72 (0.02128067831210712) +73 (0.2780522981486198) +74 (0.0004635313656910933) +75 (0.3079191906128577) +76 (0.675766456710993) +77 (0.0002325969719264994) +78 (0.01507139430969678) +79 (0.003248202245900504) +80 (0.0001527036074198602) +81 (0.005210483074735287) +82 (0.01786003606132795) +83 (0.8140382452308431) +84 (0.2787666326299093) +85 (0.0001984448148078526) +86 (0.0002246784862725794) +88 (0.01786003606132795) +89 (0.001182757048608233) +90 (0.1871234397675989) +91 (0.0884954555412755) ------------------------------------------------ @@ -256,95 +256,95 @@ Import the following part into a data processing program for further analysis -Rate/Site Rate=0.05821071099228891 Rate=1 Rate=3.642192463493435 -1 2.084596003814889e-05 0.4974045898981271 0.5025745641418347 -2 0.8453286957170657 0.1542171614223871 0.0004541428605471889 -3 0.7168384726053592 0.2772954769309865 0.005866050463654438 -4 0.9022531884974908 0.09765139148690009 9.54200156090392e-05 -5 0.582473111502837 0.3860153107229916 0.03151157777417133 -6 0.8873930284577699 0.1124576644434955 0.0001493070987347658 -7 0.7009047954385327 0.2922092193688635 0.00688598519260396 -8 0.5254125008615907 0.4181948879906606 0.05639261114774863 -9 0.001043250487314121 0.2776487380959362 0.7213080114167497 -10 0.09982049379895028 0.804396339035381 0.0957831671656687 -11 0.8192026230122673 0.1798860572736269 0.0009113197141057725 -12 0.6713725302789012 0.3180739461014921 0.01055352361960661 -13 0.8644831243369703 0.1350286193247106 0.0004882563383190259 -14 0.5619953681566967 0.3983512739769587 0.03965335786634457 -15 0.8821238681874204 0.1176561404529299 0.0002199913596497756 -16 0.8821238681874204 0.1176561404529299 0.0002199913596497756 -17 0.8453286957170657 0.1542171614223871 0.0004541428605471889 -18 0.03280817820181037 0.5357531809201853 0.4314386408780044 -19 0.6641574927169847 0.3243204780800725 0.01152202920294278 -20 0.1587703923090176 0.8078419194288662 0.03338768826211628 -21 6.359335781746676e-05 0.7545851176067316 0.2453512890354509 -22 6.062375361510889e-05 0.2026752901954078 0.7972640860509772 -23 0.8453286957170657 0.1542171614223871 0.0004541428605471889 -24 1.767824180377098e-06 0.4183646563460808 0.5816335758297388 -25 0.7255613600726152 0.2693105983827304 0.005128041544654446 -26 1.841798611457965e-07 0.09362594596741899 0.9063738698527198 -27 0.5892236281501289 0.3815759186115963 0.02920045323827476 -28 7.833484784750068e-14 0.0008046151347450235 0.9991953848651767 -29 0.9054502765141318 0.09447122206010064 7.850142576752661e-05 -30 0.4711204505233654 0.4379163946678085 0.09096315480882591 -31 0.0001951210986884978 0.4320297231811517 0.5677751557201599 -32 0.7009047954385327 0.2922092193688635 0.00688598519260396 -33 0.8192026230122673 0.1798860572736269 0.0009113197141057725 -34 0.2946838444538651 0.7008468100343328 0.004469345511802118 -35 0.3544924781425416 0.6434789069333822 0.002028614924076141 -36 0.001287098433950928 0.8945018652779779 0.1042110362880712 -37 0.01166877653551841 0.903128793539008 0.08520242992547368 -38 0.2927135126088006 0.7019399143433722 0.005346573047827193 -39 0.0001420870612777609 0.357722188743135 0.6421357241955872 -40 0.0002493538370174873 0.5463658123342177 0.453384833828765 -41 0.2109104773815808 0.7773562841217475 0.01173323849667157 -42 0.7003136079700385 0.2928863205262038 0.006800071503757644 -43 0.4837103308401287 0.4330693022422621 0.0832203669176092 -44 0.02977101275457602 0.9585344741616934 0.01169451308373057 -45 0.1882305923647887 0.7944274721722779 0.01734193546293329 -46 0.003325046883114958 0.5692468201675333 0.4274281329493518 -47 0.6296512769792614 0.3521063818017921 0.01824234121894671 -48 0.0218039849863804 0.9531268712414193 0.02506914377220041 -49 0.01339466183941398 0.9161234792467861 0.07048185891380006 -50 0.2228782911071198 0.7665935075472448 0.01052820134563541 -51 2.425314417847051e-08 0.1148710395779432 0.8851289361689126 -52 0.8821238681874204 0.1176561404529299 0.0002199913596497756 -53 0.820976221463389 0.1782638559953825 0.0007599225412283629 -54 0.01087141549056791 0.891685200748403 0.09744338376102905 -55 0.2819675488727456 0.7117538307521226 0.006278620375131812 -56 0.9054502765141318 0.09447122206010064 7.850142576752661e-05 -57 0.006964517422050386 0.7894447826309802 0.2035906999469696 -58 0.8238724112083969 0.1754080070287472 0.0007195817628559127 -59 0.004531427467599394 0.6659089796990614 0.3295595928333391 -60 0.5892236281501289 0.3815759186115963 0.02920045323827476 -61 0.1071264489775171 0.8115014400006314 0.08137211102185149 -62 0.06819732196892567 0.7393245383313544 0.1924781396997199 -63 0.01227694662945637 0.9112142991857342 0.07650875418480947 -64 0.02363000654513221 0.9551395246569291 0.02123046879793863 -65 0.02126148118289202 0.9515889601686552 0.02714955864845278 -66 2.586145918973436e-12 0.001529537663116197 0.9984704623342976 -67 0.4292109531653147 0.4452365919694803 0.1255524548652049 -68 3.030874033181131e-05 0.3966377972702633 0.6033318939894048 -69 4.144303769058226e-07 0.1678425332166536 0.8321570523529694 -70 0.1280934686037557 0.8170195903762147 0.05488694102002962 -71 0.08857715835814825 0.7895006615880403 0.1219221800538113 -72 0.02469711191552965 0.954430106833459 0.02087278125101135 -73 0.05269509152941992 0.6711200265006554 0.2761848819699247 -74 0.8453286957170657 0.1542171614223871 0.0004541428605471889 -75 0.004927288392527528 0.6895994426245532 0.3054732689829193 -76 1.247447677203241e-06 0.3263812755420193 0.6736174770103036 -77 0.888268667402347 0.1115033896212354 0.0002279429764176589 -78 0.6481294827308296 0.3369895793840385 0.01488093788513198 -79 0.3307417986836138 0.6660661097155364 0.003192091600849912 -80 0.8873930284577699 0.1124576644434955 0.0001493070987347658 -81 0.7189706093539512 0.2758994655563116 0.005129925089737361 -82 0.6315303313308913 0.350830639856428 0.01763902881268067 -83 9.261015970987599e-07 0.1871263642385988 0.8128727096598041 -84 9.613090552104351e-05 0.7241879895036305 0.2757158795908484 -85 0.8806593127882252 0.1191465368305341 0.0001941503812406847 -86 0.8821238681874204 0.1176561404529299 0.0002199913596497756 -87 1.490223413640699e-08 0.01445789285406323 0.9855420922437026 -88 0.6315303313308913 0.350830639856428 0.01763902881268067 -89 0.8115328951388447 0.1873056730637664 0.001161431797388906 -90 0.007396226844168663 0.8075696067998506 0.1850341663559807 -91 0.4754704913448099 0.4367300522727081 0.08779945638248213 +Rate/Site Rate=0.05908673874612212 Rate=1 Rate=3.631785964259932 +1 2.209886404949519e-05 0.4943345214811306 0.50564337965482 +2 0.8460161268297731 0.1535203418045359 0.0004635313656910933 +3 0.7178875037617195 0.2761595715678524 0.005952924670428214 +4 0.9027019402600399 0.09720040453059345 9.765520936665395e-05 +5 0.5835979970977249 0.3845456048802637 0.03185639802201144 +6 0.8879088189467084 0.1119384774458718 0.0001527036074198602 +7 0.7019780057351419 0.2910336652908806 0.006988328973977571 +8 0.5264685329089774 0.4166130822360376 0.05691838485498499 +9 0.001076642261722848 0.2764629478818052 0.722460409856472 +10 0.101532339047803 0.801583255845852 0.09688440510634511 +11 0.8199723700816371 0.1790989013887346 0.0009287285296281832 +12 0.6724953262661715 0.3168073115867096 0.01069736214711896 +13 0.8650858518136233 0.1344168110905064 0.0004973370958702279 +14 0.5631036283321872 0.3968375422499498 0.04005882941786322 +15 0.8826535776912857 0.1171217438224416 0.0002246784862725794 +16 0.8826535776912857 0.1171217438224416 0.0002246784862725794 +17 0.8460161268297731 0.1535203418045359 0.0004635313656910933 +18 0.03335171260600901 0.5334139715964388 0.4332343157975523 +19 0.6652728265752929 0.3230476807700157 0.01167949265469138 +20 0.1614250671074364 0.8047273936215046 0.03384753927105891 +21 6.762742110022856e-05 0.7519567395921656 0.2479756329867343 +22 6.345859930669753e-05 0.2016936723473156 0.7982428690533777 +23 0.8460161268297731 0.1535203418045359 0.0004635313656910933 +24 1.902363037223809e-06 0.415594734278146 0.5844033633588168 +25 0.7265922670148459 0.2682020400173239 0.005205692967830134 +26 1.985360958821479e-07 0.09314687502266801 0.9068529264412361 +27 0.5903547948578014 0.3801195785910386 0.02952562655116002 +28 8.656583586909364e-14 0.0008056683145924549 0.999194331685321 +29 0.9058860050357037 0.09403359878824609 8.039617605020493e-05 +30 0.472080645537712 0.4362454378221232 0.09167391664016496 +31 0.0002040673831524824 0.4296418878797017 0.5701540447371458 +32 0.7019780057351419 0.2910336652908806 0.006988328973977571 +33 0.8199723700816371 0.1790989013887346 0.0009287285296281832 +34 0.2988536138231553 0.6965995466268677 0.004546839549977139 +35 0.3590785902522919 0.6388554765057196 0.002065933241988426 +36 0.001350586629976096 0.8929319960687412 0.1057174173012827 +37 0.01206626212072677 0.9014603738070815 0.08647336407219176 +38 0.296858918274509 0.6977066954735843 0.005434386251906796 +39 0.0001486058013196755 0.3557247561483821 0.6441266380502984 +40 0.0002611293947949704 0.5437263513256004 0.4560125192796046 +41 0.2142660571258572 0.7738040687536466 0.01192987412049621 +42 0.7013946801698393 0.2917040097697954 0.006901310060365195 +43 0.4847139638726951 0.4314115934865418 0.08387444264076313 +44 0.0307909046863451 0.9572646625419317 0.01194443277172324 +45 0.1912989173751411 0.79108280460741 0.01761827801744891 +46 0.003430027354294256 0.5666984936403142 0.4298714790053914 +47 0.6307849049933654 0.3507461991043339 0.01846889590230068 +48 0.02255395263026463 0.9519006005356563 0.02554544683407915 +49 0.01385565698424025 0.9146025916898417 0.07154175132591806 +50 0.2263703277368689 0.7629267518792398 0.0107029203838912 +51 2.650022450269452e-08 0.1141396040796983 0.8858603694200771 +52 0.8826535776912857 0.1171217438224416 0.0002246784862725794 +53 0.8217575190990775 0.1774675863303552 0.0007748945705673779 +54 0.01124019864020068 0.8899175806750789 0.0988422206847205 +55 0.2860218246237924 0.7075978741019883 0.006380301274219317 +56 0.9058860050357037 0.09403359878824609 8.039617605020493e-05 +57 0.007193191545153913 0.7870351360272562 0.20577167242759 +58 0.8246404985253575 0.1746256438884198 0.0007338575862225675 +59 0.004676395117767392 0.6632462338744747 0.3320773710077579 +60 0.5903547948578014 0.3801195785910386 0.02952562655116002 +61 0.1089684432885873 0.8086845611692355 0.08234699554217713 +62 0.06935754334476603 0.7365248936970863 0.1941175629581477 +63 0.01269571982106563 0.9096129445134323 0.0776913356655021 +64 0.02443626730142882 0.9539106349531449 0.02165309774542632 +65 0.02199247943184007 0.9503471984073839 0.02766032216077592 +66 2.882265280270539e-12 0.001535215593219904 0.9984647844038979 +67 0.4300802149961221 0.4435183532697169 0.1264014317341611 +68 3.190268336358626e-05 0.3941926056040992 0.6057754917125372 +69 4.461173221076013e-07 0.1667681760945119 0.8332313777881661 +70 0.1302823124748364 0.8141194738260176 0.05559821369914605 +71 0.090097319636375 0.7866978136699793 0.1232048666936457 +72 0.02554156938720773 0.9531777523006851 0.02128067831210712 +73 0.05357529765940063 0.6683724041919796 0.2780522981486198 +74 0.8460161268297731 0.1535203418045359 0.0004635313656910933 +75 0.005086275259791111 0.6869945341273512 0.3079191906128577 +76 1.342527903885351e-06 0.3242322007611031 0.675766456710993 +77 0.8887713155227283 0.1109960875053454 0.0002325969719264994 +78 0.6492527003857581 0.335675905304545 0.01507139430969678 +79 0.3351633771448881 0.6615884206092113 0.003248202245900504 +80 0.8879088189467084 0.1119384774458718 0.0001527036074198602 +81 0.720009455314252 0.2747800616110128 0.005210483074735287 +82 0.6326662220561357 0.3494737418825364 0.01786003606132795 +83 9.899852174118305e-07 0.1859607647839394 0.8140382452308431 +84 0.0001000595004129542 0.7211333078696778 0.2787666326299093 +85 0.881198932428059 0.1186026227571332 0.0001984448148078526 +86 0.8826535776912857 0.1171217438224416 0.0002246784862725794 +87 1.605946817291359e-08 0.01446223066784761 0.9855377532726842 +88 0.6326662220561357 0.3494737418825364 0.01786003606132795 +89 0.8123225284645922 0.1864947144867997 0.001182757048608233 +90 0.007640324272833134 0.8052362359595679 0.1871234397675989 +91 0.4764392706830485 0.4350652737756759 0.0884954555412755 diff --git a/tests/hbltests/Results/HIVSweden.out_MODEL_-1.nex b/tests/hbltests/Results/HIVSweden.out_MODEL_-1.nex index a07518f9e..2569fc463 100644 --- a/tests/hbltests/Results/HIVSweden.out_MODEL_-1.nex +++ b/tests/hbltests/Results/HIVSweden.out_MODEL_-1.nex @@ -37,8 +37,8 @@ END; BEGIN HYPHY; -global c=0.9081653126969932; -global kappa=0.4052494381774001; +global c=0.911942160103597; +global kappa=0.4054809128706205; modelMatrix={61,61}; modelMatrix[0][1]:=kappa*c*t; modelMatrix[0][2]:=t; @@ -638,34 +638,35 @@ ACCEPT_ROOTED_TREES=0; UseModel (theModel); Tree givenTree=((((U68496,U68497)Node4)Node3,(U68501,(U68502,(U68503,((((U68504,U68506)Node16,U68505)Node15,U68507)Node14,U68508)Node13)Node11)Node9)Node7)Node2,U68498,(U68499,U68500)Node6); -givenTree.U68496.t=0.1930096147333227; -givenTree.U68497.t=0.6421555382913382; -givenTree.Node4.t=0.9900459236749525; -givenTree.Node3.t=0.2491332115846193; -givenTree.U68501.t=1.068053592806899; -givenTree.U68502.t=1.550506538277573; -givenTree.U68503.t=1.569612176531353; -givenTree.U68504.t=0.1540107235317644; -givenTree.U68506.t=0.5706628379540368; -givenTree.Node16.t=0.4510756497415538; -givenTree.U68505.t=0.2457312885320321; -givenTree.Node15.t=0.2974223154713735; -givenTree.U68507.t=0.4955443217476682; -givenTree.Node14.t=0.2825622955047431; -givenTree.U68508.t=1.608326349179048; -givenTree.Node13.t=0.4103735198550957; -givenTree.Node11.t=0.5193151093640216; -givenTree.Node9.t=0.2731984764401898; -givenTree.Node7.t=0.390215024883838; -givenTree.Node2.t=0.1917269400299133; -givenTree.U68498.t=0.409089543791319; -givenTree.U68499.t=0.2309850898696639; -givenTree.U68500.t=0.8103298231547824; -givenTree.Node6.t=0.677140982173375; -givenTree.Node1.t=0.09514304506367643; +givenTree.U68496.t=0.192121483894935; +givenTree.U68497.t=0.6392494100253431; +givenTree.Node4.t=0.4462505878848448; +givenTree.Node3.t=0.7884830206774067; +givenTree.U68501.t=1.064822202007258; +givenTree.U68502.t=1.54361895190365; +givenTree.U68503.t=1.564178047414112; +givenTree.U68504.t=0.1535209341229616; +givenTree.U68506.t=0.5682858444575011; +givenTree.Node16.t=0.4495915518878103; +givenTree.U68505.t=0.2449210887709239; +givenTree.Node15.t=0.296433362542081; +givenTree.U68507.t=0.4937996785015182; +givenTree.Node14.t=0.2814901272462195; +givenTree.U68508.t=1.603901882326408; +givenTree.Node13.t=0.4087267713543258; +givenTree.Node11.t=0.5166989104912423; +givenTree.Node9.t=0.2722019890411134; +givenTree.Node7.t=0.3889706412703413; +givenTree.Node2.t=0.1910629239730626; +givenTree.U68498.t=0.4076006171477853; +givenTree.U68499.t=0.2294111927752583; +givenTree.U68500.t=0.8077872067298961; +givenTree.Node6.t=0.6740793127558758; +givenTree.Node1.t=0.0006724153807641; DataSet ds = ReadDataFile(USE_NEXUS_FILE_DATA); DataSetFilter filteredData = CreateFilter(ds,3,"0-272","0,1,5-8,10,9,11,12,2-4","TAA,TAG,TGA"); ASSUME_REVERSIBLE_MODELS=0; +USE_LAST_RESULTS=1; LikelihoodFunction lf = (filteredData,givenTree); END; \ No newline at end of file diff --git a/tests/hbltests/Results/HIVSweden.out_MODEL_0.nex b/tests/hbltests/Results/HIVSweden.out_MODEL_0.nex index 8d5a44869..31cc3ec9b 100644 --- a/tests/hbltests/Results/HIVSweden.out_MODEL_0.nex +++ b/tests/hbltests/Results/HIVSweden.out_MODEL_0.nex @@ -37,11 +37,11 @@ END; BEGIN HYPHY; -global W=0.07845659836123289; +global W=0.07861747394474425; W:<1; -global P=0.4829049238283412; +global P=0.4832764870262197; P:<1; -global kappa=0.3859937269234522; +global kappa=0.3862518235736528; c.weights={1,2}; c.weights[0][0]:=P; @@ -654,34 +654,35 @@ ACCEPT_ROOTED_TREES=0; UseModel (theModel); Tree givenTree=((((U68496,U68497)Node4)Node3,(U68501,(U68502,(U68503,((((U68504,U68506)Node16,U68505)Node15,U68507)Node14,U68508)Node13)Node11)Node9)Node7)Node2,U68498,(U68499,U68500)Node6); -givenTree.U68496.t=0.3018351124085291; -givenTree.U68497.t=1.059288619148979; -givenTree.Node4.t=0.4008374094413935; -givenTree.Node3.t=1.682411335707209; -givenTree.U68501.t=1.768199058853968; -givenTree.U68502.t=2.670987023845607; -givenTree.U68503.t=2.700940838733447; -givenTree.U68504.t=0.2433073225419187; -givenTree.U68506.t=0.9049173648528123; -givenTree.Node16.t=0.7161816170887272; -givenTree.U68505.t=0.3956376568826752; -givenTree.Node15.t=0.5001904654996728; -givenTree.U68507.t=0.7736926316389544; -givenTree.Node14.t=0.2770997155633957; -givenTree.U68508.t=2.852490788962902; -givenTree.Node13.t=0.7479950200971435; -givenTree.Node11.t=0.8236027973478787; -givenTree.Node9.t=0.3098636158647936; -givenTree.Node7.t=0.6406828146702116; -givenTree.Node2.t=0.3044226041256647; -givenTree.U68498.t=0.6395185183613477; -givenTree.U68499.t=0.3596315599860557; -givenTree.U68500.t=1.320696633038675; -givenTree.Node6.t=1.138295435084; -givenTree.Node1.t=0.09447397990087528; +givenTree.U68496.t=0.3015729502329249; +givenTree.U68497.t=1.058257102031187; +givenTree.Node4.t=1.15318474939162; +givenTree.Node3.t=0.9309921194099001; +givenTree.U68501.t=1.765169045625969; +givenTree.U68502.t=2.672360864363262; +givenTree.U68503.t=2.709162795696727; +givenTree.U68504.t=0.24325406993288; +givenTree.U68506.t=0.9044931073442913; +givenTree.Node16.t=0.7151085459517377; +givenTree.U68505.t=0.3954674837568525; +givenTree.Node15.t=0.4999222691606283; +givenTree.U68507.t=0.774494812266955; +givenTree.Node14.t=0.2768696155089731; +givenTree.U68508.t=2.85524014204128; +givenTree.Node13.t=0.7481759723267783; +givenTree.Node11.t=0.8226165012238955; +givenTree.Node9.t=0.3105248433782432; +givenTree.Node7.t=0.6406594119850229; +givenTree.Node2.t=0.3045529344681134; +givenTree.U68498.t=0.639065007964962; +givenTree.U68499.t=0.3595232565084895; +givenTree.U68500.t=1.322198597699191; +givenTree.Node6.t=1.136724122974329; +givenTree.Node1.t=0.0533314624311028; DataSet ds = ReadDataFile(USE_NEXUS_FILE_DATA); DataSetFilter filteredData = CreateFilter(ds,3,"0-272","0,1,5-8,10,9,11,12,2-4","TAA,TAG,TGA"); ASSUME_REVERSIBLE_MODELS=0; +USE_LAST_RESULTS=1; LikelihoodFunction lf = (filteredData,givenTree); END; \ No newline at end of file diff --git a/tests/hbltests/Results/HIVSweden.out_MODEL_1.nex b/tests/hbltests/Results/HIVSweden.out_MODEL_1.nex index d5a89d589..28c4591c1 100644 --- a/tests/hbltests/Results/HIVSweden.out_MODEL_1.nex +++ b/tests/hbltests/Results/HIVSweden.out_MODEL_1.nex @@ -37,15 +37,15 @@ END; BEGIN HYPHY; -global P2=0.7095228147882606; +global P2=0.7075930251249289; P2:<1; -global W_1=0.05821071099228891; +global W_1=0.05908673874612212; W_1:<1; -global W_2=3.642192463493435; +global W_2=3.631785964259932; W_2:>1; -global P1=0.3745168291718436; +global P1=0.375270533842653; P1:<1; -global kappa=0.3596278255070593; +global kappa=0.3595771504468483; c.weights={1,3}; c.weights[0][0]:=P1; @@ -660,34 +660,35 @@ ACCEPT_ROOTED_TREES=0; UseModel (theModel); Tree givenTree=((((U68496,U68497)Node4)Node3,(U68501,(U68502,(U68503,((((U68504,U68506)Node16,U68505)Node15,U68507)Node14,U68508)Node13)Node11)Node9)Node7)Node2,U68498,(U68499,U68500)Node6); -givenTree.U68496.t=0.1819198025916606; -givenTree.U68497.t=0.6314852831137152; -givenTree.Node4.t=1.051943456356883; -givenTree.Node3.t=0.1931173590302015; -givenTree.U68501.t=1.053953361252853; -givenTree.U68502.t=1.74869208130719; -givenTree.U68503.t=1.774171354704112; -givenTree.U68504.t=0.1464740750651869; -givenTree.U68506.t=0.5205929359132269; -givenTree.Node16.t=0.4170746796540923; -givenTree.U68505.t=0.2412878090200677; -givenTree.Node15.t=0.2755939549762299; -givenTree.U68507.t=0.4777130414040305; -givenTree.Node14.t=0.00688102185110482; -givenTree.U68508.t=1.944312192973633; -givenTree.Node13.t=0.5086784095299535; -givenTree.Node11.t=0.5078238207269683; -givenTree.Node9.t=0.1807794504569013; -givenTree.Node7.t=0.3943032599171317; -givenTree.Node2.t=0.189811616423662; -givenTree.U68498.t=0.3346238227437736; -givenTree.U68499.t=0.1879529583721578; -givenTree.U68500.t=0.8004640342922762; -givenTree.Node6.t=0.7485876745524488; -givenTree.Node1.t=0.09438558396817996; +givenTree.U68496.t=0.1823362090160219; +givenTree.U68497.t=0.6319005932006931; +givenTree.Node4.t=0.7186608573956341; +givenTree.Node3.t=0.5266760584930447; +givenTree.U68501.t=1.055244295651116; +givenTree.U68502.t=1.749088321204769; +givenTree.U68503.t=1.77644065923493; +givenTree.U68504.t=0.1465075775527527; +givenTree.U68506.t=0.5207162468101293; +givenTree.Node16.t=0.4175230702755034; +givenTree.U68505.t=0.2414636650897602; +givenTree.Node15.t=0.2762765131975846; +givenTree.U68507.t=0.4780905520756796; +givenTree.Node14.t=0.006622253494086367; +givenTree.U68508.t=1.945288305463255; +givenTree.Node13.t=0.5084351480256487; +givenTree.Node11.t=0.5079487549393463; +givenTree.Node9.t=0.1809457716846473; +givenTree.Node7.t=0.3944024554603371; +givenTree.Node2.t=0.1898471467430669; +givenTree.U68498.t=0.3345594207692562; +givenTree.U68499.t=0.1879923629015026; +givenTree.U68500.t=0.8015647611761196; +givenTree.Node6.t=0.7495558244484987; +givenTree.Node1.t=0.07436824582250151; DataSet ds = ReadDataFile(USE_NEXUS_FILE_DATA); DataSetFilter filteredData = CreateFilter(ds,3,"0-272","0,1,5-8,10,9,11,12,2-4","TAA,TAG,TGA"); ASSUME_REVERSIBLE_MODELS=0; +USE_LAST_RESULTS=1; LikelihoodFunction lf = (filteredData,givenTree); END; \ No newline at end of file diff --git a/tests/hbltests/UnitTests/HBLCommands/Gamma.bf b/tests/hbltests/UnitTests/HBLCommands/Gamma.bf index 7a0dfa021..5a3f933ac 100644 --- a/tests/hbltests/UnitTests/HBLCommands/Gamma.bf +++ b/tests/hbltests/UnitTests/HBLCommands/Gamma.bf @@ -33,7 +33,7 @@ function runTest() assert(runCommandWithSoftErrors('Gamma("")', "Operation 'Gamma' is not implemented/defined for a String"), "Gamma String argument is invalid"); assert(runCommandWithSoftErrors('Gamma({})', "Operation 'Gamma' is not implemented/defined for a AssociativeList"), "Gamma Associative list argument is invalid"); - assert(runCommandWithSoftErrors('Gamma({{"a","b"}})', "evaluated with errors"), "Gamma Matrix argument is invalid"); + assert(runCommandWithSoftErrors('Gamma({{"a","b"}})', "Operation 'Gamma' is not implemented/defined for a Matrix"), "Gamma Matrix argument is invalid"); assert(runCommandWithSoftErrors('Gamma(T)', "Operation 'Gamma' is not implemented/defined for a Topology"), "Gamma Topology argument is invalid"); assert(runCommandWithSoftErrors('Gamma(TT)', "Operation 'Gamma' is not implemented/defined for a Tree"), "Gamma Tree argument is invalid"); diff --git a/tests/hbltests/UnitTests/HBLCommands/IBeta.bf b/tests/hbltests/UnitTests/HBLCommands/IBeta.bf index 32bd60900..57e3fbf1a 100644 --- a/tests/hbltests/UnitTests/HBLCommands/IBeta.bf +++ b/tests/hbltests/UnitTests/HBLCommands/IBeta.bf @@ -65,7 +65,7 @@ function runTest() assert(runCommandWithSoftErrors('IBeta("", 1, 1)', "Operation 'IBeta' is not implemented/defined for a String"), "IBeta String argument is invalid"); assert(runCommandWithSoftErrors('IBeta({}, 1, 1)', "Operation 'IBeta' is not implemented/defined for a AssociativeList"), "IBeta Associative list argument is invalid"); - assert(runCommandWithSoftErrors('IBeta({{"a","b"}}, 1, 1)', "evaluated with errors"), "IBeta Matrix argument is invalid"); + assert(runCommandWithSoftErrors('IBeta({{"a","b"}}, 1, 1)', "Operation 'IBeta' is not implemented/defined for a Matrix"), "IBeta Matrix argument is invalid"); assert(runCommandWithSoftErrors('IBeta(T, 1, 1)', "Operation 'IBeta' is not implemented/defined for a Topology"), "IBeta Topology argument is invalid"); assert(runCommandWithSoftErrors('IBeta(TT, 1, 1)', "Operation 'IBeta' is not implemented/defined for a Tree"), "IBeta Tree argument is invalid"); diff --git a/tests/hbltests/UnitTests/HBLCommands/LnGamma.bf b/tests/hbltests/UnitTests/HBLCommands/LnGamma.bf index 4a474a5c2..4ecd7fbfd 100644 --- a/tests/hbltests/UnitTests/HBLCommands/LnGamma.bf +++ b/tests/hbltests/UnitTests/HBLCommands/LnGamma.bf @@ -22,7 +22,7 @@ function runTest() assert(runCommandWithSoftErrors('LnGamma("")', "Operation 'LnGamma' is not implemented/defined for a String"), "LnGamma String argument is invalid"); assert(runCommandWithSoftErrors('LnGamma({})', "Operation 'LnGamma' is not implemented/defined for a AssociativeList"), "LnGamma Associative list argument is invalid"); - assert(runCommandWithSoftErrors('LnGamma({{"a","b"}})', "evaluated with errors"), "LnGamma Matrix argument is invalid"); + assert(runCommandWithSoftErrors('LnGamma({{"a","b"}})', "Operation 'LnGamma' is not implemented/defined for a Matrix"), "LnGamma Matrix argument is invalid"); assert(runCommandWithSoftErrors('LnGamma(T)', "Operation 'LnGamma' is not implemented/defined for a Topology"), "LnGamma Topology argument is invalid"); assert(runCommandWithSoftErrors('LnGamma(TT)', "Operation 'LnGamma' is not implemented/defined for a Tree"), "LnGamma Tree argument is invalid"); diff --git a/tests/hbltests/UnitTests/HBLCommands/Sin.bf b/tests/hbltests/UnitTests/HBLCommands/Sin.bf index 0dbe3f730..6a3521c54 100644 --- a/tests/hbltests/UnitTests/HBLCommands/Sin.bf +++ b/tests/hbltests/UnitTests/HBLCommands/Sin.bf @@ -39,7 +39,7 @@ function runTest() assert(runCommandWithSoftErrors('Sin("")', "Operation 'Sin' is not implemented/defined for a String"), "Sin String argument is invalid"); assert(runCommandWithSoftErrors('Sin({})', "Operation 'Sin' is not implemented/defined for a AssociativeList"), "Sin Associative list argument is invalid"); - assert(runCommandWithSoftErrors('Sin({{"a","b"}})', "evaluated with errors"), "Sin Matrix argument is invalid"); + assert(runCommandWithSoftErrors('Sin({{"a","b"}})', "Operation 'Sin' is not implemented/defined for a Matrix"), "Sin Matrix argument is invalid"); assert(runCommandWithSoftErrors('Sin(T)', "Operation 'Sin' is not implemented/defined for a Topology"), "Sin Topology argument is invalid"); assert(runCommandWithSoftErrors('Sin(TT)', "Operation 'Sin' is not implemented/defined for a Tree"), "Sin Tree argument is invalid"); diff --git a/tests/hbltests/UnitTests/HBLCommands/Sqrt.bf b/tests/hbltests/UnitTests/HBLCommands/Sqrt.bf index 1e22dd80d..e2f45068e 100644 --- a/tests/hbltests/UnitTests/HBLCommands/Sqrt.bf +++ b/tests/hbltests/UnitTests/HBLCommands/Sqrt.bf @@ -36,7 +36,7 @@ function runTest() assert(runCommandWithSoftErrors('Sqrt("")', "Operation 'Sqrt' is not implemented/defined for a String"), "Sqrt String argument is invalid"); assert(runCommandWithSoftErrors('Sqrt({})', "Operation 'Sqrt' is not implemented/defined for a AssociativeList"), "Sqrt Associative list argument is invalid"); - assert(runCommandWithSoftErrors('Sqrt({{"a","b"}})', "evaluated with errors"), "Sqrt Matrix argument is invalid"); + assert(runCommandWithSoftErrors('Sqrt({{"a","b"}})', "Operation 'Sqrt' is not implemented/defined for a Matrix"), "Sqrt Matrix argument is invalid"); assert(runCommandWithSoftErrors('Sqrt(T)', "Operation 'Sqrt' is not implemented/defined for a Topology"), "Sqrt Topology argument is invalid"); assert(runCommandWithSoftErrors('Sqrt(TT)', "Operation 'Sqrt' is not implemented/defined for a Tree"), "Sqrt Tree argument is invalid"); diff --git a/tests/hbltests/UnitTests/HBLCommands/Tan.bf b/tests/hbltests/UnitTests/HBLCommands/Tan.bf index 66cbdc7da..903640400 100644 --- a/tests/hbltests/UnitTests/HBLCommands/Tan.bf +++ b/tests/hbltests/UnitTests/HBLCommands/Tan.bf @@ -37,7 +37,7 @@ function runTest() assert(runCommandWithSoftErrors('Tan("")', "Operation 'Tan' is not implemented/defined for a String"), "Tan String argument is invalid"); assert(runCommandWithSoftErrors('Tan({})', "Operation 'Tan' is not implemented/defined for a AssociativeList"), "Tan Associative list argument is invalid"); - assert(runCommandWithSoftErrors('Tan({{"a","b"}})', "evaluated with errors"), "Tan Matrix argument is invalid"); + assert(runCommandWithSoftErrors('Tan({{"a","b"}})', "Operation 'Tan' is not implemented/defined for a Matrix"), "Tan Matrix argument is invalid"); assert(runCommandWithSoftErrors('Tan(T)', "Operation 'Tan' is not implemented/defined for a Topology"), "Tan Topology argument is invalid"); assert(runCommandWithSoftErrors('Tan(TT)', "Operation 'Tan' is not implemented/defined for a Tree"), "Tan Tree argument is invalid"); diff --git a/tests/hbltests/UnitTests/HBLCommands/Tree.bf b/tests/hbltests/UnitTests/HBLCommands/Tree.bf index f04bdfef8..d5169b69c 100644 --- a/tests/hbltests/UnitTests/HBLCommands/Tree.bf +++ b/tests/hbltests/UnitTests/HBLCommands/Tree.bf @@ -41,7 +41,7 @@ function runTest () { Tree twoNodes = (a),b; ACCEPT_ROOTED_TREES = 0; - assert (runCommandWithSoftErrors ('Tree twoNodes = (a),b;', "Cannot constuct empty trees"), "Failed error checking for trying to construct a tree with only two nodes"); + assert (runCommandWithSoftErrors ('Tree twoNodes = (a),b;', "Cannot consrtuct empty trees"), "Failed error checking for trying to construct a tree with only two nodes"); testResult = 1; diff --git a/tests/hbltests/UnitTests/HBLCommands/ZCDF.bf b/tests/hbltests/UnitTests/HBLCommands/ZCDF.bf index 153177afd..0df65fbc1 100644 --- a/tests/hbltests/UnitTests/HBLCommands/ZCDF.bf +++ b/tests/hbltests/UnitTests/HBLCommands/ZCDF.bf @@ -35,7 +35,7 @@ function runTest() assert(runCommandWithSoftErrors('ZCDF("")', "Operation 'ZCDF' is not implemented/defined for a String"), "ZCDF String argument is invalid"); assert(runCommandWithSoftErrors('ZCDF({})', "Operation 'ZCDF' is not implemented/defined for a AssociativeList"), "ZCDF Associative list argument is invalid"); - assert(runCommandWithSoftErrors('ZCDF({{"a","b"}})', "evaluated with errors"), "ZCDF Matrix argument is invalid"); + assert(runCommandWithSoftErrors('ZCDF({{"a","b"}})', "Operation 'ZCDF' is not implemented/defined for a Matrix"), "ZCDF Matrix argument is invalid"); assert(runCommandWithSoftErrors('ZCDF(T)', "Operation 'ZCDF' is not implemented/defined for a Topology"), "ZCDF Topology argument is invalid"); assert(runCommandWithSoftErrors('ZCDF(TT)', "Operation 'ZCDF' is not implemented/defined for a Tree"), "ZCDF Tree argument is invalid"); diff --git a/tests/hbltests/libv3/MEME-partitioned.wbf b/tests/hbltests/libv3/MEME-partitioned.wbf index 94089f0fb..07039626f 100644 --- a/tests/hbltests/libv3/MEME-partitioned.wbf +++ b/tests/hbltests/libv3/MEME-partitioned.wbf @@ -1,2 +1,2 @@ ExecuteAFile (HYPHY_LIB_DIRECTORY + "TemplateBatchFiles" + DIRECTORY_SEPARATOR + "SelectionAnalyses" + DIRECTORY_SEPARATOR + "MEME.bf", - {"--alignment" : PATH_TO_CURRENT_BF + "data/CD2.nex", "--branches" : "GROUP1"}); + {"--alignment" : PATH_TO_CURRENT_BF + "data/partitioned.nex", "--branches" : "Internal"}); From fc220a79c64bbad68689bd359b80a77e2c11c26f Mon Sep 17 00:00:00 2001 From: Segei L Kosakovsky Pond Date: Sat, 29 Feb 2020 09:33:26 -0500 Subject: [PATCH 3/3] Adding neighbor joining CLI options --- CMakeLists.txt | 2 +- .../modules/shared-load-file.bf | 6 ++++- res/TemplateBatchFiles/libv3/all-terms.bf | 3 +++ res/TemplateBatchFiles/libv3/tasks/trees.bf | 22 ++++++++++++++++--- src/core/batchlanhelpers.cpp | 3 +++ src/core/batchlanruntime.cpp | 15 ++++++++++--- src/core/hbl_env.cpp | 10 ++++++++- src/core/include/hbl_env.h | 3 +++ src/core/operation.cpp | 2 +- 9 files changed, 56 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97883387c..606efc09f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -420,7 +420,7 @@ if(${MPI_FOUND}) COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS} ${DEFAULT_WARNING_FLAGS} ${MPI_COMPILE_FLAGS} ${OpenMP_CXX_FLAGS} -g " LINK_FLAGS "${DEFAULT_LINK_FLAGS} ${MPI_LINK_FLAGS} ${OpenMP_CXX_FLAGS} -g " else(${OPENMP_FOUND}) - COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS} ${DEFAULT_WARNING_FLAGS} ${MPI_COMPILE_FLAGS} -g " + COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS} ${DEFAULT_WARNING_FLAGS} ${MPI_COMPILE_FLAGS} " LINK_FLAGS "${DEFAULT_LINK_FLAGS} ${MPI_LINK_FLAGS}" endif(${OPENMP_FOUND}) ) diff --git a/res/TemplateBatchFiles/SelectionAnalyses/modules/shared-load-file.bf b/res/TemplateBatchFiles/SelectionAnalyses/modules/shared-load-file.bf index a71c0c1e3..cb3a69b46 100644 --- a/res/TemplateBatchFiles/SelectionAnalyses/modules/shared-load-file.bf +++ b/res/TemplateBatchFiles/SelectionAnalyses/modules/shared-load-file.bf @@ -86,10 +86,14 @@ function load_file (prefix) { name_mapping = {}; utility.ForEach (alignments.GetSequenceNames (prefix+".codon_data"), "_value_", "`&name_mapping`[_value_] = _value_"); } - + + utility.SetEnvVariable(utility.getGlobalValue ("terms.trees.data_for_neighbor_joining"), + codon_data_info[utility.getGlobalValue("terms.data.datafilter")]); partitions_and_trees = trees.LoadAnnotatedTreeTopology.match_partitions (codon_data_info[utility.getGlobalValue("terms.data.partitions")], name_mapping); + utility.SetEnvVariable(utility.getGlobalValue ("terms.trees.data_for_neighbor_joining"), None); + /** this will return a dictionary of partition strings and trees; one set per partition, as in { "0": { diff --git a/res/TemplateBatchFiles/libv3/all-terms.bf b/res/TemplateBatchFiles/libv3/all-terms.bf index b8883290a..ede41e696 100644 --- a/res/TemplateBatchFiles/libv3/all-terms.bf +++ b/res/TemplateBatchFiles/libv3/all-terms.bf @@ -484,6 +484,9 @@ namespace terms{ branches = "branches"; meta = "meta"; comment = "comment"; + neighbor_joining = "neighbor-joining"; + data_for_neighbor_joining + = "FILTER_FOR_NEIGHBOR_JOINING"; //node_name = "Name"; //children = "Children"; diff --git a/res/TemplateBatchFiles/libv3/tasks/trees.bf b/res/TemplateBatchFiles/libv3/tasks/trees.bf index de58698fc..409881ca4 100644 --- a/res/TemplateBatchFiles/libv3/tasks/trees.bf +++ b/res/TemplateBatchFiles/libv3/tasks/trees.bf @@ -132,11 +132,27 @@ lfunction trees.GetTreeString(look_for_newick_tree) { if (!utility.GetEnvVariable("IS_TREE_PRESENT_IN_DATA")) { SetDialogPrompt("Please select a tree file for the data:"); + utility.SetEnvVariable ("LAST_FILE_IO_EXCEPTION", None); + utility.ToggleEnvVariable ("SOFT_FILE_IO_EXCEPTIONS",TRUE); fscanf(PROMPT_FOR_FILE, REWIND, "Raw", treeString); - fprintf(stdout, "\n"); - + look_for_newick_tree = utility.getGlobalValue ("LAST_FILE_PATH"); + + if (None != utility.GetEnvVariable ("LAST_FILE_IO_EXCEPTION")) { + if (utility.getGlobalValue ("LAST_RAW_FILE_PROMPT") == utility.getGlobalValue ("terms.trees.neighbor_joining")) { + datafilter_name = utility.GetEnvVariable(utility.getGlobalValue ("terms.trees.data_for_neighbor_joining")); + assert (Type (datafilter_name) == "String", "Expected a string for the datafilter to build a NJ tree from"); + treeString = tree.infer.NJ (datafilter_name, None); + } else { + assert (0, utility.GetEnvVariable ("LAST_FILE_IO_EXCEPTION")); + } + utility.SetEnvVariable ("LAST_FILE_IO_EXCEPTION", None); + } + + utility.ToggleEnvVariable ("SOFT_FILE_IO_EXCEPTIONS",None); + fprintf(stdout, "\n"); + if (regexp.Find(treeString, "^#NEXUS")) { ExecuteCommands(treeString); @@ -295,7 +311,7 @@ lfunction trees.LoadAnnotatedTreeTopology.match_partitions(partitions, mapping) utility.getGlobalValue("terms.data.tree"): trees.LoadAnnotatedTopologyAndMap(tree_matrix[i][1], mapping) }; } - } else { // no tree matrix; allow if there is a single partition + } else { // no tree matrix; apply the same tree to all partitions tree_info = trees.LoadAnnotatedTopologyAndMap(TRUE, mapping); diff --git a/src/core/batchlanhelpers.cpp b/src/core/batchlanhelpers.cpp index 4e4813d79..0db7ce707 100644 --- a/src/core/batchlanhelpers.cpp +++ b/src/core/batchlanhelpers.cpp @@ -243,17 +243,20 @@ _String const ReturnFileDialogInput(_String const * rel_path) { try { _String dialog_string (currentExecutionList->FetchFromStdinRedirect()); if (dialog_string.nonempty()) { + hy_env::EnvVariableSet (hy_env::last_raw_file_prompt, new _FString (dialog_string), false); return dialog_string; } } catch (_String const e) { if (e != kNoKWMatch) { HandleApplicationError (e); + hy_env::EnvVariableSet (hy_env::last_raw_file_prompt, new _FString(), false); return kEmptyString; } } } _String file_path = ReturnDialogInput(true, rel_path); + hy_env::EnvVariableSet (hy_env::last_raw_file_prompt, new _FString (file_path), false); terminate_execution = file_path.empty(); return file_path; } diff --git a/src/core/batchlanruntime.cpp b/src/core/batchlanruntime.cpp index 984c8bfaa..51910294a 100644 --- a/src/core/batchlanruntime.cpp +++ b/src/core/batchlanruntime.cpp @@ -2516,7 +2516,12 @@ bool _ElementaryCommand::HandleFprintf (_ExecutionList& current_program) { } catch (const _String& error) { - success = _DefaultExceptionHandler (nil, error, current_program); + if (hy_env::EnvVariableTrue(hy_env::soft_fileio_exceptions)) { + hy_env::EnvVariableSet(hy_env::last_fileio_exception, new _FString (error,false), false); + success = true; + } else { + success = _DefaultExceptionHandler (nil, error, current_program); + } } if (destination_file && destination_file != hy_message_log_file && do_close) { @@ -3317,7 +3322,7 @@ bool _ElementaryCommand::HandleFscanf (_ExecutionList& current_program, boo _String source_name = *GetIthParameter(0UL); if (source_name == kFscanfStdin) { - bool need_to_ask_user = true; + bool need_to_ask_user = true; if (current_program.has_stdin_redirect () || current_program.has_keyword_arguments()) { try { _FString * redirect = (_FString*)hy_env::EnvVariableGet(hy_env::fprintf_redirect, STRING); @@ -3545,7 +3550,11 @@ bool _ElementaryCommand::HandleFscanf (_ExecutionList& current_program, boo last_call_stream_position += current_stream_position - started_here_position; } catch (const _String& error) { - return _DefaultExceptionHandler (nil, error, current_program); + if (hy_env::EnvVariableTrue(hy_env::soft_fileio_exceptions)) { + hy_env::EnvVariableSet(hy_env::last_fileio_exception, new _FString (error,false), false); + return true; + } + return _DefaultExceptionHandler (nil, error, current_program); } return true; diff --git a/src/core/hbl_env.cpp b/src/core/hbl_env.cpp index 23ec9d52a..8584b3757 100644 --- a/src/core/hbl_env.cpp +++ b/src/core/hbl_env.cpp @@ -238,7 +238,12 @@ _String const last_file_path ("LAST_FILE_PATH"), // is set by various file read/write commands (fscanf, fprintf, dialog prompts) // to contain the **absolute** path to the last file interacted with - last_model_parameter_list ( "LAST_MODEL_PARAMETER_LIST"), + last_fileio_exception ("LAST_FILE_IO_EXCEPTION"), + // set to the value of the last exception if soft_fileio_exceptions is true, + + last_raw_file_prompt ("LAST_RAW_FILE_PROMPT"), + // the last unprocessed value obtained by PROMPT_FOR_FILE + last_model_parameter_list ("LAST_MODEL_PARAMETER_LIST"), // a stand-in for the list of model parameters for the last // declared model @@ -284,6 +289,9 @@ _String const // controls the return format of optimized functions from MPI slave nodes skip_omissions ("SKIP_OMISSIONS"), // if set, will cause data filters to _EXCLUDE_ sites with gaps or other N-fold redundancies + soft_fileio_exceptions ("SOFT_FILE_IO_EXCEPTIONS"), + // if set, read/write errors from fscanf and fprintf will not cause a program termination + // but rather set the last_fileio_exception variable to the value of the exception status_bar_update_string ("STATUS_BAR_STATUS_STRING"), // used to set the progress message displayed to the user try_numeric_sequence_match ("TRY_NUMERIC_SEQUENCE_MATCH"), diff --git a/src/core/include/hbl_env.h b/src/core/include/hbl_env.h index e908a0faf..0b0087910 100644 --- a/src/core/include/hbl_env.h +++ b/src/core/include/hbl_env.h @@ -193,6 +193,9 @@ namespace hy_env { kExpectedNumberOfSubstitutions, kStringSuppliedLengths, kDevNull, + soft_fileio_exceptions, + last_fileio_exception, + last_raw_file_prompt, include_model_spec, lf_convergence_criterion, try_numeric_sequence_match, diff --git a/src/core/operation.cpp b/src/core/operation.cpp index ea9bc4397..1b16f5bb8 100644 --- a/src/core/operation.cpp +++ b/src/core/operation.cpp @@ -447,7 +447,7 @@ bool _Operation::Execute (_Stack& theScrap, _VariableContainer const* nam if (!isRefVar) { if (argument_var->IsIndependent() && (argument_var->ObjectClass() & (TREE|TOPOLOGY)) == 0) { // if the variable exists and is independent then - // simply swap the value of the var, otherwise + // simply swap the 10value of the var, otherwise // duplicate the entire variable argument_var->varFlags &= HY_VARIABLE_SET; if (!argument_var->varValue) {