Skip to content

Commit

Permalink
updates to notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ajitjohnson committed Mar 20, 2024
1 parent c33c8db commit 7ee40da
Show file tree
Hide file tree
Showing 12 changed files with 460 additions and 8,732 deletions.
105 changes: 37 additions & 68 deletions docs/tutorials/nbs/Adding ROIs.ipynb

Large diffs are not rendered by default.

153 changes: 65 additions & 88 deletions docs/tutorials/nbs/Celltype Exploration.ipynb

Large diffs are not rendered by default.

59 changes: 17 additions & 42 deletions docs/tutorials/nbs/Compare Proximity.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/tutorials/nbs/Export.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "943955c9-a4f4-459c-9e5e-9c482fc55015",
"metadata": {},
"source": [
"# Export data from SCIMAP into csv"
"# ⬇️ Export data from SCIMAP into csv"
]
},
{
Expand All @@ -26,7 +26,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Running SCIMAP 1.3.8\n"
"Running SCIMAP 1.3.14\n"
]
}
],
Expand All @@ -49,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"id": "d2b4abb4-2dd5-47a6-ba13-394502cae60f",
"metadata": {},
"outputs": [],
Expand Down
84 changes: 21 additions & 63 deletions docs/tutorials/nbs/Misc Helper Functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "f7d61b48-b01a-47d7-888e-5607a2a5c0ec",
"metadata": {},
"source": [
"# Additional Helper Function to make Your Life Easier"
"# Additional Helper Function to make Your Life Easier"
]
},
{
Expand All @@ -18,7 +18,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Running SCIMAP 1.3.8\n"
"Running SCIMAP 1.3.14\n"
]
}
],
Expand Down Expand Up @@ -80,33 +80,10 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "e421fd19-6631-4fbd-bbb5-de8d7c6d5660",
"metadata": {},
"outputs": [
{
"ename": "KeyError",
"evalue": "None",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/pandas/core/indexes/base.py:3790\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 3789\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 3790\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_engine\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcasted_key\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3791\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n",
"File \u001b[0;32mindex.pyx:152\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
"File \u001b[0;32mindex.pyx:181\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
"File \u001b[0;32mpandas/_libs/hashtable_class_helper.pxi:7080\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
"File \u001b[0;32mpandas/_libs/hashtable_class_helper.pxi:7088\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
"\u001b[0;31mKeyError\u001b[0m: None",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[5], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# I am going to find out how many cells are CD45 and FOXP3 positive and ECAD negative likely indicating Tregs\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m adata \u001b[38;5;241m=\u001b[39m \u001b[43msm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhl\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mclassify\u001b[49m\u001b[43m(\u001b[49m\u001b[43madata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpos\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mCD45\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mFOXP3\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mneg\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mECAD\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcollapse_failed\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlabel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mT_cell_classification\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/scimap/helpers/classify.py:129\u001b[0m, in \u001b[0;36mclassify\u001b[0;34m(adata, pos, neg, classify_label, failed_label, phenotype, subclassify_phenotype, threshold, collapse_failed, label, showPhenotypeLabel, verbose)\u001b[0m\n\u001b[1;32m 126\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNo cells were found to satisfy your `classify` criteria\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 127\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 128\u001b[0m \u001b[38;5;66;03m# create new naming scheme for label and phenotype_label cols in classified\u001b[39;00m\n\u001b[0;32m--> 129\u001b[0m non_summary \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mDataFrame({phenotype: \u001b[43madata\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mobs\u001b[49m\u001b[43m[\u001b[49m\u001b[43mphenotype\u001b[49m\u001b[43m]\u001b[49m}) \u001b[38;5;66;03m# gets the index and phenotype\u001b[39;00m\n\u001b[1;32m 130\u001b[0m non_summary[phenotype] \u001b[38;5;241m=\u001b[39m non_summary[phenotype]\u001b[38;5;241m.\u001b[39mastype(\u001b[38;5;28mstr\u001b[39m)\n\u001b[1;32m 132\u001b[0m classify_idx\u001b[38;5;241m=\u001b[39mdata\u001b[38;5;241m.\u001b[39mindex\n",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/pandas/core/frame.py:3893\u001b[0m, in \u001b[0;36mDataFrame.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 3891\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcolumns\u001b[38;5;241m.\u001b[39mnlevels \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 3892\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_getitem_multilevel(key)\n\u001b[0;32m-> 3893\u001b[0m indexer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcolumns\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3894\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_integer(indexer):\n\u001b[1;32m 3895\u001b[0m indexer \u001b[38;5;241m=\u001b[39m [indexer]\n",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/pandas/core/indexes/base.py:3797\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 3792\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(casted_key, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[1;32m 3793\u001b[0m \u001b[38;5;28misinstance\u001b[39m(casted_key, abc\u001b[38;5;241m.\u001b[39mIterable)\n\u001b[1;32m 3794\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28many\u001b[39m(\u001b[38;5;28misinstance\u001b[39m(x, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m casted_key)\n\u001b[1;32m 3795\u001b[0m ):\n\u001b[1;32m 3796\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidIndexError(key)\n\u001b[0;32m-> 3797\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[1;32m 3798\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[1;32m 3799\u001b[0m \u001b[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[1;32m 3800\u001b[0m \u001b[38;5;66;03m# InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[1;32m 3801\u001b[0m \u001b[38;5;66;03m# the TypeError.\u001b[39;00m\n\u001b[1;32m 3802\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_check_indexing_error(key)\n",
"\u001b[0;31mKeyError\u001b[0m: None"
]
}
],
"outputs": [],
"source": [
"# I am going to find out how many cells are CD45 and FOXP3 positive and ECAD negative likely indicating Tregs\n",
"adata = sm.hl.classify(adata, pos=['CD45', 'FOXP3'], neg=['ECAD'], collapse_failed=False, label='T_cell_classification')"
Expand Down Expand Up @@ -149,21 +126,21 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"id": "ef105308-0ceb-41a4-871e-57ea687c47ca",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AnnData object with n_obs × n_vars = 11201 × 9\n",
" obs: 'X_centroid', 'Y_centroid', 'Area', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity', 'Solidity', 'Extent', 'Orientation', 'CellID', 'imageid', 'phenotype', 'ROI'\n",
" uns: 'all_markers', 'gates', 'spatial_distance'\n",
" obs: 'X_centroid', 'Y_centroid', 'Area', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity', 'Solidity', 'Extent', 'Orientation', 'CellID', 'imageid', 'leiden', 'leiden_phenotype', 'ROI', 'phenotype', 'spatial_pscore', 'index_info', 'neigh_kmeans', 'RCNs', 'spatial_lda_kmeans', 'spatial_expression_kmeans', 'spatial_aggregate_radius', 'tumor_similarity_ROI1'\n",
" uns: 'all_markers', 'foldchange_fc', 'foldchange_pval', 'gates', 'spatial_count', 'spatial_distance', 'spatial_expression', 'spatial_interaction_radius', 'spatial_interaction_radius_roi', 'spatial_lda', 'spatial_lda_probability', 'spatial_pscore', 'tumor_similarity'\n",
" obsm: 'umap'\n",
" layers: 'log'"
]
},
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -182,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"id": "9549352f-c6b9-4435-9a6a-62b6459debf4",
"metadata": {},
"outputs": [],
Expand All @@ -193,21 +170,21 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"id": "22ad71f7-7949-41d9-8749-6068347c7fd9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AnnData object with n_obs × n_vars = 11201 × 7\n",
" obs: 'X_centroid', 'Y_centroid', 'Area', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity', 'Solidity', 'Extent', 'Orientation', 'CellID', 'imageid', 'phenotype', 'ROI'\n",
" uns: 'all_markers', 'gates', 'spatial_distance'\n",
" obs: 'X_centroid', 'Y_centroid', 'Area', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity', 'Solidity', 'Extent', 'Orientation', 'CellID', 'imageid', 'leiden', 'leiden_phenotype', 'ROI', 'phenotype', 'spatial_pscore', 'index_info', 'neigh_kmeans', 'RCNs', 'spatial_lda_kmeans', 'spatial_expression_kmeans', 'spatial_aggregate_radius', 'tumor_similarity_ROI1'\n",
" uns: 'all_markers', 'foldchange_fc', 'foldchange_pval', 'gates', 'spatial_count', 'spatial_distance', 'spatial_expression', 'spatial_interaction_radius', 'spatial_interaction_radius_roi', 'spatial_lda', 'spatial_lda_probability', 'spatial_pscore', 'tumor_similarity'\n",
" obsm: 'umap'\n",
" layers: 'log'"
]
},
"execution_count": 8,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -226,32 +203,32 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"id": "0309a903-0241-40a5-b87b-2e56ed4cec5e",
"metadata": {},
"outputs": [],
"source": [
"# lets also drop some cells\n",
"adata = sm.hl.dropFeatures(adata, drop_groups='ROI1', groups_column='ROI')"
"adata = sm.hl.dropFeatures(adata, drop_groups='ROI3', groups_column='ROI')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"id": "cf954d9c-c8d4-45cb-95ee-68c7b8066439",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AnnData object with n_obs × n_vars = 10376 × 7\n",
" obs: 'X_centroid', 'Y_centroid', 'Area', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity', 'Solidity', 'Extent', 'Orientation', 'CellID', 'imageid', 'phenotype', 'ROI'\n",
" uns: 'all_markers', 'gates', 'spatial_distance'\n",
"AnnData object with n_obs × n_vars = 9629 × 7\n",
" obs: 'X_centroid', 'Y_centroid', 'Area', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity', 'Solidity', 'Extent', 'Orientation', 'CellID', 'imageid', 'leiden', 'leiden_phenotype', 'ROI', 'phenotype', 'spatial_pscore', 'index_info', 'neigh_kmeans', 'RCNs', 'spatial_lda_kmeans', 'spatial_expression_kmeans', 'spatial_aggregate_radius', 'tumor_similarity_ROI1'\n",
" uns: 'all_markers', 'foldchange_fc', 'foldchange_pval', 'gates', 'spatial_count', 'spatial_distance', 'spatial_expression', 'spatial_interaction_radius', 'spatial_interaction_radius_roi', 'spatial_lda', 'spatial_lda_probability', 'spatial_pscore', 'tumor_similarity'\n",
" obsm: 'umap'\n",
" layers: 'log'"
]
},
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -265,7 +242,7 @@
"id": "93c868ed-c8a8-47ff-a3dd-d60780db22c6",
"metadata": {},
"source": [
"As you can see now the dataset contains only 10376 cells now"
"As you can see now the dataset contains only 9629 cells now"
]
},
{
Expand All @@ -275,25 +252,6 @@
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "a3007780-8019-40e3-b438-b283c28a8659",
"metadata": {},
"source": [
"### Save Results"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c212f962-6bb8-4a10-abb8-85db7c212271",
"metadata": {},
"outputs": [],
"source": [
"# Save the results\n",
"adata.write('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad')"
]
}
],
"metadata": {
Expand Down
315 changes: 156 additions & 159 deletions docs/tutorials/nbs/Prior knowledge based phenotyping.ipynb

Large diffs are not rendered by default.

62 changes: 21 additions & 41 deletions docs/tutorials/nbs/Simple Spatial Analysis.ipynb

Large diffs are not rendered by default.

32 changes: 15 additions & 17 deletions docs/tutorials/nbs/Spatial LAG.ipynb

Large diffs are not rendered by default.

87 changes: 38 additions & 49 deletions docs/tutorials/nbs/Spatial LDA.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 7ee40da

Please sign in to comment.