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

Develop #218

Open
wants to merge 134 commits into
base: develop_2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
938398a
Unifying how panel column datatypes are ahndeled.
Feb 24, 2023
7a53648
Unifying how panel column datatypes are handeled.
Feb 24, 2023
8885304
Merge branch 'milad_develop' of https://github.com/BodenmillerGroup/s…
Feb 24, 2023
bb46eb3
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Apr 10, 2023
bc527b8
Merge pull request #173 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Apr 11, 2023
df532c7
added cellpose2.0 models
Apr 24, 2023
3c6cf13
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 24, 2023
886b367
Fixed reduntant conditional statements and dynamic function calls in …
May 2, 2023
a51ba29
Merge branch 'milad_develop' of https://github.com/BodenmillerGroup/s…
May 2, 2023
5110842
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 2, 2023
85a7f13
changed the onciditional statements based on Jonas' suggestions
May 2, 2023
ea1e5e4
Merge branch 'milad_develop' of https://github.com/BodenmillerGroup/s…
May 2, 2023
5cc8224
Update cellpose.py
Milad4849 May 2, 2023
8078ec4
Added cellpose to third party apps
Jun 9, 2023
db38859
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 9, 2023
179f97f
Added cellpose app and trainable model
Jul 12, 2023
96de30c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 12, 2023
6f319ec
updates to cellpose and training and documentation
Aug 9, 2023
211f7f9
Merge branch 'milad_develop' of https://github.com/BodenmillerGroup/s…
Aug 9, 2023
f5acee9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
f94457c
Updated documentation on flavors and expand functionality
Aug 9, 2023
ddedab1
Merge branch 'milad_develop' of https://github.com/BodenmillerGroup/s…
Aug 9, 2023
cf24b71
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
cac68a8
ädded steinbock to theavailale apps
Aug 16, 2023
275032c
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 21, 2023
cd0b42f
Merge pull request #213 from BodenmillerGroup/main
Milad4849 Aug 22, 2023
db53400
Merge branch 'develop' of https://github.com/BodenmillerGroup/steinbo…
Aug 23, 2023
8fc8a82
updatedthe CHANGE.LOG
Aug 23, 2023
cc9e0f3
Merge pull request #214 from BodenmillerGroup/cellpose_app
Milad4849 Aug 23, 2023
fd393ec
Merge branch 'milad_develop' into develop
Milad4849 Aug 23, 2023
5787d9a
Merge pull request #179 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Aug 23, 2023
37db81e
Update Dockerfile
Milad4849 Aug 24, 2023
dd45ac7
Update segmentation.md
Milad4849 Aug 24, 2023
acd5ff8
Update apps.py
Milad4849 Aug 24, 2023
4188719
Update segmentation.md
Milad4849 Aug 24, 2023
6da23e7
Update segmentation.md
Milad4849 Aug 24, 2023
9773717
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 24, 2023
ddeb92a
Update docs/cli/utils.md
Milad4849 Aug 24, 2023
bfefc72
Update docs/cli/utils.md
Milad4849 Aug 25, 2023
16b54c3
changes 29.08.2023
Aug 29, 2023
afb33ec
changes 30.8.23
Aug 30, 2023
3143f06
changes 30.8.23/2
Aug 30, 2023
791cf27
changes 31.08.2023
Aug 31, 2023
c649834
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 31, 2023
eeeb40a
Updated citation
nilseling Oct 19, 2023
08081e7
Added note that we can share the PDF
nilseling Oct 19, 2023
f29924c
Added citation to README
nilseling Oct 19, 2023
23fdf83
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Nov 13, 2023
4b7ee5f
Merge pull request #226 from BodenmillerGroup/citation
Milad4849 Nov 21, 2023
2bb109e
Merge pull request #221 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Nov 21, 2023
d29803d
added txt generation for xti
Milad4849 Nov 29, 2023
cabfcc7
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Dec 11, 2023
697cd98
Merge pull request #227 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Dec 11, 2023
67eaa34
fixed cellpose_cmd_group function names
Milad4849 Dec 12, 2023
736ed0b
fixed cellpose mcd function names
Milad4849 Dec 12, 2023
b2acf9c
adjusted default cellpose parameters
Milad4849 Dec 12, 2023
cbc3937
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2023
cb0cbd2
Fixed no neighborhood data in h5ad #210
Milad4849 Dec 13, 2023
436d671
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 13, 2023
bb24837
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Dec 18, 2023
5263843
Merge pull request #232 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Dec 18, 2023
1c09ce6
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Dec 25, 2023
0d6a406
Merge pull request #233 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Jan 5, 2024
a4f99b5
Resolve comments and address change requests
Milad4849 Jan 5, 2024
00ca127
Merge branch 'develop' of https://github.com/BodenmillerGroup/steinbo…
Milad4849 Jan 5, 2024
8ee813f
Resolve comments and address change requests 0.1
Milad4849 Jan 5, 2024
c6590aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 5, 2024
5aee184
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jan 8, 2024
464ca32
merged xti_txt_generation
Milad4849 Jan 14, 2024
34da6ef
corrected the logger
Milad4849 Jan 16, 2024
e81c996
fixed logger import and added pydantic<2 to requirements
Milad4849 Jan 18, 2024
67bdbd9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 18, 2024
3fc4fe1
updated CHANGELOG
Milad4849 Jan 18, 2024
6869c7f
modified hindling of torch import
Milad4849 Jan 18, 2024
66b5c11
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 18, 2024
cb7f94e
Merge pull request #234 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Jan 19, 2024
7a21bb0
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jan 29, 2024
17b47a8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 29, 2024
5cf0a10
Update steinbock/segmentation/_cli/cellpose.py
Milad4849 Feb 7, 2024
e5910e7
Update steinbock/preprocessing/_cli/imc.py
Milad4849 Feb 7, 2024
9254ae2
Update steinbock/segmentation/_cli/cellpose.py
Milad4849 Feb 7, 2024
aa78c3c
Update steinbock/segmentation/_cli/cellpose.py
Milad4849 Feb 7, 2024
5550339
Merge pull request #240 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Feb 13, 2024
b440b80
Update steinbock/segmentation/_cli/cellpose.py
Milad4849 Feb 15, 2024
76aad64
correction/changes based on comments
Milad4849 Feb 27, 2024
fffefdf
merge with head
Milad4849 Feb 27, 2024
bd156ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 27, 2024
c92be38
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Mar 18, 2024
3a184fd
Merge pull request #243 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Mar 26, 2024
b8947fd
corrected small mistake in segmentation docs
Milad4849 Mar 28, 2024
27c99d2
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Apr 15, 2024
4cb3da1
Merge pull request #250 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Apr 25, 2024
a5fba4c
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Apr 29, 2024
a035b7b
use readimc 0.7.0 w/ lenient parsing
matt-sd-watson May 14, 2024
b558aec
Add strict as click
matt-sd-watson May 14, 2024
22ad48f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 14, 2024
8cf35de
update dependencies
matt-sd-watson May 14, 2024
983bb19
Merge branch 'dev' of https://github.com/matt-sd-watson/steinbock int…
matt-sd-watson May 14, 2024
94e315a
Update steinbock/preprocessing/_cli/imc.py
Milad4849 May 19, 2024
ae5ecde
Update steinbock/preprocessing/imc.py
Milad4849 May 19, 2024
c7d9b0c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 19, 2024
a6bf141
Update steinbock/segmentation/_cli/cellpose.py
Milad4849 May 19, 2024
aac7b07
Update steinbock/preprocessing/imc.py
Milad4849 May 19, 2024
72d00d3
Update steinbock/preprocessing/imc.py
Milad4849 May 19, 2024
dec0151
Update steinbock/preprocessing/imc.py
Milad4849 May 19, 2024
fb373b4
Update steinbock/preprocessing/imc.py
Milad4849 May 19, 2024
4683975
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 19, 2024
9306345
Update steinbock/segmentation/cellpose.py
Milad4849 May 19, 2024
e843deb
corrected txt column naming
Milad4849 May 19, 2024
3ef61bd
Merge branch 'develop' of https://github.com/BodenmillerGroup/steinbo…
Milad4849 May 19, 2024
46602d6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 19, 2024
bf25fbe
fixed documentation and minor issues
Milad4849 May 28, 2024
93012e9
Merge branch 'develop' of https://github.com/BodenmillerGroup/steinbo…
Milad4849 May 28, 2024
0d05847
dependencies for lxml
matt-sd-watson May 28, 2024
c21376a
Merge pull request #262 from matt-sd-watson/dev
Milad4849 May 28, 2024
6e66670
Update docs.yml
Milad4849 May 28, 2024
f82bc18
Update docs.yml
Milad4849 May 29, 2024
d4b6a24
Merge pull request #257 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 May 29, 2024
588307f
updated changelog for minor version release
Milad4849 May 29, 2024
dc4a0c9
updated changelog for minor version release
Milad4849 May 29, 2024
88b16b0
Merge remote-tracking branch 'origin/main' into develop
Milad4849 May 29, 2024
14fc238
Merge branch 'develop' of https://github.com/BodenmillerGroup/steinbo…
Milad4849 May 29, 2024
07ec73e
Update build.yml
Milad4849 Jun 20, 2024
91dd95f
Merge pull request #264 from BodenmillerGroup/Milad4849-patch-1
Milad4849 Jun 20, 2024
d232516
Update build.yml to use a large runner
Milad4849 Jun 21, 2024
41edff4
Update build.yml to use self-hosted runner
Milad4849 Jun 21, 2024
49545cf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 21, 2024
7b73f29
Merge pull request #265 from BodenmillerGroup/Milad4849-patch-2
Milad4849 Jun 21, 2024
adf303b
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 5, 2024
42a69ce
Merge pull request #263 from BodenmillerGroup/pre-commit-ci-update-co…
Milad4849 Aug 12, 2024
676664f
minor update docs
Milad4849 Aug 12, 2024
c471ce9
merge with 0.16.3
Milad4849 Aug 12, 2024
e459155
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 12, 2024
2ef58e9
minot update requirments
Milad4849 Aug 12, 2024
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
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: ^\.vscode/.*
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -16,25 +16,25 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
rev: "5.13.2"
hooks:
- id: isort
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.1
rev: v2.2.1
hooks:
- id: autoflake
args: [--in-place, --remove-all-unused-imports]
- repo: https://github.com/psf/black
rev: '23.1.0'
rev: '23.12.1'
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: "6.0.0"
rev: "7.0.0"
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.0
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies: [types-requests, types-PyYAML]
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.17.0]
jwindhager marked this conversation as resolved.
Show resolved Hide resolved

### Added
- Cellpose2.0 segmentation and training
- Cellpose2.0 as an app
jwindhager marked this conversation as resolved.
Show resolved Hide resolved
- Added the parameter `--xti` to ` steinbockpreprocess imc images` which provides the option to generate individual txt files for ROIs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Added the parameter `--xti` to ` steinbockpreprocess imc images` which provides the option to generate individual txt files for ROIs.
- Added the parameter `--xti` to ` steinbock preprocess imc images` which provides the option to generate individual txt files for ROIs.

Also, preprocessing images "generates individual txt files"? This doesn't sound very intuitive to me, without knowing anything about the functionality or the new file format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no new format, just lack of txt backups, does steinbock export txtmake more sense?


### Changed
- Cellpose default parameters
- Segmentation, Utils and docker container Documentation
- List of contributors


### Fixed
- No neighborhood Data in h5ad-files [#210](https://github.com/BodenmillerGroup/steinbock/issues/210)
- Unifying how panel column datatypes are handled [#174](https://github.com/BodenmillerGroup/steinbock/discussions/174)
- Tissuenet model support and documentation [#208](https://github.com/BodenmillerGroup/steinbock/issues/208)
- Maximum amount of segmented cells bounded from segmentation output file format (16-bit unsigned integer TIFF images) [#207](https://github.com/BodenmillerGroup/steinbock/issues/207)


## [0.16.2] - 2023-08-15

### Changed
Expand Down
11 changes: 8 additions & 3 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

[[email protected]](mailto:[email protected])

- Logo
- Documentation
- Testing, feedback & discussion
- Logo
- Documentation
- Testing, feedback & discussion


## Milad Adibi

[[email protected]](mailto:[email protected])
30 changes: 27 additions & 3 deletions docs/cli/segmentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Various segmentation approaches are supported, each of which is described in the
!!! note "Pixel classification-based image segmentation vs end-to-end approaches"
While [pixel classification](classification.md)-based image segmentation using CellProfiler uses probability images to segment objects, end-to-end workflows such as DeepCell/Mesmer and Cellpose directly operate on images without the need for a preceding pixel classification step.


!!! note "Large masks containing more than 65535 objects"
Please refer to the [installation page](../install-docker.md##Using-the-docker-container-with-large-images-containing-more-than-65535-objects) when analizing large masks with more than 65535 objects.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that link works? I may be wrong, but the double ## looks suspicious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected




## CellProfiler

[CellProfiler](https://cellprofiler.org) is an open-source software for measuring and analyzing cell images. Here, CellProfiler is used for object detection and region growth-based object segmentation.
Expand Down Expand Up @@ -87,7 +93,7 @@ This will create grayscale cell/nuclear masks of the same x and y dimensions as
Specify `--minmax` to enable min-max normalization and `--zscore` to enable z-score normalization.

!!! note "Preprocessing/postprocessing parameters"
Application-dependent preprocessing/postprocessing parameters can be specified in YAML files using the `--preprocess`/`--postprocess` options. For the Mesmer application, this can e.g. be used to control thresholding, histogram normalization and watershed segmentation. Please refer to the DeepCell online documentation for available parameters. For example, one could specify `--preprocess preprocessing.yml`, where `preprocessing.yml` is a file in the steinbock data/working directory containing:
Application-dependent preprocessing/postprocessing parameters can be specified in YAML files using the `--preprocess`/`--postprocess` options. For the Mesmer application, this can e.g. be used to control thresholding, histogram normalization and watershed segmentation. Please refer to the DeepCell online documentation for available parameters. For example, one could specify `--preprocess preprocessing.yml`, where `preprocessing.yml` is a file in the *steinbock* data/working directory containing:

threshold: true
percentile: 99.9
Expand All @@ -99,28 +105,46 @@ This will create grayscale cell/nuclear masks of the same x and y dimensions as
!!! danger "Experimental feature"
This is an experimental feature and is only available in the `-cellpose` flavors of the *steinbock* Docker container.

Segmentation using cellpose likely requires fine-tuning of parameters, e.g. using steinbock command-line interface options.
Segmentation using cellpose likely requires fine-tuning of parameters, e.g. using steinbock command-line interface options. The steinbock default parameters for the cellpose models (cell probability threshhold, flow threshhold etc) are not the same as the default values of *cellpose* itself. The steinbock default values are the result of manual optimization of cellpose parameters for segmentation of IMC images in the Bodenmiller lab.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Where can I find these parameter values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steinbock segment cellpose run --help would display the cellpose defaults, are you suggesting that an explicit list should be kept somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps mention explicitly how to list the default parameter values here?


[Cellpose](https://www.cellpose.org) is a generalist algorithm for cellular segmentation.

!!! note "End-to-end cell segmentation"
This approach operates directly on image intensities and does not require a preceding pixel classification step.

To segment cells using the default `cyto2` model:
To segment cells using the default `tissuenet` model:

steinbock segment cellpose --minmax

To segment nuclei using the `nuclei` model:

steinbock segment cellpose --minmax --model nuclei

Models introduced in [cellpose 2.0](https://www.nature.com/articles/s41592-022-01663-4) can also be chosen, bringing the total number of available models to 14, these are 'nuclei',
'cyto', 'cyto2', 'tissuenet', 'livecell', 'CP', 'CPx', 'TN1', 'TN2', 'TN3', 'LC1', 'LC2', 'LC3' and 'LC4'. The user can utilize any of these mdoels by specifying them using the `--model` argument as demonstrated above. The default is set to `tissuenet` model. The user can choose from these by specifying them via the `--model` argument, note that `tissuenet` is also the default model for training a cellpose model (See training a cellpose model below). Furthermore user-trained models (see `Training a cellpose model` below) can be used via the `pretrained-model` argument. When both the `--model` and `pretrained_mdodel` parameters are provided, the model specified by `--model`is used. Therefoore when the user provides the `pretrained-model` argument, *steinbock* automatically sets `--model` argument to `None`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit repetitive:

The user can utilize any of these mdoels by specifying them using the --model argument

The user can choose from these by specifying them via the --model argument

Also, the "see XYZ" should probably be links.

Further, I find this a bit contradictory:

When both the --model and pretrained_mdodel parameters are provided, the model specified by --modelis used. Therefoore when the user provides the pretrained-model argument, steinbock automatically sets --model argument to None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed the repetition and removed the second block. This can be considered as redundant. However this describes what cellpose does in case you specify models both via -pretrained-model and -model-type, in that case the -model-type takes precedence. This is my understanding, but I think I leave commentary on this to cellpose itself.


!!! note "Cellpose image data"
Cellpose expects two-channel images as input, where the first channel must be a nuclear channel (e.g. DAPI) and the second channel must be a cytoplasmic channel (e.g. E-Cadherin). The nuclear channel is optional and only the cytoplasmic channel ("channel to segment") is required. Note that - compared to the original cellpose implementation - the channel order is reversed for compatibility with DeepCell/Mesmer.

If a `cellpose` column is present in the *steinbock* panel file, channels are sorted and grouped according to values in that column to generate the required input for DeepCell: For each image, each group of channels is aggregated by computing the mean along the channel axis (use the `--aggr` option to specify a different aggregation strategy). The resulting images consist of one channel per group; channels without a group label are ignored.

If no `cellpose` column is present, images are expected to be in the correct format already.

### Training a cellpose model
Training a cellpose model is performed using two commands

steinbock segment train prepare
steinbock segment train run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not match the code interface. I think it should be steinbock segment cellpose train ...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover from before the change, updated!


By default the first command generates crops of images in `img` and stores them in `cellpose_crops` folder. These crops consist of a nuclear and a Cytoplasmic channels as described above. By default crops are then segmented using the `tissuenet` pre-trained model and the resulting masks are placed in the folder `cellpose_labels`. Any model from the model zoo can be specified using the`--model_type` argument. User trained models can be specified by providing the full path to the model using the `pretrained-model` option (when `pretrained-model` is provided, the `--model_type` argument is set to `None`, see above). The user can optionally specify a list of files for cropping and training. After running the first command the user should open and inspect the generated masks and correct them if necessary. This can be done by starting the `cellpose` gui via *steinbock*: `steinbock apps cellpose` (See `Apps`in this document. For details on how to use cellpose to correct gui segmentations, see its relevant [documentation](https://cellpose.readthedocs.io/en/latest/gui.html).

The second command runs the cellpose training module. Unless specified via the `--train_data` and `--train_labels` options, the command looks in `cellpose_crops` and `cellpose_labels` for images and masks that are used as ground truth. The resulting model is by default saved in `training_out`. The trained model can subsequently be used for segmentation via the `--pretrained-model` argument, for example as following;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think the parameter spelling in the documentation need to be double-checked (e.g., replace _ by -)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected




steinbock segment cellpose run pretrained-model ./training_out/models/myModel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be --pretrained-model?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really?

steinbock segment cellpose run pretrained-model ./training_out/models/myModel



!!! note "GPU support"
Currently. steinbock does not support cellpose segmentation with GPU support.

Expand Down
7 changes: 7 additions & 0 deletions docs/cli/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ The created image tiles will have the following file name, where `{IMG}` is the
The following command will stitch all mask tiles in `masks` (following the file conventions above) to assemble masks of original size and save them to `masks_full`:

steinbock utils mosaics stitch masks -o masks_full

### Expansion

This utility incorporates the `expand_labels` from (`skimage.segmentation`)[https://scikit-image.org/docs/stable/api/skimage.segmentation.html#skimage.segmentation.expand_labels]. It expands mask objects outwards by up to a distance specified in pixels without overflowing into neighboring regions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax of this link looks wrong to me?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected.

The following command expands the masks in each fils contained in `masks` directory by a maximum of 5 pixels and saves the resulting masks in `expanded_masks`:

steinbock utils expand masks 5 -o expanded_masks
19 changes: 19 additions & 0 deletions docs/install-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ The *steinbock* toolkit can be used interactively using the *steinbock* Docker c

In this section, the installation and configuration of the *steinbock* Docker container is described.

## Docker container flavors

The *steinbock* docker container is offered in several [flavors] (https://github.com/BodenmillerGroup/steinbock/pkgs/container/steinbock). This is for the most part to avoid overly large containers. The current flavors differ from each other in inclusion of cellpose segmentation and training, [Xpra] (https://xpra.org/)(to run a steinbock-enabled desktop environment within a web browser) and gpu functionality. Apart from the default falvor of *steinbock*, the following flavors are currently available:

- cellpose
- gpu
- xpra
- cellpose-gpu
- gpu-xpra
- cellpose-xpra
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without checking in detail, shouldn't there be 2 ** 3 = 8 different flavors? Also, perhaps its easier to only explain the 3 tags (cellpose, gpu, xpra), instead of showing all the combinations (especially, since e.g. using cellpose-gpu and cellpose-gpu-xpra currently doesn't make much sense)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revised


To install a specific flavor of *steinbock* visit its [package page](https://github.com/BodenmillerGroup/steinbock/pkgs/container/steinbock) and click on the image version of your choice, from the page that follows, copy the path to the container on Github container registry and substitute it for the container path in the following instructions.


## Prerequisites

### Windows
Expand Down Expand Up @@ -131,6 +145,11 @@ The created command alias is retained for the current session and enables runnin

xhost +local:root

### Using the docker container with large images containing more than 65535 objects

by default 16-bit masks are supported at this moment. This may be problematic for large masks containing more than 2^16 - 1 = 65535 Objects. In such situations, there is the option to run the steinbock Docker container with `-e STEINBOCK_MASK_DTYPE=uint32`, for example, the steinbock alias command for linux becomes:

alias steinbock="docker run -e STEINBOCK_MASK_DTYPE=uint32 -v /path/to/data:/data -u $(id -u):$(id -g) --network host -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY ghcr.io/bodenmillergroup/steinbock:0.16.1"
Milad4849 marked this conversation as resolved.
Show resolved Hide resolved
## Usage

Please refer to [command-line usage](cli/intro.md) for usage instructions.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ networkx==3.0
numpy==1.23.5 # deepcell 0.12.4 requires <1.24
opencv-python-headless==4.7.0.68
pandas==1.5.3
pydantic<2
Milad4849 marked this conversation as resolved.
Show resolved Hide resolved
pyyaml==6.0
readimc==0.6.2
scikit-image==0.19.3
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ install_requires =
imageio
networkx
numpy
opencv-python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Isn't opencv-python-headless enough?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revising the comments, I realize this follows from #218 (comment). Still, it remains unclear to me where the opencv-python dependency comes from.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Milad4849 Any update on why this dependency is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last time checked required on my system, thorough testing on multiple machines will be done once the develop branch is ready.

opencv-python-headless
pandas
scikit-image
Expand Down
27 changes: 26 additions & 1 deletion steinbock/_cli/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def ilastik_cmd(ilastik_binary, ilastik_args, ilastik_env):
"--python",
"python_path",
type=click.Path(dir_okay=False),
default="/opt/cellprofiler-venv/bin/python",
default="usr/bin/python",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to 'python'

show_default=True,
help="Python path",
)
Expand Down Expand Up @@ -148,3 +148,28 @@ def jupyterlab_cmd(python_path, jupyter_module, jupyterlab_args):
args = [python_path, "-m", jupyter_module, "lab"] + jupyterlab_args
result = run_captured(args)
sys.exit(result.returncode)


@apps_cmd_group.command(
name="cellpose",
context_settings={"ignore_unknown_options": True},
jwindhager marked this conversation as resolved.
Show resolved Hide resolved
help="Run cellpose GUI",
add_help_option=False,
)
@click.option(
"--python",
"python_path",
type=click.Path(dir_okay=False),
default="usr/bin/python",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes to 'python'

show_default=True,
help="Python path",
)

# @click.argument("cellprofiler_args", nargs=-1, type=click.UNPROCESSED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not allow arguments to the cellpose command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was to leave everything to be specified from the gui.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! I don't see a harm in supporting the cellpose command-line parameters, too (especially since you don't need to specify them explicitly when using click.UNPROCESSED), but your choice.

usage:  cellpose [-h] [--version] [--verbose] [--use_gpu] [--gpu_device GPU_DEVICE] [--check_mkl] [--dir DIR]
        [--image_path IMAGE_PATH] [--look_one_level_down] [--img_filter IMG_FILTER]
        [--channel_axis CHANNEL_AXIS] [--z_axis Z_AXIS] [--chan CHAN] [--chan2 CHAN2] [--invert]
        [--all_channels] [--pretrained_model PRETRAINED_MODEL] [--add_model ADD_MODEL] [--unet]
        [--nclasses NCLASSES] [--no_resample] [--net_avg] [--no_interp] [--no_norm] [--do_3D]
        [--diameter DIAMETER] [--stitch_threshold STITCH_THRESHOLD] [--min_size MIN_SIZE] [--fast_mode]
        [--flow_threshold FLOW_THRESHOLD] [--cellprob_threshold CELLPROB_THRESHOLD]
        [--anisotropy ANISOTROPY] [--exclude_on_edges] [--augment] [--save_png] [--save_tif] [--no_npy]
        [--savedir SAVEDIR] [--dir_above] [--in_folders] [--save_flows] [--save_outlines] [--save_rois]
        [--save_ncolor] [--save_txt] [--train] [--train_size] [--test_dir TEST_DIR]
        [--mask_filter MASK_FILTER] [--diam_mean DIAM_MEAN] [--learning_rate LEARNING_RATE]
        [--weight_decay WEIGHT_DECAY] [--n_epochs N_EPOCHS] [--batch_size BATCH_SIZE]
        [--min_train_masks MIN_TRAIN_MASKS] [--residual_on RESIDUAL_ON] [--style_on STYLE_ON]
        [--concatenation CONCATENATION] [--save_every SAVE_EVERY] [--save_each]
        [--model_name_out MODEL_NAME_OUT]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to support unprocessed args for cellpose

@click_log.simple_verbosity_option(logger=steinbock_logger)
@catch_exception(handle=SteinbockException)
def cellpose_view_cmd(python_path):
args = [python_path, "-m", "cellpose"]

result = run_captured(args)
sys.exit(result.returncode)
2 changes: 1 addition & 1 deletion steinbock/export/_cli/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def write_anndata(adata, anndata_file, ignore_suffix=False):
del adata
if concatenate:
adata = anndata_concat(
adatas, merge="first", label="Image", index_unique=" in "
adatas, merge="first", label="Image", index_unique=" in ", pairwise=True
)
obs_cols = list(adata.obs.columns)
obs_cols.insert(0, obs_cols.pop(obs_cols.index("Image")))
Expand Down
43 changes: 41 additions & 2 deletions steinbock/preprocessing/_cli/imc.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,16 @@ def panel_cmd(
show_default=True,
help="Path to the image information output file",
)
@click.option(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also made xti file handling with the last commit as well, in brief if xti -> individual txt files are generated for the ROIs (the xti machine does not output txt backups). Added this last minute as it is high priority and currently needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I won't review this conceptually, as I'm not familiar with the XTi. But perhaps this should be added to the online documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

"--xti/--no-xti",
"xti",
default=False,
Milad4849 marked this conversation as resolved.
Show resolved Hide resolved
show_default=True,
help="generate txt files from xti imc file",
)
@click_log.simple_verbosity_option(logger=steinbock_logger)
@catch_exception(handle=SteinbockException)
def images_cmd(mcd_dir, txt_dir, unzip, panel_file, hpf, img_dir, image_info_file):
def images_cmd(mcd_dir, txt_dir, unzip, panel_file, hpf, img_dir, image_info_file, xti):
channel_names = None
if Path(panel_file).is_file():
panel = io.read_panel(panel_file)
Expand All @@ -205,14 +212,19 @@ def images_cmd(mcd_dir, txt_dir, unzip, panel_file, hpf, img_dir, image_info_fil
txt_files = imc.list_txt_files(txt_dir, unzip=unzip)
mcd_txt_files = {}
num_dupl = 0

for (
mcd_or_txt_file,
acquisition,
img,
recovery_txt_file,
recovered,
) in imc.try_preprocess_images_from_disk(
mcd_files, txt_files, channel_names=channel_names, hpf=hpf, unzip=unzip
mcd_files,
txt_files,
channel_names=channel_names,
hpf=hpf,
unzip=unzip,
):
img_file_stem = Path(mcd_or_txt_file).stem
if acquisition is not None:
Expand All @@ -239,3 +251,30 @@ def images_cmd(mcd_dir, txt_dir, unzip, panel_file, hpf, img_dir, image_info_fil
image_info = pd.DataFrame(data=image_info_data)
io.write_image_info(image_info, image_info_file)
logger.info(image_info_file)
if xti:
mcd_txt_files = {}
num_dupl = 0
for (
mcd_file,
acquisition,
img,
) in imc.try_gen_text_file_from_mcd(mcd_files, unzip=unzip):
img_file_stem = Path(mcd_file).stem
if acquisition is not None:
img_file_stem += f"_{acquisition.id:03d}"
if img_file_stem in mcd_txt_files:
num_dupl += 1
first_mcd_txt_file = mcd_txt_files[img_file_stem][0]
img_file_stem = f"DUPLICATE{num_dupl:03d}_{img_file_stem}"
logger.warning(
f"File {mcd_file} is a duplicate of {first_mcd_txt_file}, "
f"saving as {img_file_stem}"
)
mcd_txt_files[img_file_stem].append(mcd_file)
else:
mcd_txt_files[img_file_stem] = [mcd_file]

gentxt_file = Path(txt_dir) / f"{img_file_stem}.txt"
img.to_csv(gentxt_file, header=True, index=None, sep="\t")
del img
logger.info(gentxt_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without knowing too much about this: Why generate txt files instead of images (especially, since the command is called preprocess images)? Also, doesn't generating txt files AFTER extracting images destroy the whole txt-for-broken-mcd recovery mechanism implemented above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In brief, downstream analysis relies on the txt files which are not provided by the new xti IMC machines.Therefore the txt files are not meant as back ups. It is a feature requested exactly in this format: steinbock preprocess --xti but perhaps best implemented as a part of export? At any rate, the txt files have to be generated directly from the mcd to avoid any unwanted changes.

Loading