Skip to content

Commit

Permalink
dimReds updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mvfki committed Mar 15, 2024
1 parent 0b1f1db commit 2f3997c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 19 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export("datasets<-")
export("defaultCluster<-")
export("defaultDimRed<-")
export("dimRed<-")
export("dimReds<-")
export("featureMeta<-")
export("h5fileInfo<-")
export("normData<-")
Expand Down Expand Up @@ -84,6 +85,7 @@ export(datasets)
export(defaultCluster)
export(defaultDimRed)
export(dimRed)
export(dimReds)
export(downsample)
export(exportInteractTrack)
export(featureMeta)
Expand Down Expand Up @@ -210,6 +212,7 @@ exportMethods("datasets<-")
exportMethods("defaultCluster<-")
exportMethods("defaultDimRed<-")
exportMethods("dimRed<-")
exportMethods("dimReds<-")
exportMethods("dimnames<-")
exportMethods("featureMeta<-")
exportMethods("h5fileInfo<-")
Expand All @@ -230,6 +233,7 @@ exportMethods(defaultCluster)
exportMethods(defaultDimRed)
exportMethods(dim)
exportMethods(dimRed)
exportMethods(dimReds)
exportMethods(dimnames)
exportMethods(featureMeta)
exportMethods(getH5File)
Expand Down
21 changes: 3 additions & 18 deletions R/classConversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ as.liger.Seurat <- function(
for (rd in SeuratObject::Reductions(object)) {
mat <- object[[rd]][[]]
colnames(mat) <- seq_len(ncol(mat))
cellMeta(lig, rd) <- mat
dimRed(lig, rd) <- mat
}
return(lig)
}
Expand Down Expand Up @@ -341,29 +341,14 @@ ligerToSeurat <- function(
}

# Split normal data.frame compatible info and dimReds
metadata <- data.frame(row.names = colnames(object))
dimReds <- list()
for (i in seq_along(cellMeta(object))) {
varname <- names(cellMeta(object))[i]
var <- cellMeta(object)[[i]]
if (is.null(dim(var))) metadata[[varname]] <- var
else dimReds[[varname]] <- var
}
metadata <- .DataFrame.as.data.frame(cellMeta(object))
dimReds <- dimReds(object)
srt <- Seurat::CreateSeuratObject(counts = Assay, assay = assay,
meta.data = metadata)

srt$orig.ident <- orig.ident
Seurat::Idents(srt) <- idents

# if (!is.null(data)) {
# srt <- .setSeuratData(srt, layer = "ligerNormData", slot = "data",
# value = data, assay = assay, denseIfNeeded = FALSE)
# }
# if (!is.null(scale.data)) {
# srt <- .setSeuratData(srt, layer = "ligerScaleData", slot = "scale.data",
# value = scale.data, assay = assay,
# denseIfNeeded = TRUE)
# }
# Attempt to get H.norm primarily. If it is NULL, then turn to H
h <- getMatrix(object, "H.norm") %||%
getMatrix(object, "H", returnList = TRUE)
Expand Down
14 changes: 14 additions & 0 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ setGeneric(
#' default cluster labeling, we also constructed the feature of default dimRed.
#' It can be set with \code{defaultDimRed(obj) <- "existingMatLikeVar"} and the
#' matrix can be retrieved with \code{defaultDimRed(obj)}.
setGeneric(
"dimReds",
function(x) standardGeneric("dimReds")
)

#' @export
#' @rdname liger-class
setGeneric(
"dimReds<-",
function(x, value) standardGeneric("dimReds<-")
)

#' @export
#' @rdname liger-class
setGeneric(
"dimRed",
function(x, name = NULL, useDatasets = NULL, cellIdx = NULL, ...) {
Expand Down
20 changes: 20 additions & 0 deletions R/liger-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,26 @@ setReplaceMethod(
}
)

#' @export
#' @rdname liger-class
setMethod(
"dimReds",
signature = c(x = "liger"),
function(x) x@dimReds
)

#' @export
#' @rdname liger-class
setReplaceMethod(
"dimReds",
signature(x = "liger", value = "list"),
function(x, value) {
x@dimReds <- value
validObject(x)
return(x)
}
)

#' @export
#' @rdname liger-class
setMethod(
Expand Down
2 changes: 1 addition & 1 deletion R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ searchH <- function(object, useRaw = NULL) {
# use when you have objects created when this package was named by `rliger2`
# now we rename the package back to `rliger` and you'll need to have the objects
# compatible with "new" package name.
rliger2_to_rliger_namespace <- function(obj, dimredName = NULL) {
rliger2_to_rliger_namespace <- function(obj, dimredName) {
cm <- obj@cellMeta
drList <- list()
for (i in dimredName) {
Expand Down
12 changes: 12 additions & 0 deletions man/liger-class.Rd

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

0 comments on commit 2f3997c

Please sign in to comment.