Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0.2 #343

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0
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
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +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

# scRepertoire VERSION 2.0.0 (2024-01-10)

Expand Down
26 changes: 18 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,30 @@
palette = "inferno") {
.checkSingleObject(sc.data)
meta <- .grabMeta(sc.data)
meta <- melt(table(meta[!is.na(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()
meta[,1] <- as.factor(meta[,1])

colnames(meta)[1] <- x.axis
if(!is.null(facet.by)) {
colnames(meta)[2] <- facet.by

Check warning on line 62 in R/clonalOccupy.R

View check run for this annotation

Codecov / codecov/patch

R/clonalOccupy.R#L62

Added line #L62 was not covered by tests
}

#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 +87,7 @@
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 +104,7 @@
}
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
}
24 changes: 17 additions & 7 deletions R/clonalOverlay.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
#' #Using clonalOverlay()
#' clonalOverlay(scRep_example,
#' reduction = "umap",
#' freq.cutpoint = 0.3,
#' cutpoint = 3,
#' bins = 5)
#'
#' @param sc.data The single-cell object after \code{\link{combineExpression}}.
#' @param reduction The dimensional reduction to visualize
#' @param freq.cutpoint The overlay cut point to include, this corresponds to the
#' Frequency variable in the single-cell object
#' @param reduction The dimensional reduction to visualize.
#' @param cut.category Meta data variable of the single-cell object to use for
#' filtering.
#' @param cutpoint The overlay cut point to include, this corresponds to the
#' cut.category variable in the meta data of the single-cell object.
#' @param bins The number of contours to the overlay
#' @param facet.by meta data variable to facet the comparison
#'
Expand All @@ -40,20 +42,28 @@

clonalOverlay <- function(sc.data,
reduction = NULL,
freq.cutpoint = 30,
cut.category = "clonalFrequency",
cutpoint = 30,
bins = 25,
facet.by = NULL) {
.checkSingleObject(sc.data)

#Forming the data frame to plot
tmp <- data.frame(.grabMeta(sc.data), .get.coord(sc.data, reduction))

if(cut.category %!in% colnames(tmp)) {
stop("If filtering the data using a cutpoint, ensure the cut.category correspond to a variable in the meta data.")

Check warning on line 55 in R/clonalOverlay.R

View check run for this annotation

Codecov / codecov/patch

R/clonalOverlay.R#L55

Added line #L55 was not covered by tests
}
#Add facet variable if present
if (!is.null(facet.by)) {
facet.by <- tmp[,facet.by]
tmp <- data.frame(facet.by, tmp)
}
tmp$include <- ifelse(tmp[,"clonalFrequency"] >= freq.cutpoint, "Yes", NA)
tmp2 <- subset(tmp, include == "Yes")
#If using cut.category for filtering
if(!is.null(cut.category) & !is.null(cutpoint)) {
tmp$include <- ifelse(tmp[,cut.category] >= cutpoint, "Yes", NA)
tmp2 <- subset(tmp, include == "Yes")
}

#Plotting
plot <- ggplot(tmp2, mapping = aes(x = tmp2[,(ncol(tmp2)-2)],
Expand Down
14 changes: 9 additions & 5 deletions man/clonalOverlay.Rd

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

Loading
Loading