create_ti_method_r: Create a TI method from an R function wrapper

View source: R/method_create_ti_method_r.R

create_ti_method_rR Documentation

Create a TI method from an R function wrapper

Description

Create a TI method from an R function wrapper

Usage

create_ti_method_r(
  definition,
  run_fun,
  package_required = character(),
  package_loaded = character(),
  remotes_package = character(),
  return_function = TRUE
)

Arguments

definition

A definition, see definition()

run_fun

A function to infer a trajectory, with parameters counts/expression, parameters, priors, verbose and seed

package_required

The packages that need to be installed before executing the method.

package_loaded

The packages that need to be loaded before executing the method.

remotes_package

Package from which the remote locations of dependencies have to be extracted, eg. dynmethods.

return_function

Whether to return a function that allows you to override the default parameters, or just return the method meta data as is.

Value

A method definition

Examples

# define the parameters and other metadata
definition <- definition(
  method = def_method(
    id = "comp1"
  ),
  parameters = def_parameters(
    dynparam::integer_parameter(
      id = "component",
      default = 1,
      distribution = dynparam::uniform_distribution(1, 10),
      description = "The nth component to use"
    )
  ),
  wrapper = def_wrapper(
    input_required = "expression",
    input_optional = "start_id"
  )
)

# define a wrapper function
run_fun <- function(expression, priors, parameters, seed, verbose) {
  pca <- prcomp(expression)

  pseudotime <- pca$x[, parameters$component]

  # flip pseudotimes using start_id
  if (!is.null(priors$start_id)) {
    if(mean(pseudotime[start_id]) > 0.5) {
     pseudotime <- 1-pseudotime
    }
  }

  wrap_data(cell_ids = rownames(expression)) %>%
    add_linear_trajectory(pseudotime = pseudotime)
}

method <- create_ti_method_r(definition, run_fun, package_loaded = "dplyr")
trajectory <- infer_trajectory(example_dataset, method())


dynwrap documentation built on July 26, 2023, 5:15 p.m.