Skip to content

Commit

Permalink
Fix file export
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Oct 2, 2023
1 parent d340050 commit 16b310b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ data/
check/
vignettes/data/
*.Rproj
.RData
.RData
my_vitessce_files/
20 changes: 15 additions & 5 deletions R/export.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@
#' vc$export(to = "files", out_dir = "./data")
export_to_files <- function(config, with_config, base_url, out_dir) {
routes <- config$get_routes()


for(route in routes) {
# Get the intended web server route, removing the initial "/"
route_path <- substr(route$path, 2, stringr::str_length(route$path))
out_path <- file.path(out_dir, route_path)

dir.create(out_path, showWarnings = FALSE, recursive = TRUE)
# Copy the converted files from their original directory to the `out_dir`.
static_dir <- route$directory
files_to_copy = list.files(static_dir, full.names = TRUE)
file.copy(files_to_copy, out_path, recursive = TRUE)
if(class(route)[1] == "VitessceConfigServerStaticRoute") {
# This is a directory.
dir.create(out_path, showWarnings = FALSE, recursive = TRUE)
# Copy the converted files from their original directory to the `out_dir`.
static_dir <- route$directory
files_to_copy <- list.files(static_dir, full.names = TRUE)
file.copy(files_to_copy, out_path, recursive = TRUE)
} else {
# This is a single file.
dir.create(dirname(out_path), showWarnings = FALSE, recursive = TRUE)
# Copy the converted files from their original directory to the `out_dir`.
file_to_copy <- route$file_path
file.copy(file_to_copy, out_path, recursive = TRUE)
}
}

if(with_config) {
Expand Down
19 changes: 12 additions & 7 deletions vignettes/export_files.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,32 @@ First, install the dependencies:
```r
install.packages("devtools")
devtools::install_github("satijalab/seurat-data")
devtools::install_github("vitessce/vitessceAnalysisR")
```

Create the Vitessce configuration:

```r
library(vitessceR)
library(vitessceAnalysisR)
library(SeuratData)

SeuratData::InstallData("pbmc3k")
data("pbmc3k.final")
force(pbmc3k.final)

vc <- VitessceConfig$new("My config")
adata_path <- file.path("data", "seurat", "pbmc3k.final.h5ad.zarr")

vitessceAnalysisR::seurat_to_anndata_zarr(pbmc3k.final, adata_path)

vc <- VitessceConfig$new(schema_version = "1.0.16", name = "My config")
dataset <- vc$add_dataset("My dataset")
dataset <- dataset$add_object(
SeuratWrapper$new(
pbmc3k.final,
cell_embeddings = c("pca", "umap"),
cell_embedding_names = c("PCA", "UMAP"),
cell_set_meta_names = c("seurat_annotations", "seurat_clusters"),
out_dir = file.path("data", "seuratdata")
AnnDataWrapper$new(
adata_path=adata_path,
obs_embedding_paths = c("obsm/X_pca", "obsm/X_umap"),
obs_embedding_names = c("PCA", "UMAP"),
obs_set_paths = c("obs/seurat_annotations", "obs/seurat_clusters")
)
)
scatterplot <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "PCA")
Expand Down

0 comments on commit 16b310b

Please sign in to comment.