Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8bf7566
added function to read fasta and nexus for tree inference
foersterst Jan 27, 2026
796aa49
New simplified structure
maribraga Jan 27, 2026
63f71dd
Add package overview vignette
maribraga Jan 28, 2026
f788816
Merge pull request #2 from foersterst/read-aln
maribraga Jan 28, 2026
23c9a24
added function to read fasta and nexus for tree inference
foersterst Jan 27, 2026
f249da0
Complete merge of tp_data
maribraga Jan 28, 2026
811041b
Merge branch 'main' into reorg
maribraga Jan 28, 2026
db8069d
Remove option of path to json in tp_data
maribraga Jan 28, 2026
29ad813
Replace magrittr with base r pipe
maribraga Jan 30, 2026
dfe951f
Update coin vignette with new functions
maribraga Jan 30, 2026
3fedd23
Move fasta and nexus to data R file
maribraga Jan 30, 2026
53f1d88
Remove models from subfolders and some unused functions
maribraga Jan 30, 2026
ba80bf6
Remove tutorials that are not updated
maribraga Jan 30, 2026
0864a10
Remove tutorials that are not updated
maribraga Jan 30, 2026
d5b7fae
Models and data now come from treeppl repo
maribraga Jan 30, 2026
0459e6e
Add test_compile
maribraga Jan 30, 2026
4e7b968
Small fixes
maribraga Jan 30, 2026
20238d2
Add test_run
maribraga Jan 30, 2026
e7ec04e
Finish adding tests
maribraga Feb 2, 2026
53d5440
Fix all check errors and warnings
maribraga Feb 2, 2026
c5c457f
Remove outdated vignettes
maribraga Feb 2, 2026
2d858c7
Trying to fix pkgdown error
maribraga Feb 2, 2026
45a09e5
Test crbd vignette
maribraga Feb 2, 2026
7acb60b
Dont run test
maribraga Feb 2, 2026
1476b64
Remove all calls to the self-contained models folder
maribraga Feb 2, 2026
35a23dc
Merge branch 'treeppl:main' into main
maribraga Feb 2, 2026
55c5b6b
Rename getting started vignette
maribraga Feb 2, 2026
d817aca
Make the test Platform and version proof + now handle more corner cas…
ThimotheeV Feb 5, 2026
3adaed4
Merge pull request #3 from ThimotheeV/Correction_failing_path
maribraga Feb 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ Depends:
Imports:
assertthat,
methods,
readr,
jsonlite,
stringr,
tidytree,
utils,
gh,
curl,
cli,
magrittr,
bnpsd
bnpsd,
rlang,
phangorn
Suggests:
devtools,
ggplot2,
Expand All @@ -40,8 +39,7 @@ Suggests:
treeio (>= 1.32.0),
rmarkdown,
pandoc,
dplyr,
rlang
dplyr
VignetteBuilder: knitr
Config/Needs/website: rmarkdown
Remotes:
Expand Down
21 changes: 10 additions & 11 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(tp_compile)
export(tp_data)
export(tp_fp_fetch)
export(tp_expected_input)
export(tp_json_to_phylo)
export(tp_list)
export(tp_map_tree)
export(tp_model)
export(tp_model_names)
export(tp_parse)
export(tp_model_library)
export(tp_parse_host_rep)
export(tp_parse_mcmc)
export(tp_parse_smc)
export(tp_phylo_to_tpjson)
export(tp_run)
export(tp_run_options)
export(tp_smc_convergence)
export(tp_stored_compiled)
export(tp_stored_data)
export(tp_stored_model)
export(tp_tempdir)
export(tp_treeppl)
export(tp_treeppl_json)
export(tp_write)
export(tp_write_data)
export(tp_write_model)
importFrom(bnpsd,tree_reorder)
importFrom(magrittr,"%>%")
importFrom(methods,is)
importFrom(phangorn,add_edge_length)
importFrom(phangorn,allCompat)
importFrom(rlang,.data)
14 changes: 0 additions & 14 deletions R/checker.R

This file was deleted.

176 changes: 176 additions & 0 deletions R/compile.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#' Options that can be passed to TreePPL compiler
#'
#' @returns A string with the output from the compiler's help <tpplc --help>
#'
tp_compile_options <- function() {

#### under development ####

# text from tpplc --help
return()

}



#' Compile a TreePPL model and create inference machinery
#'
#' @description
#' `tp_compile` compile a TreePPL model and create inference machinery to be
#' used by [treepplr::tp_run].
#'
#' @param model One of tree options:
#' * The full path of the model file that contains the TreePPL code, OR
#' * A string with the name of a model supported by treepplr
#' (see [treepplr::tp_model_library()]), OR
#' * A string containing the entire TreePPL code.
#' @param method Inference method to be used. See tp_compile_options()
#' for all supported methods.
#' @param iterations The number of MCMC iterations to be run.
#' @param particles The number of SMC particles to be run.
#' @param dir The directory where you want to save the executable. Default is
#' [base::tempdir()]
#' @param output Complete path to the compiled TreePPL program that will be
#' created. Default is dir/<name of the model object>.exe
#' @param ... See tp_compile_options() for all supported arguments.
#'
#' @return The path for the compiled TreePPL program.
#' @export

tp_compile <- function(model,
method,
iterations = NULL,
particles = NULL,
dir = NULL,
output = NULL,
...) {

options(scipen=999)

if(is.null(dir)){
dir_path <- tp_tempdir()
} else {
dir_path <- dir
}

# check path, find or write model
model_file_name <- tp_model(model)

musts <- paste("-m", method)

if(is.null(iterations) & is.null(particles)){
stop("If using MCMC, please choose number of iterations.
If using SMC, please choose number of particles.")
}

if(!is.null(iterations)){
musts <- paste(musts, "--particles", iterations)
}

if(!is.null(particles)){
musts <- paste(musts, "--particles", particles)
}

# create string with other options to tpplc
args_list <- list(...)
args_vec <- unlist(args_list)

vec <- c()
for(i in seq_along(args_vec)) {
str <- paste0("--", names(args_vec[i]), " ", args_vec[[i]])
vec <- c(vec, str)
}

args_str <- paste(vec, collapse = " ")

# output
if(is.null(output)){
output_path <- paste0(dir_path, names(model_file_name), ".exe")
} else {
output_path <- output
}

options <- paste("--output", output_path, args_str)

# Preparing the command line program
tpplc_path <- installing_treeppl() #### move this? ####
command <- paste(tpplc_path, model_file_name, musts, options)

# Compile program
# Empty LD_LIBRARY_PATH from R_env for this command specifically
# due to conflict with internal env from treeppl self-contained
system(paste0("LD_LIBRARY_PATH= MCORE_LIBS= ", command))

return(output_path)
}



#' Import a TreePPL model
#'
#' @description
#' `tp_model` takes TreePPL code and prepares it to be used by
#' [treepplr::tp_compile()].
#'
#' @param model_input One of tree options:
#' * The full path of the model file that contains the TreePPL code, OR
#' * A string with the name of a model supported by treepplr
#' (see [treepplr::tp_model_library()]), OR
#' * A string containing the entire TreePPL code.
#'
#' @return The path to the TreePPL model file
#' @export
tp_model <- function(model_input) {

if (!assertthat::is.string(model_input)){
stop("Input has to be a sring.")
}

res <- try(file.exists(model_input), silent = TRUE)

# If path exists, it's all good
if (!is(res,"try-error") && res) {
model_path <- model_input
# name the model
if (is.null(names(model_path))){
names(model_path) <- "custom_model"
}

# If path doesn't exist
} else {
# It can be a model name in the library
res_lib <- try(tp_find_model(model_input), silent = TRUE)
# model_input has the name of a known model
if (!is(res_lib,"try-error") && length(res_lib) != 0) {
model_path <- res_lib
names(model_path) <- model_input
# OR model_input contains the model
#### (needs to be verified as an appropriate model later) ####
} else {
model_path <- tp_write_model(model_input)
names(model_path) <- "custom_model"
}
}
return(model_path)
}




#' Write out a custom model to tp_tempdir()
#'
#' @param model A string containing the entire TreePPL code.
#' @param model_file_name An optional name to the file created
#'
#' @returns The path to the file created
#' @export
#'
tp_write_model <- function(model, model_file_name = "tmp_model_file") {

path <- paste0(tp_tempdir(), model_file_name, ".tppl")
cat(model, file = path)

return(path)

}

Loading