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

Development #135

Merged
merged 28 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
871f7f6
simplify if statement to assertion
sophiamaedler Dec 9, 2024
599895c
ensure that channel order is also remapped
sophiamaedler Dec 9, 2024
52961a3
add remap parameter
sophiamaedler Dec 9, 2024
d2be9dc
add/update docstrings
sophiamaedler Dec 9, 2024
c3cb3e8
fix pre-commit issues
sophiamaedler Dec 9, 2024
3afabcb
make methods non-public that aren't relevant for user
sophiamaedler Dec 9, 2024
29f1111
update doc strings
sophiamaedler Dec 9, 2024
5579b73
move public methods to hidden methods
sophiamaedler Dec 9, 2024
5796f9f
ruff linting
sophiamaedler Dec 9, 2024
7007157
restructure API docs
sophiamaedler Dec 9, 2024
f7d78a2
add docstring
sophiamaedler Dec 9, 2024
3f754bb
update example notebook
sophiamaedler Dec 9, 2024
f40796a
ruff linting
sophiamaedler Dec 9, 2024
129fd8f
Update submodule
sophiamaedler Dec 9, 2024
055b89f
add function where user can get information on what will be stitched …
sophiamaedler Dec 10, 2024
c8330c4
fix bug in incorrectly defined function name
sophiamaedler Dec 10, 2024
dbfcaee
ensure channel names are written out in ome-zarr files
sophiamaedler Dec 10, 2024
eae1eca
update stitching example
sophiamaedler Dec 10, 2024
ab09f63
ruff linting
sophiamaedler Dec 10, 2024
9d56ea9
update pre-commit config to new version
sophiamaedler Dec 10, 2024
1555116
relocate redundant code to sdata_io
sophiamaedler Dec 11, 2024
b95f045
improve docstrings
sophiamaedler Dec 11, 2024
3a4041c
improve docstrings
sophiamaedler Dec 11, 2024
7e2ecd3
remove outdated function calls
sophiamaedler Dec 11, 2024
0be5e59
fix typing
sophiamaedler Dec 11, 2024
8023b1c
add docstrings
sophiamaedler Dec 11, 2024
a94b8cb
Merge pull request #134 from MannLabs/improve_docs_docstrings
sophiamaedler Dec 13, 2024
f7cf794
Merge branch 'main' into development
sophiamaedler Dec 15, 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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ fail_fast: false
default_language_version:
python: python3
default_stages:
- commit
- push
- pre-commit
- pre-push
minimum_pre_commit_version: 2.16.0
repos:
- repo: https://github.com/pre-commit/mirrors-prettier
Expand Down
7 changes: 5 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ Documentation
pages/example_notebooks.ipynb

.. toctree::
:maxdepth: 2
:maxdepth: 4
:includehidden:
:caption: Module API

pages/module
pages/module/pipeline
pages/module/processing
pages/module/io
pages/module/tools
7 changes: 0 additions & 7 deletions docs/pages/module.rst

This file was deleted.

76 changes: 8 additions & 68 deletions docs/pages/module/pipeline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,11 @@ pipeline
*******************

.. toctree::
:maxdepth: 3

project
#######

Within scPortrait, all operations are centered around the concept of a ``Project``. A ``Project`` is a python class which manages all of the scPortrait processing steps and is the central element through which all operations are performed. Each ``Project`` directly maps to a directory on the file system which contains all of the inputs to a specific scPortrait run as well as the generated outputs. Depending on the structure of the data that is to be processed a different Project class is required. Please see :ref:`here <projects>` for more information.

Project
=========
.. autoclass:: scportrait.pipeline.project.Project
:members:
:show-inheritance:

segmentation
#############

Segmentation
==============
.. autoclass:: scportrait.pipeline.segmentation.Segmentation
:members:
:show-inheritance:

ShardedSegmentation
=====================
.. autoclass:: scportrait.pipeline.segmentation.ShardedSegmentation
:members:
:show-inheritance:

segmentation workflows
######################
.. automodule:: scportrait.pipeline.segmentation.workflows
:members:

extraction
###########

HDF5CellExtraction
===================
.. autoclass:: scportrait.pipeline.extraction.HDF5CellExtraction
:members:
:show-inheritance:


Featurization
#############

MLClusterClassifier
===================
.. autoclass:: scportrait.pipeline.featurization.MLClusterClassifier
:members:

.. automethod:: __call__

CellFeaturizer
==============
.. autoclass:: scportrait.pipeline.featurization.CellFeaturizer
:members:

.. automethod:: __call__

selection
###########

LMDSelection
==============
.. autoclass:: scportrait.pipeline.selection.LMDSelection
:members:
:show-inheritance:
:maxdepth: 2

pipeline/project
pipeline/segmentation
pipeline/segmentation_workflows
pipeline/extraction
pipeline/featurization
pipeline/selection
8 changes: 8 additions & 0 deletions docs/pages/module/pipeline/extraction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extraction
###########

HDF5CellExtraction
===================
.. autoclass:: scportrait.pipeline.extraction.HDF5CellExtraction
:members:
:show-inheritance:
16 changes: 16 additions & 0 deletions docs/pages/module/pipeline/featurization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Featurization
#############

MLClusterClassifier
===================
.. autoclass:: scportrait.pipeline.featurization.MLClusterClassifier
:members:

.. automethod:: __call__

CellFeaturizer
==============
.. autoclass:: scportrait.pipeline.featurization.CellFeaturizer
:members:

.. automethod:: __call__
2 changes: 2 additions & 0 deletions docs/pages/module/pipeline/project.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. automodule:: scportrait.pipeline.project
:members:
14 changes: 14 additions & 0 deletions docs/pages/module/pipeline/segmentation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
segmentation
#############

Segmentation
==============
.. autoclass:: scportrait.pipeline.segmentation.Segmentation
:members:
:show-inheritance:

ShardedSegmentation
=====================
.. autoclass:: scportrait.pipeline.segmentation.ShardedSegmentation
:members:
:show-inheritance:
5 changes: 5 additions & 0 deletions docs/pages/module/pipeline/segmentation_workflows.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
segmentation workflows
######################

.. automodule:: scportrait.pipeline.segmentation.workflows
:members:
8 changes: 8 additions & 0 deletions docs/pages/module/pipeline/selection.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
selection
###########

LMDSelection
==============
.. autoclass:: scportrait.pipeline.selection.LMDSelection
:members:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/pages/module/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tools
*******************

.. toctree::
:maxdepth: 4
:maxdepth: 2

tools/parsing
tools/stitching
Expand Down
177 changes: 103 additions & 74 deletions docs/pages/tools/stitching/example_stitching_notebook.ipynb

Large diffs are not rendered by default.

60 changes: 57 additions & 3 deletions src/scportrait/pipeline/_utils/sdata_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import xarray
from alphabase.io import tempmmap
from spatialdata import SpatialData
from spatialdata.models import PointsModel, TableModel
from spatialdata.models import Image2DModel, PointsModel, TableModel
from spatialdata.transformations.transformations import Identity

from scportrait.pipeline._base import Logable
Expand All @@ -19,7 +19,8 @@
get_chunk_size,
)

ChunkSize: TypeAlias = tuple[int, int]
ChunkSize2D: TypeAlias = tuple[int, int]
ChunkSize3D: TypeAlias = tuple[int, int, int]
ObjectType: TypeAlias = Literal["images", "labels", "points", "tables"]


Expand Down Expand Up @@ -143,6 +144,58 @@ def _get_input_image(self, sdata: SpatialData) -> xarray.DataArray:
return input_image

## write elements to sdata object
def _write_image_sdata(
self,
image,
image_name: str,
channel_names: list[str] = None,
scale_factors: list[int] = None,
chunks: ChunkSize3D = (1, 1000, 1000),
overwrite=False,
):
"""
Write the supplied image to the spatialdata object.

Args:
image (dask.array): Image to be written to the spatialdata object.
image_name (str): Name of the image to be written to the spatialdata object.
channel_names list[str]: List of channel names for the image. Default is None.
scale_factors list[int]: List of scale factors for the image. Default is [2, 4, 8]. This will load the image at 4 different resolutions to allow for fluid visualization.
chunks (tuple): Chunk size for the image. Default is (1, 1000, 1000).
overwrite (bool): Whether to overwrite existing data. Default is False.
"""

if scale_factors is None:
scale_factors = [2, 4, 8]
if scale_factors is None:
scale_factors = [2, 4, 8]

_sdata = self._read_sdata()

if channel_names is None:
channel_names = [f"channel_{i}" for i in range(image.shape[0])]

# transform to spatialdata image model
transform_original = Identity()
image = Image2DModel.parse(
image,
dims=["c", "y", "x"],
chunks=chunks,
c_coords=channel_names,
scale_factors=scale_factors,
transformations={"global": transform_original},
rgb=False,
)

if overwrite:
self._force_delete_object(_sdata, image_name, "images")

_sdata.images[image_name] = image
_sdata.write_element(image_name, overwrite=True)

self.log(f"Image {image_name} written to sdata object.")
self._check_sdata_status()

def _write_segmentation_object_sdata(
self,
segmentation_object: spLabels2DModel,
Expand Down Expand Up @@ -177,7 +230,7 @@ def _write_segmentation_sdata(
segmentation: xarray.DataArray | np.ndarray,
segmentation_label: str,
classes: set[str] | None = None,
chunks: ChunkSize = (1000, 1000),
chunks: ChunkSize2D = (1000, 1000),
overwrite: bool = False,
) -> None:
"""Write segmentation data to SpatialData.
Expand Down Expand Up @@ -268,6 +321,7 @@ def _add_centers(self, segmentation_label: str, overwrite: bool = False) -> None
centroids_object = self._get_centers(_sdata, segmentation_label)
self._write_points_object_sdata(centroids_object, self.centers_name, overwrite=overwrite)

## load elements from sdata to a memory mapped array
def _load_input_image_to_memmap(
self, tmp_dir_abs_path: str | Path, image: np.typing.NDArray[Any] | None = None
) -> str:
Expand Down
6 changes: 4 additions & 2 deletions src/scportrait/pipeline/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,10 @@ def process(self, partial=False, n_cells=None, seed=42):
self.log("Loading input images to memory mapped arrays...")
start_data_transfer = timeit.default_timer()

self.path_seg_masks = self.project._load_seg_to_memmap(seg_name=self.masks, tmp_dir_abs_path=self._tmp_dir_path)
self.path_image_data = self.project._load_input_image_to_memmap(tmp_dir_abs_path=self._tmp_dir_path)
self.path_seg_masks = self.filehandler._load_seg_to_memmap(
seg_name=self.masks, tmp_dir_abs_path=self._tmp_dir_path
)
self.path_image_data = self.filehandler._load_input_image_to_memmap(tmp_dir_abs_path=self._tmp_dir_path)

stop_data_transfer = timeit.default_timer()
time_data_transfer = stop_data_transfer - start_data_transfer
Expand Down
Loading
Loading