Updated ADMM and cytokine fact Stdev filtering - #33
Draft
nbedanova wants to merge 4 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
It introduces a non-portable default absolute CSV path (not present in-repo) and contains correctness/diagnostic mismatches (edge-case iteration crash and final stats computed from non-returned matrices).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
pf2rnaseq/factorization.py:388
deconvolution_cytokine_admmintroduces a new optimization routine but has no test coverage. Sincepf2rnaseq/testsalready validates reproducibility/outputs for other factorization code, it would be valuable to add a lightweight test on a small syntheticAthat asserts output shapes, diagonal constraints onZ_W, and non-negativity when enabled.
def deconvolution_cytokine_admm(
A: np.ndarray,
alpha_h: float = 0.1,
alpha_w: float = 0.01,
rho_w_init: float | None = None,
rho_h_init: float | None = None,
max_iter: int = 10000,
tol_abs: float = 1e-4,
tol_rel: float = 1e-3,
random_state: int = 1,
adaptive_rho: bool = True,
rho_bounds: tuple[float, float] = (1e-4, 1e4),
non_negative_w: bool = True,
non_negative_h: bool = True,
) -> tuple[np.ndarray, np.ndarray, dict]:
- Files reviewed: 1/1 changed files
- Comments generated: 6
- Review effort level: Lite
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
There are a few concrete portability/correctness issues (hard-coded paths, indexing consistency, RNG side effects, and missing alignment validation) that should be addressed before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (2)
pf2rnaseq/factorization.py:49
- This helper hard-codes a machine-specific absolute CSV path, and it returns 0-indexed component IDs even though most component-facing helpers in this repo take 1-indexed component numbers (and index arrays with
cmp - 1). Computing the default path relative to the package and returning 1-indexed IDs by default will make this easier to use and avoid off-by-one mistakes.
def filter_components_by_cytokine_quantile(
threshold: float,
csv_path: str = "/home/nicoleb/Pf2-scRNAseq-1/pf2rnaseq/Data/donor_vs_cytokine_variability_sd.csv",
) -> np.ndarray:
pf2rnaseq/factorization.py:380
- New public helpers in factorization.py (cytokine quantile filtering, ADMM deconvolution, and correct_conditions_from_npy) aren’t covered by tests; existing tests already exercise this module, so adding at least lightweight shape/invariant checks would help prevent regressions.
def deconvolution_cytokine_admm(
A: np.ndarray,
alpha_h: float = 0.1,
alpha_w: float = 0.01,
rho_w_init: float | None = None,
rho_h_init: float | None = None,
max_iter: int = 10000,
- Files reviewed: 22/23 changed files
- Comments generated: 3
- Review effort level: Lite
Comment on lines
+429
to
+434
| n_cytokines, n_components = A.shape | ||
| np.random.seed(random_state) | ||
|
|
||
| # Initialize | ||
| W = np.random.rand(n_cytokines, n_cytokines) * 0.1 + np.eye(n_cytokines) | ||
| H = np.random.rand(n_cytokines, n_components) * np.mean(np.abs(A)) |
Comment on lines
+656
to
+669
| X = an.read_h5ad(h5ad_path, backed="r") | ||
| obs = X.obs | ||
|
|
||
| if "total_counts" in obs.columns: | ||
| per_cell = obs["total_counts"] | ||
| else: | ||
| per_cell = pd.Series(np.ones(len(obs), dtype=np.float64), index=obs.index) | ||
|
|
||
| # Sum read counts (or cell counts) per cytokine condition | ||
| cyt_totals = per_cell.groupby(obs[cytokine_col]).sum() | ||
| X.file.close() | ||
|
|
||
| # Align to the row order of A using cyt_order | ||
| counts = cyt_totals.reindex(cyt_order).to_numpy(dtype=np.float64).reshape(-1, 1) |
Comment on lines
29
to
33
| "parafac2 @ git+https://github.com/meyer-lab/parafac2.git", | ||
| "wandb>=0.19.9", | ||
| "doubletdetection>=4.3.0.post1", | ||
| "pytest>=9.0.1", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.