Skip to content

Commit 64670d0

Browse files
committed
add more roxygen to the functions
1 parent dded568 commit 64670d0

19 files changed

+375
-210
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ Collate:
8282
'plot_strip.R'
8383
'plot_topology.R'
8484
'theme_clean.R'
85+
Roxygen: list(markdown = TRUE)

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
export(add_milestone_coloring)
43
export(empty_plot)
54
export(get_milestone_palette_names)
65
export(linearise_cells)

R/add_cell_coloring.R

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
11
#' Add colouring to a set of cells.
22
#'
3+
#' The cells can be coloured by a grouping (clustering), according to a feature
4+
#' (gene expression), closest milestone, or pseudotime from the root of the trajectory.
5+
#'
36
#' @param cell_positions The positions of the cells, represented by a tibble.
47
#' Must contain column `cell_id` (character) and may contain columns `from`,
58
#' `to`, `pseudotime`, depending on the value of `color_cells`.
6-
#' @param color_cells How to color the cells
7-
#' @param trajectory The trajectory
8-
#' @param grouping The grouping of the cells
9-
#' @param groups Tibble containing information of the cell groups
10-
#' @param feature_oi feature to plot expression
11-
#' @param expression_source Source of the feature expression, defaults to `expression`
12-
#' @param pseudotime The pseudotime
13-
#' @param milestone_percentages The milestone percentages
9+
#' @param color_cells How to color the cells.
10+
#' * `"auto"`: Try to figure out how to color cells depending on whether
11+
#' one of the `grouping`, `feature_io`, `milestones` or `pseudotime` parameters are defined.
12+
#' * `"none"`: Cells are not coloured.
13+
#' * `"grouping"`: Cells are coloured according to a grouping (e.g. clustering).
14+
#' Either the `grouping` parameter or `trajectory$grouping` must be a named character vector.
15+
#' * `"feature"`: Cells are coloured according to the values of a given feature (e.g. gene expression).
16+
#' Either the `expression_source` parameter or `get_expression(trajectory)` must be a matrix.
17+
#' Parameter `feature_oi` must also be defined.
18+
#' * `"milestone"` (recommended): Cells are coloured according their position in the trajectory. The positioning of the
19+
#' cells are determined by parameter `milestone_percentages` or else by `trajectory$milestone_percentages`. The colours
20+
#' of the milestones can be determined automatically or can be specified by passing a tibble containing character columns
21+
#' `milestone_id` and `color` (See `add_milestone_coloring()` for help in constructing this object).
22+
#' * `"pseudotime"`: Cells are coloured according to the pseudotime value from the root.
23+
#'
24+
#' @param trajectory A dynwrap trajectory.
25+
#' @param grouping A grouping of the cells (e.g. clustering) as a named character vector.
26+
#' @param groups A tibble containing character columns `group_id` and `color`. If `NULL`, this object is inferred from the `grouping` itself.
27+
#' @param feature_oi The name of a feature to use for colouring the cells.
28+
#' @param expression_source Source of the feature expression, defaults to `get_expression(trajectory)`.
29+
#' @param pseudotime The pseudotime from the root of the trajectory to the cells as a named numeric vector.
30+
#' @param milestone_percentages The milestone percentages.
31+
#'
32+
#' @returns
33+
#' A named list with following objects:
34+
#' * cell_positions: The `trajectory$progressions` object with a `color` column added.
35+
#' * color_scale: A ggplot colour scale to add to the downstream ggplot.
36+
#' * fill_scale: A ggplot fill scale to add to the downstream ggplot.
37+
#' * color_cells: The input `color_cells` value, except `"auto"` will have been replaced depending
38+
#' on which other parameters were passed.
39+
#'
40+
# @examples
41+
# add_cell_coloring(example_bifurcating$progressions)
1442
#'
1543
#' @inheritParams add_milestone_coloring
1644
#'

R/add_density_coloring.R

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
#' Color cells using a background density
22
#'
3-
#' @param cell_positions The positions of the cells in 2D
4-
#' @param color_density How to color density, can be "none", "grouping", or "feature"
5-
#' @param padding The padding in the edges to the plot, relative to the size of the plot
6-
#' @param nbins Number of bins for calculating the density
7-
#' @param bw Bandwidth, relative to the size of the plot
8-
#' @param density_cutoff Cutoff for density, the lower the larger the areas
9-
#' @param density_cutoff_label Cutoff for density for labelling, the lower the further way from cells
3+
#' @param cell_positions The positions of the cells in 2D. Must be a tibble with character column `cell_id` and numeric columns `comp_1` and `comp_2`.
4+
#' @param color_density How to color density, can be "none", "grouping", or "feature".
5+
#' @param padding The padding in the edges to the plot, relative to the size of the plot.
6+
#' @param nbins Number of bins for calculating the density.
7+
#' @param bw Bandwidth, relative to the size of the plot.
8+
#' @param density_cutoff Cutoff for density, the lower the larger the areas.
9+
#' @param density_cutoff_label Cutoff for density for labeling, the lower the further way from cells.
1010
#' @inheritParams add_cell_coloring
11+
#'
12+
#' @returns A named list with objects:
13+
#' * polygon: A layer to add to the ggplot.
14+
#' * scale: A scale to add to the ggplot.
15+
#'
16+
# @examples
17+
# pca <- prcomp(example_bifurcating$expression, rank. = 2)$x
18+
# cell_positions <- pca %>% as.matrix %>% as.data.frame %>% magrittr::set_colnames(c("comp_1", "comp_2")) %>% rownames_to_column("cell_id")
19+
# add_density_coloring(cell_positions, "feature", trajectory = example_bifurcating, feature_oi = "B1_TF1")
1120
add_density_coloring <- function(
1221
cell_positions,
1322
color_density = c("none", "grouping", "feature"),
@@ -26,7 +35,9 @@ add_density_coloring <- function(
2635

2736
if (color_density == "none") return(list())
2837

29-
if (any(!c("comp_1", "comp_2", "cell_id") %in% colnames(cell_positions))) {stop("Invalid cell positions")}
38+
if (any(!c("comp_1", "comp_2", "cell_id") %in% colnames(cell_positions))) {
39+
stop("Invalid value for cell_positions. See documentation for more details.")
40+
}
3041

3142
xlims <- c(min(cell_positions$comp_1), max(cell_positions$comp_1))
3243
ylims <- c(min(cell_positions$comp_2), max(cell_positions$comp_2))

R/add_milestone_coloring.R

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@
1717
#'
1818
#' @include milestone_palette.R
1919
#'
20-
#' @export
21-
#'
22-
#' @examples
23-
#' milestones <- data.frame(
24-
#' milestone_id = c("A", "B", "C")
25-
#' )
26-
#' add_milestone_coloring(milestones)
27-
#'
28-
#' milestones <- data.frame(
29-
#' milestone_id = c("A", "B", "C"),
30-
#' color = c("#111111", "#222222", "#333333")
31-
#' )
32-
#' add_milestone_coloring(milestones)
20+
# @examples
21+
# milestones <- data.frame(
22+
# milestone_id = c("A", "B", "C")
23+
# )
24+
# add_milestone_coloring(milestones)
25+
#
26+
# milestones <- data.frame(
27+
# milestone_id = c("A", "B", "C"),
28+
# color = c("#111111", "#222222", "#333333")
29+
# )
30+
# add_milestone_coloring(milestones)
3331
add_milestone_coloring <- function(
3432
milestones = NULL,
3533
color_milestones = c("auto", "given", get_milestone_palette_names())

R/milestone_palette.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ milestone_palette_list <- list(
3232
}
3333
)
3434

35-
#' @param name The name of the palette. Must be one of \code{"cubeHelix"}, \code{"Set3"}, or \code{"rainbow"}.
35+
#' @param name The name of the palette. Must be one of `"cubeHelix"`, `"Set3"`, or `"rainbow"`.
3636
#' @param n The number of colours to be in the palette.
3737
#'
3838
#' @rdname get_milestone_palette_names

R/project_waypoints.R

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#' Project the waypoints
22
#'
33
#' @inheritParams add_cell_coloring
4-
#' @param waypoints The waypoints to use for projecting, as generated by [dynwrap::select_waypoints()]
5-
#' @param trajectory_projection_sd The standard deviation of the gaussian kernel
6-
#' @param color_trajectory How to color the trajectory, can be "nearest" for coloring to nearest cell, or "none"
7-
#' @param edge_positions The positions of the edges
4+
#' @param cell_positions The positions of the cells in 2D. Must be a tibble with character column `cell_id` and numeric columns `comp_1` and `comp_2`.
5+
#' @param waypoints The waypoints to use for projecting. Can by generated using [dynwrap::select_waypoints()].
6+
#' @param trajectory_projection_sd The standard deviation of the gaussian kernel.
7+
#' @param color_trajectory How to color the trajectory, can be "nearest" for coloring to nearest cell, or "none".
8+
#' @param edge_positions The positions of the edges.
9+
#'
10+
#' @returns
11+
#' A named list containing items:
12+
#' * segments: A tibble containing columns `comp_1` (numeric), `comp_2` (numeric), `waypoint_id` (character), `milestone_id` (character), `from` (character), `to` (character)
13+
#' `percentage` (numeric), `group` (factor), and `arrow` (logical).
14+
#'
15+
# @examples
16+
# pca <- prcomp(example_bifurcating$expression, rank. = 2)$x
17+
# cell_positions <- pca %>% as.matrix %>% as.data.frame %>% magrittr::set_colnames(c("comp_1", "comp_2")) %>% rownames_to_column("cell_id")
18+
# project_waypoints_coloured(example_bifurcating, cell_positions)
819
project_waypoints_coloured <- function(
920
trajectory,
1021
cell_positions,

man/add_cell_coloring.Rd

Lines changed: 51 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/add_density_coloring.Rd

Lines changed: 19 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/add_milestone_coloring.Rd

Lines changed: 14 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)