8000 GitHub - songw01/CID: Cell type interaction deconvolution (CID) · GitHub
[go: up one dir, main page]

Skip to content
songw01Public

About

Cell type interaction deconvolution (CID)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

CID: Cell-Type Interaction Decomposition

CID decomposes gene-gene covariance in bulk RNA-seq into cell type × cell type entries, and each entry into an abundance, a co-regulation and a mixed (recruitment-like) block. It uses cell type-resolved expression from deconvolution with a single-cell reference (e.g. InstaPrism, BayesPrism).

Bulk expression is the sum of cell-type contributions, but covariances are computed on log2 bulk, where the sum is not additive. CID splits each sample's centred log2 bulk value exactly into cell-type contributions with the log-mean Divisia index (LMDI):

log2(T_i / G) = Σ_k (Z_ik − G·π_k) / (L(T_i, G)·ln 2)

Here T_i = 2^(log2 bulk), G is the geometric mean, π_k is the average share of component k, and L(a, b) = (a − b)/(ln a − ln b) is the logarithmic mean. The prior count and any deconvolution mismatch form an extra eta component. Each cell type is credited with its change from its usual level, so a high but stable expresser gets almost nothing. Each contribution is then split again into abundance and per-cell expression parts (two-factor LMDI, below).

Install

# from the CID project folder
devtools::install("CIDpkg")            # or devtools::load_all("CIDpkg") while developing
# optional
BiocManager::install("BiocParallel")

Tutorial

vignette("liu2019_tutorial", package = "CID") walks through CID on the Liu et al. (2019) anti-PD-1 melanoma cohort: inputs, one gene pair (CXCL9–CXCR3) split by cell type pair and by source, the full ligand-receptor screen with empirical-null calibration, pathway networks, and responders vs non-responders, including the label permutation test (cid_group_perm()). The prepared inputs ship in system.file("extdata", "liu2019_lr.rds", package = "CID"). Install with devtools::install("CIDpkg", build_vignettes = TRUE) to build it (about 3 minutes).

What's in it

Step Functions
Normalize bulk lognormalize_cpm()
Cell type-resolved expression (Z) and fractions as_z_list() / as_z_array() for InstaPrism get_Z_array() or BayesPrism output; mrna_fractions(), proportions_from_z(), refine_fractions()
CID per gene pair (cell type × cell type; A, E, M blocks; studentized tests) cid_pair_components() ("lmdi2", "pearson"), lmdi2_contrib(), lmdi_contrib(), pearson_contrib(), pearson_residuals(), abundance_cov()
Ligand-receptor workflow cid_lr_each(), cid_lr_workflow(), pct_expressed(), pct_expressed_seurat(), add_pct_expressed()
Empirical-null recalibration cid_empirical_null() (applied by default in cid_lr_workflow())
Cohorts and groups cid_meta() (cross-cohort Stouffer), cid_group_perm()
Cell type networks per signaling pathway cid_lr_table(), cid_network(), cid_networks(), cid_pathway_summary(), plot_cid_network()
Abundance × co-regulation quadrants cid_quadrants(), cid_quadrant_diff(), plot_cid_quadrants()
Simulation with known truth simulate_cid_components()

See NEWS.md for what was removed in 0.2.0. Version 0.1.8 is needed only to rerun analyses that used the single-factor cid_pair() or the legacy wrappers.

Abundance-aware CID

Each cell type's contribution is abundance × per-cell expression, Z_ik = w_ik · x_ik. Much bulk covariance comes from cell-type abundance alone: two T-cell genes co-vary whenever T-cell infiltration varies. cid_pair_components() separates this from co-regulation.

method = "lmdi2" (log2 scale; default). Each LMDI term splits exactly as Z − Z* = L(Z, Z*)·[ln(w/w*) + ln(x/x*)], so each cell type × cell type entry splits into three parts that add up to the LMDI total. target = "total" tests the whole entry (A + E + M) by the same studentized statistic.

Block Meaning Example
cov.abund both genes through cell-type abundance T-cell markers co-varying with infiltration
cov.expr per-cell co-regulation (the abundance-marginalized CID) genes co-regulated within myeloid cells
cov.mixed one gene's per-cell expression with the other's abundance tumor ligand rising with T-cell influx

The mixed block is where recruitment-type ligand-receptor biology appears. Removing all abundance-coupled covariance would remove it too, so the blocks are reported separately rather than discarded.

method = "pearson" (fully marginalized). Pearson residuals from a composition-mean negative binomial model, mu_i = Σ_k w_ik β_k with variance mu/s + φmu². The residual splits exactly as Σ_k w_ik (x_ik − β_k)/sd_i. Abundance variation alone creates no covariance here, and neither does recruitment. The total residual depends only on the bulk, W and β, so it is a check that does not rely on per-sample deconvolved profiles. abundance_cov() gives the matching bulk-only moment term, M Cov(W) Mᵀ.

Proportions. Use mRNA fractions over all genes (mrna_fractions() on the full deconvolution, before subsetting), so that x = Z/w is a CPM profile per cell type. refine_fractions() optionally moves each sample's median per-cell shift across genes into the abundance term, as TMM does for libraries.

Inference. Both genes' parts share composition-dependent scaling, so they are uncorrelated but not independent under the null, and a plain permutation test over-rejects: 38–58% at nominal 5% in simulation. Tests therefore use the studentized covariance (DiCiccio & Romano 2017, JASA). By default its p-values come from the normal approximation, which was calibrated in simulation at n = 47 and 72: 4.4–5.2% at α = 0.05 and 0.7–1.2% at α = 0.01. A studentized permutation test is available with nperm. It needs tens of thousands of permutations for BH across 24 × 24 cell-type pairs, because the smallest attainable p is 1/(nperm + 1).

In simulation, each planted signal lands in its block: abundance-only → cov.abund, myeloid co-regulation → cov.expr (and cov.abund, since the genes are myeloid-specific), recruitment → cov.mixed at Tumor → Tcell. Pearson keeps only co-regulation.

Cell type networks per signaling pathway

The ligand-receptor results can be summarized as three directed sender → receiver cell type networks per signaling pathway, one per block:

Network Block An edge sender → receiver means
Abundance abund ligand and receptor co-vary because the amounts of the two cell types co-vary (shared composition)
Co-regulatory expr per-cell ligand in the sender co-varies with per-cell receptor in the receiver
Recruitment mixed.recv per-cell ligand in the sender co-varies with the abundance of the receiver

The recruitment network uses the receiver half of the mixed block, mixed.recv = Cov(per-cell gene 1 in the sender, abundance part of gene 2 in the receiver); the other half, mixed.send, is reported too, and cov.mixed = cov.mixed.send + cov.mixed.recv. Results from CID < 0.1.1 lack the halves, and the pooled mixed block is used with a message.

An interaction is called for a sender → receiver pair when its gene pairs pass fdr, min.effect and pct.cutoff (every subunit gene pair with subunits = "all"). Each edge sums the called interactions of the pathway: n interactions, weight = Σ|ρ|, net = Σρ, and the top interactions.

load("CellChatDB.human.rda")                  # from the CellChat package
DB <- CellChatDB.human$interaction            # needs pathway_name
res <- lapply(groups, function(G)             # e.g. responders, non-responders
  cid_lr_workflow(int.table, G$bulk.lognorm, G$Zarr, pct = pct,
                  method = "lmdi2", W = G$W.cpm))
tab <- do.call(rbind, Map(function(r, g) cbind(cid_lr_table(r, DB), group = g),
                          res, names(res)))

cid_pathway_summary(tab)                      # which pathways have edges, per block
nl <- cid_networks(tab, pathway = "CXCL")     # abundance, co-regulatory, recruitment
nl$recruitment$edges                          # edge table
plot_cid_network(nl)                          # circle plots, panels by block x group
plot_cid_network(nl, type = "heatmap")        # sender x receiver heat maps

Several cohorts can be combined first with cid_meta() (Stouffer's method on the studentized statistics, BH within gene pair), and the result passed to the same functions.

Abundance × co-regulation quadrants

A ligand-receptor pathway can be co-regulated per cell while its sender and receiver cell types are mutually exclusive in abundance, or the reverse. To read the two blocks together, summarize them per pathway, or per pathway × sender → receiver, and place each unit in a quadrant:

Quadrant Co-regulation (x) Abundance (y) Reading
Q1 + + co-regulated and co-abundant
Q2 − + anti-regulated, co-abundant
Q3 − − anti-regulated, mutually exclusive
Q4 + − co-regulated, mutually exclusive
meta <- cid_meta(list(Liu = liu, Riaz = riaz, GidePD1 = gide1, GideCombo = gide2))  # or one cid_lr_table()
qp <- cid_quadrants(meta, level = "pathway", exclude.genes = "CD8B2")   # competitive null, B gene-pair sets
qe <- cid_quadrants(meta, level = "edge", exclude.genes = "CD8B2")      # conservative Z per pathway x edge
dp <- cid_quadrant_diff(meta, groups = c("NR", "RE"), level = "pathway", studies = list(liu, riaz, gide1, gide2))
de <- cid_quadrant_diff(meta, groups = c("NR", "RE"), level = "edge", studies = list(liu, riaz, gide1, gide2))
plot_cid_quadrants(qp)                       # groups overlaid, arrows from the second to the first group
plot_cid_quadrants(qe, group = "NR", highlight = "MHC-I: Tumor cells -> CD8+ T cells TOX+")
plot_cid_quadrants(dp)                       # differences, NR - RE
  • Effects are the mean cor.* over a unit's entries. By default only cross-cell type entries with both genes in ≥ 5% of reference cells are used.
  • Pathway level: each pathway is tested against random sets of the same number of ligand-receptor gene pairs, with all their entries (competitive null).
  • Edge level: Z is the mean of the entry z.*, which assumes fully dependent gene pairs (conservative).
  • The two axes are combined by a 2-df chi-square test with BH per group. sig requires q < 0.05 and |Z| ≥ 1.96 on both axes.
  • Group differences are taken on cor.*, since Z grows with sample size. With studies, per-cohor 739F t differences and sign agreement (nsame.x, nsame.y) are added. At edge level, sig then means the same sign in ≥ 75% of cohorts on both axes.

A worked example is in inst/scripts/quadrant_workflow.R.

Label permutation test of group differences

cid_group_perm() tests whether chosen entries differ in ρ between two groups. Within each cohort it permutes whole samples between the groups, recomputes the LMDI parts in each permuted group and recomputes the difference.

ent <- data.frame(set = "XCL1/2 > XCR1", gene.1 = c("XCL1", "XCL2"), gene.2 = "XCR1",
                  celltype.1 = "Cycling T-cells", celltype.2 = "cDC1")
cid_group_perm(list(Liu = liu, Riaz = riaz, Gide_PD1 = gide1, Gide_combo = gide2), ent,
               groups = c("NR", "RE"), blocks = c("expr", "abund"), B = 5000, seed = 7)
  • Entries sharing a set are averaged; the across-cohort p compares the mean difference with the mean of the per-cohort permutation draws, and z.stouffer combines the per-cohort permutation z scores.
  • q is BH over all sets and blocks; attr(, "by_cohort") has the per-cohort table.

Size factor as its own LMDI term

After TMM normalization, CPM-closed mRNA fractions sum to 1 / f_i per sample rather than 1. By default (size = "separate") cid_pair_components() gives this per-sample size factor its own LMDI part, so the abundance block reflects closed composition only; every covariance term involving the size factor is reported as cov.size / cor.size, and cov.abund + cov.expr + cov.mixed + cov.size == ct.cov. The expression block is unchanged. size = "abundance" reproduces the earlier two-factor split.

Empirical-null recalibration for deconvolved inputs

With deconvolved inputs (InstaPrism, MuSiC, CIBERSORT, ...) every gene pair in a cell-type entry inherits the same re-allocation error, so the expression and mixed blocks are shifted and over-dispersed under the null and nominal p-values are anti-conservative. cid_empirical_null() estimates the null from the tested pairs themselves (Efron 2004), one fit per directed cell-type entry and block, and adds recalibrated statistics:

res <- cid_empirical_null(net, blocks = c("expr", "mixed"))   # adds z.emp.*, p.emp.*, adj.p.emp.*
attr(res, "null.fit")                                           # per-entry null mean and SD

The fit assumes most tested pairs in an entry do not interact; the abundance block is left alone by default.

Since 0.1.5, cid_lr_workflow(..., method = "lmdi2") applies it by default (null = "empirical"): the null for each sender -> receiver entry is estimated from all tested gene pairs that pass pct.cutoff, p.* / adj.p.* hold the recalibrated values (BH within gene pair, as before), the theoretical values are kept as p.nominal.* / adj.p.nominal.*, and res$null.fit lists the fitted null mean and SD per entry (SD near 1: clean inputs; near 2: strong deconvolution distortion). Entries with fewer than 30 expressed pairs use the null pooled over entries; with fewer than 200 expressed entries in total the workflow keeps the theoretical null and warns. Use null = "theoretical" for a hand-picked list of known interactors, where most tested pairs are expected to interact.

About

Cell type interaction deconvolution (CID)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0