symphonypy 0.2.2__tar.gz → 0.2.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.
- {symphonypy-0.2.2/symphonypy.egg-info → symphonypy-0.2.3}/PKG-INFO +1 -1
- {symphonypy-0.2.2 → symphonypy-0.2.3}/setup.cfg +1 -1
- {symphonypy-0.2.2 → symphonypy-0.2.3}/symphonypy/_utils.py +26 -7
- {symphonypy-0.2.2 → symphonypy-0.2.3}/symphonypy/tl.py +4 -6
- {symphonypy-0.2.2 → symphonypy-0.2.3/symphonypy.egg-info}/PKG-INFO +1 -1
- {symphonypy-0.2.2 → symphonypy-0.2.3}/LICENSE +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/README.md +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/pyproject.toml +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/symphonypy/__init__.py +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/symphonypy/datasets.py +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/symphonypy/pp.py +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/symphonypy.egg-info/SOURCES.txt +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/symphonypy.egg-info/dependency_links.txt +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/symphonypy.egg-info/requires.txt +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/symphonypy.egg-info/top_level.txt +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/tests/test_preprocessing.py +0 -0
- {symphonypy-0.2.2 → symphonypy-0.2.3}/tests/test_tools.py +0 -0
|
@@ -24,6 +24,7 @@ def _harmony_integrate_python(
|
|
|
24
24
|
ref_basis_adjusted: str = "X_pca_harmony",
|
|
25
25
|
ref_basis_loadings: str = "PCs",
|
|
26
26
|
verbose: bool = False,
|
|
27
|
+
force_transpose_output: bool = False,
|
|
27
28
|
**harmony_kwargs,
|
|
28
29
|
) -> None:
|
|
29
30
|
ref_ho = run_harmony(
|
|
@@ -34,22 +35,40 @@ def _harmony_integrate_python(
|
|
|
34
35
|
**harmony_kwargs,
|
|
35
36
|
)
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
# compatibility with old harmonypy implementations:
|
|
39
|
+
if ref_ho.Z_corr.shape[0] != adata.shape[0] or force_transpose_output:
|
|
40
|
+
logger.info(
|
|
41
|
+
"Assuming that the second dimension of Z_corr is the number of cells, transposing the output of harmonypy. "
|
|
42
|
+
)
|
|
43
|
+
Z_corr = ref_ho.Z_corr.T
|
|
44
|
+
R = ref_ho.R
|
|
45
|
+
else:
|
|
46
|
+
logger.info(
|
|
47
|
+
"Assuming that the first dimension of Z_corr is the number of cells, not transposing the output of harmonypy. "
|
|
48
|
+
)
|
|
49
|
+
if ref_ho.Z_corr.shape[0] == ref_ho.Z_corr.shape[1]:
|
|
50
|
+
logger.warning(
|
|
51
|
+
"Number of cells in the output of harmonypy is equal to the number of dimensions, can't automatically determine if transposition is needed. Use force_transpose_output parameter to specify the correct orientation of the output."
|
|
52
|
+
)
|
|
53
|
+
Z_corr = ref_ho.Z_corr
|
|
54
|
+
R = ref_ho.R.T
|
|
55
|
+
|
|
56
|
+
adata.obsm[ref_basis_adjusted] = Z_corr
|
|
38
57
|
|
|
39
58
|
converged = ref_ho.check_convergence(1)
|
|
40
59
|
|
|
41
|
-
# [K, d] = [K, Nref] x [
|
|
42
|
-
C =
|
|
60
|
+
# [K, d] = [K, Nref] x [N_ref, d]
|
|
61
|
+
C = R @ Z_corr
|
|
43
62
|
|
|
44
63
|
adata.uns["harmony"] = {
|
|
45
64
|
# [K] the number of cells softly belonging to each cluster
|
|
46
|
-
"Nr":
|
|
65
|
+
"Nr": R.sum(axis=1),
|
|
47
66
|
# ref cluster centroids
|
|
48
67
|
# [K, d]
|
|
49
68
|
"C": C,
|
|
50
69
|
# number of clusters
|
|
51
70
|
"K": ref_ho.K,
|
|
52
|
-
# sigma [K] (cluster cross
|
|
71
|
+
# sigma [K] (cluster cross entropy regularization coef)
|
|
53
72
|
"sigma": ref_ho.sigma,
|
|
54
73
|
"ref_basis_loadings": ref_basis_loadings,
|
|
55
74
|
"ref_basis_adjusted": ref_basis_adjusted,
|
|
@@ -57,7 +76,7 @@ def _harmony_integrate_python(
|
|
|
57
76
|
"harmony_kwargs": harmony_kwargs,
|
|
58
77
|
"converged": converged,
|
|
59
78
|
# [K, Nref]
|
|
60
|
-
"R":
|
|
79
|
+
"R": R,
|
|
61
80
|
}
|
|
62
81
|
|
|
63
82
|
if not converged:
|
|
@@ -141,7 +160,7 @@ def _harmony_integrate_R(
|
|
|
141
160
|
"converged": converged,
|
|
142
161
|
"R": R,
|
|
143
162
|
"harmony_kwargs": harmony_kwargs,
|
|
144
|
-
"vars_use": key
|
|
163
|
+
"vars_use": key,
|
|
145
164
|
}
|
|
146
165
|
adata.obsm[ref_basis_adjusted] = Z_corr
|
|
147
166
|
|
|
@@ -157,8 +157,8 @@ def per_cluster_confidence(
|
|
|
157
157
|
reference_cluster_centroids_norm = reference_cluster_centroids / np.linalg.norm(
|
|
158
158
|
reference_cluster_centroids, ord=2, axis=1, keepdims=True
|
|
159
159
|
)
|
|
160
|
-
|
|
161
|
-
dists =
|
|
160
|
+
grouped = adata_query.obs.groupby(cluster_key, observed=True)
|
|
161
|
+
dists = grouped.apply(
|
|
162
162
|
_cluster_maha_dist,
|
|
163
163
|
adata_query,
|
|
164
164
|
transferred_primary_basis=transferred_primary_basis,
|
|
@@ -175,8 +175,7 @@ def per_cluster_confidence(
|
|
|
175
175
|
"cluster_labels": dists.index.to_numpy(),
|
|
176
176
|
}
|
|
177
177
|
if obs is not None:
|
|
178
|
-
|
|
179
|
-
adata_query.obs[obs] = grouped.transform(lambda x: dists[x[0]])
|
|
178
|
+
adata_query.obs[obs] = grouped[cluster_key].transform(lambda x: dists[x.name])
|
|
180
179
|
|
|
181
180
|
|
|
182
181
|
def ingest(
|
|
@@ -260,7 +259,7 @@ def ingest(
|
|
|
260
259
|
for i, col in enumerate(obs):
|
|
261
260
|
ing.map_labels(col, labeling_method[i])
|
|
262
261
|
|
|
263
|
-
logger.info("
|
|
262
|
+
logger.info("finished")
|
|
264
263
|
|
|
265
264
|
if "rep" in ing._obsm:
|
|
266
265
|
del ing._obsm["rep"]
|
|
@@ -465,7 +464,6 @@ def tsne(
|
|
|
465
464
|
:type return_model: bool, optional
|
|
466
465
|
"""
|
|
467
466
|
|
|
468
|
-
|
|
469
467
|
import pickle
|
|
470
468
|
|
|
471
469
|
try:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|