Skip to content

Commit

Permalink
added pyqt for napari
Browse files Browse the repository at this point in the history
  • Loading branch information
ajitjohnson committed Mar 20, 2024
1 parent d031b79 commit c33c8db
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 94 deletions.
98 changes: 47 additions & 51 deletions docs/tutorials/nbs/Adding ROIs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "0306ed12-7279-4054-b23d-492a83888018",
"metadata": {},
"source": [
"# Add Region of Interest (ROIs) for Comparitive Analysis"
"# 🙌 Add Region of Interest (ROIs) for Comparitive Analysis"
]
},
{
Expand All @@ -29,17 +29,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Running SCIMAP 1.3.8\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning:\n",
"\n",
"IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
"\n"
"Running SCIMAP 1.3.12\n"
]
}
],
Expand All @@ -51,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 2,
"id": "3097da7e-73ae-4435-a7b8-b6f3379043d8",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -82,18 +72,37 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"id": "3348de48-94ac-478f-a4bc-5f00049cfe2e",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ERROR:root:\n",
" Could not load requested Qt binding. Please ensure that\n",
" PyQt4 >= 4.7, PyQt5, PyQt6, PySide >= 1.0.3, PySide2, or\n",
" PySide6 is available, and only one is imported per session.\n",
"\n",
" Currently-imported Qt library: None\n",
" PyQt5 available (requires QtCore, QtGui, QtSvg, QtWidgets): False\n",
" PyQt6 available (requires QtCore, QtGui, QtSvg, QtWidgets): False\n",
" PySide2 installed: False\n",
" PySide6 installed: False\n",
" Tried to load: ['pyqtdefault', 'pyqt6', 'pyside6', 'pyqt5', 'pyside2']\n",
" \n"
]
}
],
"source": [
"%gui qt\n",
"image_path = '/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/registration/exemplar-001.ome.tif'"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 5,
"id": "82ed75f2-fb12-45d0-91ba-f4a6cd8c3eff",
"metadata": {},
"outputs": [
Expand All @@ -108,44 +117,31 @@
" Multiple shape layers are supported\n",
" ROI's should not overlap\n",
" Close Napari to save ROI's.\n",
" \n",
"Identifying cells within selected ROI's\n"
" \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/scimap/plotting/addROI_image.py:378: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" inside['ROI_internal'] = all_rois[all_rois['id'] == roi_id]['ROI'][roi_id]\n",
"/Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/scimap/plotting/addROI_image.py:378: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" inside['ROI_internal'] = all_rois[all_rois['id'] == roi_id]['ROI'][roi_id]\n",
"/Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/scimap/plotting/addROI_image.py:378: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" inside['ROI_internal'] = all_rois[all_rois['id'] == roi_id]['ROI'][roi_id]\n",
"/Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/scimap/plotting/addROI_image.py:378: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" inside['ROI_internal'] = all_rois[all_rois['id'] == roi_id]['ROI'][roi_id]\n",
"/Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/scimap/plotting/addROI_image.py:378: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" inside['ROI_internal'] = all_rois[all_rois['id'] == roi_id]['ROI'][roi_id]\n"
"ename": "ImportError",
"evalue": "An error occured when importing Qt dependencies. Cannot show napari window. See cause above",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mQtBindingsNotFoundError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/napari/_qt/__init__.py:8\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m----> 8\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mqtpy\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m API_NAME, QtCore\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/qtpy/__init__.py:287\u001b[0m\n\u001b[1;32m 286\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m:\n\u001b[0;32m--> 287\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m QtBindingsNotFoundError \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 288\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
"\u001b[0;31mQtBindingsNotFoundError\u001b[0m: No Qt bindings could be found",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/napari/window.py:14\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m---> 14\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mnapari\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_qt\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Window\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/napari/_qt/__init__.py:18\u001b[0m\n\u001b[1;32m 14\u001b[0m installed_with_conda \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(\n\u001b[1;32m 15\u001b[0m Path(sys\u001b[38;5;241m.\u001b[39mprefix, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mconda-meta\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39mglob(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnapari-*.json\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 16\u001b[0m )\n\u001b[0;32m---> 18\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m(\n\u001b[1;32m 19\u001b[0m trans\u001b[38;5;241m.\u001b[39m_(\n\u001b[1;32m 20\u001b[0m cleandoc(\n\u001b[1;32m 21\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 22\u001b[0m \u001b[38;5;124;03m No Qt bindings could be found.\u001b[39;00m\n\u001b[1;32m 23\u001b[0m \n\u001b[1;32m 24\u001b[0m \u001b[38;5;124;03m napari requires either PyQt5 (default) or PySide2 to be installed in the environment.\u001b[39;00m\n\u001b[1;32m 25\u001b[0m \n\u001b[1;32m 26\u001b[0m \u001b[38;5;124;03m With pip, you can install either with:\u001b[39;00m\n\u001b[1;32m 27\u001b[0m \u001b[38;5;124;03m $ pip install -U 'napari[all]' # default choice\u001b[39;00m\n\u001b[1;32m 28\u001b[0m \u001b[38;5;124;03m $ pip install -U 'napari[pyqt5]'\u001b[39;00m\n\u001b[1;32m 29\u001b[0m \u001b[38;5;124;03m $ pip install -U 'napari[pyside2]'\u001b[39;00m\n\u001b[1;32m 30\u001b[0m \n\u001b[1;32m 31\u001b[0m \u001b[38;5;124;03m With conda, you need to do:\u001b[39;00m\n\u001b[1;32m 32\u001b[0m \u001b[38;5;124;03m $ conda install -c conda-forge pyqt\u001b[39;00m\n\u001b[1;32m 33\u001b[0m \u001b[38;5;124;03m $ conda install -c conda-forge pyside2\u001b[39;00m\n\u001b[1;32m 34\u001b[0m \n\u001b[1;32m 35\u001b[0m \u001b[38;5;124;03m Our heuristics suggest you are using '{tool}' to manage your packages.\u001b[39;00m\n\u001b[1;32m 36\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m 37\u001b[0m ),\n\u001b[1;32m 38\u001b[0m deferred\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[1;32m 39\u001b[0m tool\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mconda\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m installed_with_conda \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpip\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 40\u001b[0m )\n\u001b[1;32m 41\u001b[0m ) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[1;32m 42\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m\n",
"\u001b[0;31mImportError\u001b[0m: No Qt bindings could be found.\n\nnapari requires either PyQt5 (default) or PySide2 to be installed in the environment.\n\nWith pip, you can install either with:\n $ pip install -U 'napari[all]' # default choice\n $ pip install -U 'napari[pyqt5]'\n $ pip install -U 'napari[pyside2]'\n\nWith conda, you need to do:\n $ conda install -c conda-forge pyqt\n $ conda install -c conda-forge pyside2\n\nOur heuristics suggest you are using 'pip' to manage your packages.",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[5], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m adata \u001b[38;5;241m=\u001b[39m \u001b[43msm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpl\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43maddROI_image\u001b[49m\u001b[43m(\u001b[49m\u001b[43mimage_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43madata\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/scimap/plotting/addROI_image.py:332\u001b[0m, in \u001b[0;36maddROI_image\u001b[0;34m(image_path, adata, subset, imageid, overlay, flip_y, overlay_category, markers, channel_names, x_coordinate, y_coordinate, point_size, point_color, seg_mask, n_jobs, verbose, overwrite, label, **kwargs)\u001b[0m\n\u001b[1;32m 323\u001b[0m a \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\"\"\u001b[39m\n\u001b[1;32m 324\u001b[0m \u001b[38;5;124m Opening Napari;\u001b[39m\n\u001b[1;32m 325\u001b[0m \u001b[38;5;124m Add shape layers (on left) to draw ROI\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124ms. \u001b[39m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 329\u001b[0m \u001b[38;5;124m Close Napari to save ROI\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124ms.\u001b[39m\n\u001b[1;32m 330\u001b[0m \u001b[38;5;124m \u001b[39m\u001b[38;5;124m\"\"\"\u001b[39m\n\u001b[1;32m 331\u001b[0m \u001b[38;5;28mprint\u001b[39m(a)\n\u001b[0;32m--> 332\u001b[0m \u001b[43mviewer\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mshow\u001b[49m\u001b[43m(\u001b[49m\u001b[43mblock\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m \n\u001b[1;32m 335\u001b[0m \u001b[38;5;66;03m# Find all the shape layers\u001b[39;00m\n\u001b[1;32m 336\u001b[0m my_shapes \u001b[38;5;241m=\u001b[39m [layer \u001b[38;5;28;01mfor\u001b[39;00m layer \u001b[38;5;129;01min\u001b[39;00m viewer\u001b[38;5;241m.\u001b[39mlayers \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(layer, Shapes)]\n",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/napari/viewer.py:139\u001b[0m, in \u001b[0;36mViewer.show\u001b[0;34m(self, block)\u001b[0m\n\u001b[1;32m 137\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mshow\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39m, block\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m):\n\u001b[1;32m 138\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Resize, show, and raise the viewer window.\"\"\"\u001b[39;00m\n\u001b[0;32m--> 139\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwindow\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mshow\u001b[49m(block\u001b[38;5;241m=\u001b[39mblock)\n",
"File \u001b[0;32m~/miniconda3/envs/scimap/lib/python3.10/site-packages/napari/window.py:27\u001b[0m, in \u001b[0;36mWindow.__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__getattr__\u001b[39m(\u001b[38;5;28mself\u001b[39m, name):\n\u001b[0;32m---> 27\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;28mtype\u001b[39m(err)(\n\u001b[1;32m 28\u001b[0m trans\u001b[38;5;241m.\u001b[39m_(\n\u001b[1;32m 29\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAn error occured when importing Qt dependencies. Cannot show napari window. See cause above\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 30\u001b[0m )\n\u001b[1;32m 31\u001b[0m ) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n",
"\u001b[0;31mImportError\u001b[0m: An error occured when importing Qt dependencies. Cannot show napari window. See cause above"
]
}
],
Expand Down
34 changes: 20 additions & 14 deletions docs/tutorials/nbs/Prepare Data for SCIMAP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "2d4d6a28-e944-42fe-b6f9-2be7c2ff034f",
"metadata": {},
"source": [
"# Getting started with SCIMAP"
"# 🥷 Getting started with SCIMAP"
]
},
{
Expand All @@ -18,17 +18,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Running SCIMAP 1.3.8\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning:\n",
"\n",
"IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
"\n"
"Running SCIMAP 1.3.12\n"
]
}
],
Expand Down Expand Up @@ -516,7 +506,15 @@
"id": "a008ce44-222c-419b-be83-d0bcad8e3afd",
"metadata": {},
"source": [
"## What if your data was not generated using the MCMICRO pipeline?"
"## 🧐 What if your data was not generated using the MCMICRO pipeline?"
]
},
{
"cell_type": "markdown",
"id": "c69ca8e3-b3aa-4b1f-98bf-b5aa75a5be4c",
"metadata": {},
"source": [
"If you're working with data not produced by mcmicro, it's crucial to consult the documentation for each function used in this series of tutorials. Each function operates under specific assumptions about its parameters. For instance, all spatial functions assume that XY coordinates are located in the 'X_centroid' and 'Y_centroid' columns. If your dataset organizes this information differently, you'll need to specify your column names when running the function."
]
},
{
Expand Down Expand Up @@ -617,7 +615,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"id": "cc19d2dc-66a3-4a71-817e-71650206e5be",
"metadata": {},
"outputs": [],
Expand All @@ -633,6 +631,14 @@
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f3a3d63d-548b-4d29-8969-ddb034ac60f3",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
54 changes: 27 additions & 27 deletions docs/tutorials/nbs/Unsupervised clustering to phenotype cells.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit c33c8db

Please sign in to comment.