cytocommunity2 0.1.2__tar.gz → 0.1.3__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 (42) hide show
  1. {cytocommunity2-0.1.2/src/cytocommunity2.egg-info → cytocommunity2-0.1.3}/PKG-INFO +1 -2
  2. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/README.md +0 -1
  3. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/pyproject.toml +1 -1
  4. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/plotting/recurrence.py +1 -1
  5. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/learning/api.py +7 -10
  6. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/learning/dataset.py +9 -7
  7. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/learning/selection.py +28 -3
  8. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3/src/cytocommunity2.egg-info}/PKG-INFO +1 -2
  9. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/LICENSE +0 -0
  10. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/setup.cfg +0 -0
  11. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/__init__.py +0 -0
  12. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/colors.py +0 -0
  13. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/config.py +0 -0
  14. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/__init__.py +0 -0
  15. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/coherence.py +0 -0
  16. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/communication/__init__.py +0 -0
  17. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/communication/between.py +0 -0
  18. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/communication/cca.py +0 -0
  19. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/communication/utils.py +0 -0
  20. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/communication/within.py +0 -0
  21. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/composition.py +0 -0
  22. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/moran.py +0 -0
  23. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/plotting/__init__.py +0 -0
  24. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/plotting/cn_selection.py +0 -0
  25. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/plotting/coherence.py +0 -0
  26. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/plotting/common.py +0 -0
  27. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/plotting/communication.py +0 -0
  28. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/plotting/composition.py +0 -0
  29. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/plotting/dominant.py +0 -0
  30. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/plotting/dotplots.py +0 -0
  31. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/downstream/runtime.py +0 -0
  32. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/ensemble.py +0 -0
  33. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/learning/__init__.py +0 -0
  34. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/learning/model.py +0 -0
  35. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/learning/training.py +0 -0
  36. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/paths.py +0 -0
  37. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/visualization/__init__.py +0 -0
  38. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2/visualization/spatial.py +0 -0
  39. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2.egg-info/SOURCES.txt +0 -0
  40. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2.egg-info/dependency_links.txt +0 -0
  41. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/src/cytocommunity2.egg-info/requires.txt +0 -0
  42. {cytocommunity2-0.1.2 → cytocommunity2-0.1.3}/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.2
3
+ Version: 0.1.3
4
4
  Summary: Weakly supervised cellular-neighborhood learning for spatial omics
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -81,7 +81,6 @@ conda create -n cytocommunity2 python=3.10
81
81
  conda activate cytocommunity2
82
82
  ```
83
83
 
84
- Install PyTorch for your compute platform before installing CytoCommunity2.
85
84
  For an NVIDIA GPU on Windows or Linux, first install the appropriate
86
85
  CUDA-enabled PyTorch build from the
87
86
  [official PyTorch installation page](https://pytorch.org/get-started/locally/).
@@ -60,7 +60,6 @@ conda create -n cytocommunity2 python=3.10
60
60
  conda activate cytocommunity2
61
61
  ```
62
62
 
63
- Install PyTorch for your compute platform before installing CytoCommunity2.
64
63
  For an NVIDIA GPU on Windows or Linux, first install the appropriate
65
64
  CUDA-enabled PyTorch build from the
66
65
  [official PyTorch installation page](https://pytorch.org/get-started/locally/).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cytocommunity2"
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
  description = "Weakly supervised cellular-neighborhood learning for spatial omics"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -62,7 +62,7 @@ def plot_recurrence_results(config):
62
62
  output_dir.mkdir(parents=True, exist_ok=True)
63
63
  real = pd.read_csv(overlap_dir / "RealDistribution_sameCN.csv")
64
64
  background = pd.read_csv(overlap_dir / "BackgroundDistribution_randomCN.csv")
65
- tests = pd.read_csv(overlap_dir / "KSTest_Results.csv")
65
+ tests = pd.read_csv(overlap_dir / "TTest_Results.csv")
66
66
  real["CN"] = real["CN"].astype(str).str.strip()
67
67
  real["OverlapCoefficient"] = pd.to_numeric(real["OverlapCoefficient"], errors="coerce")
68
68
  background["OverlapCoefficient"] = pd.to_numeric(
@@ -7,8 +7,9 @@ import shutil
7
7
 
8
8
  import pandas as pd
9
9
 
10
- from ..config import CytoCommunityConfig
11
- from ..ensemble import ensemble_cn
10
+ from ..config import CytoCommunityConfig
11
+ from ..ensemble import ensemble_cn
12
+ from ..paths import build_paths
12
13
  from .dataset import SpatialGraphDataset
13
14
  from .model import TrainingConfig
14
15
  from .selection import evaluate_cn_num, select_cn_num
@@ -33,11 +34,9 @@ class LearningResult:
33
34
  def load_learning_result(
34
35
  dataset: SpatialGraphDataset,
35
36
  config: CytoCommunityConfig,
36
- *,
37
- output_dir,
38
37
  ) -> LearningResult:
39
38
  """Restore a :class:`LearningResult` from a completed learning run."""
40
- output_dir = Path(output_dir).expanduser().resolve()
39
+ output_dir = build_paths(config).learning_output
41
40
  paths = {
42
41
  "selected CN number": output_dir / "SelectedCNNum.txt",
43
42
  "cell-type list": output_dir / "UniqueCellTypeList.txt",
@@ -86,13 +85,11 @@ def _training_config(config, num_cn, num_class):
86
85
 
87
86
 
88
87
  def run_learning(
89
- dataset: SpatialGraphDataset,
90
- config: CytoCommunityConfig,
91
- *,
92
- output_dir,
88
+ dataset: SpatialGraphDataset,
89
+ config: CytoCommunityConfig,
93
90
  ) -> LearningResult:
94
91
  """Select the CN number, train final runs, and export consensus labels."""
95
- output_dir = Path(output_dir).expanduser().resolve()
92
+ output_dir = build_paths(config).learning_output
96
93
  input_dir = config.input_dir
97
94
  unique_celltypes_file = output_dir / "UniqueCellTypeList.txt"
98
95
  selected_model_dir = output_dir / "SelectedModel"
@@ -5,9 +5,11 @@ from pathlib import Path
5
5
  import numpy as np
6
6
  from scipy.sparse import csr_matrix
7
7
  from sklearn.neighbors import NearestNeighbors
8
- import torch
9
- from torch_geometric.data import Data
10
-
8
+ import torch
9
+ from torch_geometric.data import Data
10
+
11
+ from ..config import CytoCommunityConfig
12
+
11
13
 
12
14
  class SpatialGraphDataset(torch.utils.data.Dataset):
13
15
  """In-memory collection of real spatial graphs."""
@@ -64,9 +66,9 @@ def _build_knn_edge_index(coordinates, knn_k):
64
66
  ).contiguous()
65
67
 
66
68
 
67
- def build_spatial_graphs(input_dir, *, knn_k):
68
- """Read real samples and construct their coordinate-based KNN graphs once."""
69
- input_folder = Path(input_dir)
69
+ def build_spatial_graphs(config: CytoCommunityConfig):
70
+ """Build spatial graphs from the input folder associated with ``config``."""
71
+ input_folder = config.input_dir
70
72
  sample_names = _read_lines(input_folder / "ImageNameList.txt")
71
73
  labels_by_sample = {
72
74
  sample: _read_lines(input_folder / f"{sample}_CellTypeLabel.txt")
@@ -125,7 +127,7 @@ def build_spatial_graphs(input_dir, *, knn_k):
125
127
  data_list.append(Data(
126
128
  x=x,
127
129
  y=torch.tensor([training_label], dtype=torch.long),
128
- edge_index=_build_knn_edge_index(coordinates, knn_k),
130
+ edge_index=_build_knn_edge_index(coordinates, config.main.knn_k),
129
131
  ))
130
132
 
131
133
  return SpatialGraphDataset(
@@ -5,8 +5,10 @@ from pathlib import Path
5
5
 
6
6
  import numpy as np
7
7
  import pandas as pd
8
- from scipy.stats import hypergeom, ttest_ind
9
-
8
+ from scipy.stats import hypergeom, ttest_ind
9
+
10
+ from ..paths import build_paths
11
+
10
12
 
11
13
  MIN_FLOAT_P = np.finfo(np.float64).tiny
12
14
 
@@ -419,7 +421,30 @@ def evaluate_cn_num(
419
421
  return result, per_cn.copy()
420
422
 
421
423
 
422
- def select_cn_num(results):
424
+ def evaluate_selected_cn(result, config):
425
+ """Evaluate the selected model using the configured project layout."""
426
+ paths = build_paths(config)
427
+ metrics, recurrence = evaluate_cn_num(
428
+ num_cn=result.selected_cn,
429
+ dataset=result.input_dir,
430
+ cn_label_dir=result.hard_assignment_dir,
431
+ celltype_file=result.unique_celltypes_file,
432
+ output_dir=paths.downstream_data,
433
+ enrichment_p_threshold=config.enrichment.p_value_threshold,
434
+ minimum_adjusted_p=config.enrichment.minimum_adjusted_p,
435
+ recurrence_p_threshold=config.recurrence.recurrence_p_threshold,
436
+ n_random=config.recurrence.null_draws,
437
+ seed=config.random_seed,
438
+ )
439
+ export_enrichment_long(
440
+ dataset=result.input_dir,
441
+ enrichment_dir=paths.enrichment,
442
+ output_file=paths.communication_config / "EnrichScoreMatrix_long.csv",
443
+ )
444
+ return metrics, recurrence
445
+
446
+
447
+ def select_cn_num(results):
423
448
  """Select maximum score, using smaller K as the deterministic tie-break."""
424
449
  if not results:
425
450
  raise ValueError("No CN-number results were supplied")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cytocommunity2
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Weakly supervised cellular-neighborhood learning for spatial omics
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -81,7 +81,6 @@ conda create -n cytocommunity2 python=3.10
81
81
  conda activate cytocommunity2
82
82
  ```
83
83
 
84
- Install PyTorch for your compute platform before installing CytoCommunity2.
85
84
  For an NVIDIA GPU on Windows or Linux, first install the appropriate
86
85
  CUDA-enabled PyTorch build from the
87
86
  [official PyTorch installation page](https://pytorch.org/get-started/locally/).
File without changes
File without changes