|
47 | 47 | "from vitessce.data_utils import (\n", |
48 | 48 | " sdata_morton_sort_points,\n", |
49 | 49 | " sdata_points_process_columns,\n", |
50 | | - " sdata_points_write_bounding_box_attrs,\n", |
51 | 50 | " sdata_points_modify_row_group_size,\n", |
52 | 51 | " sdata_morton_query_rect,\n", |
53 | 52 | ")" |
|
59 | 58 | "metadata": {}, |
60 | 59 | "outputs": [], |
61 | 60 | "source": [ |
62 | | - "from spatialdata import read_zarr" |
| 61 | + "from spatialdata import read_zarr\n", |
| 62 | + "from spatialdata.models import PointsModel" |
63 | 63 | ] |
64 | 64 | }, |
65 | 65 | { |
|
70 | 70 | "source": [ |
71 | 71 | "data_dir = \"data\"\n", |
72 | 72 | "zip_filepath = join(data_dir, \"xenium_rep1_io.spatialdata.zarr.zip\")\n", |
73 | | - "spatialdata_filepath = join(data_dir, \"xenium_rep1_io.spatialdata.zarr\")" |
| 73 | + "spatialdata_filepath = join(data_dir, \"xenium_rep1_io2.spatialdata.zarr\")" |
74 | 74 | ] |
75 | 75 | }, |
76 | 76 | { |
|
82 | 82 | "if not isdir(spatialdata_filepath):\n", |
83 | 83 | " if not isfile(zip_filepath):\n", |
84 | 84 | " os.makedirs(data_dir, exist_ok=True)\n", |
85 | | - " urlretrieve('https://s3.embl.de/spatialdata/spatialdata-sandbox/xenium_rep1_io.zip', zip_filepath)\n", |
| 85 | + " urlretrieve('https://data-2.vitessce.io/sdata-datasets/xenium_rep1_io.spatialdata.zarr.zip', zip_filepath)\n", |
86 | 86 | " with zipfile.ZipFile(zip_filepath,\"r\") as zip_ref:\n", |
87 | 87 | " zip_ref.extractall(data_dir)\n", |
88 | 88 | " os.rename(join(data_dir, \"data.zarr\"), spatialdata_filepath)\n", |
|
161 | 161 | "sdata.points['transcripts'].head()" |
162 | 162 | ] |
163 | 163 | }, |
| 164 | + { |
| 165 | + "cell_type": "code", |
| 166 | + "execution_count": null, |
| 167 | + "metadata": {}, |
| 168 | + "outputs": [], |
| 169 | + "source": [ |
| 170 | + "transformations = sdata['transcripts'].attrs['transform']" |
| 171 | + ] |
| 172 | + }, |
164 | 173 | { |
165 | 174 | "cell_type": "markdown", |
166 | 175 | "metadata": {}, |
|
223 | 232 | "metadata": {}, |
224 | 233 | "outputs": [], |
225 | 234 | "source": [ |
226 | | - "sdata[\"transcripts_with_morton_codes\"] = ddf\n", |
227 | | - "sdata.write_element(\"transcripts_with_morton_codes\")" |
228 | | - ] |
229 | | - }, |
230 | | - { |
231 | | - "cell_type": "markdown", |
232 | | - "metadata": {}, |
233 | | - "source": [ |
234 | | - "### Step 4. Write bounding box metadata with `sdata_points_write_bounding_box_attrs`" |
| 235 | + "del ddf.attrs['transform']" |
235 | 236 | ] |
236 | 237 | }, |
237 | 238 | { |
|
240 | 241 | "metadata": {}, |
241 | 242 | "outputs": [], |
242 | 243 | "source": [ |
243 | | - "sdata_points_write_bounding_box_attrs(sdata, \"transcripts_with_morton_codes\")" |
| 244 | + "sdata[\"transcripts_with_morton_codes\"] = PointsModel.parse(ddf, feature_key=\"feature_name\", instance_key=\"cell_id\", transformations=transformations)\n", |
| 245 | + "sdata.write_element(\"transcripts_with_morton_codes\")" |
244 | 246 | ] |
245 | 247 | }, |
246 | 248 | { |
247 | 249 | "cell_type": "markdown", |
248 | 250 | "metadata": {}, |
249 | 251 | "source": [ |
250 | | - "### Step 5. Modify the row group sizes of the Parquet files with `sdata_points_modify_row_group_size`" |
| 252 | + "### Step 4. Modify the row group sizes of the Parquet files with `sdata_points_modify_row_group_size`" |
251 | 253 | ] |
252 | 254 | }, |
253 | 255 | { |
|
278 | 280 | "import pyarrow.parquet as pq\n", |
279 | 281 | "from os.path import join\n", |
280 | 282 | "\n", |
281 | | - "parquet_file = pq.ParquetFile(join(sdata.path, \"points\", \"transcripts_with_morton_codes\", \"points.parquet\", \"part.0.parquet\"))\n", |
| 283 | + "parquet_file = pq.ParquetFile(join(sdata.path, \"points\", \"transcripts_with_morton_codes\", \"points.parquet\", \"part.1.parquet\"))\n", |
282 | 284 | "\n", |
283 | 285 | "# Get the number of row groups in this part-0 file.\n", |
284 | 286 | "num_groups = parquet_file.num_row_groups\n", |
|
308 | 310 | "wrapper = SpatialDataWrapper(\n", |
309 | 311 | " sdata_path=spatialdata_filepath,\n", |
310 | 312 | " # The following paths are relative to the root of the SpatialData zarr store on-disk.\n", |
311 | | - " image_path=\"images/rasterized\",\n", |
| 313 | + " image_path=\"images/morphology_focus\",\n", |
312 | 314 | " table_path=\"tables/table\",\n", |
313 | 315 | " obs_feature_matrix_path=\"tables/table/X\",\n", |
314 | | - " obs_spots_path=\"shapes/cells\",\n", |
| 316 | + " obs_spots_path=\"shapes/cell_circles\",\n", |
315 | 317 | " coordinate_system=\"global\",\n", |
316 | 318 | " coordination_values={\n", |
317 | 319 | " # The following tells Vitessce to consider each observation as a \"spot\"\n", |
318 | 320 | " \"obsType\": \"cell\",\n", |
319 | 321 | " }\n", |
320 | 322 | ")\n", |
321 | | - "dataset = vc.add_dataset(name='MERFISH').add_object(wrapper)\n", |
| 323 | + "points_wrapper = SpatialDataWrapper(\n", |
| 324 | + " sdata_path=spatialdata_filepath,\n", |
| 325 | + " # The following paths are relative to the root of the SpatialData zarr store on-disk.\n", |
| 326 | + " obs_points_path=\"points/transcripts_with_morton_codes\",\n", |
| 327 | + " obs_feature_matrix_path=\"tables/dense_table/X\",\n", |
| 328 | + " coordinate_system=\"global\",\n", |
| 329 | + " coordination_values={\n", |
| 330 | + " \"obsType\": \"point\",\n", |
| 331 | + " \"featureType\": \"gene\",\n", |
| 332 | + " }\n", |
| 333 | + ")\n", |
| 334 | + "dataset = vc.add_dataset(name='MERFISH').add_object(wrapper).add_object(points_wrapper)\n", |
322 | 335 | "\n", |
323 | 336 | "# Add views (visualizations) to the configuration:\n", |
324 | 337 | "spatial = vc.add_view(\"spatialBeta\", dataset=dataset)\n", |
|
332 | 345 | " }]),\n", |
333 | 346 | "}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"obsSpots\"))\n", |
334 | 347 | "\n", |
| 348 | + "vc.link_views_by_dict([spatial, layer_controller], {\n", |
| 349 | + " 'pointLayer': CL([{\n", |
| 350 | + " 'obsType': 'point',\n", |
| 351 | + " }]),\n", |
| 352 | + "}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"obsPoints\"))\n", |
| 353 | + "\n", |
335 | 354 | "vc.link_views([spatial, layer_controller, feature_list, obs_sets], ['obsType'], [wrapper.obs_type_label])\n", |
336 | 355 | "\n", |
337 | 356 | "# Layout the views\n", |
|
379 | 398 | "name": "python", |
380 | 399 | "nbconvert_exporter": "python", |
381 | 400 | "pygments_lexer": "ipython3", |
382 | | - "version": "3.10.14" |
| 401 | + "version": "3.12.5" |
383 | 402 | } |
384 | 403 | }, |
385 | 404 | "nbformat": 4, |
|
0 commit comments