2
2
import json
3
3
import os
4
4
5
- from delayedarray import is_sparse , to_dense_array , to_scipy_sparse_matrix
6
- from dolomite_base import alt_read_object , alt_read_object_function , read_object
5
+ from dolomite_base import alt_read_object , alt_read_object_function
7
6
from gypsum_client import cache_directory , save_file , save_version
8
- from singlecellexperiment import SingleCellExperiment
9
7
from summarizedexperiment import SummarizedExperiment
10
8
9
+ from .utils import single_cell_load_object
10
+
11
11
__author__ = "Jayaram Kancherla"
12
12
__copyright__ = "Jayaram Kancherla"
13
13
__license__ = "MIT"
@@ -24,7 +24,24 @@ def fetch_dataset(
24
24
realize_reduced_dims : bool = True ,
25
25
** kwargs ,
26
26
) -> SummarizedExperiment :
27
- """Fetch a dataset from the gypsum backend.
27
+ """Fetch a single-cell dataset from the gypsum backend.
28
+
29
+ See Also:
30
+ `metadata index <https://github.com/ArtifactDB/bioconductor-metadata-index>`_,
31
+ on the expected schema for the metadata.
32
+
33
+ :py:func:`~scrnaseq.save_dataset.save_dataset` and
34
+ :py:func:`~gypsum_client.upload_file_operations.upload_directory`,
35
+ to save and upload a dataset.
36
+
37
+ :py:func:`~scrnaseq.survey_datasets.survey_datasets` and :py:func:`~scrnaseq.list_versions.list_versions`,
38
+ to get possible values for `name` and `version`.
39
+
40
+ Example:
41
+
42
+ .. code-block:: python
43
+
44
+ sce = fetch_dataset("zeisel-brain-2015", "2023-12-14")
28
45
29
46
Args:
30
47
name:
@@ -99,6 +116,16 @@ def fetch_metadata(
99
116
):
100
117
"""Fetch metadata for a dataset from the gypsum backend.
101
118
119
+ See Also:
120
+ :py:func:`~.fetch_dataset`,
121
+ to fetch a dataset.
122
+
123
+ Example:
124
+
125
+ .. code-block:: python
126
+
127
+ meta = fetch_metadata("zeisel-brain-2015", "2023-12-14")
128
+
102
129
Args:
103
130
name:
104
131
Name of the dataset.
@@ -133,85 +160,3 @@ def fetch_metadata(
133
160
metadata = json .load (f )
134
161
135
162
return metadata
136
-
137
-
138
- def single_cell_load_object (
139
- path : str ,
140
- metadata : dict = None ,
141
- scrnaseq_realize_assays : bool = False ,
142
- scrnaseq_realize_reduced_dims : bool = True ,
143
- ** kwargs ,
144
- ):
145
- """Load a ``SummarizedExperiment`` or ``SingleCellExperiment`` object from a file.
146
-
147
- Args:
148
- path:
149
- Path to the dataset.
150
-
151
- metadata:
152
- Metadata for the dataset.
153
- Defaults to None.
154
-
155
- scrnaseq_realize_assays:
156
- Whether to realize assays into memory.
157
- Defaults to False.
158
-
159
- scrnaseq_realize_reduced_dims:
160
- Whether to realize reduced dimensions into memory.
161
- Defaults to True.
162
-
163
- **kwargs:
164
- Further arguments to pass to
165
- :py:func:`~dolomite_base.read_object.read_object`.
166
-
167
- Returns:
168
- A `SummarizedExperiment` of the object.
169
- """
170
- obj = read_object (
171
- path ,
172
- metadata = metadata ,
173
- scrnaseq_realize_assays = scrnaseq_realize_assays ,
174
- scrnaseq_realize_reduced_dims = scrnaseq_realize_reduced_dims ,
175
- ** kwargs ,
176
- )
177
-
178
- if isinstance (obj , SummarizedExperiment ):
179
- if scrnaseq_realize_assays :
180
- _assays = {}
181
- for y in obj .get_assay_names ():
182
- _assays [y ] = realize_array (obj .assay (y ))
183
-
184
- obj = obj .set_assays (_assays )
185
-
186
- if isinstance (obj , SingleCellExperiment ):
187
- if scrnaseq_realize_reduced_dims :
188
- _red_dims = {}
189
- for z in obj .get_reduced_dim_names ():
190
- _red_dims [z ] = realize_array (obj .reduced_dim (z ))
191
-
192
- obj = obj .set_reduced_dims (_red_dims )
193
-
194
- return obj
195
-
196
-
197
- def realize_array (x ):
198
- """
199
- Realize a `ReloadedArray` into a dense array or sparse matrix.
200
-
201
- Args:
202
- x:
203
- `ReloadedArray` object.
204
-
205
- Returns:
206
-
207
- Realized array or matrix.
208
- """
209
- from dolomite_matrix import ReloadedArray
210
-
211
- if isinstance (x , ReloadedArray ):
212
- if is_sparse (x ):
213
- x = to_scipy_sparse_matrix (x , "csr" )
214
- else :
215
- x = to_dense_array (x )
216
-
217
- return x
0 commit comments