# 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())
Run the code above in your browser using DataLab