Skip to content

Commit

Permalink
Merge pull request #17 from xiangpin/master
Browse files Browse the repository at this point in the history
add the meta.data of cell for Seurat
  • Loading branch information
GuangchuangYu authored Dec 12, 2023
2 parents 7c02be5 + 972061e commit 9e822be
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ gh-pages
^\.Rproj\.user$
^\.Rproj$
docs
^\.github
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Authors@R: c(
),
person("Noriaki", "Sato",
email = "[email protected]",
role = "cbt")
role = "ctb")
)
Description: Useful functions to visualize single cell and spatial
data. It supports visualizing 'Seurat', 'SingleCellExperiment' and 'SpatialExperiment' objects through grammar of graphics syntax implemented in 'ggplot2'.
Expand Down
3 changes: 2 additions & 1 deletion R/sc-dim.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ get_dim_data <- function(object, features = NULL,
if (is.null(cells)) {
cells <- colnames(object)
}
xx <- data.frame(ident=SeuratObject::Idents(object)[cells])
#xx <- data.frame(ident=SeuratObject::Idents(object)[cells])
xx <- cbind(data.frame(ident = SeuratObject::Idents(object)[cells]), object@meta.data[cells,,drop=FALSE])

if (!is.null(dims)) {
if (is.null(reduction)) {
Expand Down
7 changes: 5 additions & 2 deletions R/sc-dot.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ setMethod("sc_dot", 'Seurat', function(object, features,
features <- unlist(features)
}
d <- get_dim_data(object, dims=NULL, features=features, slot=slot)
d <- tidyr::pivot_longer(d, 2:ncol(d), names_to = "features")

indx.f <- seq(ncol(d) - length(features) + 1, ncol(d))
d <- tidyr::pivot_longer(d, cols=indx.f, names_to = "features")

d$features <- factor(d$features, levels = features)

if (!is.null(.fun)) {
Expand Down Expand Up @@ -290,4 +293,4 @@ setMethod('sc_dot', 'SingleCellExperiment',
data2[data2 > max] <- max
data2[data2 < min] <- min
return(data2)
}
}
4 changes: 2 additions & 2 deletions R/sc-spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ setMethod("sc_spatial", 'Seurat',
p <- p + img.annot
}

if (!remove.point && !(is.null(features) || missing(features))){
if ((!remove.point && (!is.null(features) || (any(names(mapping) %in% c('color', 'colour')) && is.null(features))))){
p <- p + sc_geom_point(pointsize = point.size, ...)
}else{
p <- p + geom_blank()
Expand Down Expand Up @@ -251,7 +251,7 @@ setMethod('sc_spatial', 'SingleCellExperiment', function(object,
p <- p + img.annot
}

if (!remove.point && !(is.null(features) || missing(features))){
if ((!remove.point && (!is.null(features) || (any(names(mapping) %in% c('color', 'colour')) && is.null(features))))){
p <- p + sc_geom_point(pointsize = point.size, ...)
}else{
p <- p + geom_blank()
Expand Down
3 changes: 2 additions & 1 deletion R/sc-violin.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ setMethod("sc_violin", 'Seurat', function(object, features,
cells=NULL, slot = "data", .fun = NULL,
mapping = NULL, ncol=3, ...) {
d <- get_dim_data(object, dims=NULL, features=features)
d <- tidyr::pivot_longer(d, 2:ncol(d), names_to = "features")
indx.f <- seq(ncol(d) - length(features) + 1, ncol(d))
d <- tidyr::pivot_longer(d, cols=indx.f, names_to = "features")
d$features <- factor(d$features, levels = features)
if (!is.null(.fun)) {
d <- .fun(d)
Expand Down
12 changes: 9 additions & 3 deletions man/ggsc-package.Rd

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

0 comments on commit 9e822be

Please sign in to comment.