Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/notebooks/spatial_data_kpmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,37 @@ def clean_adata(adata):
shapes_key = "shapes" + labels_key[labels_key.index("_"):]
sdata.shapes[shapes_key] = to_polygons(sdata.labels[labels_key])

# Convert boolean columns to set names
ptc_obs = sdata.tables['table_peritubular_capillaries'].obs
ptc_obs['PTC_in_Cortex'] = sdata.tables['table_peritubular_capillaries'].X[:,2]
ptc_obs['PTC_in_IFTA'] = sdata.tables['table_peritubular_capillaries'].X[:,3]

def row_to_cortex_name(row):
if row['PTC_in_Cortex'] == 1.0:
return "Inside Cortex"
if row['PTC_in_Cortex'] == 0.0:
return "Outside Cortex"

def row_to_ifta_name(row):
if row['PTC_in_IFTA'] == 1.0:
return "IFTA"
if row['PTC_in_IFTA'] == 0.0:
return "non-IFTA"

def row_to_cortical_ifta_name(row):
if row['PTC_in_Cortex'] == 1.0 and row['PTC_in_IFTA'] == 1.0:
return "Cortical IFTA"
if row['PTC_in_Cortex'] == 1.0 and row['PTC_in_IFTA'] == 0.0:
return "Cortical non-IFTA"
if row['PTC_in_Cortex'] == 0.0:
return "Outside Cortex"

ptc_obs['cortex_set'] = ptc_obs.apply(row_to_cortex_name, axis='columns')
ptc_obs['ifta_set'] = ptc_obs.apply(row_to_ifta_name, axis='columns')
ptc_obs['cortex_ifta_set'] = ptc_obs.apply(row_to_cortical_ifta_name, axis='columns')

sdata.tables['table_peritubular_capillaries'].obs = ptc_obs

sdata.write(join(base_dir, "sdata.zarr"), overwrite=True)
print(join(base_dir, "S-1905-017737.sdata.zarr"))
print("Done")
126 changes: 74 additions & 52 deletions docs/notebooks/spatial_data_kpmp_vis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@
" table_path=\"tables/table_tubules\",\n",
" labels_path=\"labels/labels_tubules\",\n",
" obs_feature_matrix_path=\"tables/table_tubules/X\",\n",
" #obs_feature_matrix_path=\"tables/table/X\",\n",
" #obs_set_paths=[\"tables/table/obs/annotation\"],\n",
" #obs_set_names=[\"Annotation\"],\n",
" #region=\"tubules\",\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"fileUid\": \"labels_tubules\",\n",
Expand All @@ -111,10 +107,6 @@
" SpatialDataWrapper(\n",
" sdata_url=sdata_url,\n",
" labels_path=\"labels/labels_arteries_arterioles\",\n",
" #obs_feature_matrix_path=\"tables/table/X\",\n",
" #obs_set_paths=[\"tables/table/obs/annotation\"],\n",
" #obs_set_names=[\"Annotation\"],\n",
" #region=\"tubules\",\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"fileUid\": \"labels_arteries_arterioles\",\n",
Expand All @@ -129,11 +121,6 @@
" table_path=\"tables/table_cortical_interstitia\",\n",
" labels_path=\"labels/labels_cortical_interstitia\",\n",
" obs_feature_matrix_path=\"tables/table_cortical_interstitia/X\",\n",
" \n",
" #obs_feature_matrix_path=\"tables/table/X\",\n",
" #obs_set_paths=[\"tables/table/obs/annotation\"],\n",
" #obs_set_names=[\"Annotation\"],\n",
" #region=\"tubules\",\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"fileUid\": \"labels_cortical_interstitia\",\n",
Expand All @@ -148,10 +135,6 @@
" table_path=\"tables/table_globally_sclerotic_glomeruli\",\n",
" labels_path=\"labels/labels_globally_sclerotic_glomeruli\",\n",
" obs_feature_matrix_path=\"tables/table_globally_sclerotic_glomeruli/X\",\n",
" #obs_feature_matrix_path=\"tables/table/X\",\n",
" #obs_set_paths=[\"tables/table/obs/annotation\"],\n",
" #obs_set_names=[\"Annotation\"],\n",
" #region=\"tubules\",\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"fileUid\": \"labels_globally_sclerotic_glomeruli\",\n",
Expand All @@ -166,10 +149,6 @@
" table_path=\"tables/table_non_globally_sclerotic_glomeruli\",\n",
" labels_path=\"labels/labels_non_globally_sclerotic_glomeruli\",\n",
" obs_feature_matrix_path=\"tables/table_non_globally_sclerotic_glomeruli/X\",\n",
" #obs_feature_matrix_path=\"tables/table/X\",\n",
" #obs_set_paths=[\"tables/table/obs/annotation\"],\n",
" #obs_set_names=[\"Annotation\"],\n",
" #region=\"tubules\",\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"fileUid\": \"labels_non_globally_sclerotic_glomeruli\",\n",
Expand All @@ -183,10 +162,6 @@
" sdata_url=sdata_url,\n",
" table_path=\"tables/table_interstitialfibrosis_and_tubular_atrophy\",\n",
" labels_path=\"labels/labels_interstitialfibrosis_and_tubular_atrophy\",\n",
" #obs_feature_matrix_path=\"tables/table/X\",\n",
" #obs_set_paths=[\"tables/table/obs/annotation\"],\n",
" #obs_set_names=[\"Annotation\"],\n",
" #region=\"tubules\",\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"fileUid\": \"labels_interstitialfibrosis_and_tubular_atrophy\",\n",
Expand All @@ -201,10 +176,18 @@
" table_path=\"tables/table_peritubular_capillaries\",\n",
" labels_path=\"labels/labels_peritubular_capillaries\",\n",
" obs_feature_matrix_path=\"tables/table_peritubular_capillaries/X\",\n",
" #obs_feature_matrix_path=\"tables/table/X\",\n",
" #obs_set_paths=[\"tables/table/obs/annotation\"],\n",
" #obs_set_names=[\"Annotation\"],\n",
" #region=\"tubules\",\n",
" obs_set_paths=[\n",
" \"tables/table_peritubular_capillaries/obs/cortex_ifta_set\",\n",
" \"tables/table_peritubular_capillaries/obs/cortex_set\",\n",
" \"tables/table_peritubular_capillaries/obs/ifta_set\",\n",
" [\"tables/table_peritubular_capillaries/obs/cortex_set\", \"tables/table_peritubular_capillaries/obs/ifta_set\"],\n",
" ],\n",
" obs_set_names=[\n",
" \"Cortex and IFTA membership\",\n",
" \"Cortex membership\",\n",
" \"IFTA membership\",\n",
" \"Cortex and IFTA hierarchy\",\n",
" ],\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"fileUid\": \"labels_peritubular_capillaries\",\n",
Expand All @@ -231,6 +214,12 @@
"ngsg_feature_list = vc.add_view(\"featureList\", dataset=dataset).set_props(title=\"Non-Globally Sclerotic Glomeruli\")\n",
"ngsg_histogram = vc.add_view(\"featureValueHistogram\", dataset=dataset)\n",
"\n",
"# Add obsSets, obsSetSizes, and violin plot views for PTC sets+areas/aspectRatio\n",
"pt_sets = vc.add_view(\"obsSets\", dataset=dataset)\n",
"pt_bar_plot = vc.add_view(\"obsSetSizes\", dataset=dataset)\n",
"pt_violin_plot = vc.add_view(\"obsSetFeatureValueDistribution\", dataset=dataset).set_props(jitter=True)\n",
"\n",
"\n",
"# Coordination of views.\n",
"[ft_scope, fvt_scope] = vc.add_coordination(\"featureType\", \"featureValueType\")\n",
"ft_scope.set_value(\"feature\")\n",
Expand All @@ -242,7 +231,8 @@
"\n",
"[pt_ot_scope, pt_fs_scope, pt_oce_scope] = vc.add_coordination(\"obsType\", \"featureSelection\", \"obsColorEncoding\")\n",
"pt_ot_scope.set_value(ptc_obstype)\n",
"pt_oce_scope.set_value(\"spatialChannelColor\")\n",
"pt_fs_scope.set_value([\"Area\"])\n",
"pt_oce_scope.set_value(\"cellSetSelection\")\n",
"\n",
"\n",
"[gsg_ot_scope, gsg_fs_scope, gsg_oce_scope, gsg_fvcr_scope] = vc.add_coordination(\"obsType\", \"featureSelection\", \"obsColorEncoding\", \"featureValueColormapRange\")\n",
Expand All @@ -257,6 +247,7 @@
"\n",
"vc.link_views_by_dict([spatial, layer_controller], {\n",
" \"imageLayer\": CL([{\n",
" \"spatialLayerOpacity\": 0.1,\n",
" \"photometricInterpretation\": \"RGB\",\n",
" }]),\n",
"}, meta=True, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"image\"))\n",
Expand All @@ -271,12 +262,13 @@
" \"featureType\": ft_scope,\n",
" \"featureValueType\": fvt_scope,\n",
" \"featureSelection\": t_fs_scope,\n",
" \"spatialChannelVisible\": True,\n",
" \"spatialChannelColor\": [255, 255, 255],\n",
" \"spatialChannelVisible\": False,\n",
" \"spatialChannelColor\": [73, 155, 119],\n",
" \"spatialChannelOpacity\": 0.5,\n",
" \"obsColorEncoding\": t_oce_scope,\n",
" \"featureValueColormapRange\": [0, 1],\n",
" \"featureAggregationStrategy\": \"first\",\n",
" \"spatialSegmentationFilled\": True,\n",
" \"obsHighlight\": None,\n",
" }]),\n",
" },\n",
Expand All @@ -287,12 +279,13 @@
" \"obsType\": \"Artery\",\n",
" \"featureType\": ft_scope,\n",
" \"featureValueType\": fvt_scope,\n",
" \"spatialChannelVisible\": True,\n",
" \"spatialChannelColor\": [255, 255, 255],\n",
" \"spatialChannelVisible\": False,\n",
" \"spatialChannelColor\": [237, 226, 107],\n",
" \"spatialChannelOpacity\": 0.5,\n",
" \"obsColorEncoding\": \"spatialChannelColor\",\n",
" \"featureValueColormapRange\": [0, 1],\n",
" \"featureAggregationStrategy\": \"first\",\n",
" \"spatialSegmentationFilled\": True,\n",
" \"obsHighlight\": None,\n",
" }]),\n",
" },\n",
Expand All @@ -309,6 +302,7 @@
" \"obsColorEncoding\": \"spatialChannelColor\",\n",
" \"featureValueColormapRange\": [0, 1],\n",
" \"featureAggregationStrategy\": \"first\",\n",
" \"spatialSegmentationFilled\": True,\n",
" \"obsHighlight\": None,\n",
" }]),\n",
" },\n",
Expand All @@ -321,11 +315,12 @@
" \"featureValueType\": fvt_scope,\n",
" \"featureSelection\": gsg_fs_scope,\n",
" \"spatialChannelVisible\": False,\n",
" \"spatialChannelColor\": [255, 255, 255],\n",
" \"spatialChannelColor\": [52, 113, 171],\n",
" \"spatialChannelOpacity\": 0.5,\n",
" \"obsColorEncoding\": gsg_oce_scope,\n",
" \"featureValueColormapRange\": gsg_fvcr_scope,\n",
" \"featureAggregationStrategy\": \"first\",\n",
" \"spatialSegmentationFilled\": True,\n",
" \"obsHighlight\": None,\n",
" }]),\n",
" },\n",
Expand All @@ -338,11 +333,12 @@
" \"featureValueType\": fvt_scope,\n",
" \"featureSelection\": ngsg_fs_scope,\n",
" \"spatialChannelVisible\": False,\n",
" \"spatialChannelColor\": [255, 255, 255],\n",
" \"spatialChannelColor\": [114, 179, 226],\n",
" \"spatialChannelOpacity\": 0.5,\n",
" \"obsColorEncoding\": ngsg_oce_scope,\n",
" \"featureValueColormapRange\": ngsg_fvcr_scope,\n",
" \"featureAggregationStrategy\": \"first\",\n",
" \"spatialSegmentationFilled\": True,\n",
" \"obsHighlight\": None,\n",
" }]),\n",
" },\n",
Expand All @@ -353,12 +349,13 @@
" \"obsType\": \"Interstitial Fibrosis and Tubular Atrophy\",\n",
" \"featureType\": ft_scope,\n",
" \"featureValueType\": fvt_scope,\n",
" \"spatialChannelVisible\": False,\n",
" \"spatialChannelColor\": [255, 255, 255],\n",
" \"spatialChannelOpacity\": 0.5,\n",
" \"spatialChannelVisible\": True,\n",
" \"spatialChannelColor\": [218, 161, 66],\n",
" \"spatialChannelOpacity\": 1.0,\n",
" \"obsColorEncoding\": \"spatialChannelColor\",\n",
" \"featureValueColormapRange\": [0, 1],\n",
" \"featureAggregationStrategy\": \"first\",\n",
" \"spatialSegmentationFilled\": False,\n",
" \"obsHighlight\": None,\n",
" }]),\n",
" },\n",
Expand All @@ -370,12 +367,13 @@
" \"featureType\": ft_scope,\n",
" \"featureValueType\": fvt_scope,\n",
" \"featureSelection\": pt_fs_scope,\n",
" \"spatialChannelVisible\": False,\n",
" \"spatialChannelColor\": [255, 255, 255],\n",
" \"spatialChannelOpacity\": 0.5,\n",
" \"spatialChannelVisible\": True,\n",
" \"spatialChannelColor\": [197, 101, 47],\n",
" \"spatialChannelOpacity\": 1.0,\n",
" \"obsColorEncoding\": pt_oce_scope,\n",
" \"featureValueColormapRange\": [0, 1],\n",
" \"featureValueColormapRange\": [0, 0.5],\n",
" \"featureAggregationStrategy\": \"first\",\n",
" \"spatialSegmentationFilled\": True,\n",
" \"obsHighlight\": None,\n",
" }]),\n",
" }\n",
Expand All @@ -388,6 +386,11 @@
"pt_feature_list.use_coordination(pt_ot_scope, ft_scope, fvt_scope, pt_fs_scope, pt_oce_scope)\n",
"pt_histogram.use_coordination(pt_ot_scope, ft_scope, fvt_scope, pt_fs_scope, pt_oce_scope)\n",
"\n",
"pt_sets.use_coordination(pt_ot_scope, ft_scope, fvt_scope, pt_fs_scope, pt_oce_scope)\n",
"pt_bar_plot.use_coordination(pt_ot_scope, ft_scope, fvt_scope, pt_fs_scope, pt_oce_scope)\n",
"pt_violin_plot.use_coordination(pt_ot_scope, ft_scope, fvt_scope, pt_fs_scope, pt_oce_scope)\n",
"\n",
"\n",
"gsg_feature_list.use_coordination(gsg_ot_scope, ft_scope, fvt_scope, gsg_fs_scope, gsg_oce_scope, gsg_fvcr_scope)\n",
"gsg_histogram.use_coordination(gsg_ot_scope, ft_scope, fvt_scope, gsg_fs_scope, gsg_oce_scope, gsg_fvcr_scope)\n",
"\n",
Expand All @@ -396,26 +399,45 @@
"\n",
"\n",
"# Layout the views in a grid arrangement.\n",
"vc.layout(vconcat(hconcat(spatial, layer_controller, split=[3, 1]), hconcat(\n",
" (tubules_feature_list / tubules_histogram),\n",
" (pt_feature_list / pt_histogram),\n",
" (gsg_feature_list / gsg_histogram),\n",
" (ngsg_feature_list / ngsg_histogram)\n",
")));"
"vc.layout(vconcat(\n",
" hconcat(spatial, layer_controller, split=[3, 1]),\n",
" hconcat(\n",
" (tubules_feature_list / tubules_histogram),\n",
" (pt_feature_list / pt_histogram),\n",
" (gsg_feature_list / gsg_histogram),\n",
" (ngsg_feature_list / ngsg_histogram)\n",
" ),\n",
" hconcat(pt_sets, pt_bar_plot, pt_violin_plot)\n",
"));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"vw = vc.widget(height=1000)\n",
"vw"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#import json\n",
"#print(json.dumps(vc.to_dict(), indent=2))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down