Skip to content

Commit

Permalink
Merge pull request #248 from saeyslab/unit-test
Browse files Browse the repository at this point in the history
Unit testing
  • Loading branch information
csangara authored Jan 17, 2024
2 parents ff76e11 + 8effcd6 commit e9ddb3a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check-bioc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ jobs:
fail-fast: false
matrix:
config:
- { os: ubuntu-latest, r: '4.1', bioc: '3.13', cont: "bioconductor/bioconductor_docker:RELEASE_3_13", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" }
- { os: macOS-latest, r: '4.1', bioc: '3.13'}
- { os: windows-latest, r: '4.1', bioc: '3.13'}
- { os: ubuntu-latest, r: '4.3.2', bioc: '3.18', cont: "bioconductor/bioconductor_docker:RELEASE_3_18", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" }
- { os: macOS-latest, r: '4.3.2', bioc: '3.18'}
- { os: windows-latest, r: '4.3.2', bioc: '3.18'}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM_ROOT: https://packagemanager.posit.co.
Expand Down
15 changes: 5 additions & 10 deletions R/application_visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,9 @@ make_heatmap_bidir_lt_ggplot = function(matrix, y_name, x_name, y_axis = TRUE, x
#'
#' @description \code{make_mushroom_plot} Make a plot in which each glyph consists of two semicircles corresponding to ligand- and receptor- information. The size of the semicircle is the percentage of cells that express the protein, while the saturation corresponds to the scaled average expression value.
#'
#' @usage
#' make_mushroom_plot(prioritization_table, top_n = 30, show_ranking = FALSE, show_all_datapoints = FALSE, true_color_range = FALSE, size = "scaled_avg_exprs", color = "scaled_lfc",
#' ligand_fill_colors = c("#DEEBF7", "#08306B"), receptor_fill_colors = c("#FEE0D2", "#A50F15"),
#' unranked_ligand_fill_colors = c(alpha("#FFFFFF", alpha=0.2), alpha("#252525", alpha=0.2)), unranked_receptor_fill_colors = c( alpha("#FFFFFF", alpha=0.2), alpha("#252525", alpha=0.2)))
#'
#' @param prioritization_table A prioritization table as generated by \code{\link{generate_prioritization_tables}}
#' @param top_n An integer indicating how many ligand-receptor pairs to show
#' @param show_ranking A logical indicating whether to show the ranking of the ligand-receptor pairs (default: FALSE)
#' @param show_rankings A logical indicating whether to show the ranking of the ligand-receptor pairs (default: FALSE)
#' @param show_all_datapoints A logical indicating whether to show all ligand-receptor pairs (default: FALSE, if true they will be grayed out)
#' @param true_color_range A logical indicating whether to use the true color range for the ligand-receptor pairs (default: FALSE; range 0-1 is used)
#' @param size A string indicating which column to use for the size of the semicircles (default: "scaled_avg_exprs"; use column name without "_ligand" or "_receptor" suffix)
Expand All @@ -576,13 +571,13 @@ make_heatmap_bidir_lt_ggplot = function(matrix, y_name, x_name, y_axis = TRUE, x
#' # Create a prioritization table
#' prior_table <- generate_prioritization_tables(processed_expr_table, processed_DE_table, ligand_activities, processed_condition_markers, prioritizing_weights)
#' make_mushroom_plot(prior_table)
#'
#'
#' # Show only top 20, and write rankings on the plot
#' make_mushroom_plot(prior_table, top_n = 20, show_ranking = TRUE)
#'
#' make_mushroom_plot(prior_table, top_n = 20, show_rankings = TRUE)
#'
#' # Show all datapoints, and use true color range
#' make_mushroom_plot(prior_table, show_all_datapoints = TRUE, true_color_range = TRUE)
#'
#'
#' # Change the size and color columns
#' make_mushroom_plot(prior_table, size = "pct_expressed", color = "scaled_avg_exprs")
#' }
Expand Down
5 changes: 3 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@
"annotation_data_sources"
#' Optimized data source weights
#'
#' A data.frame/tibble describing weight associated to each data source. These weights will be used for weighted aggregagion of source networks and were determined via parameter optimization (see NicheNet paper).
#' A data.frame/tibble describing weight associated to each data source. These weights will be used for weighted aggregation of source networks and were determined via parameter optimization (see NicheNet paper).
#'
#' @format A data frame/tibble
#' \describe{
#' \item{source}{name of data source}
#' \item{weight}{weight associated to a data source}
#' \item{avg_weight}{weight associated to a data source, averaged over cross-validation folds}
#' \item{median_weight}{weight associated to a data source, averaged over cross-validation folds}
#' }
#'
"optimized_source_weights_df"
Expand Down
24 changes: 18 additions & 6 deletions man/make_mushroom_plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/optimized_source_weights_df.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test-application_prediction.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test_that("Seurat wrapper works", {
lr_network = readRDS(url("https://zenodo.org/record/7074291/files/lr_network_mouse_21122021.rds"))
weighted_networks = readRDS(url("https://zenodo.org/record/7074291/files/weighted_networks_nsga2r_final_mouse.rds"))
seurat_object_lite = readRDS(url("https://zenodo.org/record/3531889/files/seuratObj_test.rds"))
seurat_object_lite = Seurat::UpdateSeuratObject(seurat_object_lite)

nichenet_output = nichenet_seuratobj_aggregate(seurat_obj = seurat_object_lite, receiver = "CD8 T", condition_oi = "LCMV", condition_reference = "SS", condition_colname = "aggregate", sender = c("Mono"), ligand_target_matrix = ligand_target_matrix, weighted_networks = weighted_networks, lr_network = lr_network)
expect_type(nichenet_output,"list")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-differential_nichenet.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ test_that("Differential NicheNet pipeline works", {
lr_network = lr_network %>% dplyr::rename(ligand = from, receptor = to) %>% distinct(ligand, receptor)

seurat_object_lite = readRDS(url("https://zenodo.org/record/3531889/files/seuratObj_test.rds"))
seurat_object_lite = Seurat::UpdateSeuratObject(seurat_object_lite)

seurat_object_lite@meta.data$celltype_aggregate = paste(seurat_object_lite@meta.data$celltype, seurat_object_lite@meta.data$aggregate,sep = "_") # user adaptation required on own dataset

celltype_id = "celltype_aggregate" # metadata column name of the cell type of interest
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-prioritization.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test_that("Prioritization scheme works", {
lr_network = readRDS(url("https://zenodo.org/record/7074291/files/lr_network_mouse_21122021.rds"))
weighted_networks = readRDS(url("https://zenodo.org/record/7074291/files/weighted_networks_nsga2r_final_mouse.rds"))
seurat_obj_test = readRDS(url("https://zenodo.org/record/3531889/files/seuratObj_test.rds"))
seurat_obj_test = Seurat::UpdateSeuratObject(seurat_obj_test)

lr_network = lr_network %>% distinct(from, to)
weighted_networks_lr = weighted_networks$lr_sig %>% inner_join(lr_network, by = c("from","to"))
Expand Down

0 comments on commit e9ddb3a

Please sign in to comment.