Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Oct 2, 2023
1 parent fcd6b61 commit 13be60b
Show file tree
Hide file tree
Showing 24 changed files with 692 additions and 85 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(AbstractWrapper)
export(AnnDataWrapper)
export(Component)
export(CoordinationType)
export(CsvWrapper)
export(DataType)
export(FileType)
export(MultiImageWrapper)
Expand Down
11 changes: 11 additions & 0 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ VitessceConfigDatasetFile <- R6::R6Class("VitessceConfigDatasetFile",
#' @param data_type A data type for the file.
#' @param file_type A file type for the file.
#' @param options A list of options to include for the file.
#' @param coordination_values A list of coordination values to include in the file definition.
#' @return A new `VitessceConfigDatasetFile` object.
initialize = function(url = NA, file_type = NA, options = NA, coordination_values = NA, data_type = NA) {
private$file <- obj_list()
Expand Down Expand Up @@ -103,6 +104,7 @@ VitessceConfigDataset <- R6::R6Class("VitessceConfigDataset",
#' Create a new dataset object.
#' @param uid A unique identifier string for the dataset.
#' @param name A name for the dataset
#' @param base_dir A directory which local files are configured relative to.
#' @return A new `VitessceConfigDataset` object.
initialize = function(uid, name, base_dir = NA) {
self$dataset <- list(
Expand All @@ -113,9 +115,15 @@ VitessceConfigDataset <- R6::R6Class("VitessceConfigDataset",
private$objs <- list()
self$base_dir <- base_dir
},
#' @description
#' Get the dataset name.
#' @return The name as a string.
get_name = function() {
return(self$dataset[['name']])
},
#' @description
#' Get the dataset UID.
#' @return The uid as a string.
get_uid = function() {
return(self$dataset[['uid']])
},
Expand Down Expand Up @@ -231,6 +239,7 @@ VitessceConfigCoordinationScope <- R6::R6Class("VitessceConfigCoordinationScope"
#' Create a new coordination scope object.
#' @param c_type A coordination type name.
#' @param c_scope A coordination scope name.
#' @param c_value An initial value for the coordination scope.
#' @return A new `VitessceConfigCoordinationScope` object.
initialize = function(c_type, c_scope, c_value = NA) {
self$c_type <- c_type
Expand Down Expand Up @@ -374,6 +383,7 @@ VitessceConfigView <- R6::R6Class("VitessceConfigView",
}
invisible(self)
},
#' @description
use_coordination_by_dict = function(scopes) {
# TODO
invisible(self)
Expand Down Expand Up @@ -429,6 +439,7 @@ VitessceConfig <- R6::R6Class("VitessceConfig",
base_dir = NULL,
#' @description
#' Create a new config object.
#' @param schema_version The Vitessce config schema version to use.
#' @param name A name for the config.
#' @param description A description for the config.
#' @return A new `VitessceConfig` object.
Expand Down
39 changes: 39 additions & 0 deletions R/wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,42 @@ AbstractWrapper <- R6::R6Class("AbstractWrapper",
)
return(route)
},
#' @description
#' Construct a URL to a local directory.
#'
#' @param base_url The base URL on which the web server is serving.
#' @param dataset_uid The ID for this dataset.
#' @param obj_i The index of this data object within the dataset.
#' @param local_dir_path The path to the local directory.
#' @param local_dir_uid A unique identifier for this local directory in this dataset.
#' @return A string for the URL.
get_local_dir_url = function(base_url, dataset_uid, obj_i, local_dir_path, local_dir_uid) {
if(!self$is_remote && !is.na(self$base_dir)) {
return(self$get_url_simple(base_url, file_path_to_url_path(local_dir_path, prepend_slash = FALSE)))
}
return(self$get_url(base_url, dataset_uid, obj_i, local_dir_uid))
},
#' @description
#' Construct a URL to a local file.
#'
#' @param base_url The base URL on which the web server is serving.
#' @param dataset_uid The ID for this dataset.
#' @param obj_i The index of this data object within the dataset.
#' @param local_file_path The path to the local file.
#' @param local_file_uid A unique identifier for this local file in this dataset.
#' @return A string for the URL.
get_local_file_url = function(base_url, dataset_uid, obj_i, local_file_path, local_file_uid) {
# Same logic as get_local_dir_url
return(self$get_local_dir_url(base_url, dataset_uid, obj_i, local_file_path, local_file_uid))
},
#' @description
#' Create a web server route for this object.
#'
#' @param dataset_uid The ID for this dataset.
#' @param obj_i The index of this data object within the dataset.
#' @param local_dir_path The path to the local directory.
#' @param local_dir_uid A unique identifier for this local directory in this dataset.
#' @return A new `VitessceConfigServerStaticRoute` instance.
get_local_dir_route = function(dataset_uid, obj_i, local_dir_path, local_dir_uid) {
if(!self$is_remote) {
if(is.na(self$base_dir)) {
Expand All @@ -137,6 +163,14 @@ AbstractWrapper <- R6::R6Class("AbstractWrapper",
}
return(list())
},
#' @description
#' Create a web server route for this object.
#'
#' @param dataset_uid The ID for this dataset.
#' @param obj_i The index of this data object within the dataset.
#' @param local_file_path The path to the local file.
#' @param local_file_uid A unique identifier for this local file in this dataset.
#' @return A new `VitessceConfigServerFileRoute` instance.
get_local_file_route = function(dataset_uid, obj_i, local_file_path, local_file_uid) {
if(!self$is_remote) {
if(is.na(self$base_dir)) {
Expand Down Expand Up @@ -166,6 +200,11 @@ AbstractWrapper <- R6::R6Class("AbstractWrapper",
retval <- paste0(base_url, self$get_route_str(dataset_uid, obj_i, ...))
return(retval)
},
#' @description
#' Construct a URL.
#' @param base_url The base URL on which the web server is serving.
#' @param suffix The suffix to append to the base URL.
#' @return A URL as a string like {base_url}/{suffix}
get_url_simple = function(base_url, suffix) {
return(paste0(base_url, "/", suffix))
},
Expand Down
77 changes: 61 additions & 16 deletions R/wrappers_anndata.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
#' Seurat object wrapper class
#' @title SeuratWrapper Class
#' AnnData object wrapper class
#' @title AnnDataWrapper Class
#' @docType class
#' @description
#' Class representing a local Seurat object in a Vitessce dataset.
#' Class representing an AnnData object (saved to a Zarr store) in a Vitessce dataset.
#'
#' @rdname SeuratWrapper
#' @rdname AnnDataWrapper
#' @export
#' @examples
#' obj <- get_seurat_obj()
#' w <- SeuratWrapper$new(
#' obj,
#' cell_embeddings = c("pca"),
#' cell_embedding_names = c("PCA")
#' )
AnnDataWrapper <- R6::R6Class("AnnDataWrapper",
inherit = AbstractWrapper,
public = list(
Expand All @@ -25,30 +18,77 @@ AnnDataWrapper <- R6::R6Class("AnnDataWrapper",
#' @field local_dir_uid The path to the local zarr store.
#' @keywords internal
local_dir_uid = NULL,


#' @field obs_feature_matrix_path The path to the observation-by-feature matrix within the Zarr store.
#' @keywords internal
obs_feature_matrix_path=NULL,
#' @field feature_filter_path The path to the a column of adata.var within the Zarr store.
#' Use this if obs_feature_matrix_path points to a subset of adata.X (relative to the full adata.var).
#' @keywords internal
feature_filter_path=NULL,
#' @field initial_feature_filter_path The path to the a column of adata.var within the Zarr store.
#' Use this to load a subset of the matrix at obs_feature_matrix_path initially.
#' @keywords internal
initial_feature_filter_path=NULL,
#' @field obs_set_paths A list of paths to the observation sets within the Zarr store.
#' @keywords internal
obs_set_paths=NULL,
#' @field obs_set_names A list of names for the observation sets.
#' @keywords internal
obs_set_names=NULL,
#' @field obs_locations_path The path to the observation locations within the Zarr store.
#' @keywords internal
obs_locations_path=NULL,
#' @field obs_segmentations_path The path to the observation segmentations within the Zarr store.
#' @keywords internal
obs_segmentations_path=NULL,
#' @field obs_embedding_paths A list of paths to the observation embeddings within the Zarr store.
#' @keywords internal
obs_embedding_paths=NULL,
#' @field obs_embedding_names A list of names for the observation embeddings.
#' @keywords internal
obs_embedding_names=NULL,
#' @field obs_embedding_dims A list of dimensions for the observation embeddings.
#' @keywords internal
obs_embedding_dims=NULL,
request_init=NULL,
#' @field feature_labels_path The path to the feature labels within the Zarr store.
#' @keywords internal
feature_labels_path=NULL,
#' @field obs_labels_path The path to the observation labels within the Zarr store.
#' @keywords internal
obs_labels_path=NULL,
#' @field obs_labels_paths A list of paths to the observation labels within the Zarr store.
#' @keywords internal
obs_labels_paths=NULL,
#' @field obs_labels_names A list of names for the observation labels.
#' @keywords internal
obs_labels_names=NULL,
#' @field coordination_values A list of coordination values for the file definition.
#' @keywords internal
coordination_values=NULL,

#' @field request_init A list of requestInit options for the Zarr store.
#' @keywords internal
request_init=NULL,
#' @description
#' Create a wrapper around an AnnData object saved to a Zarr store.
#' @param adata_path The path to a local Zarr store.
#' @param adata_url The URL to a remote Zarr store.
#' @param obs_feature_matrix_path The path to the observation-by-feature matrix within the Zarr store.
#' @param feature_filter_path The path to the a column of adata.var within the Zarr store. Use this if obs_feature_matrix_path points to a subset of adata.X (relative to the full adata.var).
#' @param initial_feature_filter_path The path to the a column of adata.var within the Zarr store. Use this to load a subset of the matrix at obs_feature_matrix_path initially.
#' @param obs_set_paths A list of paths to the observation sets within the Zarr store.
#' @param obs_set_names A list of names for the observation sets.
#' @param obs_locations_path The path to the observation locations within the Zarr store.
#' @param obs_segmentations_path The path to the observation segmentations within the Zarr store.
#' @param obs_embedding_paths A list of paths to the observation embeddings within the Zarr store.
#' @param obs_embedding_names A list of names for the observation embeddings.
#' @param obs_embedding_dims A list of dimensions for the observation embeddings.
#' @param request_init A list of requestInit options for the Zarr store.
#' @param feature_labels_path The path to the feature labels within the Zarr store.
#' @param obs_labels_paths A list of paths to the observation labels within the Zarr store.
#' @param obs_labels_names A list of names for the observation labels.
#' @param coordination_values A list of coordination values for the file definition.
#' @param ... Parameters inherited from `AbstractWrapper`.
#' @return A new `SeuratWrapper` object.
#' @return A new `AnnDataWrapper` object.
initialize = function(adata_path = NA, adata_url = NA, obs_feature_matrix_path = NA, feature_filter_path = NA, initial_feature_filter_path = NA, obs_set_paths = NA, obs_set_names = NA, obs_locations_path = NA, obs_segmentations_path = NA, obs_embedding_paths = NA, obs_embedding_names = NA, obs_embedding_dims = NA, request_init = NA, feature_labels_path = NA, obs_labels_path = NA, coordination_values = NA, obs_labels_paths = NA, obs_labels_names = NA, ...) {
super$initialize(...)
self$adata_path <- adata_path
Expand Down Expand Up @@ -91,6 +131,7 @@ AnnDataWrapper <- R6::R6Class("AnnDataWrapper",
#' Create the JSON output files, web server routes, and file definition creators.
#' @param dataset_uid The ID for this dataset.
#' @param obj_i The index of this data object within the dataset.
#' @param base_dir A base directory for local data.
convert_and_save = function(dataset_uid, obj_i, base_dir = NA) {
if(self$is_remote) {
super$convert_and_save(dataset_uid, obj_i, base_dir = base_dir)
Expand All @@ -108,6 +149,10 @@ AnnDataWrapper <- R6::R6Class("AnnDataWrapper",
self$routes <- append(self$routes, route)
}
},
#' @description
#' Get a list of server route objects.
#' @param dataset_uid The ID for this dataset.
#' @param obj_i The index of this data object within the dataset.
make_routes = function(dataset_uid, obj_i) {
return(self$get_local_dir_route(dataset_uid, obj_i, self$adata_path, self$local_dir_uid))
},
Expand Down
47 changes: 28 additions & 19 deletions R/wrappers_csv.R
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
#' Seurat object wrapper class
#' @title SeuratWrapper Class
#' CSV file wrapper class
#' @title CsvWrapper Class
#' @docType class
#' @description
#' Class representing a local Seurat object in a Vitessce dataset.
#' Class representing a CSV file in a Vitessce dataset.
#'
#' @rdname SeuratWrapper
#' @rdname CsvWrapper
#' @export
#' @examples
#' obj <- get_seurat_obj()
#' w <- SeuratWrapper$new(
#' obj,
#' cell_embeddings = c("pca"),
#' cell_embedding_names = c("PCA")
#' )
CsvWrapper <- R6::R6Class("CsvWrapper",
inherit = AbstractWrapper,
public = list(
#' @field adata_path The object to wrap.
#' @field csv_path The object to wrap.
#' @keywords internal
csv_path = NULL,
#' @field adata_url The object to wrap.
#' @field csv_url The object to wrap.
#' @keywords internal
csv_url = NULL,
#' @field local_dir_uid The path to the local zarr store.
#' @field local_csv_uid The path to the local zarr store.
#' @keywords internal
local_csv_uid = NULL,


#' @field data_type The Vitessce data type for this file.
#' @keywords internal
data_type = NULL,
#' @field options A list of options to pass to the Vitessce file definition.
#' @keywords internal
options=NULL,
#' @field coordination_values A list of coordination values to pass to the Vitessce file definition.
#' @keywords internal
coordination_values=NULL,
#' @field request_init A list of requestInit values to pass to fetch when loading the CSV over HTTP.
#' @keywords internal
request_init = NULL,

#' @description
#' Create a wrapper around an AnnData object saved to a Zarr store.
#' @param adata_path The path to a local Zarr store.
#' Create a wrapper around a CSV file.
#' @param csv_path The path to a local CSV file.
#' @param csv_url The URL to a remote CSV file.
#' @param data_type The Vitessce data type for this file.
#' @param options A list of options to pass to the Vitessce file definition.
#' @param coordination_values A list of coordination values to pass to the Vitessce file definition.
#' @param request_init A list of requestInit values to pass to fetch when loading the CSV over HTTP.
#' @param ... Parameters inherited from `AbstractWrapper`.
#' @return A new `SeuratWrapper` object.
#' @return A new `CsvWrapper` object.
initialize = function(csv_path = NA, csv_url = NA, data_type = NA, options = NA, coordination_values = NA, request_init = NA, ...) {
super$initialize(...)
self$csv_path <- csv_path
Expand Down Expand Up @@ -71,6 +75,7 @@ CsvWrapper <- R6::R6Class("CsvWrapper",
#' Create the JSON output files, web server routes, and file definition creators.
#' @param dataset_uid The ID for this dataset.
#' @param obj_i The index of this data object within the dataset.
#' @param base_dir A base directory for local data.
convert_and_save = function(dataset_uid, obj_i, base_dir = NA) {
if(self$is_remote) {
super$convert_and_save(dataset_uid, obj_i, base_dir = base_dir)
Expand All @@ -88,6 +93,10 @@ CsvWrapper <- R6::R6Class("CsvWrapper",
self$routes <- append(self$routes, route)
}
},
#' @description
#' Get a list of server route objects.
#' @param dataset_uid The ID for this dataset.
#' @param obj_i The index of this data object within the dataset.
make_routes = function(dataset_uid, obj_i) {
return(self$get_local_file_route(dataset_uid, obj_i, self$csv_path, self$local_csv_uid))
},
Expand Down
Loading

0 comments on commit 13be60b

Please sign in to comment.