Skip to content

Commit 38fdb68

Browse files
Add jupyter notebooks (#3)
* Added notebooks - updated docs - added notebooks * Remove workflows in favor of notebooks * Update segment-cells-nuclei.ipynb corrected typo * [docs] add summary for how to use ImJoy * [docs] improved overview * corrected typo in index.md * Added section for how to create single-channel images * Update data.md corrected typos * changed imjoy ws
1 parent 0bbccc1 commit 38fdb68

16 files changed

+370
-83
lines changed
File renamed without changes.

docs/data.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Data organization
44
We strongly recommend the following data-organization on which this workflow has been tested.
5-
1. Images are store as single-channel multi-z-stack tif files, e.g on tif per position and channel.
5+
6+
1. Images are store as single-channel multi-z-stack tif files, e.g on tif per position and channel. If your data are not single-channel, see the section on how to split channels with [Fiji](fiji-split-channels.md).
67
2. All raw 3D images are stored in a folder `acquisition`
78
3. All analysis results are stored in subfolder `analysis`, where each analysis step has a separate subfolder.
89

docs/diverse-workflows-overview.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
Here we provide a description of less frequently used workflows.
3+
4+
* [**Split multi-channel images**](fiji-split-channels.md) to obain single-channel images for analysis.
5+
* [**Convert segmentation results in FQ outlines**](create-fq-outlines.md) that can be used by the older Matlab version of FISH-quant.
6+
7+
Each workflow is documented in a dedicated section.

docs/fiji-split-channels.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Split channeles
2+
This workflow requires that each channel is stored as a separate z-stack.
3+
If your images are stored as multi-channel z-stacks you have to split these images into
4+
individual channels. This can be done with different software packages, below we describe some options.
5+
6+
## Manual conversion with Fiji
7+
For this you need to install [Fiji](https://fiji.sc/).
8+
9+
1. Create a new folder for each multi-channel image.
10+
2. Open image stack (`.dv`) in FIJI.
11+
3. Split channels (FQ only supports mono-channel input images)
12+
a. From menu: `Image` > `Color` > `Split channels`
13+
a. Save each channels with a unique channel identifier, e.g. `C1-` or `DAPI_`.
14+
15+
## Batch conversion with Fiji
16+
For this you need to
17+
* install [Fiji](https://fiji.sc/).
18+
* Use the provided macro `MacroBatchSplitChannel.ijm`, provided in the folder `workflows`.
19+
20+
### Workflow of macro
21+
1. Scan recursively a specified folder for files ending in a specified suffix.
22+
2. Images will be opened, split in different channels and maximum intensity projections (MIP) created
23+
3. Results will be saved in a new folder
24+
1. Macro will replace specified string in full file path by "acquisition", and created this folder to save the data.
25+
2. Will create additional subfolders 'MIP' to store the MIPs.
26+
27+
28+
### How to use the macro
29+
1. By default your data has to be in a folder `multi_channel_stacks`
30+
0. Open Fiji and drag the macro file in Fiji.
31+
0. This will open the macro, here you can modify two parameters
32+
* `suffix` (default `ome.tif`): last part of the file-name. Only files containing this string will be processed.
33+
* `folder_img` (default `multi_channel_stacks`): part of the file-name that will be replaced by `acquisition` in order to save the results.
34+
0. Press the `Run` button and you will be asked to specify the folder that should be processed.

docs/imjoy-overview.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
We provide several ImJoy plugins to
33

4-
* Pre-process 3D images
5-
* Perform segmentation
4+
* [**Pre-process 3D images**](imjoy-pre-processing.md) to obain 2D images ready for segmentation.
5+
* Perform [**segmentation**](imjoy-segmentation.md) of 2D images.
66

77
Each workflow is documented in a dedicated section.

docs/imjoy-pre-processing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Segmentation is done on 2D images. In this step, 3D images are transformed into
44
2D images by applying a projection.
55

66
Preprocessing is done with the ImJoy plugin `PreProcess`:
7-
<a href="https://imjoy.io/#/app?w=cellpose&plugin=fish-quant/segmentation:PreProcess@stable&upgrade=1" target="_blank">**install from here.**</a>
7+
<a href="https://imjoy.io/#/app?w=fq-seg&plugin=fish-quant/segmentation:PreProcess@stable&upgrade=1" target="_blank">**install from here.**</a>
88

99
1. Before running the plugin, you have to specify a few parameters. Note that you have to perform this
1010
projection for each channel-type. This allows to use different projection methods for a channel. This can be set in the plugin interface, avaible after clicking on the arrow down next to the plugin name.

docs/imjoy-segmentation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Segmentation of cells and nuclei
33

44
Preprocessing is done with the ImJoy plugin `SegmentCellsNuclei`:
5-
<a href="https://imjoy.io/#/app?w=cellpose&plugin=fish-quant/segmentation:SegmentCellsNuclei@stable&upgrade=1" target="_blank">**install from here.**</a>
5+
<a href="https://imjoy.io/#/app?w=fq-seg&plugin=fish-quant/segmentation:SegmentCellsNuclei@stable&upgrade=1" target="_blank">**install from here.**</a>
66

77

88
**Resizing to speed up prediction**: segmentation speed depends on the image size. In our experience, resizing the images

docs/index.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11

22
This repository provides wrapper code to use the generalist cell/nuclei segmentation package [**Cellpose**](https://github.com/mouseland/cellpose).
33

4+
In the other **overview sections** below we describe
5+
6+
* How to install the **tools** needed for this analysis.
7+
* How to organize the **data**.
8+
49
Example of **nuclear segmentation**:
510
![segmentation__nuclei](img/segmentation__nuclei.png)
611

7-
812
Example of **cytoplasmic segmentation**:
913
![segmentation__cells](img/segmentation__cells.png)
1014

1115

16+
You can then find a **detailed description of each workflow** in dedicated sections accessible from the menu above.
17+

docs/tools.md

+31-20
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
# Tools
2-
Here, we describe the different software packages that are used.
2+
Here, we describe the different software packages that are used, and how to install them.
33

4-
We provide for all analysis workflows dedicated **ImJoy plugins**, to faciliate their use.
5-
The ImJoy plugins are build on Python and require that you connect to a Jupyter Notebook.
6-
Once you followed the instructions below you can connect ImJoy to a Jupyter notebook with:
4+
* Most tasks are performed by **Python plugins running in ImJoy**, and described in the section [**ImJoy analysis**](imjoy-overview.md).
5+
* For less frequently tasks, we provide some explanations in [**Diverse workflows**](Diverse-workflows.md).
76

8-
1. **Activate the environment**: `conda activate cellpose`
9-
2. **Start Jupyter notebook**: `jupyter notebook --NotebookApp.allow_origin='*' --no-browser`
10-
3. Copy the provided URL including the token, in ImJoy connect to this Jupyter notebook.
7+
A detailed description of each analysis workflow is provided in the dedicated sections.
118

12-
We also provide Python source code illustrating the basic usage in the folder `workflows`.
13-
14-
A more detailed description of each workflow is provided in the dedicated sections.
9+
## Summary
10+
Here, you find a brief summary of the installation steps detailed in the sections below.
1511

12+
* The analysis workflows are provided as dedicated **ImJoy plugins**.
13+
* Once the plugin are installed in ImJoy, you can access them in a dedicated **workspace** `fq-seg`.
14+
* To use the plugins them you have to connect to the **Jupyter engine**
15+
1. **Activate the environment**:
16+
```
17+
conda activate cellpose
18+
```
19+
1. **Start Jupyter notebook**:
20+
```
21+
jupyter notebook --NotebookApp.allow_origin='*' --no-browser
22+
```
23+
3. Copy the provided URL including the token. In ImJoy connect to this Jupyter notebook.
1624
1725
## Installation
1826
In order to use the workflows in this repository, you need to follows these steps, which we detail below:
@@ -40,10 +48,11 @@ conda activate cellpose
4048
4149
## ImJoy
4250
[**ImJoy**](https://imjoy.io/docs/#/) is image processing platform with an easy
43-
to use interface. ImJoy can be used directly in your browser, withoyt any prior installation.
44-
While ImJoy is running in the browser, NO data will be transferred.
51+
to use interface. ImJoy can be used directly in your browser, without any prior installation.
52+
53+
While ImJoy is an app running in the browser, **NO** user data will be transferred over the internet.
4554
46-
Some important features
55+
Some important **features**:
4756
4857
2. Specific functionality is provided by plugins, which can be installed with simple links. Available
4958
plugins are listed in the plugin list on the left part of the interface. Depending on the implementation
@@ -67,9 +76,10 @@ dialog asking if you want to install the specified plugin. To confirm, press the
6776
Once installed, ImJoy remembers the workspaces and plugins and you simply have to
6877
open the ImJoy app and select the workspace (which will be `cellpose`): [https://imjoy.io/#/app](https://imjoy.io/#/app)
6978
70-
### Jupyter notebook for Python plugins
71-
Some of the provided plugins use code written in Python. In order for ImJoy this code, it can connect
72-
to a **Jupyter notebook**, which can be installed via Miniconda.
79+
### Running Python plugins
80+
Most of the provided plugins use Python for the processing. In order for ImJoy these plugins, you have
81+
to connect ImJoy to a **Jupyter notebook server**, which can be installed via Miniconda. Please note
82+
that this "server" can run on your local machine, so no data-transfer over the internet is taking place.
7383
7484
Once you have the computational environment set up (see Installation), you start an Jupyter Notebook,
7585
to which ImJoy can connect:
@@ -89,11 +99,12 @@ to which ImJoy can connect:
8999
next to the plugin name, and selecting the Juypyter Notebook as engine.
90100
91101
92-
## Workflows
93-
We also provide the Python code that is called in the ImJoy plugins, as simple
94-
Python files in the folder `workflow`.
102+
## Jupyter notebooks
103+
We also illustrate the workflow in the ImJoy Python plugins in dedicated Jupyter notebooks, which can
104+
be found in the folder `notebooks`.
95105
96-
To run this code, install this repository in a dedicated conda environment, e.g. with
106+
To run this code, we recommend following the instructions above to create a dedicated conda environment,
107+
and install the code of this plugin in this env, e.g. with
97108
```
98109
pip install git+https://github.com/muellerflorian/segmentation/ --upgrade
99110
```

mkdocs.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ nav:
5959
- Tools: tools.md # This is strange but only with this organization this file shows upd in the overview together with the index.md
6060
- Data: data.md # This is strange but only with this organization this file shows upd in the overview together with the index.md
6161

62-
- Analysis with ImJoy:
62+
- ImJoy Analysis:
6363
- Overview: imjoy-overview.md
6464
- Preprocessing: imjoy-pre-processing.md
6565
- Segmentation: imjoy-segmentation.md
6666

67-
- Post-processing:
68-
- Create FQ outline files: post-processing-fq.md
67+
- Diverse workflows:
68+
- Overview: diverse-workflows-overview.md
69+
- Split channels: fiji-split-channels.md
70+
- Create FQ outline files: create-fq-outlines.md
6971

7072
- Advanced:
7173
- Developer notes: developer-notes.md

notebooks/pre-processing.ipynb

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Notebook to perform preprocessing of images for segmentation\n",
8+
"* Takes 3D images and performs a 2D projection to obtain 2D png that can be used in the segmentation algorithm.\n",
9+
"* Requires that `cellpose` and the code of this respository are installed. One way to do this is with a pip install (recommended in a dedicated conda environment as explained in the documentation).\n",
10+
" ```\n",
11+
" pip install git+https://github.com/muellerflorian/segmentation/ --upgrade\n",
12+
" ```"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": null,
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"# >>> Imports \n",
22+
"from pathlib import Path\n",
23+
"from segwrap import utils_segmentation # Either on sys path or pip installed"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": null,
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"# >>> Function call\n",
33+
"\n",
34+
"# Parameters\n",
35+
"path_process = Path(r'paste-path-to-data') # For example data: \\example_data\\acquisition\n",
36+
"path_save = Path(r'paste-path-to-save-results') # For example data: example_data\\analysis\\segmentation-input\n",
37+
"channel_ident = 'dapi' # Identifier of channel that should be pre-processed \n",
38+
"projection_type = 'max' # Projection type (mean, max, indiv)\n",
39+
"\n",
40+
"# Call pre-processing function\n",
41+
"utils_segmentation.folder_prepare_prediction(\n",
42+
" path_process=path_process,\n",
43+
" search_type=None,\n",
44+
" channel_ident=channel_ident,\n",
45+
" projection_type=projection_type,\n",
46+
" path_save=path_save,\n",
47+
" callback_log=None)"
48+
]
49+
}
50+
],
51+
"metadata": {
52+
"kernelspec": {
53+
"display_name": "Python 3.7.6 64-bit ('cellpose': conda)",
54+
"language": "python",
55+
"name": "python37664bitcellposecondafe33b8fac7d34fcb85d1f0e07041e8c2"
56+
},
57+
"language_info": {
58+
"codemirror_mode": {
59+
"name": "ipython",
60+
"version": 3
61+
},
62+
"file_extension": ".py",
63+
"mimetype": "text/x-python",
64+
"name": "python",
65+
"nbconvert_exporter": "python",
66+
"pygments_lexer": "ipython3",
67+
"version": "3.7.6"
68+
}
69+
},
70+
"nbformat": 4,
71+
"nbformat_minor": 4
72+
}

notebooks/segment-cells-nuclei.ipynb

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Notebook to perform segmentation of cells and nuclei with cellpose.\n",
8+
"* Requires that `cellpose` and the code of this respository are installed. One way to do this is with a pip install (recommended in a dedicated conda environment as explained in the documentation).\n",
9+
" ```\n",
10+
" pip install git+https://github.com/muellerflorian/segmentation/ --upgrade\n",
11+
" ```"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"# Imports \n",
21+
"from pathlib import Path\n",
22+
"import utils_cellpose # Either on sys path or pip installed"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": null,
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"# >> Function call\n",
32+
"\n",
33+
"# Parameters\n",
34+
"path_scan = Path(r'paste-path-to-data') # For example data: example_data\\analysis\\segmentation-input\n",
35+
"path_save = Path(r'paste-path-to-save-results') # For example data: example_data\\analysis\\segmentation-results\n",
36+
"str_cyto = 'cy3' # Identifier of channel for cytoplasmic segmentation\n",
37+
"str_nuclei = 'dapi' # Identifier of channel for nuclear segmentation\n",
38+
"img_ext = '.png' # Extension of images to be segmented\n",
39+
"new_size = (512, 512) # Size of images (when resize should be applied, empty tuple otherwise)\n",
40+
"\n",
41+
"size_cells = 100 # Typical size (diameter) of cells\n",
42+
"size_nuclei = 50 # Typical size (diameter) of nuclei\n",
43+
"\n",
44+
"# Call segmentation function\n",
45+
"utils_cellpose.segment_cells_nuclei_indiv(path_scan=path_scan, \n",
46+
" strings=(str_cyto, str_nuclei), \n",
47+
" img_ext=img_ext, \n",
48+
" new_size=new_size,\n",
49+
" sizes=(size_cells, size_nuclei), \n",
50+
" models=('cyto','nuclei'),\n",
51+
" path_save=path_save)"
52+
]
53+
}
54+
],
55+
"metadata": {
56+
"kernelspec": {
57+
"display_name": "Python 3.7.6 64-bit ('cellpose': conda)",
58+
"language": "python",
59+
"name": "python37664bitcellposecondafe33b8fac7d34fcb85d1f0e07041e8c2"
60+
},
61+
"language_info": {
62+
"codemirror_mode": {
63+
"name": "ipython",
64+
"version": 3
65+
},
66+
"file_extension": ".py",
67+
"mimetype": "text/x-python",
68+
"name": "python",
69+
"nbconvert_exporter": "python",
70+
"pygments_lexer": "ipython3",
71+
"version": "3.7.6"
72+
}
73+
},
74+
"nbformat": 4,
75+
"nbformat_minor": 4
76+
}

readme.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ Example of **cytoplasmic segmentation**:
2020

2121
# Licensing
2222

23-
24-
- **Cellpose** is (general) are BSD-licenced (3 clause)
23+
- **Cellpose** is BSD-licenced (3 clause)
2524

2625
> Copyright © 2020 Howard Hughes Medical Institute
2726
>

0 commit comments

Comments
 (0)