cytocommunity2 0.1.6__tar.gz → 0.1.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {cytocommunity2-0.1.6/src/cytocommunity2.egg-info → cytocommunity2-0.1.7}/PKG-INFO +1 -1
  2. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/pyproject.toml +1 -1
  3. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/__init__.py +1 -1
  4. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/plotting/dominant.py +1 -4
  5. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/plotting/recurrence.py +76 -6
  6. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7/src/cytocommunity2.egg-info}/PKG-INFO +1 -1
  7. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/LICENSE +0 -0
  8. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/README.md +0 -0
  9. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/setup.cfg +0 -0
  10. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/colors.py +0 -0
  11. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/config.py +0 -0
  12. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/__init__.py +0 -0
  13. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/coherence.py +0 -0
  14. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/communication/__init__.py +0 -0
  15. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/communication/between.py +0 -0
  16. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/communication/cca.py +0 -0
  17. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/communication/utils.py +0 -0
  18. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/communication/within.py +0 -0
  19. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/differential_composition.py +0 -0
  20. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/dominant_celltype.py +0 -0
  21. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/moran.py +0 -0
  22. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/plotting/__init__.py +0 -0
  23. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/plotting/cn_selection.py +0 -0
  24. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/plotting/coherence.py +0 -0
  25. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/plotting/common.py +0 -0
  26. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/plotting/communication.py +0 -0
  27. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/plotting/composition.py +0 -0
  28. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/plotting/dotplots.py +0 -0
  29. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/downstream/runtime.py +0 -0
  30. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/ensemble.py +0 -0
  31. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/learning/__init__.py +0 -0
  32. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/learning/api.py +0 -0
  33. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/learning/dataset.py +0 -0
  34. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/learning/model.py +0 -0
  35. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/learning/selection.py +0 -0
  36. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/learning/training.py +0 -0
  37. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/paths.py +0 -0
  38. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/visualization/__init__.py +0 -0
  39. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2/visualization/spatial.py +0 -0
  40. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2.egg-info/SOURCES.txt +0 -0
  41. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2.egg-info/dependency_links.txt +0 -0
  42. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2.egg-info/requires.txt +0 -0
  43. {cytocommunity2-0.1.6 → cytocommunity2-0.1.7}/src/cytocommunity2.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cytocommunity2
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: Weakly supervised cellular-neighborhood learning for spatial omics
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cytocommunity2"
7
- version = "0.1.6"
7
+ version = "0.1.7"
8
8
  description = "Weakly supervised cellular-neighborhood learning for spatial omics"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -10,7 +10,7 @@ from .learning import (
10
10
  )
11
11
  from .visualization import visualize_results
12
12
 
13
- __version__ = "0.1.6"
13
+ __version__ = "0.1.7"
14
14
 
15
15
  __all__ = [
16
16
  "CytoCommunityConfig",
@@ -53,10 +53,7 @@ def plot_dominant_celltype_results(result, config):
53
53
  label.set_horizontalalignment("right")
54
54
  heat_axis.tick_params(axis="x", length=0, bottom=True, top=False, labelbottom=True)
55
55
  heat_axis.tick_params(axis="y", length=0, pad=6)
56
- heat_axis.set_xticks(np.arange(-0.5, columns, 1), minor=True)
57
- heat_axis.set_yticks(np.arange(-0.5, rows, 1), minor=True)
58
- heat_axis.grid(which="minor", color="white", linewidth=0.35)
59
- heat_axis.tick_params(which="minor", bottom=False, left=False)
56
+ heat_axis.grid(False, which="both")
60
57
  for spine in heat_axis.spines.values():
61
58
  spine.set_visible(False)
62
59
  heatmap_output = output_dir / "heatmap_main.pdf"
@@ -8,6 +8,8 @@ from ...paths import build_paths
8
8
 
9
9
  NULL_LABEL = "Random-CN null distribution"
10
10
  NULL_COLOR = "#0071B2"
11
+ CN_PALETTE = "d3_category20"
12
+ DENSITY_NULL_COLOR = "#B8B8B8"
11
13
 
12
14
 
13
15
  def _significance_label(pvalue):
@@ -28,11 +30,11 @@ def _kde_curve(values, x_grid):
28
30
  if len(values) == 0:
29
31
  return np.zeros_like(x_grid)
30
32
  if np.allclose(values, values[0]):
31
- density = np.zeros_like(x_grid)
32
- density[np.argmin(np.abs(x_grid - values[0]))] = 1.0
33
- density = np.convolve(density, np.array([0.2, 0.6, 0.2]), mode="same")
34
- area = np.trapz(density, x_grid)
35
- return density / area if area > 0 else density
33
+ # gaussian_kde cannot estimate a singular distribution. Draw a narrow,
34
+ # finite kernel so a constant-valued CN still remains visible.
35
+ bandwidth = 0.04
36
+ scaled = (x_grid - values[0]) / bandwidth
37
+ return np.exp(-0.5 * scaled**2) / (bandwidth * np.sqrt(2 * np.pi))
36
38
  try:
37
39
  return gaussian_kde(values)(x_grid)
38
40
  except Exception:
@@ -40,8 +42,21 @@ def _kde_curve(values, x_grid):
40
42
  return np.interp(x_grid, (edges[:-1] + edges[1:]) / 2, hist, left=0, right=0)
41
43
 
42
44
 
45
+ def _cn_color_map(cn_levels):
46
+ """Return the same CN-to-color mapping used by the spatial CN plots."""
47
+ import sci_palettes
48
+
49
+ colors = list(sci_palettes.PALETTES[CN_PALETTE].values())
50
+ if len(cn_levels) > len(colors):
51
+ raise ValueError(
52
+ f"Palette {CN_PALETTE!r} has {len(colors)} colors, but "
53
+ f"{len(cn_levels)} CNs were provided."
54
+ )
55
+ return dict(zip(cn_levels, colors))
56
+
57
+
43
58
  def plot_recurrence_results(config):
44
- """Save the three original recurrence violin/KDE figures."""
59
+ """Save recurrence violin/KDE figures, including per-CN densities."""
45
60
  import matplotlib as mpl
46
61
  import matplotlib.pyplot as plt
47
62
  import seaborn as sns
@@ -196,8 +211,63 @@ def plot_recurrence_results(config):
196
211
  kde_output = output_dir / "Overall_Real_vs_randomCN_null_KDE.pdf"
197
212
  figure.savefig(kde_output, dpi=1200)
198
213
  plt.close(figure)
214
+
215
+ cn_colors = _cn_color_map(cn_levels)
216
+ null_density = _kde_curve(background_values, x_grid)
217
+ figure, axis = plt.subplots(figsize=(8.4, 5.8))
218
+ axis.fill_between(
219
+ x_grid, 0, null_density, color=DENSITY_NULL_COLOR, alpha=0.18, zorder=0
220
+ )
221
+ axis.plot(
222
+ x_grid,
223
+ null_density,
224
+ color=DENSITY_NULL_COLOR,
225
+ linewidth=2.2,
226
+ linestyle="--",
227
+ label="Null distribution",
228
+ zorder=1,
229
+ )
230
+ for cn in cn_levels:
231
+ values = real.loc[real["CN"] == cn, "OverlapCoefficient"].to_numpy()
232
+ density = _kde_curve(values, x_grid)
233
+ color = cn_colors[cn]
234
+ axis.fill_between(x_grid, 0, density, color=color, alpha=0.09, zorder=2)
235
+ axis.plot(x_grid, density, color=color, linewidth=2.0, label=cn, zorder=3)
236
+
237
+ axis.set_xlabel("Overlap of dominant celltypes across samples")
238
+ axis.set_ylabel("Density")
239
+ axis.set_xlim(0, 1)
240
+ axis.set_ylim(bottom=0)
241
+ axis.spines["top"].set_visible(False)
242
+ axis.spines["right"].set_visible(False)
243
+ handles, labels = axis.get_legend_handles_labels()
244
+ legend_columns = min(6, len(labels))
245
+ legend_order = [
246
+ index
247
+ for column in range(legend_columns)
248
+ for index in (column, legend_columns + column)
249
+ if index < len(labels)
250
+ ]
251
+ axis.legend(
252
+ [handles[index] for index in legend_order],
253
+ [labels[index] for index in legend_order],
254
+ frameon=False,
255
+ ncol=legend_columns,
256
+ loc="upper center",
257
+ bbox_to_anchor=(0.5, -0.17),
258
+ columnspacing=1.25,
259
+ handlelength=2.0,
260
+ )
261
+ figure.subplots_adjust(left=0.12, right=0.98, bottom=0.25, top=0.96)
262
+ by_cn_density_output = output_dir / "OC_density_by_CN_with_randomCN_null.pdf"
263
+ figure.savefig(by_cn_density_output, dpi=1200, bbox_inches="tight")
264
+ figure.savefig(
265
+ by_cn_density_output.with_suffix(".png"), dpi=300, bbox_inches="tight"
266
+ )
267
+ plt.close(figure)
199
268
  return {
200
269
  "by_cn": detailed_output,
201
270
  "pooled": pooled_output,
202
271
  "kde": kde_output,
272
+ "by_cn_density": by_cn_density_output,
203
273
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cytocommunity2
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: Weakly supervised cellular-neighborhood learning for spatial omics
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
File without changes
File without changes
File without changes