cellink.tl.external.scores_to_covar#
- cellink.tl.external.scores_to_covar(scores, out_file, gene_map=None, negate=False)#
Convert a genes × cell-types score DataFrame to a MAGMA gene covariate file.
All genes with at least one non-NaN score are included (no top/bottom threshold). This is the Python-API equivalent of
make_magma_covar.pyin the combined_pipeline.The covariate file is tab-delimited with
GENEas the index name, one column per cell type, andNAfor missing values:GENE ExcL2-3 ExcL4 InhSST ENSG00001234 0.52 0.01 0.08 ENSG00005678 0.11 0.43 0.22
- Parameters:
scores (
DataFrame) – DataFrame with genes as rows and cell types as columns. Index should contain gene identifiers (ENSG IDs or gene symbols).gene_map (
str|Path|Series|None(default:None)) – Optional mapping from gene symbols to ENSG IDs — same formats as inscores_to_gmt(). Non-ENSG rows are dropped after mapping.negate (
bool(default:False)) – IfTrue, multiply all scores by-1before writing. Use this to test enrichment in genes with low scores (e.g. negative Vg).
- Return type:
- Returns:
Path Path to the written covariate file.
Examples
>>> from cellink.tl.external import scores_to_covar, run_magma_gpa >>> covar = scores_to_covar(specificity_df, "brainscope_seismic.covar") >>> run_magma_gpa(gene_results="scz.genes.raw", gene_covar=str(covar), out_prefix="results/scz_gpa")
See also
scores_to_gmtConvert scores to GMT for gene-set analysis.
run_magma_gpaRun MAGMA gene property analysis with the covariate file.