Skip to content

Commit 724c8ad

Browse files
committed
presence test
1 parent 699aefc commit 724c8ad

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎src/scloop/computing/coherence.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _greedy_reversal(
9494
triangles: tuple[frozenset[int], ...],
9595
num_vertices: int,
9696
embedding: np.ndarray,
97-
death_scale: float | None = None,
97+
death_scale: float,
9898
) -> float | None:
9999
target_coords = _cycle_coords(target, num_vertices, embedding)
100100
source_coords = _cycle_coords(source, num_vertices, embedding)
@@ -165,7 +165,7 @@ def path_finding_coherence(
165165
triangles: Sequence[Sequence[int]],
166166
num_vertices: int,
167167
embedding: np.ndarray,
168-
death_scale: float | None = None,
168+
death_scale: float,
169169
) -> float | None:
170170

171171
source = frozenset(source_edges)
@@ -201,7 +201,7 @@ def compute_coherence(
201201
triangles: Sequence[Sequence[int]],
202202
num_vertices: int,
203203
embedding: np.ndarray,
204-
death_scale: float | None = None,
204+
death_scale: float,
205205
method: HomotopyCoherenceMethod = "path_finding",
206206
) -> float | None:
207207
return path_finding_coherence(

‎src/scloop/data/analysis_containers.py‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pydantic import BaseModel, ConfigDict, Field
88
from pydantic.dataclasses import dataclass
99
from pynndescent import NNDescent
10-
from scipy.stats import chi2_contingency, fisher_exact, gamma
10+
from scipy.stats import chi2_contingency, fisher_exact, gamma, wilcoxon
1111
from scipy.stats.contingency import odds_ratio
1212

1313
from ..computing import compute_weighted_hodge_embedding
@@ -501,15 +501,15 @@ def summarize_homotopy_coherence(
501501
self,
502502
mode: Literal["full", "mean", "median"] = "full",
503503
mode_match: Literal["max", "mean", "median"] = "max",
504-
) -> list[Percent_t | None] | Percent_t | None:
504+
) -> list[tuple] | Percent_t | None:
505505
values = [
506-
match.summarize_homotopy_coherence(mode=mode_match)
506+
(match.idx_bootstrap, match.summarize_homotopy_coherence(mode=mode_match))
507507
for match in self.filter_matches(keep="equivalent")
508508
]
509509
if mode == "full":
510510
return values
511511

512-
valid_values = [value for value in values if value is not None]
512+
valid_values = [value[1] for value in values if value[1] is not None]
513513
if not valid_values:
514514
return None
515515
match mode:
@@ -752,6 +752,35 @@ def chi2_test_presence(
752752
pvalues_corrected=pvalues_corrected_presence,
753753
)
754754

755+
def wilcoxon_test_presence(
756+
self, method_pval_correction: MultipleTestCorrectionMethod
757+
):
758+
n_tracks = len(self.loop_tracks)
759+
presence_matrix = np.zeros([self.num_bootstraps, n_tracks])
760+
for ti, trk in self.loop_tracks.items():
761+
coherence_values = trk.summarize_homotopy_coherence(
762+
mode="full",
763+
mode_match="mean",
764+
)
765+
for bi, cv in coherence_values:
766+
presence_matrix[bi, ti] = cv if cv else 0
767+
presence_global = np.mean(presence_matrix, axis=1)
768+
pvalues_raw_presence = []
769+
for i in range(n_tracks):
770+
result = wilcoxon(
771+
x=presence_matrix[:, i], y=presence_global, alternative="greater"
772+
)
773+
pvalues_raw_presence.append(result.pvalue)
774+
pvalues_corrected_presence = correct_pvalues(
775+
pvalues_raw_presence, method=method_pval_correction
776+
)
777+
return PresenceTestResult(
778+
probabilities=[],
779+
odds_ratios=[],
780+
pvalues_raw=pvalues_raw_presence,
781+
pvalues_corrected=pvalues_corrected_presence,
782+
)
783+
755784
def gamma_test_persistence(
756785
self,
757786
selected_loop_classes: list,

0 commit comments

Comments
 (0)