Skip to content

Commit

Permalink
Merge pull request #1766 from veg/develop
Browse files Browse the repository at this point in the history
2.5.64
  • Loading branch information
spond authored Nov 25, 2024
2 parents cc6eee3 + 5997213 commit 0abf1c4
Show file tree
Hide file tree
Showing 8 changed files with 881 additions and 24 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enable_testing()

set(CMAKE_CONFIGURATION_TYPES Release)


#-------------------------------------------------------------------------------
# OPTIONS
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -170,12 +171,14 @@ set_source_files_properties(${SRC_CORE} ${SRC_NEW} {SRC_UTILS} PROPERTIES COMPIL

set(DEFAULT_WARNING_FLAGS " -w -Weffc++ -Wextra -Wall ")
set(DEFAULT_DEBUG_WARNING_FLAGS "-Wall -Wno-int-to-pointer-cast -Wno-conversion-null -Wno-sign-compare")
set(ADDITIONAL_FLAGS "")
set(ADDITIONAL_FLAGS "-g")

if (DEBUGFLAGS)
set(ADDITIONAL_FLAGS "-g")
endif()

#include_directories("/Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk/usr/include/c++/v1")


if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
execute_process(
Expand Down Expand Up @@ -371,6 +374,7 @@ endif(NOT NOZLIB)




#-------------------------------------------------------------------------------
# uninstall target
#-------------------------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ And then run make install to install the software
+ libhyphy_mp.(so/dylib/dll) will be installed at `/location/of/choice/lib`
+ HyPhy's standard library of batchfiles will go into `/location/of/choice/lib/hyphy`

#### Building HyPhy for Web Assembly

Use [Emscripten](https://emscripten.org/docs/compiling/Building-Projects.html) to produce web assembly files, which can be run entirely within a modern browser. See https://observablehq.com/@spond/hyphy-biowasm for an example.

```
emcmake cmake -DCMAKE_EXE_LINKER_FLAGS="-sTOTAL_STACK=2097152 -02 -sASSERTIONS=1 -sMODULARIZE=1 -sALLOW_MEMORY_GROWTH -sFORCE_FILESYSTEM=1 -sEXIT_RUNTIME=0 -s EXPORTED_RUNTIME_METHODS=["callMain","FS","PROXYFS","WORKERFS","UTF8ToString","getValue","AsciiToString"] -lworkerfs.js -lproxyfs.js -s INVOKE_RUN=0 -s ENVIRONMENT="web,worker" ${EM_FLAGS//-s /-s} -fwasm-exceptions --preload-file res@/hyphy --preload-file tests/hbltests@/tests"
```

```
emmake make -j hyphy
```

This creates

```
hyphy.js
hyphy.wasm
hyphy.data
```

Which should be served from the same directory.

#### Testing

Expand Down
30 changes: 10 additions & 20 deletions res/TemplateBatchFiles/F_ST.bf
Original file line number Diff line number Diff line change
Expand Up @@ -242,42 +242,32 @@ if (distanceChoice == "Full likelihood") {
{
for (j = 0; j<=i; j = j+1)
{
if (dataType)
{
if (dataType == "Codon") {
DataSetFilter twoSpecFilter = CreateFilter (filteredData,3,"",(speciesIndex==i+1)||(speciesIndex==j),GeneticCodeExclusions);
}
else
{
else {
DataSetFilter twoSpecFilter = CreateFilter (filteredData,1,"",(speciesIndex==i+1)||(speciesIndex==j));
}
if (FREQUENCY_SENSITIVE)
{
if (USE_POSITION_SPECIFIC_FREQS)
{
if (FREQUENCY_SENSITIVE) {
if (USE_POSITION_SPECIFIC_FREQS) {
HarvestFrequencies (vectorOfFrequencies,filteredData,3,1,1);
}
else
{
else {
HarvestFrequencies (vectorOfFrequencies,twoSpecFilter,1,1,0);
}
}
if (FREQUENCY_SENSITIVE)
{
if (FREQUENCY_SENSITIVE) {
MULTIPLY_BY_FREQS = PopulateModelMatrix ("modelMatrix",vectorOfFrequencies);
if (dataType)
{
if (dataType == "Codon") {
codonFrequencies = BuildCodonFrequencies (vectorOfFrequencies);
Model pairModel = (modelMatrix, codonFrequencies, MULTIPLY_BY_FREQS);
}
else
{
else {
Model pairModel = (modelMatrix, vectorOfFrequencies, MULTIPLY_BY_FREQS);
}
}
else
{
if (i+j==0)
{
else {
if (i+j==0) {
MULTIPLY_BY_FREQS = PopulateModelMatrix ("modelMatrix",equalFreqs);
Model pairModel = (modelMatrix, equalFreqs, MULTIPLY_BY_FREQS);
}
Expand Down
114 changes: 114 additions & 0 deletions res/TemplateBatchFiles/libv3/models/codon/MG_GTR.bf
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
RequireVersion ("2.5.60");

LoadFunctionLibrary("../codon.bf");
LoadFunctionLibrary("../DNA.bf");
LoadFunctionLibrary("../parameters.bf");
LoadFunctionLibrary("../frequencies.bf");
LoadFunctionLibrary("../../UtilityFunctions.bf");
LoadFunctionLibrary("MG_REV.bf");
LoadFunctionLibrary("../protein.bf");

/** @module models.codon.GTR */
//----------------------------------------------------------------------------------------------------------------


lfunction model.codon.MG_GTR.prompt_and_define (type, code) {
console.log (type);
return models.codon.MG_GTR.ModelDescription(type, code);
}

lfunction models.codon.MG_GTR.ModelDescription(type, code) {


io.CheckAssertion ("`&type` == '`^'terms.global'`'", "MG_GTR only supports `^'terms.global'` type");

// piggyback on the standard MG_REV model for most of the code

mg_base = models.codon.MG_REV.ModelDescription (type, code);
mg_base[utility.getGlobalValue("terms.description")] = "The Muse-Gaut 94 codon-substitution model coupled with the general time reversible (GTR) model of nucleotide substitution, which defines a separate dN/dS ratio for each pair of amino-acids";
mg_base[utility.getGlobalValue("terms.model.q_ij")] = "models.codon.MG_GTR._GenerateRate";
mg_base[utility.getGlobalValue("terms.model.post_definition")] = "models.codon.MG_GTR.post_definition";
return mg_base;
}

lfunction models.codon.MG_GTR._GenerateRate(fromChar, toChar, namespace, model_type, model) {

return models.codon.MG_GTR._GenerateRate_generic (fromChar, toChar, namespace, model_type,
model[utility.getGlobalValue("terms.translation_table")],
"alpha", utility.getGlobalValue("terms.parameters.synonymous_rate"),
"omega", utility.getGlobalValue("terms.parameters.omega_ratio"),
);
}

/**
* @name models.codon.MG_GTR._GenerateRate
* @param {Number} fromChar
* @param {Number} toChar
* @param {String} namespace
* @param {String} model_type
* @param {Matrix} _tt - translation table
*/


lfunction models.codon.MG_GTR._GenerateRate_generic (fromChar, toChar, namespace, model_type, _tt, alpha, alpha_term, omega, omega_term) {

_GenerateRate.p = {};
_GenerateRate.diff = models.codon.diff.complete(fromChar, toChar);
diff_count = utility.Array1D (_GenerateRate.diff);

if (diff_count == 1) {

_GenerateRate.p[model_type] = {};
_GenerateRate.p[utility.getGlobalValue("terms.global")] = {};

nuc_rate = "";

for (i = 0; i < diff_count; i += 1) {
if ((_GenerateRate.diff[i])[utility.getGlobalValue("terms.diff.from")] > (_GenerateRate.diff[i])[utility.getGlobalValue("terms.diff.to")]) {
nuc_p = "theta_" + (_GenerateRate.diff[i])[utility.getGlobalValue("terms.diff.to")] + (_GenerateRate.diff[i])[utility.getGlobalValue("terms.diff.from")];
} else {
nuc_p = "theta_" + (_GenerateRate.diff[i])[utility.getGlobalValue("terms.diff.from")] +(_GenerateRate.diff[i])[utility.getGlobalValue("terms.diff.to")];
}
nuc_p = parameters.ApplyNameSpace(nuc_p, namespace);
(_GenerateRate.p[utility.getGlobalValue("terms.global")])[terms.nucleotideRateReversible((_GenerateRate.diff[i])[utility.getGlobalValue("terms.diff.from")], (_GenerateRate.diff[i])[utility.getGlobalValue("terms.diff.to")])] = nuc_p;

nuc_rate = parameters.AppendMultiplicativeTerm (nuc_rate, nuc_p);
}

rate_entry = nuc_rate;

if (_tt[fromChar] != _tt[toChar]) {

if (_tt[fromChar] < _tt[toChar]) {
aa_pair = _tt[fromChar] + " and " + _tt[toChar];
aa_tag = "_" + _tt[fromChar] + _tt[toChar];
} else {
aa_pair = _tt[toChar] + " and " + _tt[fromChar];
aa_tag = "_" + _tt[toChar] + _tt[fromChar];
}

omega_p = parameters.ApplyNameSpace (omega + aa_tag , namespace);
(_GenerateRate.p[model_type]) [^"terms.parameters.omega_ratio" + " for " + aa_pair] = omega_p;

rate_entry = parameters.AppendMultiplicativeTerm (rate_entry, omega_p);
} else {
_GenerateRate.p[utility.getGlobalValue("terms.model.rate_entry")] = nuc_rate;
}

_GenerateRate.p[utility.getGlobalValue("terms.model.rate_entry")] = rate_entry;
}
return _GenerateRate.p;
}

lfunction models.codon.MG_GTR.post_definition (model) {

for (id; in ; model.GetParameters_RegExp (model, ^"terms.parameters.omega_ratio")) {
parameters.SetValue(id, 0.25);
}

models.generic.post.definition (model);
}

lfunction models.codon.MG_GTR.set_branch_length(model, value, parameter) {
return models.codon.MG_REV.set_branch_length(model,value,parameter);
}
Loading

0 comments on commit 0abf1c4

Please sign in to comment.