Add methods baysor#29
Merged
Merged
Conversation
…he ifrst input scripts.py
rcannood
reviewed
May 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR integrates a new baysor method component into the spatial segmentation benchmark workflow, intending to run the Baysor (C++/cpp-branch) pipeline as part of run_benchmark.
Changes:
- Added
baysorto the list of benchmarked methods and included it as a workflow dependency. - Introduced a new Viash component at
src/methods/baysor/(config + Python entry script) that runs Baysor and writes a SpatialData Zarr output.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
src/workflows/run_benchmark/main.nf |
Adds baysor to the default methods list executed by the benchmark workflow. |
src/workflows/run_benchmark/config.vsh.yaml |
Adds the methods/baysor dependency so the workflow can run the new component. |
src/methods/baysor/script.py |
New method implementation: reads SpatialData, attempts to use a prior segmentation, runs Baysor, and writes a prediction Zarr. |
src/methods/baysor/config.vsh.yaml |
New Viash component definition, including arguments and Docker build steps to install Baysor C++. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+24
to
+25
| description: The key for the prior segmentation stored within the spatial data | ||
| default: nucleus_labels |
Comment on lines
+50
to
+65
|
|
||
| print(sdata) | ||
|
|
||
| # Check if coordinate system is available in input data | ||
| transcripts_coord_systems = sd.transformations.get_transformation(sdata[par["transcripts_key"]], get_all=True).keys() | ||
| assert par['coordinate_system'] in transcripts_coord_systems, f"Coordinate system '{par['coordinate_system']}' not found in input data." | ||
| segmentation_coord_systems = sd.transformations.get_transformation(sdata[par['prior_segmentation_key']], get_all=True).keys() | ||
| assert par['coordinate_system'] in segmentation_coord_systems, f"Coordinate system '{par['coordinate_system']}' not found in input data." | ||
|
|
||
| # Transform transcript coordinates to the coordinate system | ||
| print('Transforming transcripts coordinates', flush=True) | ||
| transcripts = sd.transform(sdata[par['transcripts_key']], to_coordinate_system=par['coordinate_system']) | ||
|
|
||
| # In case of a translation transformation of the segmentation (e.g. crop of the data), we need to adjust the transcript coordinates | ||
| trans = sd.transformations.get_transformation(sdata[par['prior_segmentation_key']], get_all=True)[par['coordinate_system']].inverse() | ||
| transcripts = sd.transform(transcripts, trans, par['coordinate_system']) |
Comment on lines
+81
to
+86
| toml_str = f"""[data] | ||
| x = "x" | ||
| y = "y" | ||
| z = "z" | ||
| gene = "feature_name" | ||
| force_2d = {par['force_2d']} |
Comment on lines
+99
to
+107
| # Run Baysor | ||
| n_threads = meta['cpus'] or os.cpu_count() | ||
| n_threads = max(n_threads-2, 1) | ||
| os.environ['JULIA_NUM_THREADS'] = str(n_threads) | ||
| print('Running Baysor', flush=True) | ||
| baysor_cmd = f"baysor run --output-style legacy -c {CONFIG_TOML} -o {BAYSOR_OUTPUT_DIR} {TRANSCRIPTS_CSV} {SEGMENTATION_TIF}" | ||
| print("\t" + baysor_cmd, flush=True) | ||
| os.system(baysor_cmd) | ||
|
|
Comment on lines
+152
to
+161
| ), | ||
| index=sdata[par['transcripts_key']].index | ||
| ) | ||
| sdata[par['transcripts_key']]["cell_id"] = cell_id_dask_series | ||
|
|
||
|
|
||
| # Create objects for cells table | ||
| print('Creating objects for cells table', flush=True) | ||
| #create new .obs for cells based on the segmentation output (corresponding with the transcripts 'cell_id') | ||
| unique_cells = np.unique(cell_id_dask_series) |
Comment on lines
+67
to
+86
| # Write transcripts to csv | ||
| print('Writing transcripts to csv', flush=True) | ||
| transcripts[['x', 'y', 'z', 'feature_name']].compute().to_csv(TRANSCRIPTS_CSV) | ||
|
|
||
| # Write segmentation to tif | ||
| print('Writing segmentation to tif', flush=True) | ||
| if isinstance(sdata[par['prior_segmentation_key']], xr.DataTree): | ||
| label_image = sdata[par['prior_segmentation_key']]["scale0"].image.to_numpy() | ||
| else: | ||
| label_image = sdata[par['prior_segmentation_key']].to_numpy() | ||
| imwrite(SEGMENTATION_TIF, label_image) | ||
|
|
||
| # Write config to toml | ||
| print('Writing config to toml', flush=True) | ||
| toml_str = f"""[data] | ||
| x = "x" | ||
| y = "y" | ||
| z = "z" | ||
| gene = "feature_name" | ||
| force_2d = {par['force_2d']} |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Robrecht Cannoodt <rcannood@gmail.com>
…_spatial_segmentation into add-methods-baysor
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Adding the cpp version of bayor to the pipeline.
Need the initial segmentation now to finalize it.
Checklist before requesting a review
I have performed a self-review of my code
Check the correct box. Does this PR contain:
Proposed changes are described in the CHANGELOG.md
CI Tests succeed and look good!