
Cluster enhancer-like anchors into spatial cliques or promoter hubs
Source:R/enhancer_cliques.R
cluster_enhancer_cliques.RdExtracts enhancer-like (E/eP family) or promoter (P family) loops from an annotated (optionally refined) looplook result, builds the anchor network, and identifies enhancer cliques (dense E-E modules) or promoter hubs (P-P modules) via connected components, with an optional Leiden community refinement.
Usage
cluster_enhancer_cliques(
annotation_res,
validation_res = NULL,
loop_types = c("E-E", "E-eP", "eP-eP"),
require_chromatin_evidence = TRUE,
promote_evidenced_eP = TRUE,
community_method = c("components", "leiden"),
resolution_parameter = 1,
min_clique_size = 2,
neighbor_hop = 0,
include_unresolved = FALSE,
gene_mode = c("auto", "anchors", "linked"),
peak_bed = NULL,
run_peak_enrichment = FALSE,
peak_ntimes = 1000L,
peak_mappability_bed = NULL,
comparison_region_bed = NULL,
clustering_significance = FALSE,
clustering_ntimes = 200L,
clustering_seed = NULL,
write_output = FALSE,
out_dir = "./results",
project_name = "EnhancerCliques",
quiet = FALSE
)Arguments
- annotation_res
List. Output of
annotate_peaks_and_loopsor a refined variant.- validation_res
Data frame or
NULL. Output ofvalidate_epeG_by_chromatin, providing per-anchorenhancer_evidencegrades andH3K4me3overlap status. DefaultNULL(evidence filtering inactive with a warning whenrequire_chromatin_evidence = TRUE).- loop_types
Character vector. Loop types to cluster. Default
c("E-E", "E-eP", "eP-eP")for enhancer cliques; usec("P-P", "eP-P")for promoter hubs.- require_chromatin_evidence
Logical. If
TRUE, only anchors with enhancer marks (canonical/strong/supported) enter the enhancer network. DefaultTRUE.- promote_evidenced_eP
Logical. Promote eP/eG anchors with enhancer marks into the enhancer network. Default
TRUE.- community_method
Character.
"components"(default; connected components, consistent with the package's cluster semantics) or"leiden"(additional modularity-based refinement recorded incommunity_idandsummary$modularity). The Leiden refinement is an exploratory partition of an unweighted binary interaction graph – it is not a significance test and may be sensitive toresolution_parameteron sparse chain-like networks; components remain the primary, interpretation-grade grouping inclique_id.- resolution_parameter
Numeric. Leiden resolution parameter, used only when
community_method = "leiden". Values > 1 favour finer partitions, values in (0, 1) coarser ones. Default1. This is an exploratory granularity control, not a statistical significance threshold.- min_clique_size
Integer. Minimum number of anchors per clique (component). Default
2.- neighbor_hop
Integer.
0(default): clique genes are promoters directly looped to clique anchors.1: additionally includes promoters reached through one extra anchor hop.- include_unresolved
Logical. If
TRUE, eP/eG anchors without chromatin evidence stay in the network under their original type (structural exploration). DefaultFALSE.- gene_mode
Character.
"auto"(default): anchor genes for promoter-mode types, linked promoter genes for enhancer-mode types (both when loop types mix families)."anchors"/"linked"force one behaviour.- peak_bed
Character or
NULL. Optional BED of genomic features (GWAS/eQTL variants, TF ChIP peaks, ATAC regions, etc.) to overlay onto clique anchors. When supplied, produces the descriptiveclique_peakstable and then_target_peakscolumn. This is an annotation layer only – it does not affect anchor inclusion or gene assignment. DefaultNULL.- run_peak_enrichment
Logical. If
TRUE(requirespeak_bed), an aggregate matched-background permutation test (regioneRoverlapPermTest) is run on the merged clique-anchor regions vs the feature set, reporting fold-enrichment and p-value. This is not a per-clique significance test; per-clique confidence is descriptive only. Fails soft when regioneR is unavailable or the genome cannot be resolved. DefaultFALSE.- peak_ntimes
Integer. Number of permutations for
run_peak_enrichment. Default1000L.- peak_mappability_bed
Character or
NULL. Optional BED mask (e.g. mappability/blacklist) used to constrain randomisation of the enrichment background. DefaultNULL.- comparison_region_bed
Character or
NULL. Optional BED of a 1D baseline region set (e.g. super-enhancers) run through the identical enrichment procedure, so 3D-clique enrichment can be contrasted with a 1D baseline. DefaultNULL.- clustering_significance
Logical. If
TRUE, a network-level anti-noise test is run: the observed Leiden modularity (modularity objective) of the clique graph is compared with a degree-preserving rewiring null (igraph::rewire(keeping_degseq)). The resulting empirical p-value (summary$clustering_p,clustering_test) answers whether the E-E/E-P module structure is more modular than random wiring with the same degrees. It is a structural check only: per-clique p-values are deliberately NOT computed (multiple testing over hundreds to thousands of cliques and size confounding), and clique relevance is supported by the functional layers (peak enrichment and perturbation response). DefaultFALSE.- clustering_ntimes
Integer. Number of rewiring permutations for
clustering_significance. Default200L.- clustering_seed
Integer or
NULL. Optional seed for the rewiring permutation, applied withwithr::local_seedso the caller's RNG state is restored on exit (no leakage).NULL(default) uses the current RNG state, matching the package convention inprofile_target_genes().- write_output
Logical. If
TRUE, write an Excel workbook with the Cliques, Membership and CliqueGenes sheets toout_dir. DefaultFALSE.- out_dir
Character. Output directory (used when
write_output = TRUE). Default"./results".- project_name
Character. File-name prefix for exported workbooks. Default
"EnhancerCliques".- quiet
Logical. If
TRUE, suppress progress messages. DefaultFALSE.
Value
A named list:
cliques– one row per clique: size, span, trans-chromosomal status, chromatin evidence composition, internal connectivity (mean_intra_degree,max_intra_degree), and genes.membership– one row per eligible anchor: coordinates, original and effective types, chromatin evidence, promotion reason, clique/community assignment, andintra_clique_degree(number of edges to other anchors of the same clique; anchor-local connectivity, not a whole-network label).clique_genes– long-format clique-to-gene provenance (gene_role,anchor_role,evidence,n_paths).dropped– traceability table of anchors excluded from the network (anchor_id, coordinates,anchor_type,chromatin_evidence,drop_category: one ofinsufficient_chromatin_evidence,promoter_signal_not_enhancer,rerouted_to_enhancer,unresolved_no_chromatin_evidence,not_in_loop_family). Kept in the output so every boundary decision remains auditable.clique_peaks– descriptive overlay ofpeak_bedfeatures onto clique anchors (clique_id,peak_id,anchor_id,overlap_bp);NULLwhenpeak_bedis not supplied.peak_enrichment– aggregate matched-background permutation enrichment of merged clique-anchor regions againstpeak_bed, optionally alongside acomparison_region_bedbaseline (region_set,n_regions,n_observed_overlaps,mean_expected,fold_enrichment,z_score,p_value);NULLunlessrun_peak_enrichment = TRUE.clustering_test– network-level degree-preserving rewiring test of Leiden modularity (observed_modularity,null_mean_modularity,null_sd_modularity,p_value,n_permutations);NULLunlessclustering_significance = TRUE. Structural anti-noise check only; not a per-clique test.network– igraph object with vertex attributesanchor_id,anchor_type,effective_type,chromatin_evidence,clique,community.summary– clustering and boundary-rule counts (n_dropped,n_dropped_insufficient_evidence,n_promoter_signal_not_enhancer,n_rerouted_to_enhancer,n_unresolved_dropped,n_not_in_family, promotions), plusmodularity(NA unlesscommunity_method = "leiden"; reported for partition-quality assessment, not as a significance test).metadata– parameters, QC status and boundary rules.
Details
Refinement inheritance: the function consumes
annotate_peaks_and_loops() output directly, or its
expression-/chromatin-refined variants. Reclassified anchor types
(e.g., P -> eP from expression refinement) are inherited from the
supplied object; the function never re-runs refinements. The
recommended chain is annotation -> refine_loop_anchors_by_expression()
-> refine_loop_anchors_by_chromatin() (or
validate_epeG_by_chromatin()) -> clustering.
Which mode? One call runs one mode, selected by
loop_types:
Enhancer cliques (default):
loop_types = c("E-E","E-eP","eP-eP"). Asks which distal enhancers cluster in 3D, and which promoters they loop to.clique_genesis populated withgene_role = "linked_promoter"andcliques$anchor_genesisNA.Promoter hubs:
loop_types = c("P-P","eP-P"). Asks which promoters cluster in space.clique_genesis populated withgene_role = "anchor_gene"(the anchor's own genes).
The two modes are independent calls and are exported as separate workbooks; run the function twice to compare.
Boundary rules:
E/dual anchors enter the enhancer network; P/dual anchors enter the promoter network.
eP/eG anchors are dual-identity: with enhancer marks (canonical/strong/supported) they are promoted into the enhancer network; with an H3K4me3-positive signal they are promoted into the promoter network.
Anchors absent from
validation_resare treated as lacking evidence. Without evidence, eP/eG anchors are dropped by default (conservative); setinclude_unresolved = TRUEfor structural exploration.When
require_chromatin_evidence = TRUE, E anchors without sufficient enhancer marks are dropped from the enhancer network.
Examples
loop_df <- data.frame(
loop_ID = c("L1", "L2", "L3", "L4"),
chr1 = c("chr1", "chr1", "chr2", "chr1"),
start1 = c(100L, 200L, 50L, 400L),
end1 = c(200L, 300L, 150L, 500L),
chr2 = c("chr1", "chr1", "chr2", "chr1"),
start2 = c(210L, 310L, 160L, 510L),
end2 = c(310L, 410L, 260L, 610L),
anchor1_type = c("E", "E", "E", "eP"),
anchor2_type = c("E", "E", "E", "E"),
anchor1_gene = NA_character_,
anchor2_gene = NA_character_,
loop_type = c("E-E", "E-E", "E-E", "E-eP"),
a1_id = c("A1", "A2", "A3", "A4"),
a2_id = c("A2", "A3", "A4", "A5"),
stringsAsFactors = FALSE
)
res <- list(loop_annotation = loop_df)
cl <- cluster_enhancer_cliques(res,
require_chromatin_evidence = FALSE, quiet = TRUE
)
head(cl$cliques)
#> clique_id n_anchors n_internal_loops chr start end is_trans_chromosomal
#> 1 Clique_01 3 2 chr1;chr2 NA NA TRUE
#> n_chromatin_validated weakest_evidence mean_intra_degree max_intra_degree
#> 1 NA <NA> 1.333333 2
#> anchor_genes linked_promoter_genes n_genes n_target_peaks
#> 1 <NA> <NA> 0 NA
# Promoter hubs: switch loop_types (and this time show anchor genes)
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
)
head(ph$cliques)
#> clique_id n_anchors n_internal_loops chr start end is_trans_chromosomal
#> 1 Clique_01 3 2 chr1 100 420 FALSE
#> n_chromatin_validated weakest_evidence mean_intra_degree max_intra_degree
#> 1 NA <NA> 1.333333 2
#> anchor_genes linked_promoter_genes n_genes n_target_peaks
#> 1 GENE1;GENE2;GENE3 <NA> 3 NA