Skip to content

Commit

Permalink
added color, removed scatterplot
Browse files Browse the repository at this point in the history
  • Loading branch information
srivarra committed Apr 29, 2024
1 parent 02a34ab commit c9c6047
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 47 deletions.
Binary file modified data/embedded_data.zarr/obs/cell_type_patient/categories/0
Binary file not shown.
24 changes: 0 additions & 24 deletions data/embedded_data.zarr/uns/cell_type_patient_color/.zarray

This file was deleted.

4 changes: 0 additions & 4 deletions data/embedded_data.zarr/uns/cell_type_patient_color/.zattrs

This file was deleted.

Binary file removed data/embedded_data.zarr/uns/cell_type_patient_color/0
Binary file not shown.
17 changes: 4 additions & 13 deletions scripts/process_fcs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,13 @@
"cell_type_mapping = {0: \"Healthy\", 1: \"Healthy\", 2: \"Cancer\"}\n",
"patient_annotation = {0: \"Healthy\", 1: \"Cancer\", 2: \"Cancer\"}\n",
"cell_type_patient_mapping = {\n",
" 0: \"Healthy Patient's Healthy Cells\",\n",
" 1: \"Cancer Patient's Healthy Cells\",\n",
" 2: \"Cancer Patient's Cancer Cells\",\n",
" 0: \"Healthy_Patient_Healthy_Cells\",\n",
" 1: \"Cancer_Patient_Healthy_Cells\",\n",
" 2: \"Cancer_Patient_Cancer_Cells\",\n",
"}\n",
"new_adata.obs[\"cell_type\"] = new_adata.obs[\"OmiqFileIndex\"].map(cell_type_mapping).astype(\"category\")\n",
"new_adata.obs[\"patient\"] = new_adata.obs[\"OmiqFileIndex\"].map(patient_annotation).astype(\"category\")\n",
"new_adata.obs[\"cell_type_patient\"] = new_adata.obs[\"OmiqFileIndex\"].map(cell_type_patient_mapping).astype(\"category\")\n",
"new_adata.uns[\"cell_type_patient_color\"] = [\"red\", \"gray\", \"green\"]"
"new_adata.obs[\"cell_type_patient\"] = new_adata.obs[\"OmiqFileIndex\"].map(cell_type_patient_mapping).astype(\"category\")"
]
},
{
Expand All @@ -141,7 +140,6 @@
"source": [
"sc.pp.neighbors(adata=new_adata)\n",
"new_adata.obsm[\"X_umap_2D\"] = sc.tl.umap(adata=new_adata, n_components=2, copy=True).obsm[\"X_umap\"].copy()\n",
"\n",
"new_adata.obsm[\"X_umap_3D\"] = sc.tl.umap(adata=new_adata, n_components=3, copy=True).obsm[\"X_umap\"].copy()"
]
},
Expand Down Expand Up @@ -172,13 +170,6 @@
"source": [
"new_adata.write_zarr(\"../data/embedded_data.zarr\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
65 changes: 59 additions & 6 deletions scripts/vitessce.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
"source": [
"from pathlib import Path\n",
"\n",
"import numpy as np\n",
"from matplotlib.colors import to_rgb\n",
"from vitessce import (\n",
" AnnDataWrapper,\n",
" VitessceConfig,\n",
")\n",
"from vitessce import (\n",
" Component as cm,\n",
")"
"from vitessce import Component as cm\n",
"from vitessce import CoordinationType as ct"
]
},
{
Expand All @@ -47,6 +48,40 @@
"## Create Vitessce Config"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hphc = \"Healthy_Patient_Healthy_Cells\"\n",
"cphc = \"Cancer_Patient_Healthy_Cells\"\n",
"cpcc = \"Cancer_Patient_Cancer_Cells\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def color_name_to_int(color_name):\n",
" \"\"\"Converts a color name to a list of integers representing the color in RGB\n",
"\n",
" Parameters\n",
" ----------\n",
" color_name : str\n",
" The color to convert\n",
"\n",
" Returns\n",
" -------\n",
" list[int]\n",
" The integer RGB values\n",
" \"\"\"\n",
" rgb = to_rgb(color_name)\n",
" return (np.array(rgb) * 255).astype(int).tolist()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -64,7 +99,7 @@
"source": [
"vc = VitessceConfig(schema_version=\"1.0.15\", name=\"Science Under the Stars\", description=\"The Dataset for the event\")\n",
"\n",
"dataset = vc.add_dataset(name=\"Cancer_Patient\").add_object(\n",
"dataset = vc.add_dataset(name=\"Dataset\").add_object(\n",
" AnnDataWrapper(\n",
" adata_path=vit_adata_path,\n",
" obs_embedding_paths=[\"obsm/X_umap_2D\"],\n",
Expand All @@ -88,13 +123,31 @@
"metadata": {},
"outputs": [],
"source": [
"scatterplot_umap = vc.add_view(view_type=cm.SCATTERPLOT, dataset=dataset, mapping=\"UMAP\")\n",
"# scatterplot_umap = vc.add_view(view_type=cm.SCATTERPLOT, dataset=dataset, mapping=\"UMAP\")\n",
"cell_sets = vc.add_view(view_type=cm.OBS_SETS, dataset=dataset)\n",
"markers = vc.add_view(view_type=cm.FEATURE_LIST, dataset=dataset)\n",
"heatmap = vc.add_view(view_type=cm.HEATMAP, dataset=dataset)\n",
"cell_set_sizes = vc.add_view(view_type=cm.OBS_SET_SIZES, dataset=dataset)\n",
"\n",
"vc.layout((scatterplot_umap | (cell_sets / markers)) / (heatmap | cell_set_sizes));"
"vc.link_views_by_dict(\n",
" views=[cell_sets, heatmap, cell_set_sizes],\n",
" input_val={\n",
" ct.OBS_COLOR_ENCODING: \"cellSetSelection\",\n",
" ct.OBS_SET_SELECTION: [\n",
" [\"Cell Type\", hphc],\n",
" [\"Cell Type\", cphc],\n",
" [\"Cell Type\", cpcc],\n",
" ],\n",
" ct.OBS_SET_COLOR: [\n",
" {\"path\": [\"Cell Type\", hphc], \"color\": color_name_to_int(\"xkcd:grey\")},\n",
" {\"path\": [\"Cell Type\", cphc], \"color\": color_name_to_int(\"xkcd:green\")},\n",
" {\"path\": [\"Cell Type\", cpcc], \"color\": color_name_to_int(\"xkcd:red\")},\n",
" ],\n",
" },\n",
" meta=False,\n",
")\n",
"vc.layout((heatmap | cell_set_sizes) / (cell_sets | markers))\n",
"# vc.layout((scatterplot_umap | (cell_sets / markers)) / (heatmap | cell_set_sizes));"
]
},
{
Expand Down

0 comments on commit c9c6047

Please sign in to comment.