From ad3e1f7aa913b74899afb8aab7e1e55c224a378e Mon Sep 17 00:00:00 2001 From: Hannah Pliner Date: Fri, 3 Jan 2025 14:01:24 +0100 Subject: [PATCH] Update deprecated igraph for 2.1, #69 #70 --- DESCRIPTION | 2 +- R/classify_cells.R | 6 +- R/get_training_sample.R | 2 +- R/train_cell_classifier.R | 6 +- R/utils.R | 2 +- garnett.Rproj | 1 + .../utils/basic-marker-plot-change-amb.svg | 55 ++++++++++--------- .../_snaps/utils/basic-marker-plot.svg | 55 ++++++++++--------- tests/testthat/test-classify_cells.R | 6 +- tests/testthat/test-overall.R | 52 +++++++++--------- tests/testthat/test-utils.R | 2 +- 11 files changed, 98 insertions(+), 91 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7c8ff99..0b82233 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: garnett Type: Package Title: Automated cell type classification -Version: 0.1.23 +Version: 0.1.24 Author: c( person("Hannah", "Pliner", email = "hpliner@uw.edu", role = c("aut", "cre")), person("Cole", "Trapnell", email = "coletrap@uw.edu", role = c("aut"))) diff --git a/R/classify_cells.R b/R/classify_cells.R index 45ae53c..992a63e 100755 --- a/R/classify_cells.R +++ b/R/classify_cells.R @@ -234,7 +234,7 @@ run_classifier <- function(classifier, for (v in igraph::V(classifier@classification_tree)){ child_cell_types <- igraph::V(classifier@classification_tree)[ - suppressWarnings(outnei(v))]$name + suppressWarnings(.outnei(v))]$name if (length(child_cell_types) > 0){ new_gate_res <- make_predictions(cds, classifier, v, @@ -258,7 +258,7 @@ run_classifier <- function(classifier, imputed_gate_res, level_table){ for (child in igraph::V(classifier@classification_tree)[ - suppressWarnings(outnei(v))]){ + suppressWarnings(.outnei(v))]){ curr_level <- paste0("level", tree_levels[child]) if(!curr_level %in% names(level_table)) { level_table[[curr_level]] <- "Unknown" @@ -362,7 +362,7 @@ make_predictions <- function(cds, predictions <- tryCatch({ if(is.null(cvfit)) { child_cell_types <- igraph::V(classifier@classification_tree)[ - suppressWarnings(outnei(curr_node)) ]$name + suppressWarnings(.outnei(curr_node)) ]$name predictions <- matrix(FALSE, nrow=nrow(pData(cds)), ncol=length(child_cell_types), dimnames=list(row.names(pData(cds)), diff --git a/R/get_training_sample.R b/R/get_training_sample.R index 41bbbea..2093849 100755 --- a/R/get_training_sample.R +++ b/R/get_training_sample.R @@ -16,7 +16,7 @@ get_training_sample <- function(cds, ##### Find type assignment from expressed/not expressed ##### child_cell_types <- igraph::V(classifier@classification_tree)[ - suppressWarnings(outnei(curr_node)) ]$name + suppressWarnings(.outnei(curr_node)) ]$name parent <- igraph::V(classifier@classification_tree)[curr_node]$name if (length(child_cell_types) > 0) { if (length(intersect(child_cell_types, diff --git a/R/train_cell_classifier.R b/R/train_cell_classifier.R index 665c9b4..e9c88d7 100755 --- a/R/train_cell_classifier.R +++ b/R/train_cell_classifier.R @@ -284,7 +284,7 @@ train_cell_classifier <- function(cds, for (v in igraph::V(classifier@classification_tree)){ child_cell_types <- igraph::V(classifier@classification_tree)[ - suppressWarnings(outnei(v))]$name + suppressWarnings(.outnei(v))]$name if(length(child_cell_types) > 0) { ### Get CDS subset for training ### @@ -297,7 +297,7 @@ train_cell_classifier <- function(cds, make_predictions(norm_cds, classifier, igraph::V(classifier@classification_tree)[ - suppressWarnings(innei(v))]$name, + suppressWarnings(.innei(v))]$name, rank_prob_ratio = 1.1, s = "lambda.min") if(!igraph::V(classifier@classification_tree)[v]$name %in% @@ -557,7 +557,7 @@ propogate_func <- function(curr_node, parse_list, classifier) { children <- igraph::V(classifier@classification_tree)[ - suppressWarnings(outnei(curr_node))]$name + suppressWarnings(.outnei(curr_node))]$name if(length(children) == 0) { return(parse_list[[curr_node]]@expressed) diff --git a/R/utils.R b/R/utils.R index 0d83959..e1c172d 100755 --- a/R/utils.R +++ b/R/utils.R @@ -403,7 +403,7 @@ check_markers <- function(cds, ##### For each node ##### for (v in igraph::V(classifier@classification_tree)){ child_cell_types <- - igraph::V(classifier@classification_tree)[suppressWarnings(outnei(v))]$name + igraph::V(classifier@classification_tree)[suppressWarnings(.outnei(v))]$name if(length(child_cell_types) == 0) next diff --git a/garnett.Rproj b/garnett.Rproj index 497f8bf..1cd9836 100755 --- a/garnett.Rproj +++ b/garnett.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 1f11074e-b3a3-45d7-991d-16847e3f34b1 RestoreWorkspace: Default SaveWorkspace: Default diff --git a/tests/testthat/_snaps/utils/basic-marker-plot-change-amb.svg b/tests/testthat/_snaps/utils/basic-marker-plot-change-amb.svg index 5dd61ff..753d2dc 100644 --- a/tests/testthat/_snaps/utils/basic-marker-plot-change-amb.svg +++ b/tests/testthat/_snaps/utils/basic-marker-plot-change-amb.svg @@ -28,7 +28,7 @@ - + @@ -181,31 +181,34 @@ Ambiguity - -Marker -score - - - -20 -40 -60 - - -20 -40 -60 -80 -% of -assigned - - - - - - - - + +% of +assigned + + + + + + + + + +20 +40 +60 +80 + +Marker +score + + + + + + +20 +40 +60 basic_marker_plot change amb diff --git a/tests/testthat/_snaps/utils/basic-marker-plot.svg b/tests/testthat/_snaps/utils/basic-marker-plot.svg index 560f229..e842575 100644 --- a/tests/testthat/_snaps/utils/basic-marker-plot.svg +++ b/tests/testthat/_snaps/utils/basic-marker-plot.svg @@ -28,7 +28,7 @@ - + @@ -181,31 +181,34 @@ Ambiguity - -Marker -score - - - -20 -40 -60 - - -20 -40 -60 -80 -% of -assigned - - - - - - - - + +% of +assigned + + + + + + + + + +20 +40 +60 +80 + +Marker +score + + + + + + +20 +40 +60 basic_marker_plot diff --git a/tests/testthat/test-classify_cells.R b/tests/testthat/test-classify_cells.R index cc3eea1..cbdd68f 100755 --- a/tests/testthat/test-classify_cells.R +++ b/tests/testthat/test-classify_cells.R @@ -14,7 +14,7 @@ test_that("get_communities works", { expect_equal(ncol(pData(new_cds)) - 1, ncol(pData(test_cds))) expect_identical(fData(new_cds), fData(test_cds)) expect_equal(length(unique(pData(new_cds)$louv_cluster)), 5) - expect_equal(sum(pData(new_cds)$louv_cluster == 2), 172) + expect_equal(sum(pData(new_cds)$louv_cluster == 2), 161) expect_equal(as.character(pData(new_cds)$louv_cluster[5]), "2") }) @@ -34,8 +34,8 @@ test_that("classify_cells works", { expect_equal(sum(pData(new_cds)$cell_type == "CD8 T cells"), 48) expect_equal(sum(pData(new_cds)$cell_type == "T cells"), 142) expect_equal(sum(pData(new_cds)$cluster_ext_type == "B cells"), 402) - expect_equal(sum(pData(new_cds)$cluster_ext_type == "CD4 T cells"), 204) - expect_equal(sum(pData(new_cds)$cluster_ext_type == "T cells"), 194) + expect_equal(sum(pData(new_cds)$cluster_ext_type == "CD4 T cells"), 267) + expect_equal(sum(pData(new_cds)$cluster_ext_type == "T cells"), 131) }) pData(test_cds)$garnett_cluster <- c(rep(1, times=200), rep(2, times=200), diff --git a/tests/testthat/test-overall.R b/tests/testthat/test-overall.R index cfd3e2a..b8a6d67 100755 --- a/tests/testthat/test-overall.R +++ b/tests/testthat/test-overall.R @@ -19,13 +19,13 @@ test_cds <- garnett::classify_cells(test_cds, test_classifier, cds_gene_id_type = "SYMBOL") test_that("whole process is the same", { - expect_equal(sum(pData(test_cds)$cell_type == "B cells"), 218) - expect_equal(sum(pData(test_cds)$cell_type == "CD4 T cells"), 92) - expect_equal(sum(pData(test_cds)$cell_type == "CD8 T cells"), 56) - expect_equal(sum(pData(test_cds)$cell_type == "T cells"), 120) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "B cells"), 401) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "CD4 T cells"), 265) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "T cells"), 134) + expect_equal(sum(pData(test_cds)$cell_type == "B cells"), 227) + expect_equal(sum(pData(test_cds)$cell_type == "CD4 T cells"), 97) + expect_equal(sum(pData(test_cds)$cell_type == "CD8 T cells"), 61) + expect_equal(sum(pData(test_cds)$cell_type == "T cells"), 113) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "B cells"), 404) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "CD4 T cells"), 0) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "T cells"), 396) }) @@ -61,13 +61,13 @@ test_cds <- garnett::classify_cells(test_cds, test_classifier, cds_gene_id_type = "SYMBOL") test_that("whole process is the same matrix", { - expect_equal(sum(pData(test_cds)$cell_type == "B cells"), 218) - expect_equal(sum(pData(test_cds)$cell_type == "CD4 T cells"), 92) - expect_equal(sum(pData(test_cds)$cell_type == "CD8 T cells"), 56) - expect_equal(sum(pData(test_cds)$cell_type == "T cells"), 120) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "B cells"), 401) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "CD4 T cells"), 265) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "T cells"), 134) + expect_equal(sum(pData(test_cds)$cell_type == "B cells"), 227) + expect_equal(sum(pData(test_cds)$cell_type == "CD4 T cells"), 97) + expect_equal(sum(pData(test_cds)$cell_type == "CD8 T cells"), 61) + expect_equal(sum(pData(test_cds)$cell_type == "T cells"), 113) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "B cells"), 404) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "CD4 T cells"), 0) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "T cells"), 396) expect_is(exprs(test_cds), "matrix") }) @@ -89,13 +89,13 @@ test_cds <- garnett::classify_cells(test_cds, test_classifier, cds_gene_id_type = "SYMBOL") test_that("whole process is the same multi-core", { - expect_equal(sum(pData(test_cds)$cell_type == "B cells"), 218) - expect_equal(sum(pData(test_cds)$cell_type == "CD4 T cells"), 92) - expect_equal(sum(pData(test_cds)$cell_type == "CD8 T cells"), 56) - expect_equal(sum(pData(test_cds)$cell_type == "T cells"), 120) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "B cells"), 401) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "CD4 T cells"), 265) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "T cells"), 134) + expect_equal(sum(pData(test_cds)$cell_type == "B cells"), 227) + expect_equal(sum(pData(test_cds)$cell_type == "CD4 T cells"), 97) + expect_equal(sum(pData(test_cds)$cell_type == "CD8 T cells"), 61) + expect_equal(sum(pData(test_cds)$cell_type == "T cells"), 113) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "B cells"), 404) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "CD4 T cells"), 0) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "T cells"), 396) }) data(test_cds) @@ -116,12 +116,12 @@ test_cds <- garnett::classify_cells(test_cds, test_classifier, cds_gene_id_type = "SYMBOL") test_that("whole process is the same db = 'none'", { - expect_equal(sum(pData(test_cds)$cell_type == "B cells"), 202) - expect_equal(sum(pData(test_cds)$cell_type == "CD4 T cells"), 65) + expect_equal(sum(pData(test_cds)$cell_type == "B cells"), 225) + expect_equal(sum(pData(test_cds)$cell_type == "CD4 T cells"), 82) expect_equal(sum(pData(test_cds)$cell_type == "CD8 T cells"), 52) - expect_equal(sum(pData(test_cds)$cell_type == "T cells"), 100) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "B cells"), 401) + expect_equal(sum(pData(test_cds)$cell_type == "T cells"), 114) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "B cells"), 404) expect_equal(sum(pData(test_cds)$cluster_ext_type == "CD4 T cells"), 0) - expect_equal(sum(pData(test_cds)$cluster_ext_type == "T cells"), 399) + expect_equal(sum(pData(test_cds)$cluster_ext_type == "T cells"), 396) }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 55b095e..686268b 100755 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -9,7 +9,7 @@ ensembl <- garnett:::cds_to_other_id(test_cds, db=org.Hs.eg.db, test_that("cds_to_other_id works", { expect_is(ensembl, "CellDataSet") - expect_equal(nrow(fData(ensembl)), 18893) + expect_equal(nrow(fData(ensembl)), 18813) expect_equal(row.names(fData(ensembl)[ fData(ensembl)$gene_short_name == "FAM87B",]), "ENSG00000177757") expect_identical(exprs(test_cds)["FAM87B",],