From ced1942215064462692144adab046a19ec4f5ec2 Mon Sep 17 00:00:00 2001 From: theHumanBorch Date: Tue, 2 Apr 2024 11:23:36 -0500 Subject: [PATCH] clonalOccupy NA include argument fix #337 --- DESCRIPTION | 2 +- NEWS.md | 8 +- R/clonalOccupy.R | 25 ++- .../clonaloccupy-default-plot.new.svg | 146 ++++++++++++++++++ .../clonaloccupy-proportion-plot.new.svg | 119 ++++++++++++++ .../clonalOccupy_exportTable.rds | Bin 396 -> 544 bytes vignettes/articles/SC_Visualizations.Rmd | 9 +- vignettes/vignette.Rmd | 6 +- 8 files changed, 296 insertions(+), 19 deletions(-) create mode 100644 tests/testthat/_snaps/clonalOccupy/clonaloccupy-default-plot.new.svg create mode 100644 tests/testthat/_snaps/clonalOccupy/clonaloccupy-proportion-plot.new.svg diff --git a/DESCRIPTION b/DESCRIPTION index ad129539..ec7d97d9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: scRepertoire Title: A toolkit for single-cell immune receptor profiling -Version: 2.0.1 +Version: 2.0.2 Authors@R: c( person(given = "Nick", family = "Borcherding", role = c("aut", "cre"), email = "ncborch@gmail.com"), person(given = "Qile", family = "Yang", role = c("aut"), email = "qile0317@gmail.com"), diff --git a/NEWS.md b/NEWS.md index 9f946495..78d0f22f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,14 @@ +# scRepertoire VERSION 2.0.2 + +## UNDERLYING CHANGES + +*```clonalOccupy()``` rewrite counting and NA handling + # scRepertoire VERSION 2.0.1 ## UNDERLYING CHANGES *```clonalOverlay()``` arguments now cutpoint and use cut.category to select either clonalProportion or clonalFrequency -* ```clonalOccupy()``` allow NA calls - # scRepertoire VERSION 2.0.0 (2024-01-10) diff --git a/R/clonalOccupy.R b/R/clonalOccupy.R index 39786601..13d93419 100644 --- a/R/clonalOccupy.R +++ b/R/clonalOccupy.R @@ -33,7 +33,7 @@ #' environment in addition to the visualization. #' @param palette Colors to use in visualization - input any #' \link[grDevices]{hcl.pals}. -#' @importFrom dplyr %>% group_by mutate +#' @importFrom dplyr %>% group_by mutate count #' @importFrom reshape2 melt #' @import ggplot2 #' @export @@ -50,20 +50,29 @@ clonalOccupy <- function(sc.data, palette = "inferno") { .checkSingleObject(sc.data) meta <- .grabMeta(sc.data) - meta <- melt(table(meta[(meta[,"clonalFrequency"]), - c(x.axis, facet.by, "cloneSize")], useNA = "ifany")) + + meta <- meta %>% + group_by(meta[,x.axis], meta[,facet.by], cloneSize) %>% + count() %>% + as.data.frame() + + colnames(meta)[1] <- x.axis + if(!is.null(facet.by)) { + colnames(meta)[2] <- facet.by + } + #Check for NAs if (!na.include) { meta <- na.omit(meta) } - meta <- meta[meta$value != 0,] + meta <- meta[meta$n != 0,] #Convert to proportion if(proportion) { meta <- meta %>% group_by(meta[,1]) %>% - mutate(total = sum(value), - prop = value/total) + mutate(total = sum(n), + prop = n/total) meta <- as.data.frame(meta) } if (exportTable) { @@ -77,7 +86,7 @@ clonalOccupy <- function(sc.data, lab <- "Proportion of Cells" } else { - plot <- ggplot(meta, aes(x = meta[,x.axis], y = value, fill = cloneSize)) + + plot <- ggplot(meta, aes(x = meta[,x.axis], y = n, fill = cloneSize)) + geom_bar(stat = "identity", color = "black", lwd = 0.25) lab <- "Single Cells" @@ -94,7 +103,7 @@ clonalOccupy <- function(sc.data, } if (label) { plot <- plot + - geom_text(aes(label = value), position = position_stack(vjust = 0.5)) + geom_text(aes(label = n), position = position_stack(vjust = 0.5)) } plot } \ No newline at end of file diff --git a/tests/testthat/_snaps/clonalOccupy/clonaloccupy-default-plot.new.svg b/tests/testthat/_snaps/clonalOccupy/clonaloccupy-default-plot.new.svg new file mode 100644 index 00000000..c04c8b9c --- /dev/null +++ b/tests/testthat/_snaps/clonalOccupy/clonaloccupy-default-plot.new.svg @@ -0,0 +1,146 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +34 +41 +18 +27 +1 +34 +5 +11 +18 +8 +23 +11 +26 +3 +1 +25 +1 +19 +5 +5 +3 +16 +4 +1 +12 +4 +6 +1 +2 + + + +0 +20 +40 +60 + + + + + + + + + + + + + + + + + + + + + +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +Single Cells + +cloneSize + + + + + + +Hyperexpanded (0.1 < X <= 1) +Large (0.01 < X <= 0.1) +Medium (0.001 < X <= 0.01) +clonalOccupy_default_plot + + diff --git a/tests/testthat/_snaps/clonalOccupy/clonaloccupy-proportion-plot.new.svg b/tests/testthat/_snaps/clonalOccupy/clonaloccupy-proportion-plot.new.svg new file mode 100644 index 00000000..635b1f4a --- /dev/null +++ b/tests/testthat/_snaps/clonalOccupy/clonaloccupy-proportion-plot.new.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 + + + + + + + + + + + + + + + + + + + + + + +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +Proportion of Cells + +cloneSize + + + + + + +Hyperexpanded (0.1 < X <= 1) +Large (0.01 < X <= 0.1) +Medium (0.001 < X <= 0.01) +clonalOccupy_proportion_plot + + diff --git a/tests/testthat/testdata/seuratFunctions/clonalOccupy_exportTable.rds b/tests/testthat/testdata/seuratFunctions/clonalOccupy_exportTable.rds index 529524e69fccad611b07649ba8ba30c8e6374664..c0d7d65aa523e763a87064ed35c5626eabc81ff3 100644 GIT binary patch literal 544 zcmV+*0^j`~iwFP!000001Fe+bQ`0~Y$FI4x+5)zKfFNqbUqxvrf%3x{e06+KA4F$( zW6tKvWF}3RORC}@?VkYbHM^Iy)AGc_XYSkGP4-8&ciLc#aprP|@hV7G{qg-{=Ll@e zV+Z34a6SPlh=Xto*P@Elkb4&QfjZJa=74!X=Xn4$fmVU*jB~o<_*yJ~$v8vrB3df} ziCq$VBzh$FNgR+kBymLIJqjoAjS7s~HEPeOo>BWo9T;^uQGT@_i;Su_Jq<)ZPZg*u zYtl4bIx92uZE?;N`z&}-YULWMt6_DUpDr(?l7B8l63WnP``y4h_D;Ry4_>g1F>9ZN zI+xn#8z;n(d*h1?qtS5ew*&k#;$$e|*lP!}uehBeW3JeRGV=a|(+-#qGC`4#?OibM=0 zEd@toGm|4F^0R(C%5tePG}rqvw0aW#m9(;34n` z+tFk2uqU3zS?fw**MB4&(-@@sW?GDN_ z?`Fljr+#}k9Y%TSFXyGw-(C6w_BH3Q@+z~hE&HmXYibEsU`@l@0;D3o$VC}AsW#&_!=-I#`Dun^9p8_NFZbt*u}99 zECDh|0o2sGjLxB+2Tb%W11q@C8c+mE3*yb0M~lx^GN}JVTa2zoXX#NcInJhx`(^TOF%sb*`;;13lF{Dqfk?oJ0g)EZ6RtHwcH3o;EmhM|Vg$ zx9m1+I+rQK+_CXUg*+iSTRLO0^e`TQm;^R5l^HIleq2~mZlAirSitBj^#BxXrh=Dr z2$WO*s>~MH1}fOl5;j-CN1$Vqf-WqDgtWm#H9nm3+Q`K;>=(AAJ;Kk*k zA28wLvgvZDyF2(~aqyJ#kY#o>#rUli@A}s}FJn3D@~VMNEOiS@tzj8;jNb$H0Sh<) qj(}s}1ULoG02|9c2QFqwso$9<6g(QxR$oARvJpT0P6RTk0{{Rb7q*oE diff --git a/vignettes/articles/SC_Visualizations.Rmd b/vignettes/articles/SC_Visualizations.Rmd index 23fa8983..d9b8aea0 100644 --- a/vignettes/articles/SC_Visualizations.Rmd +++ b/vignettes/articles/SC_Visualizations.Rmd @@ -88,7 +88,7 @@ This visualization was authored by Dr. Francesco Mazziotta and inspired by Drs. ```{r tidy = FALSE} clonalOverlay(scRep_example, reduction = "umap", - freq.cutpoint = 1, + cutpoint = 1, bins = 10, facet.by = "Patient") + guides(color = "none") @@ -129,7 +129,6 @@ clonalNetwork(scRep_example, filter.clones = NULL, filter.identity = NULL, cloneCall = "aa") - ``` We can look at the clonal relationships relative to a single cluster using the **filter.identity** parameter. @@ -185,9 +184,9 @@ clonalOccupy(scRep_example, x.axis = "seurat_clusters") clonalOccupy(scRep_example, - x.axis = "ident", - proportion = TRUE, - label = FALSE) + x.axis = "ident", + proportion = TRUE, + label = FALSE) ``` ## alluvialClones diff --git a/vignettes/vignette.Rmd b/vignettes/vignette.Rmd index 6a437491..7924c76e 100644 --- a/vignettes/vignette.Rmd +++ b/vignettes/vignette.Rmd @@ -996,9 +996,9 @@ clonalOccupy(scRep_example, x.axis = "seurat_clusters") clonalOccupy(scRep_example, - x.axis = "ident", - proportion = TRUE, - label = FALSE) + x.axis = "ident", + proportion = TRUE, + label = FALSE) ``` ## alluvialClones