Skip to content

Commit

Permalink
Update ts_load/ts_save
Browse files Browse the repository at this point in the history
  • Loading branch information
bodkan committed Oct 28, 2024
1 parent 6a35b87 commit a32be78
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions tests/testthat/test-simulate-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test_that("basic simulate_model() runs produce a tree-sequence file (SLiM)", {
format = "files",
data = data_list
)
expect_s3_class(ts_load(norm_path(file.path(result$path, "slim.trees"))), "slendr_ts")
expect_s3_class(ts_read(norm_path(file.path(result$path, "slim.trees"))), "slendr_ts")
})

test_that("basic simulate_model() runs produce a tree-sequence file (msprime)", {
Expand All @@ -57,7 +57,7 @@ test_that("basic simulate_model() runs produce a tree-sequence file (msprime)",
format = "files",
data = data_list
)
expect_s3_class(ts_load(norm_path(file.path(result$path, "msprime.trees"))), "slendr_ts")
expect_s3_class(ts_read(norm_path(file.path(result$path, "msprime.trees"))), "slendr_ts")
})

test_that("for customized files, data-generating functions must be provided", {
Expand All @@ -76,8 +76,8 @@ test_that("format = 'ts' allows only 'ts' and 'model' to be available in data fu
engine = "slim",
format = "ts",
data = list(
ts = function(path, model) file.path(path, "slim.trees") %>% ts_load(model),
gt = function(path, model) file.path(path, "slim.trees") %>% ts_load(model) %>% ts_mutate(1e-8) %>% ts_genotypes()
ts = function(path, model) file.path(path, "slim.trees") %>% ts_read(model),
gt = function(path, model) file.path(path, "slim.trees") %>% ts_read(model) %>% ts_mutate(1e-8) %>% ts_genotypes()
)
),
"The following function arguments are not valid: \"path\"."
Expand All @@ -89,8 +89,8 @@ test_that("format = 'ts' allows only 'ts' and 'model' to be available in data fu
sequence_length = 1e6, recombination_rate = 1e-8,
engine = "slim",
format = "files", data = list(
ts = function(path, model) file.path(path, "slim.trees") %>% ts_load(model),
gt = function(path, model) file.path(path, "slim.trees") %>% ts_load(model) %>% ts_mutate(1e-8) %>% ts_genotypes()
ts = function(path, model) file.path(path, "slim.trees") %>% ts_read(model),
gt = function(path, model) file.path(path, "slim.trees") %>% ts_read(model) %>% ts_mutate(1e-8) %>% ts_genotypes()
)
))
)
Expand All @@ -107,8 +107,8 @@ test_that("format = 'ts' allows only 'ts' and 'model' to be available in data fu
engine = "msprime",
format = "ts",
data = list(
ts = function(path, model) file.path(path, "slim.trees") %>% ts_load(model),
gt = function(path, model) file.path(path, "slim.trees") %>% ts_load(model) %>% ts_mutate(1e-8) %>% ts_genotypes()
ts = function(path, model) file.path(path, "slim.trees") %>% ts_read(model),
gt = function(path, model) file.path(path, "slim.trees") %>% ts_read(model) %>% ts_mutate(1e-8) %>% ts_genotypes()
)
),
"The following function arguments are not valid: \"path\"."
Expand All @@ -120,8 +120,8 @@ test_that("format = 'ts' allows only 'ts' and 'model' to be available in data fu
sequence_length = 1e6, recombination_rate = 1e-8,
engine = "msprime",
format = "files", data = list(
ts = function(path, model) file.path(path, "msprime.trees") %>% ts_load(model),
gt = function(path, model) file.path(path, "msprime.trees") %>% ts_load(model) %>% ts_mutate(1e-8) %>% ts_genotypes()
ts = function(path, model) file.path(path, "msprime.trees") %>% ts_read(model),
gt = function(path, model) file.path(path, "msprime.trees") %>% ts_read(model) %>% ts_mutate(1e-8) %>% ts_genotypes()
)
))
)
Expand Down Expand Up @@ -151,7 +151,7 @@ test_that("format = 'custom' allows only 'path' and 'model' to be available", {
engine = "slim",
format = "files",
data = list(
gt = function(path, model) file.path(path, "slim.trees") %>% ts_load(model) %>% ts_mutate(1e-8) %>% ts_genotypes()
gt = function(path, model) file.path(path, "slim.trees") %>% ts_read(model) %>% ts_mutate(1e-8) %>% ts_genotypes()
)
)$gt,
"data.frame"
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-summarise-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ data <- simulate_model(
engine = "slim",
format = "files",
data = list(
ts = function(path, model) file.path(path, "slim.trees") %>% ts_load(model),
samples = function(path, model) file.path(path, "slim.trees") %>% ts_load(model) %>% ts_names(split = "pop"),
ts = function(path, model) file.path(path, "slim.trees") %>% ts_read(model),
samples = function(path, model) file.path(path, "slim.trees") %>% ts_read(model) %>% ts_names(split = "pop"),
stats = function(path) file.path(path, "stats.tsv") %>% read.table(header = TRUE)
)
)
Expand Down Expand Up @@ -90,7 +90,7 @@ test_that("summarise_data produces data frames for every summary function", {
test_that("summarise_data can utilize pre-computed statistics as data (pre-defined data functions)", {
data_functions <- list(
ts_pi = function(path, model) {
ts <- file.path(path, "slim.trees") %>% ts_load(model)
ts <- file.path(path, "slim.trees") %>% ts_read(model)
ts_diversity(ts, ts_names(ts, split = "pop"))
},
slim_pi = function(path) file.path(path, "stats.tsv") %>%
Expand Down Expand Up @@ -118,7 +118,7 @@ test_that("summarise_data can utilize pre-computed statistics as data (inline da
format = "files",
data = list(
ts_pi = function(path, model) {
ts <- file.path(path, "slim.trees") %>% ts_load(model)
ts <- file.path(path, "slim.trees") %>% ts_read(model)
ts_diversity(ts, ts_names(ts, split = "pop"))
},
slim_pi = function(path) file.path(path, "stats.tsv") %>%
Expand Down
2 changes: 1 addition & 1 deletion vignettes/vignette-05-custom-engines.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ functions <- list(
# data-generating functions for computing summary statistics
data <- list(
ts = function(path) ts_load(file.path(path, "result.trees"))
ts = function(path) ts_read(file.path(path, "result.trees"))
)
```

Expand Down
2 changes: 1 addition & 1 deletion vignettes/vignette-07-selection.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ simulate_model(
model, priors,
model_args = list(origin_pop = "EUR", target_pop = "EUR"),
outputs = list(
ts = function(paths, model) ts_load(paths[1], model) %>% ts_mutate(1e-8),
ts = function(paths, model) ts_read(paths[1], model) %>% ts_mutate(1e-8),
freq = function(paths) readr::read_tsv(paths[2]),
paths
)
Expand Down

0 comments on commit a32be78

Please sign in to comment.