Skip to content

Commit

Permalink
Merge pull request SGDDNB#80 from zpohk/Seurat-v5
Browse files Browse the repository at this point in the history
Support Seurat v5 object
  • Loading branch information
jfouyang authored Jan 13, 2024
2 parents 8bc0b5f + 91519f0 commit d8869bf
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions R/makeShinyFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,21 @@ makeShinyFiles <- function(
if(class(obj)[1] == "Seurat"){
# Seurat Object
if(is.na(gex.assay[1])){gex.assay = "RNA"}
gex.matdim = dim(slot(obj@assays[[gex.assay[1]]], gex.slot[1]))
gex.rownm = rownames(slot(obj@assays[[gex.assay[1]]], gex.slot[1]))
gex.colnm = colnames(slot(obj@assays[[gex.assay[1]]], gex.slot[1]))
if(class(obj@assays[[gex.assay[1]]]) == "Assay5"){
# Seurat v5
# check if layers are joined
if(!(gex.slot[1] %in% names(obj@assays[[gex.assay[1]]]@layers))){
stop(paste0("gex.slot not found in gex.assay. ",
"Are layers joined? run obj <- JoinLayers(obj)"))
}
gex.matdim = dim(obj@assays[[gex.assay[1]]]@layers[[gex.slot[1]]])
gex.rownm = rownames(obj)
gex.colnm = colnames(obj)
}else{
gex.matdim = dim(slot(obj@assays[[gex.assay[1]]], gex.slot[1]))
gex.rownm = rownames(slot(obj@assays[[gex.assay[1]]], gex.slot[1]))
gex.colnm = colnames(slot(obj@assays[[gex.assay[1]]], gex.slot[1]))
}
# defGenes = obj@assays[[gex.assay[1]]]@var.features[1:10]
defGenes = Seurat::VariableFeatures(obj)[1:10]
if(is.na(defGenes[1])){
Expand Down Expand Up @@ -309,13 +321,22 @@ makeShinyFiles <- function(
}
if(class(obj)[1] == "Seurat"){
# Seurat Object
for(i in 1:floor((gex.matdim[1]-8)/chk)){
sc1gexpr.grp.data[((i-1)*chk+1):(i*chk), ] <- as.matrix(
slot(obj@assays[[gex.assay[1]]], gex.slot[1])[((i-1)*chk+1):(i*chk),])
}
sc1gexpr.grp.data[(i*chk+1):gex.matdim[1], ] <- as.matrix(
slot(obj@assays[[gex.assay[1]]], gex.slot[1])[(i*chk+1):gex.matdim[1],])

if(class(obj@assays[[gex.assay[1]]]) == "Assay5"){
# Seurat v5
for(i in 1:floor((gex.matdim[1]-8)/chk)){
sc1gexpr.grp.data[((i-1)*chk+1):(i*chk), ] <- as.matrix(
obj@assays[[gex.assay[1]]]@layers[[gex.slot[1]]][((i-1)*chk+1):(i*chk),])
}
sc1gexpr.grp.data[(i*chk+1):gex.matdim[1], ] <- as.matrix(
obj@assays[[gex.assay[1]]]@layers[[gex.slot[1]]][(i*chk+1):gex.matdim[1],])
}else{
for(i in 1:floor((gex.matdim[1]-8)/chk)){
sc1gexpr.grp.data[((i-1)*chk+1):(i*chk), ] <- as.matrix(
slot(obj@assays[[gex.assay[1]]], gex.slot[1])[((i-1)*chk+1):(i*chk),])
}
sc1gexpr.grp.data[(i*chk+1):gex.matdim[1], ] <- as.matrix(
slot(obj@assays[[gex.assay[1]]], gex.slot[1])[(i*chk+1):gex.matdim[1],])
}
} else if (class(obj)[1] == "SingleCellExperiment"){
# SCE Object
for(i in 1:floor((gex.matdim[1]-8)/chk)){
Expand Down

0 comments on commit d8869bf

Please sign in to comment.