Skip to content

Commit

Permalink
clonalOccupy NA include argument fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ncborcherding committed Apr 2, 2024
1 parent 25a8137 commit ced1942
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person(given = "Qile", family = "Yang", role = c("aut"), email = "[email protected]"),
Expand Down
8 changes: 6 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
25 changes: 17 additions & 8 deletions R/clonalOccupy.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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"

Expand All @@ -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
}
146 changes: 146 additions & 0 deletions tests/testthat/_snaps/clonalOccupy/clonaloccupy-default-plot.new.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
9 changes: 4 additions & 5 deletions vignettes/articles/SC_Visualizations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions vignettes/vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ced1942

Please sign in to comment.