Skip to content
Draft
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 .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
^\.covrignore$
^.*\.log$
^touchstone$
^README\.Rmd$
^touchstone$
28 changes: 17 additions & 11 deletions .github/workflows/touchstone-receive.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Modified to follow workflow in EpiNow2
name: Continuous Benchmarks (Receive)

concurrency:
Expand All @@ -6,20 +7,26 @@ concurrency:

on:
pull_request:
paths:
# Where model code is defined: R/, src/, inst/include/
- "inst/include/**"
- "src/**"
- "R/**"
# Benchmarking code, config file, and manual trigger
- "touchstone/**"
- ".github/workflows/touchstone-receive.yaml"
- ".github/workflows/touchstone-comment.yaml"
- ".benchmark"

permissions:
contents: read
statuses: write
pull-requests: write

jobs:
prepare:
runs-on: ubuntu-latest
if:
true &&
(
github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'COLLABORATOR'
)
runs-on: ubuntu-latest
# Allow benchmarking workflow to run for external contribs
outputs:
config: ${{ steps.read_touchstone_config.outputs.config }}
steps:
Expand Down Expand Up @@ -50,10 +57,9 @@ jobs:
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: lorenzwalthert/touchstone/actions/receive@v1
- uses: lorenzwalthert/touchstone/actions/receive@main
with:
cache-version: 1
benchmarking_repo: ${{ matrix.config.benchmarking_repo }}
benchmarking_ref: ${{ matrix.config.benchmarking_ref }}
benchmarking_path: ${{ matrix.config.benchmarking_path }}
force_upstream: true
benchmarking_path: ${{ matrix.config.benchmarking_path }}
64 changes: 35 additions & 29 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
Package: pathomove
Title: Individual-based model of animal movement strategies evolved under pathogen risk
Version: 1.0.0.0000
Title: Individual-based model of animal movement strategies evolved under
pathogen risk
Version: 1.0.1
Authors@R:
c(person(given = "Pratik",
family = "Gupte",
role = c("aut", "cre", "cph"),
email = "pratikgupte16@gmail.com",
comment = c(ORCID = "https://orcid.org/0000-0001-5294-7819")))
Description: Runs the Pathomove simulation, a mechanisitic, spatially explicit, individual-based model of the evolution of animal social movement strategies under different scenarios of pathogen transmission risk, primarily focusing on the introduction of a novel pathogen to a population, as described in Gupte et al. (2022) <doi:10.1101/2022.03.09.483239>.
person("Pratik", "Gupte", , "pratikgupte16@gmail.com", role = c("aut", "cre", "cph"),
comment = c(ORCID = "https://orcid.org/0000-0001-5294-7819"))
Description: Runs the Pathomove simulation, a mechanisitic, spatially
explicit, individual-based model of the evolution of animal social
movement strategies under different scenarios of pathogen transmission
risk, primarily focusing on the introduction of a novel pathogen to a
population, as described in Gupte et al. (2022)
<doi:10.1101/2022.03.09.483239>.
License: MIT + file LICENSE
URL: https://github.com/pratikunterwegs/pathomove
BugReports: https://github.com/pratikunterwegs/pathomove/issues
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
LinkingTo:
Rcpp,
RcppParallel,
BH,
testthat
Imports:
Rcpp,
RcppParallel,
assertthat,
data.table,
glue,
igraph,
tidygraph,
methods
methods,
Rcpp,
RcppParallel,
tidygraph
Suggests:
testthat (>= 3.0.0),
ssh,
xml2,
covr,
knitr,
rmarkdown,
covr
SystemRequirements:
C++14
VignetteBuilder: knitr
spelling,
ssh,
testthat (>= 3.0.0),
xml2
LinkingTo:
BH,
Rcpp,
RcppEigen,
RcppParallel,
testthat
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-GB
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
SystemRequirements: C++14
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export(make_parameter_file)
export(run_pathomove)
export(use_cluster)
exportClasses(pathomove_output)
import(RcppEigen)
import(data.table)
importFrom(Rcpp,sourceCpp)
importFrom(RcppParallel,RcppParallelLibs)
Expand Down
5 changes: 3 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ get_test_landscape <- function(nItems, landsize, nClusters, clusterSpread, regen
#' pathogen introduction are drawn.
#' @param seed An integer number that is the seed for the R RNG. Defaults to
#' zero.
#' @param print_progress A boolean for whether to print progress.
#' @export
#' @return An S4 class, `pathomove_output`, with simulation outcomes.
run_pathomove <- function(scenario = 1L, popsize = 100L, nItems = 1800L, landsize = 60.0, nClusters = 60L, clusterSpread = 1.0, tmax = 100L, genmax = 100L, g_patho_init = 70L, n_samples = 5L, range_food = 1.0, range_agents = 1.0, range_move = 1.0, handling_time = 5L, regen_time = 50L, pTransmit = 0.05, p_v_transmit = 0.05, initialInfections = 20L, costInfect = 0.25, multithreaded = TRUE, dispersal = 2.0, infect_percent = FALSE, vertical = FALSE, reprod_threshold = FALSE, mProb = 0.01, mSize = 0.01, spillover_rate = 1.0, seed = 0L) {
.Call(`_pathomove_run_pathomove`, scenario, popsize, nItems, landsize, nClusters, clusterSpread, tmax, genmax, g_patho_init, n_samples, range_food, range_agents, range_move, handling_time, regen_time, pTransmit, p_v_transmit, initialInfections, costInfect, multithreaded, dispersal, infect_percent, vertical, reprod_threshold, mProb, mSize, spillover_rate, seed)
run_pathomove <- function(scenario = 1L, popsize = 100L, nItems = 1800L, landsize = 60.0, nClusters = 60L, clusterSpread = 1.0, tmax = 100L, genmax = 100L, g_patho_init = 70L, n_samples = 5L, range_food = 1.0, range_agents = 1.0, range_move = 1.0, handling_time = 5L, regen_time = 50L, pTransmit = 0.05, p_v_transmit = 0.05, initialInfections = 20L, costInfect = 0.25, multithreaded = TRUE, dispersal = 2.0, infect_percent = FALSE, vertical = FALSE, reprod_threshold = FALSE, mProb = 0.01, mSize = 0.01, spillover_rate = 1.0, seed = 0L, print_progress = FALSE) {
.Call(`_pathomove_run_pathomove`, scenario, popsize, nItems, landsize, nClusters, clusterSpread, tmax, genmax, g_patho_init, n_samples, range_food, range_agents, range_move, handling_time, regen_time, pTransmit, p_v_transmit, initialInfections, costInfect, multithreaded, dispersal, infect_percent, vertical, reprod_threshold, mProb, mSize, spillover_rate, seed, print_progress)
}

6 changes: 4 additions & 2 deletions R/fun_check_cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#' @return None, should check and prepare cluster.
#' @export
#'
check_prepare_cluster <- function(ssh_con = "some_server",
password = "your_password") {
check_prepare_cluster <- function(
ssh_con = "some_server",
password = "your_password"
) {
message("checking cluster for pathomove")
# connect to server
s <- ssh::ssh_connect(ssh_con, passwd = password)
Expand Down
20 changes: 12 additions & 8 deletions R/fun_handle_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#' @return A `data.table` with all reported generations.
#' @export
#'
get_trait_data <- function(object,
scaled_preferences = TRUE) {
get_trait_data <- function(object, scaled_preferences = TRUE) {
# setting variables to NULL
sF <- NULL
sH <- NULL
Expand Down Expand Up @@ -40,7 +39,8 @@ get_trait_data <- function(object,
)

trait_data_ <- Map(
trait_data_, generations_,
trait_data_,
generations_,
f = function(td_, g_) {
td_$gen <- g_
data.table::as.data.table(td_)
Expand All @@ -52,11 +52,15 @@ get_trait_data <- function(object,

# scale weights if required
if (scaled_preferences) {
trait_data_[, c("sF", "sH", "sN") := lapply(
.SD, function(tr_) {
tr_ / (abs(sF) + abs(sH) + abs(sN))
}
), .SDcols = c("sF", "sH", "sN")][] # add [] for printing output
trait_data_[,
c("sF", "sH", "sN") := lapply(
.SD,
function(tr_) {
tr_ / (abs(sF) + abs(sH) + abs(sN))
}
),
.SDcols = c("sF", "sH", "sN")
][] # add [] for printing output
}

return(trait_data_)
Expand Down
5 changes: 1 addition & 4 deletions R/fun_make_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
#' @return Writes a parameter file.
#' @export
#'
make_parameter_file <- function(replicates,
...,
which_file = "this_file.csv") {

make_parameter_file <- function(replicates, ..., which_file = "this_file.csv") {
# make combinations
parameters <- data.table::CJ(
...,
Expand Down
27 changes: 12 additions & 15 deletions R/fun_process_networks.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' Get network data from Rds files.
#'
#' @param output A `pathomove_output` object.
Expand Down Expand Up @@ -41,20 +40,18 @@ get_networks <- function(output, assoc_threshold = 5) {
}

# work on nodes
nodes <- Map(nodes, output@gens_edge_lists,
f = function(n, g) {
n$gen <- g
n$id <- seq_len(nrow(n))
data.table::setDT(n)

# add simulation parameter data
n[, names(agent_parameters) := agent_parameters]
n[, names(eco_parameters) := eco_parameters]

n <- get_social_strategy(n)
n
}
)
nodes <- Map(nodes, output@gens_edge_lists, f = function(n, g) {
n$gen <- g
n$id <- seq_len(nrow(n))
data.table::setDT(n)

# add simulation parameter data
n[, names(agent_parameters) := agent_parameters]
n[, names(eco_parameters) := eco_parameters]

n <- get_social_strategy(n)
n
})

assertthat::assert_that(
length(el) == length(nodes),
Expand Down
33 changes: 21 additions & 12 deletions R/fun_social_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ get_social_strategy <- function(df) {
msg = "get_social_strat: data does not have social weights"
)
data.table::setDT(df)
df[, social_strat := data.table::fcase(
(sH > 0 & sN > 0), "agent tracking",
(sH > 0 & sN < 0), "handler tracking",
(sH < 0 & sN > 0), "non-handler tracking",
(sH < 0 & sN < 0), "agent avoiding"
)][]
df[,
social_strat := data.table::fcase(
(sH > 0 & sN > 0),
"agent tracking",
(sH > 0 & sN < 0),
"handler tracking",
(sH < 0 & sN > 0),
"non-handler tracking",
(sH < 0 & sN < 0),
"agent avoiding"
)
][]
}

#' Get functional variation in movement weights.
Expand All @@ -45,10 +51,11 @@ get_functional_variation <- function(df) {
)

# transform weights
df[, c("sF", "sH", "sN") := lapply(.SD, function(x) {
x / (abs(sF) + abs(sH) + abs(sN))
}),
.SDcols = c("sF", "sH", "sN")
df[,
c("sF", "sH", "sN") := lapply(.SD, function(x) {
x / (abs(sF) + abs(sH) + abs(sN))
}),
.SDcols = c("sF", "sH", "sN")
][]
}

Expand Down Expand Up @@ -95,8 +102,10 @@ get_agent_avoidance <- function(df) {
data.table::setDT(df)
d_ <- copy(df)
# avoidance is sum of negative agent weights
d_[, agent_avoidance := (fifelse(sH < 0, sH, 0) + fifelse(sN < 0, sN, 0)) /
(abs(sH) + abs(sN) + abs(sF))]
d_[,
agent_avoidance := (fifelse(sH < 0, sH, 0) + fifelse(sN < 0, sN, 0)) /
(abs(sH) + abs(sN) + abs(sF))
]
# assign to original df, modified by reference
df[, agent_avoidance := d_$agent_avoidance]
}
17 changes: 9 additions & 8 deletions R/fun_use_cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
#' @return Runs a job which makes more jobs.
#' @export
#'
use_cluster <- function(ssh_con = "some_server",
password = "your_password",
script = "which_script.R",
folder = "pathomove",
tag = "scenario_tag",
template_job = "some_template.sh",
parameter_file = "which_parameters.csv") {

use_cluster <- function(
ssh_con = "some_server",
password = "your_password",
script = "which_script.R",
folder = "pathomove",
tag = "scenario_tag",
template_job = "some_template.sh",
parameter_file = "which_parameters.csv"
) {
# connect to server
s <- ssh::ssh_connect(ssh_con, passwd = password)

Expand Down
1 change: 1 addition & 0 deletions R/pathomove-package.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## usethis namespace: start
#' @import RcppEigen
#' @importFrom data.table :=
#' @importFrom data.table .BY
#' @importFrom data.table .EACHI
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Source code for _Pathomove_, an individual-based model for the evolution of animal movement strategies under the risk of pathogen transmission

<!-- badges: start -->
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.](https://www.repostatus.org/badges/latest/inactive.svg)](https://www.repostatus.org/#inactive)
[![R-CMD-check](https://github.com/pratikunterwegs/pathomove/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/pratikunterwegs/pathomove/actions/workflows/R-CMD-check.yaml)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6331816.svg)](https://doi.org/10.5281/zenodo.6331816)
[![Codecov test coverage](https://codecov.io/gh/pratikunterwegs/pathomove/branch/main/graph/badge.svg)](https://codecov.io/gh/pratikunterwegs/pathomove?branch=main)
Expand Down Expand Up @@ -159,7 +159,7 @@ The workflow to run this model to replicate the results presented in our _biorXi

A basic working example of how to use this package can be found in the script in the `vignettes` directory, `vignettes/basic_usage.Rmd`.

**Note:** In order to have completely reproducible simulations, it is necessary to run the simulation in single-threaded mode. Multi-threaded simualtion runs are _not_ reproducible.
**Note:** In order to have completely reproducible simulations, it is necessary to run the simulation in single-threaded mode. Multi-threaded simulation runs are _not_ reproducible.

The basic workflow for the package is:

Expand Down
2 changes: 2 additions & 0 deletions air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[format]
exclude = ["RcppExports.R"]
21 changes: 21 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CMD
Codecov
Github
Groningen
Groningen's
HPC
Makevars
Rcpp
RcppParallel
Rds
Rtrees
SLURM
TBB
Weissing
Zenodo
biorXiv
doi
etc
mechanisitic
timesteps
zenodo
Loading
Loading