-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sc 41 optimize flowsom clustering (#81)
* 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
- Loading branch information
1 parent
53a717f
commit 1d5fc0f
Showing
9 changed files
with
518 additions
and
1,317 deletions.
There are no files selected for viewing
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
1,409 changes: 102 additions & 1,307 deletions
1,409
docs/tutorials/general/FlowSOM_for_pixel_and_cell_clustering.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
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,68 @@ | ||
import importlib | ||
import os | ||
|
||
import matplotlib | ||
import pytest | ||
|
||
from harpy.plot._flowsom import pixel_clusters, pixel_clusters_heatmap | ||
|
||
|
||
@pytest.mark.skipif(not importlib.util.find_spec("flowsom"), reason="requires the flowSOM library") | ||
def test_plot_pixel_clusters(sdata_blobs, tmp_path): | ||
from harpy.image.pixel_clustering._clustering import flowsom | ||
from harpy.table.pixel_clustering._cluster_intensity import cluster_intensity | ||
|
||
matplotlib.use("Agg") | ||
|
||
img_layer = "blobs_image" | ||
channels = ["lineage_0", "lineage_1", "lineage_5", "lineage_9"] | ||
fraction = 0.1 | ||
|
||
sdata_blobs, fsom, mapping = flowsom( | ||
sdata_blobs, | ||
img_layer=[img_layer], | ||
output_layer_clusters=[f"{img_layer}_clusters"], | ||
output_layer_metaclusters=[f"{img_layer}_metaclusters"], | ||
channels=channels, | ||
fraction=fraction, | ||
n_clusters=20, | ||
random_state=100, | ||
chunks=(1, 200, 200), | ||
overwrite=True, | ||
) | ||
|
||
assert f"{img_layer}_clusters" in sdata_blobs.labels | ||
assert f"{img_layer}_metaclusters" in sdata_blobs.labels | ||
assert fsom.model._is_fitted | ||
|
||
pixel_clusters( | ||
sdata_blobs, | ||
labels_layer="blobs_image_metaclusters", | ||
figsize=(10, 10), | ||
coordinate_systems="global", | ||
crd=(100, 300, 100, 300), | ||
output=os.path.join(tmp_path, "pixel_clusters.png"), | ||
) | ||
|
||
sdata_blobs = cluster_intensity( | ||
sdata_blobs, | ||
mapping=mapping, | ||
img_layer=[img_layer], | ||
labels_layer=[f"{img_layer}_clusters"], | ||
to_coordinate_system=["global"], | ||
output_layer="counts_clusters", | ||
chunks="auto", | ||
overwrite=True, | ||
) | ||
|
||
for _metaclusters in [True, False]: | ||
pixel_clusters_heatmap( | ||
sdata_blobs, | ||
table_layer="counts_clusters", | ||
figsize=(30, 20), | ||
fig_kwargs={"dpi": 100}, | ||
linewidths=0.01, | ||
metaclusters=_metaclusters, | ||
z_score=True, | ||
output=os.path.join(tmp_path, f"pixel_clusters_heatmap_{_metaclusters}.png"), | ||
) |
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
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
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
Oops, something went wrong.