
Test Gene Co-expression within Promoter Hub / Enhancer Clique Gene Sets
Source:R/enhancer_cliques.R
test_hub_gene_coexpression.RdBackground-matched permutation test of whether the genes assigned to each
3D clique (promoter hubs: anchor_gene; enhancer cliques:
linked_promoter) are more transcriptionally coordinated than random
gene sets of equal size drawn from the measurable gene pool.
Usage
test_hub_gene_coexpression(
cliques_res,
expr_matrix,
gene_mode = c("auto", "anchors", "linked"),
n_perm = 1000L,
seed = NULL,
cor_method = c("pearson", "spearman"),
min_genes = 3L,
null_method = c("genome", "distance_matched"),
gene_coords = NULL,
write_output = FALSE,
out_dir = "./results",
project_name = "Coexpression",
quiet = FALSE
)Arguments
- cliques_res
List. Output of
cluster_enhancer_cliques.- expr_matrix
Matrix, data.frame, or character path. Sample-level expression matrix with gene IDs as row names (first column = gene ID when a file path). Non-negative values (TPM/FPKM/counts/CAGE/nascent).
- gene_mode
Character. Which clique genes supply the gene sets.
"auto"(default): usesanchor_generows when present, otherwiselinked_promoterrows – this matches the mode used to build the cliques (promoter hubs vs enhancer cliques)."anchors"forcesanchor_gene;"linked"forceslinked_promoter.- n_perm
Integer. Number of permutations. Default
1000L.- seed
Integer or
NULL. Optional seed for the permutations (applied withwithr::local_seedso the caller's RNG state is restored). DefaultNULLuses the current RNG state.- cor_method
Character.
"pearson"(default) or"spearman". Spearman is more robust to outliers and monotone non-linearity at the cost of power on small gene sets.- min_genes
Integer. Minimum number of expression-matched genes for a clique to be tested. Cliques below this are returned with
p_value = NA. Default3.- null_method
Character. Null sampling strategy.
"genome"(default): null gene sets are drawn uniformly from the measurable gene pool – no genomic-position matching. This is the historical behaviour."distance_matched": null gene pairs are drawn with the same same-chromosome distance distribution as the observed clique gene pairs (trans-chromosomal pairs matched separately), usinggene_coords. This removes the confound that linearly neighbouring genes share local regulatory environments, so it answers the sharper question: are 3D co-localised genes more co-expressed than random genes with the same linear genomic proximity? Requiresgene_coords.- gene_coords
Data frame or
NULL. Required whennull_method = "distance_matched". A data frame with columnsgene_id,chr,start,end(gene IDs matching the expression matrix row names / clique gene symbols, matched case-insensitively), or a TxDb object from which coordinates are extracted viaGenomicFeatures::genes(). Ignored whennull_method = "genome".- write_output
Logical. If
TRUE, write a multi-sheet Excel workbook toout_dir. DefaultFALSE.- out_dir
Character. Output directory for the Excel file (used when
write_output = TRUE). Default"./results".- project_name
Character. File-name prefix for the exported workbook. Default
"Coexpression".- quiet
Logical. Suppress progress messages. Default
FALSE.
Value
A list:
per_clique– data.frame, one row per clique, ordered by p-value:clique_id,n_genes,n_matched,n_pairs,observed_score,null_mean,null_sd,z_score,p_value,n_permutations,genes(semicolon-delimited gene list). Cliques with too few matched genes or no finite observed score haveNAstatistics.summary– named list:n_cliques,n_tested,n_skipped_small,n_skipped_no_match,n_significant(p <= 0.05),median_p_value,cor_method,n_permutations,null_method,seed.merged– data.frame,per_cliquemerged withcliques_res$cliques(anchor counts, chromosome, internal loop count);NULLwhen the cliques table is unavailable. Also includes anFDRcolumn (BH-adjusted p-values).
Details
Method. For each clique the observed statistic is the mean of all
pairwise (off-diagonal) gene-expression correlations among the clique's
matched genes, computed on sample-level expression values
(use = "pairwise.complete.obs"). The empirical p-value is the
fraction of null scores at least as large as the observed score, with a +1
pseudocount (right-sided: we ask whether clique genes are more
co-expressed than chance).
Null models. Two null strategies are available:
null_method = "genome"(default): each null gene set is drawn uniformly from the measurable gene pool (genes with finite, non-zero variance across samples) and the same statistic is recomputedn_permtimes. This tests against a genomic-random expectation.null_method = "distance_matched": null gene pairs are drawn with the same same-chromosome distance distribution as the observed clique gene pairs (binned at 10 kb / 100 kb / 1 Mb / 10 Mb, trans-chromosomal pairs matched separately). This controls for the strong genomic prior that linearly neighbouring genes share local regulatory environments and co-express by position alone, so the test answers the sharper question: are 3D co-localised genes more co-expressed than random genes with the same linear proximity? Requiresgene_coords.
Scope and interpretation. This is a background-matched enrichment,
not a per-gene or per-gene-pair test. It supplies the gene-level functional
layer for cluster_enhancer_cliques output that is symmetric to
the peak-enrichment layer. It is best read as an exploratory validation:
cliques whose genes are significantly co-expressed are more likely to reflect
coordinated regulation of the assigned genes rather than chance spatial
proximity. No multiple-testing correction is
applied in the returned per_clique p-values; when testing many
cliques, apply your own FDR control (e.g. p.adjust(..., "BH")).
Why not the anchor-level test? Promoter-anchor positions are determined by gene structure rather than 3D organisation, so position-based enrichment (as used for enhancer cliques) would largely reflect the genomic prior. Co-expression of the assigned genes is the interpretable functional readout for promoter hubs.
Examples
# Promoter-hub cliques from the enhancer-cliques example
pp_df <- data.frame(
loop_ID = c("L1", "L2"),
chr1 = c("chr1", "chr1"),
start1 = c(100L, 210L), end1 = c(200L, 310L),
chr2 = c("chr1", "chr1"),
start2 = c(210L, 320L), end2 = c(310L, 420L),
anchor1_type = c("P", "P"), anchor2_type = c("P", "P"),
anchor1_gene = c("GENE1", "GENE2"),
anchor2_gene = c("GENE2", "GENE3"),
loop_type = "P-P",
a1_id = c("B1", "B2"), a2_id = c("B2", "B3"),
stringsAsFactors = FALSE
)
ph <- cluster_enhancer_cliques(list(loop_annotation = pp_df),
loop_types = c("P-P", "eP-P"), quiet = TRUE
)
# Synthetic expression matrix with a co-expressed GENE1/GENE2 pair
set.seed(1)
fake_expr <- matrix(runif(4 * 6, 0, 10), nrow = 4)
rownames(fake_expr) <- c("GENE1", "GENE2", "GENE3", "GENE4")
colnames(fake_expr) <- paste0("S", 1:6)
res <- test_hub_gene_coexpression(ph, fake_expr, n_perm = 100, seed = 1)
#> Co-expression test: 1/1 cliques tested, 0 significant (p <= 0.05).
head(res$per_clique)
#> clique_id n_genes n_matched n_pairs observed_score null_mean null_sd
#> 1 Clique_01 3 3 3 -0.1193602 -0.008181418 0.2685189
#> z_score p_value n_permutations genes FDR
#> 1 -0.4140443 0.7425743 100 GENE1;GENE2;GENE3 0.7425743