crispyx 0.2.2__tar.gz → 0.2.4__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 (87) hide show
  1. {crispyx-0.2.2/src/crispyx.egg-info → crispyx-0.2.4}/PKG-INFO +2 -2
  2. {crispyx-0.2.2 → crispyx-0.2.4}/pyproject.toml +1 -1
  3. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/__init__.py +6 -0
  4. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_irls.py +19 -57
  5. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_kernels.py +735 -199
  6. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_memory.py +0 -21
  7. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_namespaces.py +30 -4
  8. crispyx-0.2.4/src/crispyx/_size_factors.py +277 -0
  9. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_statistics.py +2 -203
  10. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_version.py +1 -1
  11. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/batch.py +3 -3
  12. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/data.py +50 -115
  13. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/de.py +669 -1771
  14. crispyx-0.2.4/src/crispyx/glm.py +3161 -0
  15. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/plotting.py +47 -0
  16. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/pseudobulk.py +3 -1
  17. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/qc.py +222 -0
  18. {crispyx-0.2.2 → crispyx-0.2.4/src/crispyx.egg-info}/PKG-INFO +2 -2
  19. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx.egg-info/SOURCES.txt +2 -1
  20. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx.egg-info/requires.txt +1 -1
  21. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_batch_process.py +26 -0
  22. crispyx-0.2.4/tests/test_compare_controls.py +83 -0
  23. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_data_helpers.py +0 -26
  24. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_de_lowexpr_filter.py +18 -19
  25. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_glm_structured.py +50 -2
  26. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_irls.py +0 -28
  27. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_nb_glm.py +105 -572
  28. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_normalisation.py +126 -39
  29. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_preflight_dispatch.py +8 -1
  30. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_pseudobulk_profiles.py +13 -0
  31. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_read_backed.py +21 -0
  32. crispyx-0.2.4/tests/test_two_group_deseq2.py +485 -0
  33. crispyx-0.2.2/src/crispyx/_size_factors.py +0 -380
  34. crispyx-0.2.2/src/crispyx/glm.py +0 -5896
  35. crispyx-0.2.2/tests/test_streaming_control.py +0 -401
  36. {crispyx-0.2.2 → crispyx-0.2.4}/LICENSE +0 -0
  37. {crispyx-0.2.2 → crispyx-0.2.4}/README.md +0 -0
  38. {crispyx-0.2.2 → crispyx-0.2.4}/setup.cfg +0 -0
  39. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_checkpoint.py +0 -0
  40. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_disk.py +0 -0
  41. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_grouping.py +0 -0
  42. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_h5codec.py +0 -0
  43. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_messages.py +0 -0
  44. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_preflight.py +0 -0
  45. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/_provenance.py +0 -0
  46. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/dimred.py +0 -0
  47. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/hvg.py +0 -0
  48. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/profiling.py +0 -0
  49. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/residual.py +0 -0
  50. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx/sample.py +0 -0
  51. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx.egg-info/dependency_links.txt +0 -0
  52. {crispyx-0.2.2 → crispyx-0.2.4}/src/crispyx.egg-info/top_level.txt +0 -0
  53. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_cgroup_memory_budget.py +0 -0
  54. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_compress_h5ad.py +0 -0
  55. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_concat_h5ad.py +0 -0
  56. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_convert_format.py +0 -0
  57. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_de_edge_cases.py +0 -0
  58. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_de_resume.py +0 -0
  59. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_dimred.py +0 -0
  60. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_disk_dispatch.py +0 -0
  61. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_downsample_counts.py +0 -0
  62. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_groupby_alias.py +0 -0
  63. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_hvg.py +0 -0
  64. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_in_memory_input.py +0 -0
  65. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_memory_dispatch.py +0 -0
  66. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_messages.py +0 -0
  67. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_normalized_effects.py +0 -0
  68. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_normalized_effects_se.py +0 -0
  69. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_obs_writes.py +0 -0
  70. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_pickle.py +0 -0
  71. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_plotting.py +0 -0
  72. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_profiling.py +0 -0
  73. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_pseudobulk_batch.py +0 -0
  74. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_pseudobulk_memory.py +0 -0
  75. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_qc_parity.py +0 -0
  76. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_rank_genes_groups_outputs.py +0 -0
  77. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_residual_effects.py +0 -0
  78. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_result_provenance.py +0 -0
  79. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_scanpy_parity.py +0 -0
  80. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_standardize.py +0 -0
  81. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_stream_on_fast_axis.py +0 -0
  82. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_subsample.py +0 -0
  83. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_temp_file_cleanup.py +0 -0
  84. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_wilcoxon_dispatch.py +0 -0
  85. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_wilcoxon_labels.py +0 -0
  86. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_wilcoxon_stratified.py +0 -0
  87. {crispyx-0.2.2 → crispyx-0.2.4}/tests/test_workflow.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: crispyx
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Memory-efficient streaming analysis of large-scale CRISPR and Perturb-seq screens on disk-backed AnnData files
5
5
  Author: Jin-Hong Du
6
6
  License: Modified MIT License
@@ -105,7 +105,7 @@ Requires-Dist: numpy>=1.23
105
105
  Requires-Dist: numba>=0.59
106
106
  Requires-Dist: pandas>=1.5
107
107
  Requires-Dist: scipy>=1.10
108
- Requires-Dist: h5py>=3.0
108
+ Requires-Dist: h5py>=3.10
109
109
  Requires-Dist: joblib>=1.4
110
110
  Requires-Dist: scikit-learn>=1.0
111
111
  Requires-Dist: scikit-misc>=0.1.4
@@ -39,7 +39,7 @@ dependencies = [
39
39
  "numba>=0.59",
40
40
  "pandas>=1.5",
41
41
  "scipy>=1.10",
42
- "h5py>=3.0",
42
+ "h5py>=3.10", # 3.9 segfaults copying committed (named) datatypes
43
43
  "joblib>=1.4",
44
44
  "scikit-learn>=1.0",
45
45
  "scikit-misc>=0.1.4",
@@ -66,6 +66,7 @@ from .plotting import (
66
66
  materialize_rank_genes_groups,
67
67
  plot_ma,
68
68
  plot_overlap_heatmap,
69
+ plot_control_guide_correlation,
69
70
  plot_pca,
70
71
  plot_pca_loadings,
71
72
  plot_pca_variance_ratio,
@@ -83,6 +84,8 @@ from .pseudobulk import (
83
84
  compute_pseudobulk_effects,
84
85
  )
85
86
  from .qc import (
87
+ compare_controls,
88
+ control_guide_correlation,
86
89
  filter_cells_by_gene_count,
87
90
  filter_genes_by_cell_count,
88
91
  filter_perturbations_by_cell_count,
@@ -123,6 +126,9 @@ __all__ = [
123
126
  "filter_genes_by_cell_count",
124
127
  "filter_perturbations_by_cell_count",
125
128
  "quality_control_summary",
129
+ "compare_controls",
130
+ "control_guide_correlation",
131
+ "plot_control_guide_correlation",
126
132
  "highly_variable_genes",
127
133
  # Subsampling
128
134
  "subsample",
@@ -30,7 +30,6 @@ from __future__ import annotations
30
30
  from typing import Literal
31
31
 
32
32
  import numpy as np
33
- from scipy.linalg import cho_factor, cho_solve
34
33
 
35
34
  __all__ = [
36
35
  "EPS",
@@ -43,13 +42,11 @@ __all__ = [
43
42
  "irls_weights",
44
43
  "PIVOT_FLOOR",
45
44
  "precondition_columns",
46
- "sandwich_variances_2x2",
47
45
  "schur_complement",
48
46
  "schur_solve",
49
47
  "schur_variances",
50
48
  "solve_spd_2x2",
51
49
  "working_response",
52
- "wls_solve",
53
50
  ]
54
51
 
55
52
  #: Division guard. Not a modelling floor -- see the module docstring.
@@ -186,54 +183,6 @@ def solve_spd_2x2(a, b, c, r0, r1):
186
183
  return (r0 - b * x1) / d0, x1
187
184
 
188
185
 
189
- def sandwich_variances_2x2(m00, m01, m11, ridge):
190
- """Sandwich variances ``e_k' H M H e_k`` of a two-column fit's
191
- coefficients, for Fisher information ``M = [[m00, m01], [m01, m11]]``
192
- and ``H = (M + ridge I)^-1``, with ``H e_k`` from :func:`solve_spd_2x2`.
193
- Returns ``(intercept, second column)``.
194
- """
195
- a, c = m00 + ridge, m11 + ridge
196
-
197
- def quadratic(v0, v1):
198
- return v0 * v0 * m00 + 2 * v0 * v1 * m01 + v1 * v1 * m11
199
-
200
- return (quadratic(*solve_spd_2x2(a, m01, c, 1.0, 0.0)),
201
- quadratic(*solve_spd_2x2(a, m01, c, 0.0, 1.0)))
202
-
203
-
204
- def wls_solve(
205
- x_weighted: np.ndarray, z_weighted: np.ndarray | None = None, ridge: float = 0.0
206
- ) -> tuple[np.ndarray | None, np.ndarray]:
207
- """Coefficients and covariance ``(X'WX + ridge I)^-1`` of a weighted
208
- least-squares fit, from its weighted design ``W^1/2 X`` (and response
209
- ``W^1/2 z``; without one the coefficients are ``None``).
210
-
211
- A Cholesky factor of the normal matrix when it is positive definite;
212
- otherwise an SVD of the weighted design, stacked on ``sqrt(ridge) I``,
213
- gives the minimum-norm solution and the pseudo-inverse with singular
214
- values below ``matrix_rank``'s tolerance dropped -- without forming a
215
- normal matrix whose condition number is the design's squared.
216
- """
217
- n_features = x_weighted.shape[1]
218
- gram = x_weighted.T @ x_weighted
219
- gram[np.diag_indices(n_features)] += ridge
220
- try:
221
- factor = cho_factor(gram, check_finite=False)
222
- except np.linalg.LinAlgError:
223
- design, response = x_weighted, z_weighted
224
- if ridge:
225
- design = np.vstack([x_weighted, np.sqrt(ridge) * np.eye(n_features)])
226
- if z_weighted is not None:
227
- response = np.concatenate([z_weighted, np.zeros(n_features)])
228
- u, s, vt = np.linalg.svd(design, full_matrices=False)
229
- keep = s > s.max(initial=0.0) * max(design.shape) * np.finfo(np.float64).eps
230
- scaled = vt[keep].T / s[keep] # V S^-1
231
- beta = None if response is None else scaled @ (u[:, keep].T @ response)
232
- return beta, scaled @ scaled.T
233
- beta = None if z_weighted is None else cho_solve(factor, x_weighted.T @ z_weighted, check_finite=False)
234
- return beta, cho_solve(factor, np.eye(n_features), check_finite=False)
235
-
236
-
237
186
  def irls_weights(mu: np.ndarray, alpha: np.ndarray | float | None) -> np.ndarray:
238
187
  """Log-link IRLS weights ``mu**2 / V(mu)``.
239
188
 
@@ -455,7 +404,18 @@ class OneHotGroups:
455
404
  Returns shape ``(n_groups, n_genes)``. This is the diagonal of
456
405
  ``G' W G`` when ``values`` are the IRLS weights.
457
406
  """
458
- return np.asarray(self.matrix.T @ values)
407
+ return self.sums_sorted(self.sort(values))
408
+
409
+ def sums_sorted(self, values_sorted: np.ndarray) -> np.ndarray:
410
+ """:meth:`sums` of values already in :meth:`sort` order: a NumPy sum
411
+ per group's contiguous slice, which releases the GIL (a sparse
412
+ product does not, and serialised the IRLS's threads)."""
413
+ out = np.zeros((self.n_groups, values_sorted.shape[1]), dtype=np.float64)
414
+ for k in range(self.n_groups):
415
+ start, stop = self._starts[k], self._ends[k]
416
+ if stop > start:
417
+ values_sorted[start:stop].sum(axis=0, out=out[k])
418
+ return out
459
419
 
460
420
  def cross(self, design_sorted: np.ndarray, weights_sorted: np.ndarray) -> np.ndarray:
461
421
  """``X' W G`` per gene, shape ``(n_groups, n_features, n_genes)``.
@@ -478,11 +438,13 @@ class OneHotGroups:
478
438
  return out
479
439
 
480
440
  def expand(self, per_group: np.ndarray) -> np.ndarray:
481
- """Scatter ``(n_genes, n_groups)`` values back to ``(n_samples, n_genes)``."""
482
- out = np.zeros((self.n_samples, per_group.shape[0]), dtype=np.float64)
483
- assigned = self.labels >= 0
484
- out[assigned] = per_group.T[self.labels[assigned]]
485
- return out
441
+ """Scatter ``(n_genes, n_groups)`` values back to ``(n_samples, n_genes)``.
442
+
443
+ One ``take`` from the values with a zero row appended, which a cell
444
+ in no group (label ``-1``) picks."""
445
+ padded = np.zeros((self.n_groups + 1, per_group.shape[0]), dtype=np.float64)
446
+ padded[:-1] = per_group.T
447
+ return padded.take(self.labels, axis=0)
486
448
 
487
449
 
488
450
  def _arrowhead_blocks(