Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ RoxygenNote: 7.3.3
URL: https://github.com/treeppl/treepplr,
http://treeppl.org/treepplr/
BugReports: https://github.com/treeppl/treepplr/issues
Depends:
R (>= 4.1.0)
Imports:
assertthat,
methods,
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@

## Overview

treepplr is the R Interface to [TreePPL](treeppl.org), a probabilistic programming language for phylogenetics.
treepplr is the R Interface to [TreePPL](https://treeppl.org), a probabilistic programming language for phylogenetics.

treepplr converts data to a format readable by TreePPL, reads the TreePPL output, and connects to downstream analyses in model-specific packages, such as the [evolnets](github.com/maribraga/evolnets) package for the host repertoire evolution model.
treepplr converts data to a format readable by TreePPL, reads the TreePPL output,
and connects to downstream analyses in model-specific packages, such as the
[evolnets](https://github.com/maribraga/evolnets) package for the host repertoire evolution model.

See the package's documentation [here](treeppl.org/treepplr).
See the package's documentation [here](https://treeppl.org/treepplr). There you
will find all package functions under [Reference](https://treeppl.org/treepplr/reference/index.html),
and basic examples of running various models under [Articles](https://treeppl.org/treepplr/articles/index.html).


## Installation

You can install treepplr like so:

``` r
# install.packages("devtools")
# library(devtools)
if(!require("devtools", quietly = TRUE)) {
install.packages("devtools")
library(devtools)
} else {
library(devtools)
}

devtools::install_github("treeppl/treepplr")
```
36 changes: 18 additions & 18 deletions inst/extdata/hostrep3states.tppl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import "host-rep-lib/lib.tppl"
import "host-rep-lib/container-types.tppl"
import "host-rep-lib/helpers.tppl"
import "host-rep-lib/belief-propagation.tppl"
import "host-rep-lib/dist-helpers.tppl"
import "host-rep-lib/full-model.tppl"
import "host-rep-lib/rb-drift-kernels.tppl"
import "host-rep-lib/independence-model.tppl"
import "treeppl::models/host-repertoire-evolution/host-rep-lib/lib.tppl"
import "treeppl::models/host-repertoire-evolution/host-rep-lib/container-types.tppl"
import "treeppl::models/host-repertoire-evolution/host-rep-lib/helpers.tppl"
import "treeppl::models/host-repertoire-evolution/host-rep-lib/belief-propagation.tppl"
import "treeppl::models/host-repertoire-evolution/host-rep-lib/dist-helpers.tppl"
import "treeppl::models/host-repertoire-evolution/host-rep-lib/full-model.tppl"
import "treeppl::models/host-repertoire-evolution/host-rep-lib/rb-drift-kernels.tppl"
import "treeppl::models/host-repertoire-evolution/host-rep-lib/independence-model.tppl"

type ReturnType = ReturnType{
lambda: Real[], mu: Real, beta: Real, tree: HistoryTree
Expand Down Expand Up @@ -54,7 +54,7 @@ model function rejectAccept(
let leftMsg = mtxMul(newMsg, postorderTree.leftKernel);
let rightMsg = mtxMul(newMsg, postorderTree.rightKernel);

// Construct an object containing the rate matrix in a suitable format for sampling
// Construct an object containing the rate matrix in a suitable format for sampling
// from the embedded Markov chain

let embeddedQMatrix = rateMatrixToEmbeddedMarkovChain(qMatrix);
Expand Down Expand Up @@ -84,12 +84,12 @@ model function rejectAccept(
beta = beta,
tree = historyTree
};
}
}

function suggestRepAligned(msg: Matrix[Real], i: Int, max: Int) => Int[] {
if i <= max {
let param = mtx3ToSeq(msg, i);
assume x ~ Categorical(param) drift categoricalMove(x, param);
assume x ~ Categorical(param) drift categoricalMove(x, param);
return cons(x, suggestRepAligned(msg, i + 1, max));
} else {
return [];
Expand All @@ -115,7 +115,7 @@ function suggestRepRS(msg: Matrix[Real], max: Int, initialRep: Int[], depth: Int
function suggestRepUnaligned(msg: Matrix[Real], i: Int, max: Int) => Int[] {
if i <= max {
let param = mtx3ToSeq(msg, i);
assume x ~ Categorical(param);
assume x ~ Categorical(param);
return paste0([[x], suggestRepUnaligned(msg, i + 1, max)]);
} else {
return [];
Expand Down Expand Up @@ -234,11 +234,11 @@ function sampleBranch(
let orderedEvents = qSort(compAge, allHostEvents);
let nEvents = length(orderedEvents);
if allTimesValidBranch(startRep, orderedEvents, 1, nEvents, nhosts) {
// The branch is correct along the full history,
// The branch is correct along the full history,
// accept and calculate the true weight of the sample

// Calculate the debt -- this is the density of the endpoint conditioned
// (parallel) chains at the current sample.
// (parallel) chains at the current sample.
let logDebt = independenceLikelihoodEndCond(
startRep, finalRep, startAge, finalAge, unorderedBranch.history, modelParams, branchKernel
);
Expand Down Expand Up @@ -274,17 +274,17 @@ function sampleBranch(
logDebt = -log(0.0),
logExcess = log(0.0),
success = false
};
};
}
}

function compAge(left: Event, right: Event) => Int {
if (isNaN(right.eventTime)) {
return -1;
}
}
if (isNaN(left.eventTime)) {
return 1;
}
}
if (right.eventTime >= left.eventTime) {
return 1;
} else {
Expand Down