Skip to content

Commit

Permalink
Fix GH token
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Oct 2, 2024
1 parent 008d72d commit 6ebd7a9
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 31 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/rworkflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ jobs:
run_pkgdown: ${{ true }}
has_runit: ${{ false }}
has_latex: ${{ false }}
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run_docker: ${{ true }}
docker_user: bschilder
docker_org: neurogenomicslab
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
runner_os: ${{ runner.os }}
cache_version: cache-v1
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ Remotes:
github::aertslab/SCopeLoomR,
github::scverse/anndataR
VignetteBuilder: knitr
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Config/testthat/edition: 3
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ and avoid conflicts with piggyback-oriented functions.
- `is_class`
- Add new classes: "matrix_strict", "matrix_sparse", "delayed_array"
* `get_x`
- Add new args `slot` and `assay`
- Add new args `layer` and `assay`
* New funcs:
- `get_obs_names`
- `get_var_names`
Expand Down
4 changes: 2 additions & 2 deletions R/calc_cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ calc_cor <- function(obj,
keys = NULL,
graph_key = NULL,
assay = NULL,
slot = NULL,
layer = NULL,
transpose = FALSE,
method = "pearson",
fill_na = NULL,
Expand All @@ -35,7 +35,7 @@ calc_cor <- function(obj,
X <- get_x(
obj = obj,
assay = assay,
slot = slot,
layer = layer,
transpose = transpose,
n = 1,
verbose = verbose)
Expand Down
4 changes: 2 additions & 2 deletions R/get_cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
get_cor <- function(obj,
keys = NULL,
assay = NULL,
slot = NULL,
layer = NULL,
graph_key = NULL,
method = "pearson",
return_obj = FALSE,
Expand Down Expand Up @@ -53,7 +53,7 @@ get_cor <- function(obj,
if(is.null(Xcor)){
Xcor <- calc_cor(obj = obj,
assay = assay,
slot = slot,
layer = layer,
keys = keys,
method = method)
}
Expand Down
6 changes: 3 additions & 3 deletions R/get_obsm.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ get_obsm <- function(obj,
} else if (is_class(obj,"seurat")) {
## Seurat V1
if(methods::is(obj,"seurat")){
### Need a way to figure which slot names are availabe a priori ####
### Need a way to figure which layer names are availabe a priori ####
# messager("Extracting obsm from Seurat (V1).",v = verbose)
# obsm <- list(PCA=list(embeddings=as.matrix([email protected]),
# loadings=as.matrix([email protected])))
Expand Down Expand Up @@ -95,10 +95,10 @@ get_obsm <- function(obj,
# loadings="reducedDimA")
obsm <- if(methods::.hasSlot(obj,"reducedDimS") &&
ncol(obj@reducedDimS)==ncol(obj) ){
list(reducedDimS=t(methods::slot(obj, "reducedDimS")))
list(reducedDimS=t(methods::layer(obj, "reducedDimS")))
} else if (methods::.hasSlot(obj,"reducedDimA") &&
ncol(obj@reducedDimA)==ncol(obj) ) {
list(reducedDimA=t(methods::slot(obj, "reducedDimA")))
list(reducedDimA=t(methods::layer(obj, "reducedDimA")))
} else {
NULL
}
Expand Down
2 changes: 1 addition & 1 deletion R/get_uns.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ get_uns <- function(obj,
uns <- lapply(stats::setNames(methods::slotNames(obj@experimentData),
methods::slotNames(obj@experimentData)),
function(x){
methods::slot(obj@experimentData,x)
methods::layer(obj@experimentData,x)
})
#### list ####
} else if(is_class(obj,"list")){
Expand Down
2 changes: 1 addition & 1 deletion R/get_variable_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ get_variable_features <- function(obj,
}
#### Check if empty ####
if(length(Reduce(union,feat))==0){
messager("Warning:","Variable features slot was empty. Returning NULL.")
messager("Warning:","Variable features layer was empty. Returning NULL.")
return(NULL)
}
#### Reduce list ####
Expand Down
4 changes: 2 additions & 2 deletions R/get_varm.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ get_varm <- function(obj,
} else if (is_class(obj,"seurat")) {
## Seurat V1
if(methods::is(obj,"seurat")){
### Need a way to figure which slot names are available a priori ####
### Need a way to figure which layer names are available a priori ####
# messager("Extracting varm from Seurat (V1).",v = verbose)
# varm <- list(PCA=list(embeddings=as.matrix([email protected]),
# loadings=as.matrix([email protected])))
Expand Down Expand Up @@ -105,7 +105,7 @@ get_varm <- function(obj,
# loadings="reducedDimA")
varm <- if (methods::.hasSlot(obj,"reducedDimA") &&
ncol(obj@reducedDimA)==nrow(obj) ) {
list(reducedDimA=t(methods::slot(obj, "reducedDimA")))
list(reducedDimA=t(methods::layer(obj, "reducedDimA")))
} else {
return(NULL)
}
Expand Down
21 changes: 16 additions & 5 deletions R/get_x.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ get_x <- function(obj,
n=NULL,
simplify=TRUE,
assay=NULL,
slot=NULL,
layer=NULL,
as_sparse=FALSE,
verbose=TRUE){
# devoptera::args2vars(get_x)
Expand Down Expand Up @@ -55,16 +55,27 @@ get_x <- function(obj,
data <- list(RNA.counts=obj@raw.data,
RNA.data=obj@data,
RNA.scale.data=obj@scale.data)
## Seurat V2+
} else {
## Seurat V2-5
} else if(packageVersion("Seurat")<"5") {
assays <- obj@assays
if(!is.null(assay)) assays[assays %in% assay]
data <- lapply(assays,function(a){
slots <- c("counts","data","scale.data")
slots <- slots[sapply(slots,function(s){methods::.hasSlot(a,s)})]
if(!is.null(slot)) slots <- slots[slots %in% slot]
if(!is.null(layer)) slots <- slots[slots %in% layer]
lapply(stats::setNames(slots,slots), function(s){
methods::slot(a,s)
methods::layer(a,s)
})
}) |> unlist(recursive = FALSE)
## Seurat V5+
} else{
assays <- obj@assays
if(!is.null(assay)) assays <- assays[names(assays) %in% assay]
data <- lapply(assays,function(a){
layers <- SeuratObject::Layers(obj)
if(!is.null(layer)) layers <- intersect(layers,layer)
lapply(stats::setNames(layers,layers), function(s){
SeuratObject::LayerData(a,s)
})
}) |> unlist(recursive = FALSE)
}
Expand Down
2 changes: 1 addition & 1 deletion R/map_data_anndata.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ map_data_anndata <- function(obj,
genes = rownames(assays[[1]]),
original_rowdata = obj$var)
#### Construct new SummarizedExperiment ####
## Remove PC slot to avoid error:
## Remove PC layer to avoid error:
## Error: ValueError: Value passed for key 'PCs' is of incorrect shape.
obj$obsm$X_pca <- NULL
obj$varm$PCs <- NULL
Expand Down
4 changes: 2 additions & 2 deletions R/matrices_to_assayobjects.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#' Convert a named list of X_list to a named list of \pkg{Seurat}
#' assay objects (see \link[SeuratObject]{CreateAssayObject}).
#' @param X_list A named list of matrices (one per unique assay in
#' \code{X_list}) to be put in the \code{counts} slot of each
#' \code{X_list}) to be put in the \code{counts} layer of each
#' \code{AssayObject}.
#' @param var_features (Optional) A named list of feature metadata data.frames
#' (one per unique assay in \code{X_list}) to be put in the
#' \code{meta.features} slot of each \code{AssayObject}.
#' \code{meta.features} layer of each \code{AssayObject}.
#' @inheritParams converters
#' @returns A named list of \pkg{Seurat} assay objects.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/set_obs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Set unstructured data
#'
#' Set the sample observations slot (i.e. cell metadata)
#' Set the sample observations layer (i.e. cell metadata)
#' in any single-cell object that has one.
#' @param obs Observation metadata
#' as a \link[base]{data.frame} with samples as row names.
Expand Down
2 changes: 1 addition & 1 deletion R/set_uns.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Set unstructured data
#'
#' Set the unstructured data slot in any single-cell object that has one.
#' Set the unstructured data layer in any single-cell object that has one.
#' @param uns Unstructured data to be stored in object.
#' @param key Name of the list element to store \code{uns} in.
#' @inheritParams converters
Expand Down
2 changes: 1 addition & 1 deletion R/set_var.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Set unstructured data
#'
#' Set the feature variable slot (i.e. gene metadata)
#' Set the feature variable layer (i.e. gene metadata)
#' in any single-cell object that has one.
#' @param var Variable metadata
#' as a \link[base]{data.frame} with features as row names.
Expand Down
13 changes: 10 additions & 3 deletions R/seurat_to_anndata.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
#' @export
#' @examples
#' obj <- example_obj("seurat")
#' obj2 <- seurat_to_anndata(obj)
#' obj2 <- seurat_to_anndata(obj, method="seuratdisk")
seurat_to_anndata <- function(obj,
reimport = TRUE,
save_path = tempfile(fileext = ".h5ad"),
method = c("sceasy","anndatar"),
method = c("sceasy","anndatar","seuratdisk"),
verbose = TRUE,
...){

messager_to()
method <- tolower(method)[1]
#### Convert ####
if(!is.null(save_path)) save_path <- path.expand(save_path)
# Method: anndatar
if(method=="anndatar"){
adat <- anndataR::from_Seurat(
Expand All @@ -29,7 +30,7 @@ seurat_to_anndata <- function(obj,
},
file = save_path
)
} else {
} else if(method=="sceasy"){
# Method: sceasy
activate_conda(verbose=verbose)
adat <- sceasy::convertFormat(obj = obj,
Expand All @@ -48,6 +49,12 @@ seurat_to_anndata <- function(obj,
save_path = save_path,
verbose = verbose)
}
} else{
messager("Saving ==>",save_path)
h5Seurat_path <- gsub("\\.h5ad$",".h5Seurat",save_path)
SeuratDisk::SaveH5Seurat(obj, filename = h5Seurat_path)
SeuratDisk::Convert(h5Seurat_path, dest = "h5ad")
adat <- anndata::read_h5ad(save_path)
}
#### Return ###
return(adat)
Expand Down

0 comments on commit 6ebd7a9

Please sign in to comment.