-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from openproblems-bio/segm_m_cellpose
Segm m cellpose
- Loading branch information
Showing
3 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
Submodule common
updated
3 files
+1 −1 | component_tests/run_and_check_output.py | |
+17 −0 | nextflow_helpers/helper.nf | |
+40 −0 | scripts/fetch_task_run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: cellpose | ||
label: "Cellpose Segmentation" | ||
summary: "Output of the segmantation methot cellpose" | ||
description: "Output of the segmantation methot cellpose" | ||
links: | ||
documentation: "https://github.com/openproblems-bio/task_ist_preprocessing" | ||
repository: "https://github.com/openproblems-bio/task_ist_preprocessing" | ||
references: | ||
doi: "10.1038/s41592-020-01018-x" | ||
|
||
|
||
__merge__: /src/api/comp_method_segmentation.yaml | ||
|
||
arguments: | ||
- name: --batch_size | ||
type: integer | ||
default: 8 | ||
- name: --model_type | ||
type: string | ||
default: "cyto" | ||
- name: --channel_axis | ||
type: string | ||
default: "None" | ||
- name: --z_axis | ||
type: string | ||
default: "None" | ||
- name: --normalize | ||
type: boolean | ||
default: True | ||
- name: --invert | ||
type: boolean | ||
default: False | ||
- name: --rescale | ||
type: string | ||
default: "None" | ||
- name: --diameter | ||
type: double | ||
default: 30.0 | ||
- name: --do_3D | ||
type: boolean | ||
default: False | ||
- name: --anisotropy | ||
type: string | ||
default: "None" | ||
# - name: --net_avg | ||
# type: boolean | ||
# default: False | ||
- name: --augment | ||
type: boolean | ||
default: False | ||
#- name: --tile | ||
# type: boolean | ||
# default: True | ||
- name: --tile_overlap | ||
type: double | ||
default: 0.1 | ||
- name: --resample | ||
type: boolean | ||
default: True | ||
- name: --interp | ||
type: boolean | ||
default: True | ||
- name: --flow_threshold | ||
type: double | ||
default: 0.4 | ||
- name: --cellprob_threshold | ||
type: double | ||
default: 0.0 | ||
- name: --min_size | ||
type: integer | ||
default: 15 | ||
- name: --stitch_threshold | ||
type: double | ||
default: 0.0 | ||
|
||
resources: | ||
- type: python_script | ||
path: script.py | ||
|
||
engines: | ||
- type: docker | ||
image: openproblems/base_python:1.0.0 | ||
setup: | ||
- type: python | ||
pypi: spatialdata | ||
__merge__: | ||
- /src/base/setup_txsim_partial.yaml | ||
- type: native | ||
|
||
runners: | ||
- type: executable | ||
- type: nextflow | ||
directives: | ||
label: [ midtime, lowcpu, lowmem ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import txsim as tx | ||
import numpy as np | ||
import os | ||
import yaml | ||
import spatialdata as sd | ||
import anndata as ad | ||
import shutil | ||
import numpy as np | ||
from spatialdata.models import Labels2DModel | ||
import xarray as xr | ||
import datatree as dt | ||
|
||
|
||
def convert_to_lower_dtype(arr): | ||
max_val = arr.max() | ||
if max_val <= np.iinfo(np.uint8).max: | ||
new_dtype = np.uint8 | ||
elif max_val <= np.iinfo(np.uint16).max: | ||
new_dtype = np.uint16 | ||
elif max_val <= np.iinfo(np.uint32).max: | ||
new_dtype = np.uint32 | ||
else: | ||
new_dtype = np.uint64 | ||
|
||
return arr.astype(new_dtype) | ||
|
||
## VIASH START | ||
par = { | ||
"input": "../task_ist_preprocessing/resources_test/common/2023_10x_mouse_brain_xenium/dataset.zarr", | ||
"output": "segmentation.zarr" | ||
} | ||
|
||
## VIASH END | ||
|
||
hyperparameters = par.copy() | ||
|
||
hyperparameters = {k:(v if v != "None" else None) for k,v in hyperparameters.items()} | ||
del hyperparameters['input'] | ||
del hyperparameters['output'] | ||
|
||
sdata = sd.read_zarr(par["input"]) | ||
image = sdata['morphology_mip']['scale0'].image.compute().to_numpy() | ||
transformation = sdata['morphology_mip']['scale0'].image.transform.copy() | ||
|
||
sd_output = sd.SpatialData() | ||
image = sdata['morphology_mip']['scale0'].image.compute().to_numpy() | ||
transformation = sdata['morphology_mip']['scale0'].image.transform.copy() | ||
img_arr = tx.preprocessing.segment_cellpose(image[0], hyperparameters) | ||
image = convert_to_lower_dtype(img_arr) | ||
data_array = xr.DataArray(image, name=f'segmentation', dims=('y', 'x')) | ||
parsed_data = Labels2DModel.parse(data_array, transformations=transformation) | ||
sd_output.labels['segmentation'] = parsed_data | ||
|
||
print("Writing output", flush=True) | ||
if os.path.exists(par["output"]): | ||
shutil.rmtree(par["output"]) | ||
sd_output.write(par["output"]) | ||
|