Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 23, 2024
1 parent 6e63862 commit 55d9144
Show file tree
Hide file tree
Showing 25 changed files with 1,356 additions and 1,111 deletions.
21 changes: 10 additions & 11 deletions notebooks/spatialdata_tutorials/0_format_Xenium_sdata.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"metadata": {},
"outputs": [],
"source": [
"import spatialdata_io\n",
"import spatialdata as sd"
"import spatialdata as sd\n",
"import spatialdata_io"
]
},
{
Expand All @@ -39,8 +39,8 @@
}
],
"source": [
"path='/media/sergio/Discovair_final/Xenium_Prime_Mouse_Brain_Coronal_FF_outs'\n",
"sdata=spatialdata_io.xenium(path)"
"path = \"/media/sergio/Discovair_final/Xenium_Prime_Mouse_Brain_Coronal_FF_outs\"\n",
"sdata = spatialdata_io.xenium(path)"
]
},
{
Expand All @@ -66,7 +66,7 @@
}
],
"source": [
"outpath='/media/sergio/Discovair_final/mousebrain_prime.zarr'\n",
"outpath = \"/media/sergio/Discovair_final/mousebrain_prime.zarr\"\n",
"sdata.write(outpath)"
]
},
Expand Down Expand Up @@ -130,7 +130,7 @@
}
],
"source": [
"xenium_path='/media/sergio/Discovair_final/mousebrain_prime.zarr'\n",
"xenium_path = \"/media/sergio/Discovair_final/mousebrain_prime.zarr\"\n",
"sdata = sd.read_zarr(xenium_path)\n",
"sdata"
]
Expand Down Expand Up @@ -179,7 +179,7 @@
" axes=[\"x\", \"y\"],\n",
" min_coordinate=[17500, 0],\n",
" max_coordinate=[35000, 15000],\n",
" target_coordinate_system='global',\n",
" target_coordinate_system=\"global\",\n",
")\n",
"\n",
"cropped_sdata"
Expand Down Expand Up @@ -209,8 +209,7 @@
}
],
"source": [
"import spatialdata_plot\n",
"cropped_sdata.pl.render_images(\"morphology_focus\").pl.show( title=\"Morphology image\")"
"cropped_sdata.pl.render_images(\"morphology_focus\").pl.show(title=\"Morphology image\")"
]
},
{
Expand All @@ -232,8 +231,8 @@
}
],
"source": [
"xenium_path_cropped='/media/sergio/Discovair_final/mousebrain_prime_half.zarr'\n",
"cropped_sdata.write(xenium_path_cropped,overwrite=True)"
"xenium_path_cropped = \"/media/sergio/Discovair_final/mousebrain_prime_half.zarr\"\n",
"cropped_sdata.write(xenium_path_cropped, overwrite=True)"
]
}
],
Expand Down
67 changes: 45 additions & 22 deletions notebooks/spatialdata_tutorials/1_run_segmentation_free.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
"metadata": {},
"outputs": [],
"source": [
"import spatialdata_io\n",
"import spatialdata as sd\n",
"import pandas as pd\n",
"import spatialdata_plot\n",
"import sys\n",
"\n",
"import spatialdata as sd\n",
"\n",
"sys.path.append(\"../../src\")\n",
"import troutpy "
"import troutpy"
]
},
{
Expand Down Expand Up @@ -40,8 +39,8 @@
}
],
"source": [
"xenium_path_cropped='/media/sergio/Discovair_final/mousebrain_prime_crop.zarr'\n",
"sdata= sd.read_zarr(xenium_path_cropped)"
"xenium_path_cropped = \"/media/sergio/Discovair_final/mousebrain_prime_crop.zarr\"\n",
"sdata = sd.read_zarr(xenium_path_cropped)"
]
},
{
Expand Down Expand Up @@ -81,11 +80,12 @@
}
],
"source": [
"#define points2regions_params\n",
"points2regions_params={'num_clusters':100, 'pixel_width':0.4, 'pixel_smoothing':3.5}\n",
"#run_segmentation_free\n",
"troutpy.tl.segmentation_free_clustering(sdata, params=points2regions_params, \n",
" x='x', y='y', feature_name='feature_name', transcript_id='transcript_id')"
"# define points2regions_params\n",
"points2regions_params = {\"num_clusters\": 100, \"pixel_width\": 0.4, \"pixel_smoothing\": 3.5}\n",
"# run_segmentation_free\n",
"troutpy.tl.segmentation_free_clustering(\n",
" sdata, params=points2regions_params, x=\"x\", y=\"y\", feature_name=\"feature_name\", transcript_id=\"transcript_id\"\n",
")"
]
},
{
Expand All @@ -110,7 +110,7 @@
}
],
"source": [
"troutpy.pp.define_extracellular(sdata, method='segmentation_free',min_prop_of_extracellular=0.8) "
"troutpy.pp.define_extracellular(sdata, method=\"segmentation_free\", min_prop_of_extracellular=0.8)"
]
},
{
Expand All @@ -130,7 +130,7 @@
}
],
"source": [
"len(sdata.points['transcripts']['extracellular'].compute())"
"len(sdata.points[\"transcripts\"][\"extracellular\"].compute())"
]
},
{
Expand All @@ -151,7 +151,8 @@
],
"source": [
"import numpy as np\n",
"np.sum(sdata.points['transcripts']['extracellular'].compute())"
"\n",
"np.sum(sdata.points[\"transcripts\"][\"extracellular\"].compute())"
]
},
{
Expand All @@ -173,8 +174,8 @@
}
],
"source": [
"xenium_path_cropped='/media/sergio/Discovair_final/mousebrain_prime_crop_points2regions.zarr'\n",
"sdata.write(xenium_path_cropped,overwrite=True)"
"xenium_path_cropped = \"/media/sergio/Discovair_final/mousebrain_prime_crop_points2regions.zarr\"\n",
"sdata.write(xenium_path_cropped, overwrite=True)"
]
},
{
Expand All @@ -184,13 +185,35 @@
"outputs": [],
"source": [
"### work a bit into better functions for plotting here\n",
"plot_data=sdata.points['transcripts'][['segmentation_free_clusters','overlaps_cell','overlaps_nucleus']].compute()\n",
"troutpy.pl.plot_crosstab(plot_data,xvar='segmentation_free_clusters',yvar='overlaps_cell',normalize=True,axis=1,kind='bar',figsize=(20,7),stacked=True,cmap='coolwarm',sortby=True)\n",
"troutpy.pl.plot_crosstab(plot_data,xvar='segmentation_free_clusters',yvar='overlaps_nucleus',normalize=True,axis=1,kind='bar',figsize=(20,7),stacked=True,cmap='coolwarm',sortby=1)\n",
"plot_data = sdata.points[\"transcripts\"][[\"segmentation_free_clusters\", \"overlaps_cell\", \"overlaps_nucleus\"]].compute()\n",
"troutpy.pl.plot_crosstab(\n",
" plot_data,\n",
" xvar=\"segmentation_free_clusters\",\n",
" yvar=\"overlaps_cell\",\n",
" normalize=True,\n",
" axis=1,\n",
" kind=\"bar\",\n",
" figsize=(20, 7),\n",
" stacked=True,\n",
" cmap=\"coolwarm\",\n",
" sortby=True,\n",
")\n",
"troutpy.pl.plot_crosstab(\n",
" plot_data,\n",
" xvar=\"segmentation_free_clusters\",\n",
" yvar=\"overlaps_nucleus\",\n",
" normalize=True,\n",
" axis=1,\n",
" kind=\"bar\",\n",
" figsize=(20, 7),\n",
" stacked=True,\n",
" cmap=\"coolwarm\",\n",
" sortby=1,\n",
")\n",
"\n",
"\n",
"input_data=sdata.points['transcripts'][['missegmentation_associated']].compute()\n",
"troutpy.pl.pie_of_positive(input_data,groupby='missegmentation_associated',save=True)"
"input_data = sdata.points[\"transcripts\"][[\"missegmentation_associated\"]].compute()\n",
"troutpy.pl.pie_of_positive(input_data, groupby=\"missegmentation_associated\", save=True)"
]
}
],
Expand Down
58 changes: 32 additions & 26 deletions notebooks/spatialdata_tutorials/2_process_cells.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@
}
],
"source": [
"import os\n",
"import numpy as np\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"import spatialdata_io\n",
"import spatialdata as sd\n",
"# while not pip installable, add path to file\n",
"import sys\n",
"\n",
"import scanpy as sc\n",
"import spatialdata as sd\n",
"\n",
"# while not pip installable, add path to file \n",
"import sys\n",
"sys.path.append(\"../../src\")\n",
"import troutpy \n"
"sys.path.append(\"../../src\")"
]
},
{
Expand Down Expand Up @@ -61,9 +55,9 @@
}
],
"source": [
"xenium_path_cropped='/media/sergio/Discovair_final/mousebrain_prime_crop_points2regions.zarr'\n",
"output_path='/media/sergio/Discovair_final/analysis_crop'\n",
"sdata=sd.read_zarr(xenium_path_cropped)"
"xenium_path_cropped = \"/media/sergio/Discovair_final/mousebrain_prime_crop_points2regions.zarr\"\n",
"output_path = \"/media/sergio/Discovair_final/analysis_crop\"\n",
"sdata = sd.read_zarr(xenium_path_cropped)"
]
},
{
Expand All @@ -72,7 +66,7 @@
"metadata": {},
"outputs": [],
"source": [
"adata=sdata['table']"
"adata = sdata[\"table\"]"
]
},
{
Expand All @@ -81,7 +75,7 @@
"metadata": {},
"outputs": [],
"source": [
"adata.raw=adata\n",
"adata.raw = adata\n",
"sc.pp.filter_cells(adata, min_genes=100)\n",
"sc.pp.filter_genes(adata, min_cells=3)"
]
Expand Down Expand Up @@ -155,7 +149,7 @@
],
"source": [
"sc.tl.umap(adata)\n",
"sc.tl.leiden(adata,key_added='leiden')"
"sc.tl.leiden(adata, key_added=\"leiden\")"
]
},
{
Expand All @@ -175,7 +169,7 @@
}
],
"source": [
"sc.pl.umap(adata,color=\"leiden\",size=30)"
"sc.pl.umap(adata, color=\"leiden\", size=30)"
]
},
{
Expand Down Expand Up @@ -204,9 +198,7 @@
],
"source": [
"sc.tl.rank_genes_groups(adata, groupby=\"leiden\", method=\"wilcoxon\")\n",
"sc.pl.rank_genes_groups_dotplot(\n",
" adata, groupby=\"leiden\", standard_scale=\"var\", n_genes=5\n",
")"
"sc.pl.rank_genes_groups_dotplot(adata, groupby=\"leiden\", standard_scale=\"var\", n_genes=5)"
]
},
{
Expand All @@ -226,7 +218,7 @@
}
],
"source": [
"sc.pl.spatial(adata,color='leiden',spot_size=20)"
"sc.pl.spatial(adata, color=\"leiden\", spot_size=20)"
]
},
{
Expand All @@ -242,8 +234,22 @@
"metadata": {},
"outputs": [],
"source": [
"anndict={'0':'CA','1':'Astro','2':'Oligo','3':'3','4':'4','5':'5','6':'INH','7':'7','8':'','9':'9','10':'10','11':'11','12':'12'}\n",
"adata.obs['cell type']=adata.obs['leiden'].map(anndict)"
"anndict = {\n",
" \"0\": \"CA\",\n",
" \"1\": \"Astro\",\n",
" \"2\": \"Oligo\",\n",
" \"3\": \"3\",\n",
" \"4\": \"4\",\n",
" \"5\": \"5\",\n",
" \"6\": \"INH\",\n",
" \"7\": \"7\",\n",
" \"8\": \"\",\n",
" \"9\": \"9\",\n",
" \"10\": \"10\",\n",
" \"11\": \"11\",\n",
" \"12\": \"12\",\n",
"}\n",
"adata.obs[\"cell type\"] = adata.obs[\"leiden\"].map(anndict)"
]
},
{
Expand All @@ -266,8 +272,8 @@
}
],
"source": [
"xenium_path_cropped='/media/sergio/Discovair_final/mousebrain_prime_crop_points2regions_annotated.zarr'\n",
"sdata.write(xenium_path_cropped,overwrite=True)"
"xenium_path_cropped = \"/media/sergio/Discovair_final/mousebrain_prime_crop_points2regions_annotated.zarr\"\n",
"sdata.write(xenium_path_cropped, overwrite=True)"
]
}
],
Expand Down
Loading

0 comments on commit 55d9144

Please sign in to comment.