add cellex#118
Open
leoxnard wants to merge 1 commit into
Open
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
There was a problem hiding this comment.
Pull request overview
This PR adds CELLEX/CELLECT support to cellink.tl.external by introducing a new CELLEX runner for generating ESμ specificity matrices from AnnData, and a CELLECT-style linear model prioritization step that combines ESμ with MAGMA gene results. It also includes a tutorial notebook demonstrating the end-to-end workflow and a small MAGMA path-handling tweak.
Changes:
- Add
run_cellexandrun_cellect_prioritizationin a newsrc/cellink/tl/external/_cellex.pymodule. - Export the new APIs from
cellink.tl.external. - Add a CELLEX/CELLECT tutorial notebook and resolve the MAGMA gene results output path.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
src/cellink/tl/external/_magma.py |
Removes an unused top-level import and resolves MAGMA .genes.out output path. |
src/cellink/tl/external/_cellex.py |
Implements CELLEX ESμ generation and CELLECT-style regression prioritization. |
src/cellink/tl/external/__init__.py |
Re-exports the new CELLEX/CELLECT functions. |
docs/tutorials/cellex.ipynb |
Adds a tutorial walking through MAGMA → CELLEX → CELLECT prioritization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1
to
+13
| import logging | ||
| import subprocess | ||
| from pathlib import Path | ||
| from typing import Literal, Union, Tuple | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| from anndata import AnnData | ||
| import scanpy as sc | ||
| import statsmodels.api as sm | ||
| import statsmodels.tools.tools as sm_tools | ||
| import os | ||
|
|
Comment on lines
+55
to
+63
| prefix : str, optional | ||
| Prefix for output files. Default is "cellex". | ||
|
|
||
| Returns | ||
| ------- | ||
| pd.DataFrame | ||
| ESmu DataFrame with genes as rows and cell types as columns. | ||
| Values in [0, 1] representing expression specificity. | ||
|
|
Comment on lines
+103
to
+107
| logger.info("Filtering cells and genes") | ||
| sc.pp.filter_cells(adata, min_genes=min_genes) | ||
| sc.pp.filter_genes(adata, min_cells=min_cells) | ||
|
|
||
| adata = adata[~adata.obs[cell_type_col].isna()].copy() |
Comment on lines
+112
to
+121
| expr_matrix = adata.X.toarray() | ||
| else: | ||
| expr_matrix = adata.X | ||
|
|
||
| data = pd.DataFrame( | ||
| expr_matrix.T, | ||
| index=adata.var_names, | ||
| columns=adata.obs_names, | ||
| ) | ||
|
|
| logger.info("Mapping mouse Ensembl IDs to human Ensembl IDs") | ||
| cellex.utils.mapping.mouse_ens_to_human_ens(esmu, drop_unmapped=True, verbose=True) | ||
|
|
||
| out_file = f"{prefix}.esmu.csv" |
Comment on lines
+157
to
+164
|
|
||
| pval = ols_result.pvalues[1] / 2 | ||
| pval = 1 - pval if ols_result.params[1] < 0 else pval | ||
|
|
||
| results.append({ | ||
| "Name": f"{specificity_id}__{annotation}", | ||
| "Coefficient": ols_result.params[1], | ||
| "Coefficient_std_error": ols_result.bse[1], |
| return out_file | ||
|
|
||
|
|
||
| def fit_LM(specificity_id: str, es_mu: pd.DataFrame, df_magma: pd.DataFrame) -> pd.DataFrame: |
Comment on lines
+188
to
+190
| output_prefix : str | ||
| Prefix for output files. The final results will be saved as {output_prefix}_cellect_results.txt. | ||
| specificity_id : str, default="cellex" |
Comment on lines
18
to
20
| from ._magma import run_magma_pipeline | ||
| from ._cellex import run_cellex, run_cellect_prioritization | ||
|
|
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.