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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: symphonypy
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Porting of Symphony R package to Python
5
5
  Home-page: https://github.com/potulabe/symphonypy
6
6
  Author: Kseniya Petrova, Sergey Isaev
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = symphonypy
3
- version = 0.2.2
3
+ version = 0.2.3
4
4
  author = Kseniya Petrova, Sergey Isaev
5
5
  author_email = praefrontalis@gmail.com, serj.hoop@gmail.com
6
6
  description = Porting of Symphony R package to Python
@@ -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
- adata.obsm[ref_basis_adjusted] = ref_ho.Z_corr.T
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 [d, N_ref].T
42
- C = ref_ho.R @ ref_ho.Z_corr.T
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": ref_ho.R.sum(axis=1),
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 enthropy regularization coef)
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": ref_ho.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 = adata_query.obs.groupby(cluster_key).apply(
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
- grouped = adata_query.obs.groupby(cluster_key)[cluster_key]
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(" finished", time=start)
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: symphonypy
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Porting of Symphony R package to Python
5
5
  Home-page: https://github.com/potulabe/symphonypy
6
6
  Author: Kseniya Petrova, Sergey Isaev
File without changes
File without changes
File without changes
File without changes