Skip to content

Commit

Permalink
Sc 41 optimize flowsom clustering (#82)
Browse files Browse the repository at this point in the history
* SC_41_z_score

* SC_41 plot clusters

* SC_41 flowsom

* SC_41 flowsom clusering visualization

* SC_41 test flowsom

* SC_41 docs

* SC_41 update docstring

* SC_41 docs

* SC_41 docs
  • Loading branch information
ArneDefauw authored Jan 8, 2025
1 parent 1d5fc0f commit c9e22bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/harpy/image/pixel_clustering/_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def flowsom(
sdata
The input SpatialData object.
img_layer
The image layer(s) of `sdata` on which flowsom is run. It is recommended to preprocess the data with `harpy.im.pixel_clustering_preprocess`.
The image layer(s) of `sdata` on which flowsom is run. It is recommended to preprocess the data with :func:`harpy.im.pixel_clustering_preprocess`.
output_layer_clusters
The output labels layer in `sdata` to which labels layer with predicted flowsom SOM clusters are saved.
output_layer_metaclusters
Expand Down Expand Up @@ -107,7 +107,7 @@ def flowsom(
Warnings
--------
- The function is intended for use with spatial proteomics data. Input data should be appropriately preprocessed
(e.g. via `harpy.im.pixel_clustering_preprocess`) to ensure meaningful clustering results.
(e.g. via :func:`harpy.im.pixel_clustering_preprocess`) to ensure meaningful clustering results.
- The cluster and metacluster ID's found in `output_layer_clusters` and `output_layer_metaclusters` count from 1, while they count from 0 in the `FlowSOM` object.
"""
assert 0 < fraction <= 1, "Value must be between 0 and 1"
Expand Down
16 changes: 10 additions & 6 deletions src/harpy/plot/_flowsom.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def pixel_clusters(
**kwargs, # passed to pl.show() of spatialdata_plot
):
"""
Visualize spatial distribution of pixel clusters based on labels in a `SpatialData` object, obtained using `harpy.im.flowsom`.
Visualize spatial distribution of pixel clusters based on labels in a `SpatialData` object, obtained using :func:`harpy.im.flowsom`.
Parameters
----------
Expand Down Expand Up @@ -163,7 +163,7 @@ def pixel_clusters_heatmap(
sdata
The input SpatialData object.
table_layer
The table layer in `sdata` containing cluster intensity for clusters and metaclusters, obtained via `hp.tb.cluster_intensity`.
The table layer in `sdata` containing cluster intensity for clusters and metaclusters, obtained via :func:`harpy.tb.cluster_intensity`.
metaclusters
Whether to display mean channel intensity per metacluster (`True`) or per cluster (`False`).
z_score
Expand All @@ -172,13 +172,17 @@ def pixel_clusters_heatmap(
The value to clip the z-scored data to, for better visualization. If `None`, no clipping is performed.
Ignored if `z_score` is `False`.
output
The path to save the generated heatmap. If `None`, the heatmap will be displayed directly using `plt.show()`.
The path to save the generated heatmap. If `None`, the heatmap will be displayed directly using :func:`matplotlib.pyplot.show`.
figsize
Size of the figure in inches (width, height).
Tuple specifying the size of the figure in inches as `(width, height)`.
The width determines the spacing available for cluster IDs, while the height adjusts space for channels.
If labels (cluster IDs or channel names) are truncated, increase the respective dimension.
Increase `width` if cluster IDs or are not fully visible.
Increase `height` if channel names are not fully visible.
fig_kwargs
Additional keyword arguments passed to `plt.figure`, such as `dpi`.
Additional keyword arguments passed to :func:`matplotlib.pyplot.figure`, such as `dpi`.
**kwargs
Additional keyword arguments passed to `sns.heatmap`, such as `annot`, `cmap`, or `cbar_kws`.
Additional keyword arguments passed to :func:`seaborn.heatmap`, such as `annot`, `cmap`, or `cbar_kws`.
Returns
-------
Expand Down

0 comments on commit c9e22bb

Please sign in to comment.