Skip to content

Commit

Permalink
Remove select_se() and replace with embracing where required.
Browse files Browse the repository at this point in the history
  • Loading branch information
brgew committed Mar 30, 2024
1 parent 818262b commit 721d664
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 270 deletions.
1 change: 0 additions & 1 deletion .github/workflows/check_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ jobs:
# Rscript -e 'install.packages(c("ggdist", "ggforce"))'
- name: Run R CMD build and R CMD check
run: |
Rscript -e 'install.packages(c("rlang"))'
R CMD build .
R CMD check monocle3*tar.gz
shell: bash
Expand Down
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ Imports:
RColorBrewer,
Rcpp (>= 1.0.1),
reshape2 (>= 1.4.3),
rlang (>= 1.1.3),
rsample (>= 0.0.5),
RhpcBLASctl,
RcppAnnoy,
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Generated by roxygen2: do not edit by hand

S3method(select_se,data.frame)
S3method(select_se,grouped_df)
export("fData<-")
export("pData<-")
export("principal_graph<-")
Expand Down Expand Up @@ -72,7 +70,6 @@ export(save_transform_models)
export(search_cds_nn_index)
export(search_nn_index)
export(search_nn_matrix)
export(select_se)
export(set_cds_nn_index)
export(set_cds_row_order_matrix)
export(set_matrix_control)
Expand Down
6 changes: 6 additions & 0 deletions R/cluster_cells.R
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ compute_partitions <- function(g,
optim_res,
qval_thresh=0.05,
verbose = FALSE){
# The cells membership may have information about the
# clusters to which cells' nearest neighbors belong.
cell_membership <- as.factor(igraph::membership(optim_res))
membership_matrix <- Matrix::sparse.model.matrix( ~ cell_membership + 0)
num_links <- Matrix::t(membership_matrix) %*%
Expand All @@ -617,6 +619,10 @@ compute_partitions <- function(g,

num_links <- num_links_ij / total_edges

# Deal with zero total edges.
num_links[is.nan(num_links)] <- 0
cluster_mat[is.nan(cluster_mat)] <- 0

cluster_mat <- matrix(stats::p.adjust(cluster_mat),
nrow=length(louvain_modules),
ncol=length(louvain_modules))
Expand Down
152 changes: 0 additions & 152 deletions R/deprec_dplyr.R

This file was deleted.

14 changes: 8 additions & 6 deletions R/order_cells.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,30 +245,32 @@ select_trajectory_roots <- function(cds, x=1, y=2, # nocov start
if (use_3d){
edge_df <- dp_mst %>%
igraph::as_data_frame() %>%
monocle3::select_se(source = "from", target = "to") %>%
# select() and select_() behave the same with these arguments.
dplyr::select(source = "from", target = "to") %>%
dplyr::left_join(ica_space_df %>%
monocle3::select_se(source="sample_name",
dplyr::select(source="sample_name",
source_prin_graph_dim_1="prin_graph_dim_1",
source_prin_graph_dim_2="prin_graph_dim_2",
source_prin_graph_dim_3="prin_graph_dim_3"),
by = "source") %>%
dplyr::left_join(ica_space_df %>%
monocle3::select_se(target="sample_name",
dplyr::select(target="sample_name",
target_prin_graph_dim_1="prin_graph_dim_1",
target_prin_graph_dim_2="prin_graph_dim_2",
target_prin_graph_dim_3="prin_graph_dim_3"),
by = "target")
}else{
edge_df <- dp_mst %>%
igraph::as_data_frame() %>%
monocle3::select_se(source = "from", target = "to") %>%
# select() and select_() behave the same with these arguments.
dplyr::select(source = "from", target = "to") %>%
dplyr::left_join(ica_space_df %>%
monocle3::select_se(source="sample_name",
dplyr::select(source="sample_name",
source_prin_graph_dim_1="prin_graph_dim_1",
source_prin_graph_dim_2="prin_graph_dim_2"),
by = "source") %>%
dplyr::left_join(ica_space_df %>%
monocle3::select_se(target="sample_name",
dplyr::select(target="sample_name",
target_prin_graph_dim_1="prin_graph_dim_1",
target_prin_graph_dim_2="prin_graph_dim_2"),
by = "target")
Expand Down
43 changes: 25 additions & 18 deletions R/plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,29 +284,31 @@ plot_cells_3d <- function(cds,
## Graph info
if (show_trajectory_graph) {

# select() and select_() behave differently here so embrace x, y, and z.
ica_space_df <- t(cds@principal_graph_aux[[reduction_method]]$dp_mst) %>%
as.data.frame() %>%
monocle3::select_se(prin_graph_dim_1 = x, prin_graph_dim_2 = y,
prin_graph_dim_3 = z) %>%
dplyr::select(prin_graph_dim_1 = {{x}}, prin_graph_dim_2 = {{y}},
prin_graph_dim_3 = {{z}}) %>%
dplyr::mutate(sample_name = rownames(.),
sample_state = rownames(.))

dp_mst <- cds@principal_graph[[reduction_method]]

# select() and select_() behave the same with these arguments.
edge_df <- dp_mst %>%
igraph::as_data_frame() %>%
monocle3::select_se(source = "from", target = "to") %>%
dplyr::select(source = "from", target = "to") %>%
dplyr::left_join(ica_space_df %>%
monocle3::select_se(source="sample_name",
source_prin_graph_dim_1="prin_graph_dim_1",
source_prin_graph_dim_2="prin_graph_dim_2",
source_prin_graph_dim_3="prin_graph_dim_3"),
dplyr::select(source="sample_name",
source_prin_graph_dim_1="prin_graph_dim_1",
source_prin_graph_dim_2="prin_graph_dim_2",
source_prin_graph_dim_3="prin_graph_dim_3"),
by = "source") %>%
dplyr::left_join(ica_space_df %>%
monocle3::select_se(target="sample_name",
target_prin_graph_dim_1="prin_graph_dim_1",
target_prin_graph_dim_2="prin_graph_dim_2",
target_prin_graph_dim_3="prin_graph_dim_3"),
dplyr::select(target="sample_name",
target_prin_graph_dim_1="prin_graph_dim_1",
target_prin_graph_dim_2="prin_graph_dim_2",
target_prin_graph_dim_3="prin_graph_dim_3"),
by = "target")

if(nrow(edge_df) < 1) warning('bad loop: nrow(edge_df) < 1')
Expand Down Expand Up @@ -547,25 +549,27 @@ plot_cells <- function(cds,
## Graph info
if (show_trajectory_graph) {

# select() and select_() behave differently here so embrace x and y.
ica_space_df <- t(cds@principal_graph_aux[[reduction_method]]$dp_mst) %>%
as.data.frame() %>%
monocle3::select_se(prin_graph_dim_1 = x, prin_graph_dim_2 = y) %>%
dplyr::select(prin_graph_dim_1 = {{x}}, prin_graph_dim_2 = {{y}}) %>%
dplyr::mutate(sample_name = rownames(.),
sample_state = rownames(.))

dp_mst <- cds@principal_graph[[reduction_method]]

# select() and select_() behave the same with these arguments.
edge_df <- dp_mst %>%
igraph::as_data_frame() %>%
monocle3::select_se(source = "from", target = "to") %>%
dplyr::select(source = "from", target = "to") %>%
dplyr::left_join(ica_space_df %>%
monocle3::select_se(
dplyr::select(
source="sample_name",
source_prin_graph_dim_1="prin_graph_dim_1",
source_prin_graph_dim_2="prin_graph_dim_2"),
by = "source") %>%
dplyr::left_join(ica_space_df %>%
monocle3::select_se(
dplyr::select(
target="sample_name",
target_prin_graph_dim_1="prin_graph_dim_1",
target_prin_graph_dim_2="prin_graph_dim_2"),
Expand Down Expand Up @@ -1883,12 +1887,14 @@ plot_genes_by_group <- function(cds,
g <- ggplot(ExpVal, aes(y = Gene, x = Group)) +
geom_point(aes(colour = group_color_class, size = mean)) +
#viridis::scale_color_viridis(name = 'percentage') +
scale_size(name = 'log(mean + 0.1)', range = c(0, max.size))
#scale_size(name = 'log(mean + 0.1)', range = c(0, max.size))
scale_size(name = paste0('log(mean + ', pseudocount, ')'), range = c(0, max.size))
}else{
g <- ggplot(ExpVal, aes(y = Gene, x = Group)) +
geom_point(aes(colour = percentage, size = mean)) +
viridis::scale_color_viridis(name = 'percentage') +
scale_size(name = 'log(mean + 0.1)', range = c(0, max.size))
#scale_size(name = 'log(mean + 0.1)', range = c(0, max.size))
scale_size(name = paste0('log(mean + ', pseudocount, ')'), range = c(0, max.size))
}
} else {
if (color_by_group){
Expand All @@ -1899,7 +1905,8 @@ plot_genes_by_group <- function(cds,
}else{
g <- ggplot(ExpVal, aes(y = Gene, x = Group)) +
geom_point(aes(colour = mean, size = percentage)) +
viridis::scale_color_viridis(name = 'log(mean + 0.1)') +
#viridis::scale_color_viridis(name = 'log(mean + 0.1)') +
viridis::scale_color_viridis(name = paste0('log(mean + ', pseudocount, ')')) +
scale_size(name = 'percentage', range = c(0, max.size))
}
}
Expand Down
Loading

0 comments on commit 721d664

Please sign in to comment.