### Example of generated parameter documentation Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_r An example of the output from `generate_parameter_documentation`, showing how parameters are documented for R packages. ```r generate_parameter_documentation(definition) ``` ```r ## [1] "@param component The nth component to use. Domain: U(1, 10). Default: 1. Format: integer." ``` -------------------------------- ### Generate Example Dataset with Rscript Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Use this Rscript to generate an example dataset for testing your TI method. It utilizes the `dynwrap::example_dataset` and writes it to an H5 file. ```bash #!/usr/bin/env Rscript dataset <- dynwrap::example_dataset file <- commandArgs(trailingOnly = TRUE)[[1]] dynutils::write_h5(dataset, file) ``` -------------------------------- ### Test Docker Installation Source: https://dynverse.org/users/1-installation Tests if Docker is correctly installed and configured for use with dynwrap. Provides detailed output on the status of each test. ```r dynwrap::test_docker_installation(detailed = TRUE) ## ✔ Docker is installed ## ✔ Docker daemon is running ## ✔ Docker is at correct version (>1.0): 1.39 ## ✔ Docker is in linux mode ## ✔ Docker can pull images ## ✔ Docker can run image ## ✔ Docker can mount temporary volumes ## ✔ Docker test successful ----------------------------------------------------------------- ## [1] TRUE ``` -------------------------------- ### Example: Creating and Visualizing a Cyclic Trajectory Source: https://dynverse.org/reference/dynwrap/create_trajectory/add_cyclic_trajectory This example demonstrates how to create a dataset, generate random pseudotime values, and then use `add_cyclic_trajectory` to construct a cyclic trajectory. The resulting trajectory can be visualized using `dynplot::plot_graph`. ```R library(tibble) dataset <- wrap_data(cell_ids = letters) pseudotime <- tibble(cell_id = dataset$cell_ids, pseudotime = runif(length(dataset$cell_ids))) pseudotime #> # A tibble: 26 x 2 #> cell_id pseudotime #> #> 1 a 0.525 #> 2 b 0.659 #> 3 c 0.734 #> 4 d 0.0529 #> 5 e 0.979 #> 6 f 0.380 #> 7 g 0.448 #> 8 h 0.785 #> 9 i 0.207 #> 10 j 0.733 #> # … with 16 more rows trajectory <- add_cyclic_trajectory(dataset, pseudotime) # for plotting the result, install dynplot dynplot::plot_graph(trajectory) #> Coloring by milestone #> Using milestone_percentages from trajectory ``` -------------------------------- ### Make Script Executable and Run Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container These commands make the example script executable and then run it to generate the `example.h5` file. ```bash chmod +x example.sh ./example.sh example.h5 ``` -------------------------------- ### Example Usage of calculate_geodesic_distances Source: https://dynverse.org/reference/dynwrap/derive_trajectory/calculate_geodesic_distances Demonstrates how to calculate geodesic distances using an example dataset. Ensure the 'example_dataset' is loaded before running. ```R data(example_dataset) geodesic_distances <- calculate_geodesic_distances(example_dataset) ``` -------------------------------- ### Test Singularity Installation Source: https://dynverse.org/users/1-installation Tests if Singularity (version 3.0 or higher) is correctly installed and configured for use with dynwrap. Provides detailed output on the status of each test. ```r dynwrap::test_singularity_installation(detailed = TRUE) ## ✔ Singularity is installed ## ✔ Singularity is at correct version (>=3.0): v3.0.0-13-g0273e90f is installed ## ✔ Singularity can pull and run a container from Dockerhub ## ✔ Singularity can mount temporary volumes ## ✔ Singularity test successful ------------------------------------------------------------ ## [1] TRUE ``` -------------------------------- ### Docker build output Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Example output from the Docker build process, showing the steps involved in creating the image. ```text ## Sending build context to Docker daemon 4.608kB ## Step 1/3 : FROM dynverse/dynwrappy:v0.1.0 ## ---> c97bc2021452 ## Step 2/3 : COPY definition.yml run.py /code/ ## ---> f896e0f64d87 ## Step 3/3 : ENTRYPOINT ["/code/run.py"] ## ---> Running in 12f2e4570ee9 ## Removing intermediate container 12f2e4570ee9 ## ---> 1ddb71c55bbf ## Successfully built 1ddb71c55bbf ## Successfully tagged my_ti_method:latest ``` -------------------------------- ### Definition of a TI method Source: https://dynverse.org/reference/dynwrap/create_ti_method/definition Use `definition()` to create a TI method definition. This function takes arguments for the method, wrapper, manuscript, container, and parameters. The example shows a minimal setup. ```r definition( method = def_method(id = "some_method"), wrapper = def_wrapper(input_required = "expression"), parameters = parameter_set( integer_parameter(id = "k", default = 5L, distribution = uniform_distribution(3L, 20L)) ) ) ``` -------------------------------- ### Example of creating a trajectory dataset Source: https://dynverse.org/reference/dynwrap/create_trajectory/add_trajectory This example demonstrates how to use `add_trajectory` to create a trajectory dataset. It first creates a sample dataset and then defines the milestone network, divergence regions, and progressions before calling `add_trajectory`. Finally, it shows how to plot the resulting trajectory. ```R library(dplyr) library(tibble) dataset <- wrap_data(cell_ids = letters) milestone_network <- tribble( ~from, ~to, ~length, ~directed, "A", "B", 1, FALSE, "B", "C", 2, FALSE, "B", "D", 1, FALSE, ) milestone_network #> # A tibble: 3 x 4 #> from to length directed #> #> 1 A B 1 FALSE #> 2 B C 2 FALSE #> 3 B D 1 FALSE progressions <- milestone_network %>% sample_n(length(dataset$cell_ids), replace = TRUE, weight = length) %>% mutate( cell_id = dataset$cell_ids, percentage = runif(n()) ) %>% select(cell_id, from, to, percentage) progressions #> # A tibble: 26 x 4 #> cell_id from to percentage #> #> 1 a B D 0.578 #> 2 b A B 0.675 #> 3 c A B 0.857 #> 4 d B C 0.182 #> 5 e B D 0.0863 #> 6 f B C 0.0263 #> 7 g A B 0.410 #> 8 h A B 0.318 #> 9 i B C 0.145 #> 10 j A B 0.557 #> # … with 16 more rows divergence_regions <- tribble( ~divergence_id, ~milestone_id, ~is_start, "1", "A", TRUE, "1", "B", FALSE, "1", "C", FALSE ) divergence_regions #> # A tibble: 3 x 3 #> divergence_id milestone_id is_start #> #> 1 1 A TRUE #> 2 1 B FALSE #> 3 1 C FALSE trajectory <- add_trajectory( dataset, milestone_network = milestone_network, divergence_regions = divergence_regions, progressions = progressions ) # for plotting the result, install dynplot dynplot::plot_graph(trajectory) #> Coloring by milestone #> Using milestone_percentages from trajectory ``` -------------------------------- ### Install dynverse R Packages Source: https://dynverse.org/users/1-installation Installs and updates all dynverse R packages, including dynwrap, dynplot, and dynmethods. Requires the devtools package. ```r # install.packages("devtools") devtools::install_github("dynverse/dyno") ``` -------------------------------- ### TI method execution log Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Example log output from running the containerized TI method, showing the execution details and parameters. ```text ## Executing 'comp_1' on 'example' ## With parameters: list(component = 1L), ## inputs: expression, and ## priors : ## Loading required namespace: hdf5r ## Input saved to /tmp/RtmpOZDumn/file57646669dc04/ti ## Running method using babelwhale ## Running /usr/bin/docker run -e 'TMPDIR=/tmp2' --workdir /ti/workspace -v \ ## '/tmp/RtmpOZDumn/file57646669dc04/ti:/ti' -v \ ## '/tmp/RtmpOZDumn/file57644fe30169/tmp:/tmp2' my_ti_method --dataset \ ## /ti/input.h5 --output /ti/output.h5 ## Output saved to /tmp/RtmpOZDumn/file57646669dc04/ti/output.h5 ## Attempting to read in output with hdf5 ``` -------------------------------- ### Load Example Disconnected Dataset Source: https://dynverse.org/reference/dynplot/other/example_disconnected Load the `example_disconnected` dataset. This dataset is an object of class `dynwrap::with_prior` and related classes, suitable for visualization and analysis. ```r example_disconnected ``` -------------------------------- ### Plot Heatmap Example with Bifurcating Trajectory Source: https://dynverse.org/reference/dynplot/plot_trajectory/plot_heatmap Example of using `plot_heatmap` with a bifurcating trajectory. Similar to the linear example, it automatically selects the top 20 features if none are specified and identifies a root milestone. ```r data(example_bifurcating) plot_heatmap(example_bifurcating) #> No features of interest provided, selecting the top 20 features automatically #> Using dynfeature for selecting the top 20 features #> root cell or milestone not provided, trying first outgoing milestone_id #> Using 'M1' as root #> Coloring by milestone ``` -------------------------------- ### Edge Flip Score Example 2 Source: https://dynverse.org/reference/dyneval/metric/calculate_edge_flip Demonstrates calculating the edge flip score between a cyclic and a diverging network with loops. Note: This example assumes the function is available in the environment. ```r net1 <- dyntoy::generate_milestone_network("cyclic") net2 <- dyntoy::generate_milestone_network("diverging_with_loops") calculate_edge_flip(net1, net2) ``` -------------------------------- ### Edge Flip Score Example 1 Source: https://dynverse.org/reference/dyneval/metric/calculate_edge_flip Demonstrates calculating the edge flip score between a linear and a bifurcating network. Note: This example assumes the function is available in the environment. ```r net1 <- dyntoy::generate_milestone_network("linear") net2 <- dyntoy::generate_milestone_network("bifurcating") calculate_edge_flip(net1, net2) ``` -------------------------------- ### Example of using add_dimred_projection Source: https://dynverse.org/reference/dynwrap/create_trajectory/add_dimred_projection Demonstrates how to use add_dimred_projection with sample data. This includes creating a dataset, defining a milestone network, and generating dimensionality reduction matrices for cells and milestones. ```R library(tibble) dataset <- wrap_data(cell_ids = letters) milestone_network <- tibble::tibble( from = c("A", "B", "B"), to = c("B", "C", "D"), directed = TRUE, length = 1 ) milestone_network #> # A tibble: 3 x 4 #> from to directed length #> #> 1 A B TRUE 1 #> 2 B C TRUE 1 #> 3 B D TRUE 1 dimred <- matrix( runif(length(dataset$cell_ids) * 2), ncol = 2, dimnames = list(dataset$cell_ids, c("comp_1", "comp_2")) ) dimred #> comp_1 comp_2 #> a 0.518923245 0.42044692 #> b 0.713531887 0.99517996 #> c 0.996785344 0.21668160 #> d 0.773217170 0.61393193 #> e 0.895180710 0.83893684 #> f 0.281728024 0.87118008 #> g 0.139223843 0.70638636 #> h 0.046410585 0.23338931 #> i 0.794306935 0.57336944 #> j 0.818950567 0.22262171 #> k 0.417419555 0.13321490 #> l 0.747896066 0.08980882 #> m 0.057266013 0.28946283 #> n 0.468984942 0.74871216 #> o 0.746089673 0.66533637 #> p 0.278019339 0.76867310 #> q 0.619681378 0.01043518 #> r 0.735949405 0.30812903 #> s 0.052957582 0.77245419 #> t 0.725099872 0.02302861 #> u 0.275327800 0.04770981 #> v 0.585088401 0.03544533 #> w 0.000633863 0.63871647 #> x 0.962298031 0.29273069 #> y 0.484792338 0.34948312 #> z 0.218368359 0.10571620 dimred_milestones <- matrix( runif(2*4), ncol = 2, dimnames = list(c("A", "B", "C", "D"), c("comp_1", "comp_2")) ) dimred_milestones #> comp_1 comp_2 #> A 0.1502137 0.2729913 #> B 0.6010157 0.1193362 #> C 0.6299863 0.6635635 #> D 0.1103404 0.4535189 trajectory <- add_dimred_projection( dataset, milestone_network = milestone_network, dimred = dimred, dimred_milestones = dimred_milestones ) # for plotting the result, install dynplot dynplot::plot_graph(trajectory) #> Coloring by milestone #> Using milestone_percentages from trajectory ``` -------------------------------- ### Example Usage of add_linear_trajectory Source: https://dynverse.org/reference/dynwrap/create_trajectory/add_linear_trajectory Demonstrates how to create a dataset, generate pseudotime values, and then add a linear trajectory using the `add_linear_trajectory` function. ```r library(tibble) dataset <- wrap_data(cell_ids = letters) pseudotime <- tibble(cell_id = dataset$cell_ids, pseudotime = runif(length(dataset$cell_ids))) trajectory <- add_linear_trajectory(dataset, pseudotime) ``` -------------------------------- ### Example 1: Simplify a basic directed network Source: https://dynverse.org/reference/dynwrap/other/simplify_igraph_network Demonstrates simplifying a simple directed network where edges connect nodes 1 to 2 and 2 to 3. The output shows the network is simplified to a single edge from 1 to 3. ```R net <- data.frame( from = 1:2, to = 2:3, length = 1, directed = TRUE, stringsAsFactors = F ) gr <- igraph::graph_from_data_frame(net) simplify_igraph_network(gr) ``` -------------------------------- ### Load Dataset and Infer Trajectory Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Load the generated example dataset from the H5 file and then use `infer_trajectory` to test your TI method. ```r dataset <- dynutils::read_h5("example.h5") trajectory <- infer_trajectory(dataset, method()) ``` -------------------------------- ### Create and test the TI method wrapper Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_r Create a TI method wrapper using `create_ti_method_r` and test it with an example dataset. This function returns a callable method that can infer trajectories. ```r ti_comp1 <- create_ti_method_r(definition, run_fun, package_loaded = "dplyr") ``` ```r dataset <- dynwrap::example_dataset trajectory <- infer_trajectory(dataset, ti_comp1()) ``` -------------------------------- ### Example 3: Simplify a network with multiple paths Source: https://dynverse.org/reference/dynwrap/other/simplify_igraph_network Shows the simplification of a network with multiple paths, including a self-loop (1->1) and an edge from 4 to 5. The output displays the simplified network structure. ```R net <- data.frame( from = c(1, 2, 3, 4), to = c(2, 3, 1, 5), length = 1, directed = TRUE, stringsAsFactors = F ) gr <- igraph::graph_from_data_frame(net) simplify_igraph_network(gr) ``` -------------------------------- ### Plotting cells colored by pseudotime Source: https://dynverse.org/reference/dynplot/plot_trajectory/plot_dimred Example of coloring cells by pseudotime. If pseudotime is not provided, the function will attempt to calculate it. ```R plot_dimred(example_bifurcating, color_cells = "pseudotime") ``` -------------------------------- ### Example 2: Simplify a network with a cycle and self-loop Source: https://dynverse.org/reference/dynwrap/other/simplify_igraph_network Illustrates simplifying a network that includes a cycle (1->2->3->1) and a self-loop (1->4). The output reflects the simplification, potentially keeping the self-loop and one edge of the cycle. ```R net <- data.frame( from = c(1, 2, 3, 1), to = c(2, 3, 1, 4), length = 1, directed = TRUE, stringsAsFactors = F ) gr <- igraph::graph_from_data_frame(net) simplify_igraph_network(gr) ``` -------------------------------- ### Define TI method parameters with dynparam Source: https://dynverse.org/reference/dynwrap/create_ti_method/def_parameters Use `def_parameters` to create a parameter set for a TI method. This example shows how to define character, integer, and numeric parameters with their respective properties like default values, allowed values, and distributions. ```R library(dynparam) def_parameters( character_parameter(id = "method", default = "one", values = c("one", "two", "three")), integer_parameter( id = "ndim", default = 3L, distribution = uniform_distribution(lower = 2L, upper = 20L) ), numeric_parameter( id = "beta", default = 0.005, distribution = expuniform_distribution(lower = 1e-10, upper = 1) ) ) #> method | type=character | domain={one, two, three} | default=one #> ndim | type=integer | domain=U(2, 20) | default=3 #> beta | type=numeric | domain=e^U(-23.03, 0.00) | default=0.005 ``` -------------------------------- ### Load and test containerized TI method in R Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Code to load the containerized TI method using dynwrap and run it on an example dataset. ```r method <- create_ti_method_container("my_ti_method") dataset <- dynwrap::example_dataset trajectory <- infer_trajectory(dataset, method(), verbose = TRUE) ``` -------------------------------- ### Creating and testing a TI method definition Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_script This R code demonstrates how to create a TI method definition from a YAML file and a script, then use it to infer a trajectory from an example dataset. It also shows how to enable debug mode for interactive development. ```r method <- create_ti_method_definition( "definition.yml", "run.R" ) dataset <- dynwrap::example_dataset trajectory <- infer_trajectory(dataset, method(), verbose = TRUE) ``` ```r # install dynplot to plot the output if ("dynplot" %in% rownames(installed.packages())) { dynplot::plot_dimred(trajectory, color_cells = "pseudotime" , expression_source = as.matrix(dataset$expression)) } ``` ```r infer_trajectory(dataset, method(), debug = TRUE) ``` -------------------------------- ### Get all TI methods Source: https://dynverse.org/reference/dynwrap/infer_trajectory/get_ti_methods Call `get_ti_methods` to list all available TI methods. By default, it searches within the 'dynmethods' package and returns results as a tibble. ```R get_ti_methods(method_ids = NULL, as_tibble = TRUE, ti_packages = ifelse("dynmethods" %in% rownames(utils::installed.packages()), "dynmethods", "dynwrap"), evaluate = FALSE) ``` -------------------------------- ### ti_recat function call Source: https://dynverse.org/reference/dynmethods/method/ti_recat This is a basic example of calling the ti_recat function with default parameters. It generates a trajectory using the reCAT method. ```r ti_recat(TSPFold = 2L, beginNum = 10L, endNum = 15L, step_size = 2L, base_cycle_range = c(6L, 9L), max_num = 300L, clustMethod = "GMM") ``` -------------------------------- ### Plot a simple one-dimensional trajectory Source: https://dynverse.org/reference/dynplot/plot_trajectory/plot_onedim Loads example data and plots a one-dimensional trajectory using default settings. This is useful for a quick visualization of the trajectory structure. ```r data(example_linear) plot_onedim(example_linear) ``` -------------------------------- ### Run trajectory inference with infer_trajectory Source: https://dynverse.org/users/2-quick_start Run a selected trajectory inference method on the prepared dataset. Requires Docker or Singularity to be installed. This function returns the inferred trajectory model. ```r model <- infer_trajectory(dataset, first(methods_selected)) ``` -------------------------------- ### Get Divergence Triangles Source: https://dynverse.org/reference/dynwrap/other/get_divergence_triangles Call `get_divergence_triangles` with a data frame of divergence regions. This function is produced by `add_trajectory` and is used to identify combinations between the start of each divergence region and pairwise combinations of the end milestones. ```r get_divergence_triangles(divergence_regions) ``` -------------------------------- ### Load example_tree Dataset Source: https://dynverse.org/reference/dynplot/other/example_tree This snippet shows how to load the example_tree dataset. It is an object of class dynwrap::with_prior. ```r example_tree ``` -------------------------------- ### Add cluster graph to dataset Source: https://dynverse.org/reference/dynwrap/create_trajectory/add_cluster_graph Use add_cluster_graph to construct a trajectory from a dataset, milestone network, and cell grouping. This example demonstrates setting up the dataset and milestone network before calling the function. For plotting, install and use the dynplot package. ```R library(tibble) dataset <- wrap_data(cell_ids = letters) milestone_network <- tibble::tibble( from = c("A", "B", "B"), to = c("B", "C", "D"), directed = TRUE, length = 1 ) milestone_network #> # A tibble: 3 x 4 #> from to directed length #> #> 1 A B TRUE 1 #> 2 B C TRUE 1 #> 3 B D TRUE 1 grouping <- sample(c("A", "B", "C", "D"), length(dataset$cell_ids), replace = TRUE) grouping #> [1] "B" "D" "B" "A" "A" "B" "A" "D" "C" "B" "A" "C" "D" "A" "A" "D" "A" "A" "D" "B" "B" "A" "B" "C" "C" "B" trajectory <- add_cluster_graph(dataset, milestone_network, grouping) # for plotting the result, install dynplot dynplot::plot_graph(trajectory) #> Coloring by milestone #> Using milestone_percentages from trajectory ``` -------------------------------- ### Generate a dataset for rooting Source: https://dynverse.org/users/3-user-guide/5-adapting Generate a sample dataset with a bifurcating model to demonstrate the rooting process. ```r set.seed(1) model <- dyntoy::generate_dataset(model = dyntoy::model_bifurcating()) ``` -------------------------------- ### Load example_linear dataset Source: https://dynverse.org/reference/dynplot/other/example_linear Loads the example_linear dataset. This dataset is an object of class dynwrap::with_prior. ```r example_linear ``` -------------------------------- ### Minimal Dockerfile for TI method Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Dockerfile to containerize the TI method. It uses a base image, copies the method definition and script, and sets the entrypoint. ```dockerfile FROM dynverse/dynwrappy:v0.1.0 COPY definition.yml run.py /code/ ENTRYPOINT ["/code/run.py"] ``` -------------------------------- ### Get Expression from Dataset Source: https://dynverse.org/reference/dynwrap/adapt_trajectory/add_expression Use `get_expression` to retrieve expression data from a dataset. The `expression_source` argument specifies where to get the expression from, defaulting to "expression". ```r get_expression(dataset, expression_source = "expression") ``` -------------------------------- ### Open the guidelines shiny app Source: https://dynverse.org/users/3-user-guide/2-guidelines Opens the interactive shiny app for exploring method performance. It is recommended to provide your dataset to pre-calculate fields. ```r dataset <- example_dataset guidelines_shiny(dataset = dataset) ``` -------------------------------- ### Plot Heatmap Example with Linear Trajectory Source: https://dynverse.org/reference/dynplot/plot_trajectory/plot_heatmap Example of using `plot_heatmap` with a linear trajectory. If no features of interest are provided, the top 20 features are automatically selected. The function attempts to identify a root milestone if not explicitly provided. ```r data(example_linear) plot_heatmap(example_linear) #> No features of interest provided, selecting the top 20 features automatically #> Using dynfeature for selecting the top 20 features #> Loading required namespace: dynfeature #> root cell or milestone not provided, trying first outgoing milestone_id #> Using 'M1' as root #> Coloring by milestone ``` -------------------------------- ### get_milestone_palette_names Source: https://dynverse.org/reference/dynplot/plot_helpers Get the names of valid color palettes. ```APIDOC ## get_milestone_palette_names ### Description Get the names of valid color palettes. ### Function Signature `get_milestone_palette_names()` ``` -------------------------------- ### milestone_palette Source: https://dynverse.org/reference/dynplot/plot_helpers Get the names of valid color palettes. ```APIDOC ## milestone_palette ### Description Get the names of valid color palettes. ### Function Signature `milestone_palette()` ``` -------------------------------- ### Generate R package documentation for parameters Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_r Automatically generate Roxygen documentation for method parameters using `dynwrap::generate_parameter_documentation`. This ensures consistency and completeness in package documentation. ```r 'Infer a trajectory from the first principal component' #' #' @eval dynwrap::generate_parameter_documentation(definition) #' #' @import dplyr #' @export #' #' @examples #' dataset <- dynwrap::example_dataset #' model <- dynwrap::infer_trajectory(dataset, ti_comp1()) ti_comp1 <- create_ti_method_r(definition, run_fun) ``` -------------------------------- ### Get milestone labelling from a trajectory Source: https://dynverse.org/reference/dynwrap/adapt_trajectory Retrieves the milestone labelling information from a trajectory model. ```APIDOC ## get_milestone_labelling ### Description Gets the milestone labelling from a wrapped trajectory. ### Method Not specified (assumed to be an SDK function call) ### Parameters None explicitly documented. ### Request Example ``` get_milestone_labelling(trajectory) ``` ### Response Milestone labelling data. ``` -------------------------------- ### Build the Docker container Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Command to build the Docker image for the TI method. ```bash docker build -t my_ti_method . ``` -------------------------------- ### Get expression values from a dataset Source: https://dynverse.org/reference/dynwrap/adapt_trajectory Retrieves the count and normalized expression values from a dataset. ```APIDOC ## get_expression ### Description Gets count and normalised expression values from a dataset. ### Method Not specified (assumed to be an SDK function call) ### Parameters None explicitly documented. ### Request Example ``` get_expression(dataset) ``` ### Response Count and normalised expression values. ``` -------------------------------- ### Get Milestone Palette Names Source: https://dynverse.org/reference/dynplot/plot_helpers/milestone_palette Retrieves the names of all available milestone color palettes. ```APIDOC ## get_milestone_palette_names() ### Description Get the names of valid color palettes. ### Method `get_milestone_palette_names()` ### Returns - A character vector of available palette names. ``` -------------------------------- ### get_divergence_triangles Source: https://dynverse.org/reference/dynwrap/other/get_divergence_triangles Returns the combinations between the start of each divergence region and pairwise combinations of the end milestones. ```APIDOC ## get_divergence_triangles ### Description Returns the combinations between the start of each divergence region and pairwise combinations of the end milestones. ### Arguments * `divergence_regions` (data frame) - A divergence regions data frame as produced by `add_trajectory`. ``` -------------------------------- ### Add Grouping Information Source: https://dynverse.org/users/3-user-guide/1-preparing Incorporate grouping or clustering information into the dataset. This function is commented out in the example. ```r # dataset <- add_grouping( # dataset, # example_dataset$grouping # ) ``` -------------------------------- ### Get dimensionality reduction from a trajectory Source: https://dynverse.org/reference/dynwrap/adapt_trajectory Retrieves the dimensionality reduction data associated with a trajectory model. ```APIDOC ## get_dimred ### Description Gets the dimensionality reduction from a wrapped trajectory. ### Method Not specified (assumed to be an SDK function call) ### Parameters None explicitly documented. ### Request Example ``` get_dimred(trajectory) ``` ### Response Dimensionality reduction data. ``` -------------------------------- ### Check if a trajectory is rooted Source: https://dynverse.org/reference/dynwrap/adapt_trajectory Checks if the trajectory model has been rooted, indicating that a starting point has been defined. ```APIDOC ## is_rooted ### Description Checks if the trajectory is rooted. ### Method Not specified (assumed to be an SDK function call) ### Parameters None explicitly documented. ### Request Example ``` is_rooted(trajectory) ``` ### Response Boolean indicating whether the trajectory is rooted. ``` -------------------------------- ### View help for a specific TI method Source: https://dynverse.org/users/3-user-guide/3-running Access the documentation for a specific trajectory inference method, such as `ti_comp1`, to understand its parameters. ```r ?ti_comp1 ``` -------------------------------- ### Make script executable Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Command to make the run.py script executable. ```bash chmod +x run.py ``` -------------------------------- ### Add Prior Information to Dataset Source: https://dynverse.org/users/3-user-guide/1-preparing Incorporate prior information, such as a starting cell ID, into the dataset using `add_prior_information`. ```r dataset <- add_prior_information( dataset, start_id = "Cell1" ) ``` -------------------------------- ### Generate a toy dataset Source: https://dynverse.org/users/3-user-guide/4-visualisation Creates a sample dataset for testing trajectory inference and visualisation functions. Uses a bifurcating model with 200 cells. ```r set.seed(1) dataset <- dyntoy::generate_dataset(model = "bifurcating", num_cells = 200) ``` -------------------------------- ### Run Trajectory Inference Method from Command Line Source: https://dynverse.org/users/3-user-guide/3-running Execute trajectory inference methods directly from the command line using Docker. The `--help` flag provides usage information and available parameters. ```bash docker run dynverse/ti_comp1 --help ## Usage: LOCAL=/path/to/folder; MOUNT=/ti; docker run -v $LOCAL:$MOUNT dynverse/ti_comp1 ## ## ## Options: ## -h, --help ## Show this help message and exit ## ## --dataset=DATASET ## Filename of the dataset, example: $MOUNT/dataset.(h5|loom). h5 files can be created by cellranger or dyncli. ## ## --loom_expression_layer=LOOM_EXPRESSION_LAYER ## If available, the name of the loom-layer containing normalised log-transformed data. ## ## --output=OUTPUT ## Filename of the output trajectory data, example: $MOUNT/output.h5. ## ## --parameters=PARAMETERS ## A file containing method-specific parameters, example: $MOUNT/parameters.(h5|yml). ## ## --dimred=DIMRED ## Parameter: Which dimensionality reduction method to use ## Domain: {pca, mds, tsne, ica, lle, landmark_mds, mds_sammon, mds_isomds, mds_smacof, umap, dm_diffusionMap} ## Default: pca ## Format: character ## ## --ndim=NDIM ## Parameter: ## Domain: U(2, 30) ## Default: 2 ## Format: integer ## ## --component=COMPONENT ## Parameter: ## Domain: U(1, 10) ## Default: 1 ## Format: integer ## ## --verbosity=VERBOSITY ## The verbosity level: 0 => none, 1 => critical (default), 2 => info, 3 => debug. ## ## --seed=SEED ## A seed to be set to ensure reproducability. ``` -------------------------------- ### Basic plot_dimred usage Source: https://dynverse.org/reference/dynplot/plot_trajectory/plot_dimred A basic example of plotting a trajectory on a dimensionality reduction using the plot_dimred function with default settings. ```R data(example_bifurcating) plot_dimred(example_bifurcating) ``` -------------------------------- ### Plot TI method output Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Code to plot the dimensionality reduction and pseudotime results using dynplot, if the package is installed. ```r # install dynplot to plot the output if ("dynplot" %in% rownames(installed.packages())) { dynplot::plot_dimred(trajectory, color_cells = "pseudotime" , expression_source = as.matrix(dataset$expression)) } ``` -------------------------------- ### Method definition file (definition.yml) Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Defines the TI method, including its ID, parameters with their types and distributions, and wrapper input requirements. ```yaml method: id: comp_1 parameters: - id: component default: 1 type: integer distribution: type: uniform lower: 1 upper: 10 description: The nth component to use wrapper: input_required: expression input_optional: start_id ``` -------------------------------- ### create_ti_method_definition Source: https://dynverse.org/reference/dynwrap/create_ti_method/create_ti_method_definition Creates a TI method from a local definition file. The definition file describes a method that is runnable on the local system. ```APIDOC ## create_ti_method_definition ### Description Creates a TI method from a local method definition file. The definition file describes a method that is runnable on the local system. ### Function Signature ```R create_ti_method_definition(definition, script, return_function = TRUE) ``` ### Arguments - **definition** (A definition, see `definition()`): The definition of the TI method. - **script** (Location of the script): The path to the script that will be executed. This script must contain a shebang line (#!). - **return_function** (boolean) - Optional - Whether to return a function that allows overriding default parameters, or just the method meta data. ``` -------------------------------- ### Dendrogram Plot Colored by Pseudotime Source: https://dynverse.org/reference/dynplot/plot_trajectory/plot_dendro Example of plotting a dendrogram where cells are colored by pseudotime. If pseudotime is not provided, it will be calculated from the root milestone. ```r plot_dendro(example_tree, color_cells = "pseudotime") #> root cell or milestone not provided, trying first outgoing milestone_id #> Using 'M1' as root #> Pseudotime not provided, will calculate pseudotime from root milestone ``` -------------------------------- ### Visualize TI method performance using a heatmap Source: https://dynverse.org/developers/evaluating-ti-method Combine the calculated metrics with method information and visualize them using a heatmap. This helps in comparing the performance of different TI methods across various metrics. ```r bind_cols(metrics, models) %>% select(method_id, !!metric_ids) %>% gather("metric_id", "metric_value", -method_id) %>% ggplot(aes(method_id, metric_id, fill = metric_value)) + geom_tile() ``` -------------------------------- ### Create TI method definition Source: https://dynverse.org/reference/dynwrap/create_ti_method/create_ti_method_definition Use this function to create a TI method from a local definition file. The script must contain a \"#!\" shebang. Set \"return_function\" to \"TRUE\" to return a function that allows overriding default parameters. ```r create_ti_method_definition(definition, script, return_function = TRUE) ``` -------------------------------- ### Add a root to the trajectory Source: https://dynverse.org/reference/dynwrap/adapt_trajectory Roots the trajectory model, typically by specifying a starting point or cell. This is crucial for defining the directionality of the trajectory. ```APIDOC ## add_root ### Description Roots the trajectory. ### Method Not specified (assumed to be an SDK function call) ### Parameters None explicitly documented. ### Request Example ``` add_root(trajectory, root_cell) ``` ### Response None explicitly documented. ``` -------------------------------- ### Plot Topology of Tree Trajectory Source: https://dynverse.org/reference/dynplot/plot_trajectory/plot_topology Example of plotting the topology of a tree-like trajectory. The function automatically determines a root milestone if none is provided. ```r data(example_tree) plot_topology(example_tree) ``` -------------------------------- ### Plot Topology of Disconnected Trajectory Source: https://dynverse.org/reference/dynplot/plot_trajectory/plot_topology Example of plotting the topology of a disconnected trajectory. The function automatically determines a root milestone if none is provided. ```r data(example_disconnected) plot_topology(example_disconnected) ``` -------------------------------- ### Generate guidelines object Source: https://dynverse.org/users/3-user-guide/2-guidelines Generates a guidelines object by answering questions about the dataset. This code can be copied from the app for reproducibility. ```r dataset <- example_dataset guidelines <- guidelines( dataset, answers = answer_questions( dataset, multiple_disconnected = FALSE, expect_topology = TRUE, expected_topology = "linear" ) ) ## Loading required namespace: akima ``` -------------------------------- ### Basic Dendrogram Plot Source: https://dynverse.org/reference/dynplot/plot_trajectory/plot_dendro A basic example of plotting a trajectory as a dendrogram using the `plot_dendro` function with default settings. Requires `example_tree` data. ```r data(example_tree) plot_dendro(example_tree) #> root cell or milestone not provided, trying first outgoing milestone_id #> Using 'M1' as root #> Coloring by milestone #> Using milestone_percentages from trajectory ``` -------------------------------- ### Method execution script (run.py) Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_container Python script to run the TI method. It uses dynclipy to load data, performs PCA for dimensionality reduction, calculates pseudotime, and wraps the trajectory using dynclipy. ```python #!/usr/bin/env python import dynclipy dataset = dynclipy.main() import pandas as pd import sklearn.decomposition # infer trajectory pca = sklearn.decomposition.PCA() dimred = pca.fit_transform(dataset['expression']) pseudotime = pd.Series( dimred[:, dataset['parameters']['component']-1], index = dataset['expression'].index ) # build trajectory trajectory = dynclipy.wrap_data(cell_ids = dataset['expression'].index) trajectory.add_linear_trajectory(pseudotime = pseudotime) # save output trajectory.write_output(dataset['output']) ``` -------------------------------- ### Plot trajectory with dynplot Source: https://dynverse.org/developers/creating-ti-method/create_ti_method_r Visualize the inferred trajectory using `dynplot::plot_dimred` if the dynplot package is installed. This helps in assessing the quality of the trajectory. ```r if ("dynplot" %in% rownames(installed.packages())) { dynplot::plot_dimred(trajectory, color_cells = "pseudotime" , expression_source = as.matrix(dataset$expression)) } ``` -------------------------------- ### definition() Source: https://dynverse.org/reference/dynwrap/create_ti_method/definition Creates a definition object which contains meta information on a TI method and its various aspects. ```APIDOC ## definition() ### Description A definition contains meta information on a TI method and various aspects thereof. ### Parameters - **method** (any) - Meta information on the TI method (see `def_method()`). - **wrapper** (any) - Meta information on the wrapper itself (see `def_wrapper()`). - **manuscript** (any, optional) - Meta information on the manuscript, if applicable (see `def_manuscript()`). - **container** (any, optional) - Meta information on the container in which the wrapper resides, if applicable (see `def_container()`). - **parameters** (any) - Meta information on the parameters of the TI method (see `def_parameters()`). ### Request Example ```R library(dynparam) definition( method = def_method(id = "some_method"), wrapper = def_wrapper(input_required = "expression"), parameters = parameter_set( integer_parameter(id = "k", default = 5L, distribution = uniform_distribution(3L, 20L)) ) ) ``` ### Response Example ```R # $method # $method$id # [1] "some_method" # ... (rest of method details) # # $wrapper # $wrapper$input_required # [1] "expression" # ... (rest of wrapper details) # # $manuscript # NULL # # $container # NULL # # $parameters # k | type=integer | domain=U(3, 20) | default=5 # attr(,"class") # [1] "dynwrap::ti_method" "list" ``` ```