This repository contains the refactored analysis code for a multi-omic Four Core Genotypes (FCG) mouse liver study. The goal is to separate the effects of gonadal hormones from sex chromosome complement and to connect sex-biased liver gene expression with lipid metabolism.
- snRNA-seq / pseudobulk RNA: 466,986 high-quality nuclei from 48 liver samples (43 FCG + 5 wild-type males), summarized into pseudobulk profiles by sample and cell type.
- Untargeted lipidomics: lipid species measured across FCG liver samples. The current MOFA path uses the RNA-shared lipidomic sample set.
- Multi-omic integration: MOFA2-based integration of 5 RNA cell-type views and 1 lipidomic view.
- Validation and provenance: GDX RNA/lipidomic validation, Xenium spatial validation, proteomics validation, siRNA knockdown lipidomics, and collaborator Xenium/MALDI/proteomics source materials.
- Human liver comparison: optional Python workflow comparing the mouse hepatocyte gonadal t-value signature with human bulk liver sex differences from GEO accession GSE179250.
- Gonadal hormones, rather than sex chromosome complement, are the dominant driver of sex-biased adult liver physiology.
- Hepatocytes show the strongest gonad-dependent RNA effects, with roughly 4,000 gonad-dependent genes in the main analysis.
- Lipid abundance is strongly gonad-dependent, while sex chromosome effects on lipids are minimal to absent in the current analysis narrative.
- Spatial zonation modulates gonad-dependent hepatocyte expression.
- Key validated regulatory genes include
Cyp2b9,Cyp2b13,Cyp2c38,Cyp2d9,Sult3a1, andMtmr11.
For exact counts, prefer the generated result files over prose summaries. In particular, workflow 03 currently contains two different printed headline lipid counts in comments/output text, so result tables are the quantitative source.
| Group | Sex Chromosomes | Gonads | Description |
|---|---|---|---|
| XXO | XX | Ovaries | Chr3-Sry- |
| XXT | XX | Testes | Chr3-Sry+ |
| XYO | XY | Ovaries | Chr3-Sry- |
| XYT | XY | Testes | Chr3-Sry+ |
Main comparisons:
- Gonadal effect: Testes vs Ovaries, across chromosome backgrounds.
- Chromosomal effect: XY vs XX, across gonadal backgrounds.
- Group comparisons: XXT vs XXO, XYT vs XYO, XYO vs XXO, XYT vs XXT.
This repository is documented for direct agent use without an MCP server.
Start with:
AGENTS.md- repository rules and biological context for agents.docs/AGENT_GUIDE.md- static query map for extracting results.docs/workflow_plans/_meta_cross_workflow_overview.md- cross-workflow data flow and shared fragility points.docs/workflow_plans/NN_*.md- per-workflow structure, dependencies, outputs, and known vulnerabilities.
When modifying any scripts/workflows/NN_* workflow file, read the matching
plan first and update it after the code change.
.
|-- data/
| |-- RNA/ # Pseudobulk RNA CSVs and Seurat RDS inputs
| |-- metabolomics/ # Lipidomics and structural input CSVs
| |-- proteomics/ # Bulk liver proteomics validation data
| `-- Suppl_Table_1_OverviewData.xlsx
|-- scripts/
| |-- workflows/ # Main workflows 00-10
| |-- core/ # Data loading, DE, enrichment, MOFA, structural helpers
| |-- config/ # Dataset paths, contrasts, plotting config
| |-- visualization/ # Plot helpers
| |-- james/ # Collaborator source/provenance material
| |-- support_functions.R # Compatibility wrapper to config/support_functions.R
| `-- seurat_compatibility.R
|-- support/ # Gene sets, regulons, hormone targets, LINEX2 network
|-- docs/
| |-- AGENT_GUIDE.md
| `-- workflow_plans/
|-- results/
| |-- qc/
| |-- pseudobulk/
| |-- lipidomic/
| |-- mofa/
| |-- zonation/
| |-- validation/
| `-- xenium/
`-- tests/
Most users should start at workflow 01. Workflow 00 is a reference/HPC raw-data preprocessing workflow and is inactive by default.
# Optional reference workflow; requires original raw alignment environment
# source("scripts/workflows/00_snrnaseq_preprocessing.R")
source("scripts/workflows/01_data_preparation_qc.R")
source("scripts/workflows/02_fcg_pseudobulk_analysis.R")
source("scripts/workflows/03_fcg_lipidomic_analysis.R")
source("scripts/workflows/04_mofa_integration.R")
source("scripts/workflows/05_zonation_analysis.R")
source("scripts/workflows/06_structural_analysis.R")
source("scripts/workflows/07_validation_experiments.R")
source("scripts/workflows/08_variance_analysis.R")
# Optional external-data workflow; requires large GSE179250 inputs outside repo
# python scripts/workflows/09_human_analysis.py
# Optional collaborator Xenium scripts; require raw Xenium data under the
# workflow folder and are run from scripts/workflows/10_xenium_analysis/
# python 00_infer_doublets.py
# python 01_merge_doublets.py
# python 02_compositional_analysis.py
# python 03_DGE_analysis.pyRun workflows 00-08 from the repository root. Workflows 09 and 10 are optional Python analyses with their own external or folder-local path assumptions, as documented below and in their plan files.
Script: scripts/workflows/00_snrnaseq_preprocessing.R
Reference pipeline for raw sci-RNA-seq import, UMI QC, Seurat clustering,
scDblFinder doublet removal, cell-type annotation, pseudobulking, and
hepatocyte zonation annotation. Both FCG and GDX processing blocks are wrapped
in if (FALSE) and depend on original DKFZ HPC paths plus a placeholder import
function.
Key intended outputs include pseudobulks_scc.rds,
heps_zonationsubsetted_pseudobulks_gonad.rds, and GDX pseudobulk RDS files.
Script: scripts/workflows/01_data_preparation_qc.R
Converts preprocessed pseudobulk Seurat objects into CSV matrices and metadata. The main RNA CSVs are split by sample columns, with all genes retained in each file.
Key outputs:
data/RNA/scaled_RNA_1.csvdata/RNA/scaled_RNA_2.csvdata/RNA/scaled_RNA_3.csvdata/RNA/meta_data_df.csvdata/RNA/scaled_RNA_zonation.csvdata/RNA/meta_data_df_zonation.csvdata/RNA/scaled_RNA_gdxhr_{1,2,3}.csvdata/RNA/meta_data_df_gdxhr.csvresults/qc/
Script: scripts/workflows/02_fcg_pseudobulk_analysis.R
Runs RNA differential expression for 6 FCG contrasts across 5 cell types, then adds GDX RNA validation, GO pathway enrichment, TF activity inference, Xenium panel validation, hepatocyte PCA coordinates, and bulk proteomics validation.
Key outputs:
results/pseudobulk/ttop_full_list.RDataresults/pseudobulk/tval_full_df.RDataresults/pseudobulk/tval_full_df.csvresults/pseudobulk/gdxrh/gdhxr_groups_ttop_list.RDataresults/pseudobulk/gdxrh/gdhxr_groups_tval_df.csvresults/pseudobulk/volcanos/results/pseudobulk/pca/results/pseudobulk/pathways/pathway_scores_df_all.RDataresults/pseudobulk/pathways/tf_scores_df_all.RDataresults/pseudobulk/gdx_validation_comparison.pdfresults/pseudobulk/xenium_validation_volcano.pdfresults/pseudobulk/proteo_validation_comparison.pdf
Script: scripts/workflows/03_fcg_lipidomic_analysis.R
Runs lipid differential abundance for 6 FCG contrasts, optional GDX lipid validation, lipid-class enrichment, LINEX2 network extraction, and per-class chain-length/double-bond bubble plots.
Key outputs:
results/lipidomic/ttop_full_list.RDataresults/lipidomic/gdxhr_ttop_list.RDataresults/lipidomic/gdxhr_t_table.csvresults/lipidomic/fcg_gdx_correlation.pdfresults/lipidomic/volcanos/results/lipidomic/pca/results/lipidomic/enrichment/lipid_class_enrichment_scores.RDataresults/lipidomic/enrichment/lipid_class_enrichment_gonadal.csvresults/lipidomic/enrichment/lipid_class_enrichment_plot.pdfresults/lipidomic/network/significant_lipids_network_SIF.csvresults/lipidomic/network/significant_lipids_network_ATT.csvresults/lipidomic/bubbles_DBC/
Script: scripts/workflows/04_mofa_integration.R
Builds a 6-view MOFA input (5 RNA cell types + lipidomics), trains or loads 5-15 factor MOFA models, selects the 12-factor model, extracts weights, enriches factors for gonadal type, and builds gene-lipid and TF-gene-lipid networks.
Key outputs:
results/mofa/MOFA_data.RDataresults/mofa/RNA/mofa_res_12factor.hdf5results/mofa/main_model_RNA_lipid_weight.RDataresults/mofa/factor_analysis/factor_enrichment_gonadal.RDataresults/mofa/factor_analysis/*.pdfresults/mofa/networks/gene_lipid_correlations_factor1.csvresults/mofa/networks/hepatocyte_gene_lipid_network_full_SIF.csvresults/mofa/networks/hepatocyte_TF_gene_lipid_network_full_{SIF,ATT}.csvresults/mofa/networks/hepatocyte_TF_gene_lipid_network_compressed_{SIF,ATT}.csv
Script: scripts/workflows/05_zonation_analysis.R
Uses workflow 01 zonation CSVs to run duplicate-correlation limma models across periportal/pericentral and gonadal contrasts. It selects sex-specific zonation-biased genes through an entropy/stability/coverage/specificity threshold sweep, builds zonation-specific gene-lipid networks, and maps lipid classes to zonation categories using workflow 03 outputs.
Key outputs:
results/zonation/zonation_ttop_list.RDataresults/zonation/zonation_limma_results.RDataresults/zonation/t_table_zonation.csvresults/zonation/ttop_full_long.csvresults/zonation/sex_specific_zonation_genes_summary.csvresults/zonation/sex_specific_zonation_panel_AB.pdfresults/zonation/sex_specific_zonation_heatmap_faceted.pdfresults/zonation/lipid_species_zonation_association.csvresults/zonation/lipid_class_association_summary.csvresults/zonation/threshold_sensitivity_total.csvresults/zonation/optimal_threshold_metrics.csvresults/zonation/networks/cormat_*_{SIF,ATT}.csvresults/zonation/networks/cormat_*_full_{SIF,ATT}.csvresults/zonation/networks/compressed_cormat_*_{SIF,ATT}.csv
Script: scripts/workflows/06_structural_analysis.R
Current active workflow is lipid-only. It parses lipid structures from workflow 03 gonadal lipid DE results and tests whether lipid chain length, double-bond count, and their interaction explain gonadal logFC within lipid classes.
Active model:
logfc ~ chain_length + db_position + chain_length:db_positionKey outputs:
results/lipidomic/structural_model/lipids_with_structure.csvresults/lipidomic/structural_model/lipid_only_class_coefficients.csvresults/lipidomic/structural_model/lipid_only_class_summaries.csvresults/lipidomic/structural_model/lipid_only_chain_length_effects.csvresults/lipidomic/structural_model/lipid_only_db_position_effects.csvresults/lipidomic/structural_model/lipid_only_interaction_effects.csvresults/lipidomic/structural_model/lipid_only_summary_heatmap.pdfresults/lipidomic/structural_model/lipid_only_plots/
The older gene-lipid structural-regression sections are commented out in the current script.
Script: scripts/workflows/07_validation_experiments.R
Validates MOFA and zonation network predictions using siRNA knockdown lipidomics from primary hepatocytes, then evaluates whether knockdown-response consistency varies by lipid structure.
Key outputs:
results/validation/knockdown_PCA.pdfresults/validation/knockdown_ttop_list.RDataresults/validation/knockdown_t_table.csvresults/validation/knockdown_heatmap.pdfresults/validation/global_network_validation_scores.csvresults/validation/[gene]_validation_scatter.pdfresults/validation/zonation_network_validation_scores.csvresults/validation/[gene]_zonation_validation_scatter.pdfresults/validation/validation_summary.csvresults/validation/structural_consistency/[gene]_structural_consistency.pdfresults/validation/structural_consistency/consistency_structural_regression_summary.csv
Script: scripts/workflows/08_variance_analysis.R
Compares lipid variability between gonadal groups using CVs and Brown-Forsythe Levene tests at both lipid and lipid-class levels.
Key outputs:
results/lipidomic/variance_analysis/variance_analysis_results.csvresults/lipidomic/variance_analysis/significant_differential_variance_lipids.csvresults/lipidomic/variance_analysis/variance_analysis_by_class.csvresults/lipidomic/variance_analysis/variance_analysis_summary.csvresults/lipidomic/variance_analysis/cv_difference_volcano.pdfresults/lipidomic/variance_analysis/cv_difference_volcano_by_class.pdf
Script: scripts/workflows/09_human_analysis.py
Optional Python workflow that compares the mouse FCG hepatocyte gonadal
t-value signature with sex-associated gene expression in the Zhou et al. human
bulk liver cohort (GSE179250).
It translates mouse signature genes to human ortholog symbols, scores the
signature with decoupler ULM, runs PyDESeq2 male-vs-female differential
expression in human liver, and generates concordant mouse-human ranked-gene
plots.
The raw human count/TPM matrices and GEO SOFT metadata are too large for this
repository and are expected under the script's external DATA_DIR. The checked
in signature seed is:
results/pseudobulk/hepa_gonad_signature.csv
The script writes outputs to its external RESULTS_DIR, including:
ulm_sex_signature_estimates.csvadata_processed.h5addeg_zhou.csvfull_results_deg_zhou_malevsfemale.csv12_49_malevsfemale_deg_zhou.csv12_49_malevsfemale_full_results_deg_zhou.csvolderthan11female_oldvsyoung_full_results_deg_zhou.csvolderthan11female_oldvsyoung_deg_statmatrix_zhou.csvpca_by_sex.pdfulm_enrichment_12_49.pdfvolcano_male_vs_female_highlight.pdfvolcano_male_vs_female_highlight_1249.pdftop_ranked_genes_female_dot.pdftop_ranked_genes_male_dot.pdfulm_enrichment_female__old_vs_young.pdf
Folder: scripts/workflows/10_xenium_analysis/
Optional collaborator-provided Python workflow for Xenium spatial validation. Unlike workflows 00-09, this is a folder of notebook-style scripts rather than a single canonical workflow script. It infers neighboring-nucleus doublets from Xenium nucleus boundaries, annotates and fuses likely hepatocyte doublets, creates cell-type/doublet composition plots, and runs Scanpy Wilcoxon differential expression for sex, hepatocyte-zone, and doublet comparisons.
The scripts use relative paths and should be treated as folder-local: run them
from scripts/workflows/10_xenium_analysis/ with raw Xenium files under
data_raw/ and output folders such as data_tidy/ and figures/ available.
The raw Xenium bundle is not committed.
Main scripts:
00_infer_doublets.py01_merge_doublets.py02_compositional_analysis.py03_DGE_analysis.py
Key folder-local inputs include:
data_raw/output-XETG00078__0018188__Region_1__20240301__143248/nucleus_boundaries.csv.gzdata_raw/output-XETG00078__0018188__Region_1__20240301__143248/cell_feature_matrix.h5data_raw/output-XETG00078__0018188__Region_1__20240301__143248/cells.csv.gzdata_raw/XeniumTargetList_Mouse-Panel-1.xlsx
Key folder-local outputs include:
data_tidy/inferred_components.csvinferred_components.jsonfused_anndata_annotated.h5addata_tidy/fused_doublet.csvdata_tidy/fused_celltype.csvfigures/celltype_freq_cores.pdffigures/celltype_freq_sex.pdffigures/doublet_freq_core.pdfdata_tidy/DEG_results_sex_per_celltype.xlsxDEG_results.xlsxPairwise_DEG_hepatocytes.xlsxDoublets_DEG_results.xlsxDoublets_and_Sex_DEG_results_all_hepatocytes.xlsx
Additional collaborator source files that are not part of the default workflow
order are kept under scripts/james/:
scripts/james/maldi/Cleland_analysis_expt2_recal.ipynb- attachment 1 from the 2026-06-19 missing-material bundle; negative-mode MALDI-MSI liver zonation notebook using external imaging/AnnData/SCiLS inputs.scripts/james/proteomics/JamesCleland_P3225_V1.Rmd- attachment 6 from the same bundle; original P3225 fractionated TMT proteomics R Markdown analysis. Workflow 02 does not source this file; it uses the curated proteomics inputs indata/proteomics/.- Attachments 2-5 from the same bundle were Xenium scripts already present in
scripts/workflows/10_xenium_analysis/; the archived copies matched the checked-in scripts after ignoring CRLF line-ending differences.
Workflows 00-08 are R scripts and expect packages from CRAN and Bioconductor. Core R packages include:
- Data manipulation:
dplyr,tidyr,tibble,readr,readxl,reshape2 - Visualization:
ggplot2,ggrepel,pheatmap,cowplot,patchwork,gridExtra,ggridges,scales - Statistics:
limma,decoupleR,car,vsn - Single-cell/preprocessing:
Seurat,glmGamPoi, optionalscDblFinder - Multi-omic integration:
MOFA2and Pythonmofapy2for retraining models - Gene sets:
GSEABase
Workflow 09 is Python and expects packages including anndata, scanpy,
decoupler, pydeseq2, pypath, pandas, numpy, matplotlib, seaborn,
scipy, and adjustText.
Workflow 10 is Python and expects packages including scanpy, anndata,
sccoda, pandas, numpy, matplotlib, seaborn, tifffile, shapely,
rtree, networkx, tqdm, and openpyxl.
results/pseudobulk/ttop_full_list.RDataresults/pseudobulk/tval_full_df.csvresults/pseudobulk/hepa_gonad_signature.csv
results/lipidomic/ttop_full_list.RDataresults/lipidomic/enrichment/lipid_class_enrichment_gonadal.csv
results/mofa/main_model_RNA_lipid_weight.RDataresults/mofa/networks/gene_lipid_correlations_factor1.csvresults/mofa/networks/hepatocyte_gene_lipid_network_full_SIF.csvresults/mofa/networks/hepatocyte_TF_gene_lipid_network_compressed_SIF.csv
results/zonation/ttop_full_long.csvresults/zonation/sex_specific_zonation_genes_summary.csvresults/zonation/lipid_class_association_summary.csvresults/zonation/networks/
results/lipidomic/structural_model/lipids_with_structure.csvresults/lipidomic/structural_model/lipid_only_class_coefficients.csvresults/lipidomic/variance_analysis/variance_analysis_results.csvresults/lipidomic/variance_analysis/variance_analysis_by_class.csv
results/validation/global_network_validation_scores.csvresults/validation/zonation_network_validation_scores.csvresults/validation/structural_consistency/consistency_structural_regression_summary.csv
results/pseudobulk/hepa_gonad_signature.csv- Workflow 09 outputs are written outside this repository by default; see
scripts/workflows/09_human_analysis.pyanddocs/workflow_plans/09_human_analysis.md.
scripts/workflows/10_xenium_analysis/- Workflow 10 outputs are folder-local by default; see
docs/workflow_plans/10_xenium_analysis.md.
scripts/james/maldi/Cleland_analysis_expt2_recal.ipynbscripts/james/proteomics/JamesCleland_P3225_V1.Rmdscripts/james/README.md
The checked-in CSV and RData outputs support result lookup and most downstream analysis. Some raw/preprocessed inputs may not be present in all checkouts:
data/RNA/fcg_pseudobulks.rdsdata/RNA/fcg_zonation_pseudobulks.rdsdata/RNA/gdx_pseudobulks.rds- MOFA
.hdf5models if retraining/loading is needed - Workflow 09 human liver inputs from
GSE179250, including the count matrix, TPM matrix, and SOFT metadata file. - Workflow 10 raw Xenium files under
scripts/workflows/10_xenium_analysis/data_raw/, including the 10x output folder and Xenium panel workbook. - MALDI-MSI raw imaging/AnnData/registration/SCiLS inputs referenced by
scripts/james/maldi/Cleland_analysis_expt2_recal.ipynb. - Raw collaborator P3225 proteomics files referenced by
scripts/james/proteomics/JamesCleland_P3225_V1.Rmd; the curated validation inputs used by workflow 02 are checked in underdata/proteomics/.
Workflow 00 requires the original raw alignment environment and is not expected to run in a standard checkout.
Manuscript citation to be added upon publication.
GNU General Public License v3.0. See LICENSE.