Skip to content

Commit 62c2f92

Browse files
authored
Merge pull request #55 from dynverse/devel
dynplot 1.1.1
2 parents 64670d0 + 63cfdd2 commit 62c2f92

File tree

7 files changed

+59
-55
lines changed

7 files changed

+59
-55
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: dynplot
22
Type: Package
33
Title: Visualising Single-Cell Trajectories
4-
Version: 1.1.0
4+
Version: 1.1.1
55
Authors@R:
66
c(person(given = "Robrecht",
77
family = "Cannoodt",

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ importFrom(purrr,map_dbl)
103103
importFrom(purrr,map_df)
104104
importFrom(purrr,map_int)
105105
importFrom(purrr,pmap)
106+
importFrom(purrr,pmap_df)
106107
importFrom(purrr,set_names)
107108
importFrom(stats,approx)
108109
importFrom(stats,as.dendrogram)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# dynplot 1.1.1
2+
3+
* BUG FIX `project_waypoints_coloured()`: Fix refactoring issue "Must supply a symbol or a string as argument" (#54).
4+
5+
* BUG FIX `project_waypoints_coloured()`: Fix wrong results when projecting waypoint segments (#54 bis).
6+
17
# dynplot 1.1.0
28

39
Initial release on CRAN.

R/package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' @importFrom dynutils is_sparse list_as_tibble %all_in% calculate_distance scale_minmax
1818
#' @import dynwrap
1919
#' @importFrom dyndimred dimred_mds dimred_landmark_mds list_dimred_methods dimred_umap
20-
#' @importFrom purrr %>% map map_df map_chr keep pmap map2 set_names map_int map_dbl list_modify discard
20+
#' @importFrom purrr %>% map map_df map_chr keep pmap map2 set_names map_int map_dbl list_modify discard pmap_df
2121
#' @importFrom purrr map2_df map2_dbl map2_df
2222
#' @importFrom assertthat assert_that
2323
#' @importFrom tidygraph as_tbl_graph tbl_graph

R/plot_onedim.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,9 @@ plot_onedim <- dynutils::inherit_default_params(
230230

231231
#' @importFrom dplyr near
232232
make_connection_plotdata <- function(linearised) {
233-
connections <- crossing(
234-
linearised$milestone_network %>% select(.data$from, x_from = .data$cumstart),
235-
linearised$milestone_network %>% select(.data$to, x_to = .data$cumend)
236-
) %>%
233+
from <- linearised$milestone_network %>% select(.data$from, x_from = .data$cumstart)
234+
to <- linearised$milestone_network %>% select(.data$to, x_to = .data$cumend)
235+
connections <- crossing(from, to) %>%
237236
filter(
238237
.data$from == .data$to,
239238
.data$x_from != .data$x_to

R/project_waypoints.R

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,64 +24,55 @@ project_waypoints_coloured <- function(
2424
trajectory_projection_sd = sum(trajectory$milestone_network$length) * 0.05,
2525
color_trajectory = "none"
2626
) {
27-
waypoints$waypoint_network <- waypoints$waypoint_network %>%
27+
wps <- waypoints
28+
wps$waypoint_network <- wps$waypoint_network %>%
2829
rename(
2930
milestone_id_from = .data$from_milestone_id,
3031
milestone_id_to = .data$to_milestone_id
3132
)
3233

3334
assert_that(color_trajectory %in% c("nearest", "none"))
34-
assert_that(setequal(cell_positions$cell_id, colnames(waypoints$geodesic_distances)))
35+
assert_that(setequal(cell_positions$cell_id, colnames(wps$geodesic_distances)))
3536

36-
# project waypoints to dimensionality reduction using kernel and geodesic distances
37-
weights <- waypoints$geodesic_distances %>% stats::dnorm(sd = trajectory_projection_sd)
38-
assert_that(all(!is.na(weights)))
39-
40-
weights <- weights / rowSums(weights)
41-
positions <- cell_positions %>%
42-
select(.data$cell_id, .data$comp_1, .data$comp_2) %>%
43-
slice(match(colnames(weights), .data$cell_id)) %>%
44-
column_to_rownames("cell_id") %>%
45-
as.matrix()
37+
# calculate positions
38+
waypoint_positions <-
39+
if (!is.null(edge_positions)) {
40+
comp_names <- colnames(edge_positions) %>% keep(function(x) grepl("comp_", x))
4641

47-
# make sure weights and positions have the same cell_ids in the same order
48-
assert_that(all.equal(colnames(weights), rownames(positions)))
42+
wps$progressions %>%
43+
select(.data$from, .data$to) %>%
44+
unique() %>%
45+
pmap_df(function(from, to) {
46+
wp_progr <- wps$progressions %>% filter(.data$from == !!from, .data$to == !!to)
47+
edge_pos <- edge_positions %>% filter(.data$from == !!from, .data$to == !!to)
48+
for (cn in comp_names) {
49+
wp_progr[[cn]] <- approx(edge_pos$percentage, edge_pos[[cn]], wp_progr$percentage)$y
50+
}
51+
wp_progr
52+
}) %>%
53+
select(.data$waypoint_id, !!comp_names) %>%
54+
left_join(wps$waypoints, "waypoint_id")
55+
} else {
56+
# project wps to dimensionality reduction using kernel and geodesic distances
57+
weights <- wps$geodesic_distances %>% stats::dnorm(sd = trajectory_projection_sd)
58+
assert_that(all(!is.na(weights)))
4959

50-
# calculate positions
51-
matrix_to_tibble <- function(x, rownames_column) {
52-
y <- as_tibble(x)
53-
y[[rownames_column]] <- rownames(x)
54-
y
55-
}
60+
weights <- weights / rowSums(weights)
61+
positions <- cell_positions %>%
62+
select(.data$cell_id, .data$comp_1, .data$comp_2) %>%
63+
slice(match(colnames(weights), .data$cell_id)) %>%
64+
column_to_rownames("cell_id") %>%
65+
as.matrix()
5666

57-
if (!is.null(edge_positions)) {
58-
approx_funs <-
59-
edge_positions %>%
60-
gather(.data$comp_name, .data$comp_value, starts_with("comp_")) %>%
61-
group_by(.data$from, .data$to, .data$comp_name) %>%
62-
summarise(
63-
approx_fun = {
64-
pct <- .data$percentage
65-
cv <- .data$comp_value
66-
list(function(x) stats::approx(pct, cv, x)$y)
67-
},
68-
.groups = "drop"
69-
)
67+
# make sure weights and positions have the same cell_ids in the same order
68+
assert_that(all.equal(colnames(weights), rownames(positions)))
7069

71-
waypoint_position <-
72-
waypoints$progressions %>%
73-
left_join(approx_funs, by = c("from", "to")) %>%
74-
mutate(
75-
comp_value = map2_dbl(.data$approx_fun, .data$percentage, function(f, pct) f(pct))
76-
) %>%
77-
spread(.data$comp_name, .data$comp_value) %>%
78-
select(.data$waypoint_id, starts_with("comp_")) %>%
79-
left_join(waypoints$waypoints, "waypoint_id")
80-
} else {
81-
waypoint_positions <- (weights %*% positions) %>%
82-
matrix_to_tibble("waypoint_id") %>%
83-
left_join(waypoints$waypoints, "waypoint_id")
84-
}
70+
(weights %*% positions) %>%
71+
as.data.frame() %>%
72+
rownames_to_column("waypoint_id") %>%
73+
left_join(wps$waypoints, "waypoint_id") %>%
74+
as_tibble()
75+
}
8576

8677

8778
# add color of closest cell
@@ -99,7 +90,7 @@ project_waypoints_coloured <- function(
9990

10091
segments <- left_join(
10192
waypoint_positions,
102-
waypoints$progressions,
93+
wps$progressions,
10394
by = "waypoint_id"
10495
) %>%
10596
mutate(group = factor(paste0(.data$from, "---", .data$to))) %>%

cran-comments.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
First release of dynplot on CRAN.
1+
Last update was only a few days ago, but this submission fixes a critical bug
2+
in the code.
3+
4+
## Changelog
5+
6+
* BUG FIX `project_waypoints_coloured()`: Fix refactoring issue "Must supply a symbol or a string as argument" (#54).
7+
8+
* BUG FIX `project_waypoints_coloured()`: Fix wrong results when projecting waypoint segments (#54 bis).
29

310
## Test environments
411
* local R installation, R 4.0.5

0 commit comments

Comments
 (0)