Skip to content

Commit

Permalink
Merge pull request #52 from gustaveroussy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
quentinblampey authored Apr 10, 2024
2 parents acabcc7 + 19d8118 commit b10cf20
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 65 deletions.
161 changes: 110 additions & 51 deletions docs/tutorials/api_usage.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sopa/annotation/tangram/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import tangram as tg
except ImportError:
raise ImportError(
"To use tangram, you need its corresponding sopa extra: `pip install 'sopa[tangram]'`"
"To use tangram, you need its corresponding sopa extra: `pip install 'sopa[tangram]'` (normal mode) or `pip install -e '.[tangram]'` (if using snakemake)"
)

from sopa._constants import SopaKeys
Expand Down
2 changes: 1 addition & 1 deletion sopa/embedding/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import torch
except ImportError:
raise ImportError(
"For patch embedding, you need `torch` (and perhaps `torchvision`). Consider installing the sopa WSI extra: `pip install 'sopa[wsi]'`"
"For patch embedding, you need `torch` (and perhaps `torchvision`). Consider installing the sopa WSI extra: `pip install 'sopa[wsi]'` (normal mode) or `pip install -e '.[wsi]'` (if using snakemake)"
)

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion sopa/io/reader/cosmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def cosmx(
if read_proteins:
protein_dir_dict = {
int(protein_dir.parent.name[3:]): protein_dir
for protein_dir in list(path.rglob("**/ProteinImages"))
for protein_dir in list(path.rglob("**/FOV*/ProteinImages"))
}
assert len(protein_dir_dict), f"No directory called 'ProteinImages' was found under {path}"

Expand Down
7 changes: 5 additions & 2 deletions sopa/io/reader/wsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ def wsi(

multiscale_image = MultiscaleSpatialImage.from_dict(images)
multiscale_image.attrs["metadata"] = tiff_metadata
multiscale_image.name = image_name

if as_image:
multiscale_image.name = image_name
return multiscale_image

return SpatialData(images={image_name: multiscale_image})
sdata = SpatialData(images={image_name: multiscale_image})
sdata[image_name].attrs["metadata"] = tiff_metadata

return sdata


def _get_scale_transformation(scale_factor: float):
Expand Down
2 changes: 1 addition & 1 deletion sopa/segmentation/baysor/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import toml
except ImportError:
raise ImportError(
"To use baysor, you need its corresponding sopa extra: `pip install 'sopa[baysor]'`.\
"To use baysor, you need its corresponding sopa extra: `pip install 'sopa[baysor]'` (normal mode) or `pip install -e '.[baysor]'` (if using snakemake).\
\nAlso, make sure to install the baysor executable (https://github.com/kharchenkolab/Baysor)."
)

Expand Down
2 changes: 1 addition & 1 deletion sopa/segmentation/baysor/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def resolve(

image_key = get_key(sdata, "images")
points = get_element(sdata, "points")
transformations = get_transformation(points, get_all=True)
transformations = get_transformation(points, get_all=True).copy()

geo_df = ShapesModel.parse(geo_df, transformations=transformations)

Expand Down
2 changes: 1 addition & 1 deletion sopa/segmentation/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def cellpose_patch(
from cellpose import models
except ImportError:
raise ImportError(
"To use cellpose, you need its corresponding sopa extra: `pip install 'sopa[cellpose]'`"
"To use cellpose, you need its corresponding sopa extra: `pip install 'sopa[cellpose]'` (normal mode) or `pip install -e '.[cellpose]'` (if using snakemake)"
)

cellpose_model_kwargs = cellpose_model_kwargs or {}
Expand Down
2 changes: 1 addition & 1 deletion sopa/segmentation/patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def write(self, overwrite: bool = True, shapes_key: str | None = None) -> gpd.Ge
}
)
geo_df = ShapesModel.parse(
geo_df, transformations=get_transformation(self.element, get_all=True)
geo_df, transformations=get_transformation(self.element, get_all=True).copy()
)

self.sdata.shapes[shapes_key] = geo_df
Expand Down
4 changes: 3 additions & 1 deletion sopa/segmentation/stainings.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ def add_shapes(cls, sdata: SpatialData, cells: list[Polygon], image_key: str, sh
geo_df = gpd.GeoDataFrame({"geometry": cells})
geo_df.index = image_key + geo_df.index.astype(str)

geo_df = ShapesModel.parse(geo_df, transformations=get_transformation(image, get_all=True))
geo_df = ShapesModel.parse(
geo_df, transformations=get_transformation(image, get_all=True).copy()
)
sdata.shapes[shapes_key] = geo_df
save_shapes(sdata, shapes_key, overwrite=True)

Expand Down
2 changes: 1 addition & 1 deletion sopa/utils/polygon_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def polygon_selection(
geo_df = gpd.GeoDataFrame(geometry=[polygon])

geo_df = ShapesModel.parse(
geo_df, transformations=get_transformation(sdata[image_key], get_all=True)
geo_df, transformations=get_transformation(sdata[image_key], get_all=True).copy()
)
sdata.shapes[ROI.KEY] = geo_df
save_shapes(sdata, ROI.KEY)
Expand Down
2 changes: 1 addition & 1 deletion workflow/config/cosmx/cellpose_baysor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ segmentation:
segmentation:
scale: 60 # typical cell radius
scale_std: "25%" # cell radius standard deviation
prior_segmentation_confidence: 0
prior_segmentation_confidence: 1
estimate_scale_from_centers: false
n_clusters: 4
iters: 500
Expand Down
2 changes: 1 addition & 1 deletion workflow/config/merscope/baysor_cellpose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ segmentation:
segmentation:
scale: 6.25 # typical cell radius
scale_std: "25%" # cell radius standard deviation
prior_segmentation_confidence: 0.75 # confidence of the cellpose confidence (float in [0, 1])
prior_segmentation_confidence: 1 # confidence of the cellpose confidence (float in [0, 1])
estimate_scale_from_centers: false
n_clusters: 4
iters: 500
Expand Down
2 changes: 1 addition & 1 deletion workflow/config/xenium/cellpose_baysor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ segmentation:
segmentation:
scale: 6.25 # typical cell radius
scale_std: "25%" # cell radius standard deviation
prior_segmentation_confidence: 0.75 # confidence of the cellpose confidence (float in [0, 1])
prior_segmentation_confidence: 1 # confidence of the cellpose confidence (float in [0, 1])
estimate_scale_from_centers: false
n_clusters: 4
iters: 500
Expand Down

0 comments on commit b10cf20

Please sign in to comment.