Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade notebook examples with inline metadata #48

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ data/
dist/
mair/
.DS_Store
data.zip
111 changes: 47 additions & 64 deletions notebooks/getting-started.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "b640237c",
"metadata": {},
"outputs": [],
"source": [
"# /// script\n",
"# requires-python = \"==3.12\"\n",
"# dependencies = [\n",
"# \"cev\",\n",
"# \"pooch==1.8.2\",\n",
"# \"pyarrow\",\n",
"# ]\n",
"#\n",
"# [tool.uv.sources]\n",
"# cev = { path = \"../\" }\n",
"# ///"
]
},
{
"cell_type": "markdown",
"id": "8efc6d60-f207-4e54-92b0-a6070b0158b4",
Expand All @@ -16,12 +36,13 @@
"cell_type": "code",
"execution_count": null,
"id": "47c31bea-24b3-4d16-a69a-a3ad3a746234",
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"import zipfile\n",
"\n",
"import pandas as pd\n",
"import pooch\n",
"\n",
"from cev.widgets import Embedding, EmbeddingComparisonWidget"
]
Expand All @@ -43,22 +64,21 @@
"cell_type": "code",
"execution_count": null,
"id": "dbf802bc-f709-4163-9b49-8fa5f6ce59ab",
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"# download the data\n",
"!curl -sL https://figshare.com/ndownloader/articles/23063615/versions/1 -o data.zip\n",
"!unzip data.zip -d data"
"archive = pooch.retrieve(\n",
" url=\"https://figshare.com/ndownloader/articles/23063615/versions/1\",\n",
" path=pooch.os_cache(\"cev\"),\n",
" fname=\"data.zip\",\n",
" known_hash=None,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "e62390d2-1242-49a8-9780-be976d39fa42",
"metadata": {
"tags": []
},
"metadata": {},
"source": [
"## Comparing Two Embeddings of the same Data\n",
"\n",
Expand All @@ -76,26 +96,23 @@
"cell_type": "code",
"execution_count": null,
"id": "7874813c-810f-40e5-92ab-91f228046a5e",
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"tissue_umap_embedding = Embedding.from_ozette(\n",
" df=pd.read_parquet(\"./data/mair-2022-tissue-138-umap.pq\")\n",
")\n",
"tissue_ozette_embedding = Embedding.from_ozette(\n",
" df=pd.read_parquet(\"./data/mair-2022-tissue-138-ozette.pq\")\n",
")"
"with zipfile.ZipFile(archive, \"r\") as z:\n",
" with z.open(\"mair-2022-tissue-138-umap.pq\") as f:\n",
" tissue_umap_embedding = pd.read_parquet(f).pipe(Embedding.from_ozette)\n",
" with z.open(\"mair-2022-tissue-138-ozette.pq\") as f:\n",
" tissue_ozette_embedding = pd.read_parquet(f).pipe(Embedding.from_ozette)\n",
" with z.open(\"mair-2022-tumor-006-ozette.pq\") as f:\n",
" tumor_ozette_embedding = pd.read_parquet(f).pipe(Embedding.from_ozette)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3d7e114-9fd3-4785-bdca-e3f4bbf37df8",
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"umap_vs_ozette = EmbeddingComparisonWidget(\n",
Expand Down Expand Up @@ -126,9 +143,7 @@
"cell_type": "code",
"execution_count": null,
"id": "ba7a378f-4212-4953-be5b-7a273f8bc75e",
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"umap_vs_ozette.select([\"CD3+\", \"CD4+\", \"CD8-\"])"
Expand All @@ -144,27 +159,11 @@
"Instead of comparing identical data, let's take a look at two transformed and aligned embeddings: tissue vs tumor. The embeddings are both annotation-transformed and aligned, ensuring low confusion and high neighborhood similarity (check to confirm!). The abundance metric aids in identifying potential shifts in phenotype abundance, providing a comprehensive and visually intuitive method for analyzing complex cytometry data. Remember, our metric should be used as a exploratory tool guide exploration and quickly surface potentially interesting phenotypes, but robust statical methods must be applied to confirm whether any abundance differences exist."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "180f0945-d97c-4261-aa67-5368e3b560ad",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"tumor_ozette_embedding = Embedding.from_ozette(\n",
" df=pd.read_parquet(\"./data/mair-2022-tumor-006-ozette.pq\")\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0f99361b-6e96-4a6d-ad65-0533c23bece7",
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"tissue_vs_tumor = EmbeddingComparisonWidget(\n",
Expand All @@ -183,9 +182,7 @@
{
"cell_type": "markdown",
"id": "6d632c95-dff8-4b90-b763-f3055c4e8047",
"metadata": {
"tags": []
},
"metadata": {},
"source": [
"The following **CD8+ T cells** are more abundant in `tissue` (i.e., the relative abundance is higher on the left) compared to `tumor` (i.e., the relative abundance is lower on the right)"
]
Expand All @@ -194,28 +191,18 @@
"cell_type": "code",
"execution_count": null,
"id": "2f7ebd73-32e7-48ed-8575-8d14d2edc73f",
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"tissue_vs_tumor.select(\n",
" \"CD4-CD8+CD3+CD45RA+CD27+CD19-CD103-CD28-CD69+PD1+HLADR-GranzymeB-CD25-ICOS-TCRgd-CD38-CD127-Tim3-\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eefac753-7920-4c87-99ef-d155f1ec5114",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -224,12 +211,8 @@
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ dependencies = [
"jupyter-scatter>=0.14.0",
"pandas>=1.0,<2.0",
"numpy>=1.0,<2.0",
"pyarrow",
"pooch>=1.3.0",
]
dynamic = ["version"]

Expand Down
20 changes: 1 addition & 19 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading