scFates 1.2.4__tar.gz → 1.2.6__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 (61) hide show
  1. {scfates-1.2.4/scFates.egg-info → scfates-1.2.6}/PKG-INFO +2 -1
  2. {scfates-1.2.4 → scfates-1.2.6}/pyproject.toml +3 -0
  3. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/milestones.py +0 -1
  4. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/trajectory.py +2 -2
  5. {scfates-1.2.4 → scfates-1.2.6}/scFates/tests/test_w_plots.py +12 -0
  6. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/bifurcation_tools.py +3 -1
  7. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/dendrogram.py +1 -1
  8. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/linearity_deviation.py +39 -0
  9. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/pseudotime.py +1 -1
  10. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/slide_cors.py +18 -10
  11. {scfates-1.2.4 → scfates-1.2.6/scFates.egg-info}/PKG-INFO +2 -1
  12. {scfates-1.2.4 → scfates-1.2.6}/scFates.egg-info/requires.txt +1 -0
  13. {scfates-1.2.4 → scfates-1.2.6}/LICENSE +0 -0
  14. {scfates-1.2.4 → scfates-1.2.6}/MANIFEST.in +0 -0
  15. {scfates-1.2.4 → scfates-1.2.6}/README.md +0 -0
  16. {scfates-1.2.4 → scfates-1.2.6}/scFates/__init__.py +0 -0
  17. {scfates-1.2.4 → scfates-1.2.6}/scFates/datasets/__init__.py +0 -0
  18. {scfates-1.2.4 → scfates-1.2.6}/scFates/datasets/_datasets.py +0 -0
  19. {scfates-1.2.4 → scfates-1.2.6}/scFates/datasets/test.h5ad +0 -0
  20. {scfates-1.2.4 → scfates-1.2.6}/scFates/get/__init__.py +0 -0
  21. {scfates-1.2.4 → scfates-1.2.6}/scFates/get/get.py +0 -0
  22. {scfates-1.2.4 → scfates-1.2.6}/scFates/logging.py +0 -0
  23. {scfates-1.2.4 → scfates-1.2.6}/scFates/pl.py +0 -0
  24. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/__init__.py +0 -0
  25. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/binned_pseudotime_meta.py +0 -0
  26. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/covariate.py +0 -0
  27. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/dendrogram.py +0 -0
  28. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/features.py +0 -0
  29. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/linearity_deviation.py +0 -0
  30. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/matrix.py +0 -0
  31. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/module_inclusion.py +0 -0
  32. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/modules.py +0 -0
  33. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/palette_tools.py +0 -0
  34. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/palettes.py +0 -0
  35. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/slide_cors.py +0 -0
  36. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/synchro_path.py +0 -0
  37. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/test_association.py +0 -0
  38. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/test_fork.py +0 -0
  39. {scfates-1.2.4 → scfates-1.2.6}/scFates/plot/utils.py +0 -0
  40. {scfates-1.2.4 → scfates-1.2.6}/scFates/pp.py +0 -0
  41. {scfates-1.2.4 → scfates-1.2.6}/scFates/preprocessing/__init__.py +0 -0
  42. {scfates-1.2.4 → scfates-1.2.6}/scFates/preprocessing/diffusion.py +0 -0
  43. {scfates-1.2.4 → scfates-1.2.6}/scFates/preprocessing/pagoda2.py +0 -0
  44. {scfates-1.2.4 → scfates-1.2.6}/scFates/settings.py +0 -0
  45. {scfates-1.2.4 → scfates-1.2.6}/scFates/tl.py +0 -0
  46. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/__init__.py +0 -0
  47. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/_test_monocle3.R +0 -0
  48. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/cluster.py +0 -0
  49. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/conversion.py +0 -0
  50. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/correlation_tools.py +0 -0
  51. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/covariate.py +0 -0
  52. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/fit.py +0 -0
  53. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/graph_fitting.py +0 -0
  54. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/graph_operations.py +0 -0
  55. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/root.py +0 -0
  56. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/test_association.py +0 -0
  57. {scfates-1.2.4 → scfates-1.2.6}/scFates/tools/utils.py +0 -0
  58. {scfates-1.2.4 → scfates-1.2.6}/scFates.egg-info/SOURCES.txt +0 -0
  59. {scfates-1.2.4 → scfates-1.2.6}/scFates.egg-info/dependency_links.txt +0 -0
  60. {scfates-1.2.4 → scfates-1.2.6}/scFates.egg-info/top_level.txt +0 -0
  61. {scfates-1.2.4 → scfates-1.2.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scFates
3
- Version: 1.2.4
3
+ Version: 1.2.6
4
4
  Summary: scanpy compatible python suite for fast tree inference and advanced pseudotime downstream analysis
5
5
  Author: Louis Faure
6
6
  Project-URL: Repository, https://github.com/LouisFaure/scFates
@@ -13,6 +13,7 @@ Requires-Dist: tqdm>=4.45.0
13
13
  Requires-Dist: numba>=0.51.2
14
14
  Requires-Dist: scipy>=1.4.1
15
15
  Requires-Dist: scanpy>=1.7.0
16
+ Requires-Dist: umap-learn<0.6
16
17
  Requires-Dist: leidenalg>=0.8.1
17
18
  Requires-Dist: numpy
18
19
  Requires-Dist: joblib>=0.17.0
@@ -18,6 +18,9 @@ dependencies = [
18
18
  "numba>=0.51.2",
19
19
  "scipy>=1.4.1",
20
20
  "scanpy>=1.7.0",
21
+ # umap-learn 0.6 needs C-contiguous kNN arrays, not provided by scanpy <=1.12.5
22
+ # (fixed upstream in scverse/scanpy#4480); drop once a scanpy release ships it.
23
+ "umap-learn<0.6",
21
24
  "leidenalg>=0.8.1",
22
25
  "numpy",
23
26
  "joblib>=0.17.0",
@@ -100,7 +100,6 @@ def milestones(
100
100
  X = proj[list(adata.uns["graph"]["milestones"].values()), :]
101
101
  adata_m = sc.AnnData(
102
102
  X,
103
- dtype=X.dtype,
104
103
  obs=dict(mil=list(adata.uns["graph"]["milestones"].keys())),
105
104
  obsm={basis: X},
106
105
  )
@@ -484,7 +484,7 @@ def trajectory(
484
484
  headwidth=15 * scale_path,
485
485
  headaxislength=10 * scale_path,
486
486
  headlength=10 * scale_path,
487
- units="dots",
487
+ units="width",
488
488
  zorder=101,
489
489
  rasterized=rasterized,
490
490
  )
@@ -506,7 +506,7 @@ def trajectory(
506
506
  headwidth=12 * scale_path,
507
507
  headaxislength=10 * scale_path,
508
508
  headlength=10 * scale_path,
509
- units="dots",
509
+ units="width",
510
510
  color=c_arrow,
511
511
  zorder=102,
512
512
  rasterized=rasterized,
@@ -1,3 +1,4 @@
1
+ import pytest
1
2
  import scFates as scf
2
3
  import scanpy as sc
3
4
  import numpy as np
@@ -133,6 +134,17 @@ def test_pipeline():
133
134
 
134
135
  lindev = adata.var["43->88_rss"].values[:5]
135
136
 
137
+ # end milestone upstream of start milestone: no path along the tree direction
138
+ with pytest.raises(ValueError, match="No path found"):
139
+ scf.tl.linearity_deviation(adata, start_milestone="88", end_milestone="43")
140
+ # percentiles leaving the progenitor group empty
141
+ with pytest.raises(ValueError, match="putative progenitors"):
142
+ scf.tl.linearity_deviation(
143
+ adata, start_milestone="43", end_milestone="88", percentiles=[0, 80]
144
+ )
145
+ with pytest.raises(ValueError, match="not a milestone"):
146
+ scf.tl.linearity_deviation(adata, start_milestone="43", end_milestone="999")
147
+
136
148
  scf.pl.linearity_deviation(adata, start_milestone="43", end_milestone="88",show=False)
137
149
 
138
150
  scf.tl.fit(adata_2, layer="scaled")
@@ -671,7 +671,9 @@ def get_activation(data):
671
671
  fitted = (fitted - fitted.min()) / (fitted.max() - fitted.min())
672
672
  fitted = fitted[df_t.index]
673
673
  changes = wins.apply(
674
- lambda x: (fitted.loc[df_t[(df_t > x[0]) & (df_t < x[1])].index]).diff().sum(),
674
+ lambda x: (fitted.loc[df_t[(df_t > x["start"]) & (df_t < x["end"])].index])
675
+ .diff()
676
+ .sum(),
675
677
  axis=1,
676
678
  )
677
679
 
@@ -91,7 +91,7 @@ def dendrogram(adata: anndata.AnnData, crowdedness: float = 1):
91
91
 
92
92
  # Assign positions to cells based on sorted order
93
93
  for seg_id, pos_idx in seg_to_pos.items():
94
- df.loc[df.seg == seg_id, "seg_pos"] = pos_idx
94
+ df.loc[df.seg == seg_id, "seg_pos"] = str(pos_idx)
95
95
 
96
96
  df.seg_pos = df.seg_pos.astype(int).astype("category")
97
97
 
@@ -73,6 +73,16 @@ def linearity_deviation(
73
73
 
74
74
  graph = adata.uns["graph"]
75
75
 
76
+ for label, ms in (
77
+ ("start_milestone", start_milestone),
78
+ ("end_milestone", end_milestone),
79
+ ):
80
+ if ms not in graph["milestones"]:
81
+ raise ValueError(
82
+ f"{label} '{ms}' is not a milestone of the tree, available milestones are: "
83
+ + ", ".join(map(str, graph["milestones"].keys()))
84
+ )
85
+
76
86
  def lindev_map(m):
77
87
  df = adata.uns["pseudotime_list"][str(m)].copy()
78
88
  edges = graph["pp_seg"][["from", "to"]].astype(str).apply(tuple, axis=1).values
@@ -91,6 +101,18 @@ def linearity_deviation(
91
101
  df,
92
102
  )
93
103
 
104
+ if cells is None:
105
+ root_ms = [
106
+ k for k, v in graph["milestones"].items() if v == graph["root"]
107
+ ]
108
+ root_ms = root_ms[0] if len(root_ms) > 0 else graph["root"]
109
+ raise ValueError(
110
+ f"No path found from start_milestone '{start_milestone}' to end_milestone "
111
+ f"'{end_milestone}' following the direction of the tree (root: '{root_ms}'). "
112
+ "end_milestone must be downstream of start_milestone: try swapping them, "
113
+ "or re-root the tree with scf.tl.root and scf.tl.pseudotime."
114
+ )
115
+
94
116
  t_perc = [cells.t.quantile(p / 100) for p in percentiles]
95
117
 
96
118
  df[name + "_lindev_sel"] = 'none'
@@ -115,6 +137,23 @@ def linearity_deviation(
115
137
  progenies = adata.obs_names[df[name + "_lindev_sel"] == "putative progenies"]
116
138
  bridge = adata.obs_names[df[name + "_lindev_sel"] == "putative bridge"]
117
139
 
140
+ empty = [
141
+ f"{grp} (t {cond})"
142
+ for grp, cells_grp, cond in (
143
+ ("putative progenitors", progenitors, f"< {t_perc[0]:.3g}"),
144
+ ("putative bridge", bridge, f"between {t_perc[0]:.3g} and {t_perc[1]:.3g}"),
145
+ ("putative progenies", progenies, f"> {t_perc[1]:.3g}"),
146
+ )
147
+ if len(cells_grp) == 0
148
+ ]
149
+ if len(empty) > 0:
150
+ raise ValueError(
151
+ f"No cells found in: {', '.join(empty)}, among the {len(cells)} cells on the "
152
+ f"path {name} with percentiles={list(percentiles)}. This can happen when many "
153
+ "cells share the same pseudotime value (e.g. at the start or end of the path); "
154
+ "try adjusting the percentiles."
155
+ )
156
+
118
157
  X_all = get_X(adata, cells.index, adata.var_names, layer=None)
119
158
  X_progenitors = get_X(adata, progenitors, adata.var_names, layer=None)
120
159
  X_progenies = get_X(adata, progenies, adata.var_names, layer=None)
@@ -227,7 +227,7 @@ def pseudotime(
227
227
  )
228
228
  adata.obs.loc[cells_front.index, "seg"] = cells_front.values
229
229
 
230
- milestones = pd.Series(index=adata.obs_names, dtype=str)
230
+ milestones = pd.Series(index=adata.obs_names, dtype=object)
231
231
  for seg in pp_seg.n:
232
232
  cell_seg = adata.obs.loc[adata.obs["seg"] == seg, "t"]
233
233
  if len(cell_seg) > 0:
@@ -158,9 +158,12 @@ def slide_cells(
158
158
  freq = freq + [cell_probs]
159
159
  return freq
160
160
  else:
161
+ # if the first index is 0, the very first principal point already
162
+ # exceeds the window; keep it so the slice is not empty (see #60)
163
+ end = inds[0] + 1 if inds[0] == 0 else inds[0]
161
164
  pps_region = pp_next[
162
165
  np.argsort(graph["pp_info"].loc[pp_next, "time"].values)
163
- ][: inds[0]]
166
+ ][:end]
164
167
  if mapping:
165
168
  cell_probs = adata.obsm["X_R"][:, pps_region].sum(axis=1)
166
169
  else:
@@ -238,9 +241,17 @@ def slide_cells(
238
241
  .max()
239
242
  )
240
243
  segs_cur2 = seg_branch2
241
- res1 = region_extract(pt_cur1, segs_cur1, nbranch)
242
- res2 = region_extract(pt_cur2, segs_cur2, nbranch)
243
- return freq + res1 + res2
244
+ # a branch may have no remaining cells for the current
245
+ # pseudotime, yielding a NaN pt_cur; only recurse into
246
+ # branches that still have cells to extract (see #60)
247
+ res_final = freq
248
+ if not np.isnan(pt_cur1):
249
+ res1 = region_extract(pt_cur1, segs_cur1, nbranch)
250
+ res_final = res_final + res1
251
+ if not np.isnan(pt_cur2):
252
+ res2 = region_extract(pt_cur2, segs_cur2, nbranch)
253
+ res_final = res_final + res2
254
+ return res_final
244
255
 
245
256
  pt_cur = graph["pp_info"].loc[pps, "time"].min()
246
257
 
@@ -363,12 +374,9 @@ def slide_cors(
363
374
  def gather_cor(i, geneset):
364
375
  freq = freqs[i][adata.obs_names]
365
376
  with np.errstate(divide="ignore", invalid="ignore"):
366
- cormat = pd.DataFrame(
367
- DescrStatsW(X_r.values, weights=freq).corrcoef,
368
- index=genesets,
369
- columns=genesets,
370
- )
371
- np.fill_diagonal(cormat.values, np.nan)
377
+ cormat_arr = np.array(DescrStatsW(X_r.values, weights=freq).corrcoef)
378
+ np.fill_diagonal(cormat_arr, np.nan)
379
+ cormat = pd.DataFrame(cormat_arr, index=genesets, columns=genesets)
372
380
  return cormat.loc[:, geneset].mean(axis=1)
373
381
 
374
382
  gather = partial(gather_cor, geneset=genesetA)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scFates
3
- Version: 1.2.4
3
+ Version: 1.2.6
4
4
  Summary: scanpy compatible python suite for fast tree inference and advanced pseudotime downstream analysis
5
5
  Author: Louis Faure
6
6
  Project-URL: Repository, https://github.com/LouisFaure/scFates
@@ -13,6 +13,7 @@ Requires-Dist: tqdm>=4.45.0
13
13
  Requires-Dist: numba>=0.51.2
14
14
  Requires-Dist: scipy>=1.4.1
15
15
  Requires-Dist: scanpy>=1.7.0
16
+ Requires-Dist: umap-learn<0.6
16
17
  Requires-Dist: leidenalg>=0.8.1
17
18
  Requires-Dist: numpy
18
19
  Requires-Dist: joblib>=0.17.0
@@ -4,6 +4,7 @@ tqdm>=4.45.0
4
4
  numba>=0.51.2
5
5
  scipy>=1.4.1
6
6
  scanpy>=1.7.0
7
+ umap-learn<0.6
7
8
  leidenalg>=0.8.1
8
9
  numpy
9
10
  joblib>=0.17.0
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes