bio-gene-regulatory-networks-differential-networks
Compare gene co-expression and regulatory networks between biological conditions to find rewired relationships using DiffCorr, DiffCoEx, DINGO/iDINGO, and CoDiNA. Covers the differential-connectivity-is-not-differential-expression distinction, the pairwise multiple-testing explosion, marginal vs partial (direct) rewiring, and the underpowered-rewiring failure mode. Use when comparing co-expression networks between disease vs control, treatment, or developmental stages, or finding hub genes that rewire without changing mean expression. For single-condition modules see coexpression-networks; for differential expression of means see differential-expression/de-results.
What this skill does
## Version Compatibility
Reference examples tested with: DiffCorr 0.4.1+, DINGO/iDINGO 1.0.4+, CoDiNA 1.1.2+; Python path uses scipy 1.12+, statsmodels 0.14+, networkx 3.0+.
Before using code patterns, verify installed versions match. If versions differ:
- R: `packageVersion('<pkg>')` then `?function_name` to verify parameters
- Python: `pip show <package>` then `help(module.function)` to check signatures
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
In statsmodels, `multipletests()` defaults to method `'hs'` (Holm-Sidak), NOT Benjamini-Hochberg. Always pass `method='fdr_bh'` explicitly for differential-correlation FDR.
# Differential Networks
**"Compare gene co-expression networks between my disease and control groups"** -> Test whether gene-gene relationships differ between two conditions, identifying gained, lost, and reversed edges and the genes that rewire.
- R: `DiffCorr::comp.2.cc.fdr()` (pairwise Fisher z); `DiffCoEx` (module-level); `iDINGO::dingo()` (partial-correlation)
- Python: Fisher z-test with `scipy.stats` + `statsmodels` FDR
## The Single Most Important Modern Insight -- Differential Connectivity Is Not Differential Expression
A gene can have identical mean expression in two conditions yet a completely rewired set of correlation partners -- and that rewiring, not the mean shift, can be the disease signal. The classic demonstration is Hudson, Reverter & Dalrymple 2009 (*PLoS Comput Biol* 5:e1000382): myostatin received the top Regulatory Impact Factor despite **not being differentially expressed**, correctly fingering the gene carrying the causal mutation purely from the change in its correlation wiring to differentially-expressed targets. So differential expression (a shift in means) and differential connectivity (a shift in the correlation structure) are **orthogonal questions**, and the most differentially-connected hub is often not differentially expressed. Three distinct analyses are routinely conflated and must be kept separate: differential **expression** (mean shift), differential **co-expression** (pairwise correlation shift, DiffCorr/DiffCoEx), and differential **connectivity/rewiring** at the conditional-independence level (DINGO).
The dominant practical failure is **statistical power**. The variance of a *difference* of two correlations is large, so rewiring detection needs many samples per group -- far more than differential expression. Worse, pairwise differential-correlation testing has a multiple-testing explosion: p genes produce ~p^2/2 edge tests, so without aggressive FDR (or a module-level method that sidesteps per-edge testing) the results are dominated by false positives. Most "rewired hub" findings in small cohorts are underpowered noise.
## Differential-Network Method Taxonomy
| Method | Citation | Level | Edge type | Note |
|--------|----------|-------|-----------|------|
| DiffCorr | Fukushima 2013 *Gene* | per-edge | marginal | simple Fisher z; p^2/2 tests -> aggressive FDR needed |
| DiffCoEx | Tesson 2010 *BMC Bioinformatics* | module | marginal | WGCNA-based; tests modules, sidesteps per-edge multiplicity |
| DINGO | Ha 2015 *Bioinformatics* | per-edge | **partial** | group-specific GGM; bootstrap differential score (direct rewiring) |
| iDINGO | Class 2018 *Bioinformatics* | per-edge | partial, multi-omics | chain-graph across data types (e.g. miRNA->mRNA->protein) |
| CoDiNA | Gysi 2020 *PLoS ONE* | per-edge | on supplied nets | compares >=2 networks; common/specific/different edge classes |
## Decision Tree by Scenario
| Scenario | Recommended | Why |
|----------|-------------|-----|
| Two conditions, quick pairwise rewiring | DiffCorr (Fisher z) + strict FDR | simplest; report gained/lost/reversed |
| Want modules that rewire, not edges | DiffCoEx | module-level testing avoids the p^2/2 explosion |
| Need direct (not indirect) rewiring | DINGO/iDINGO | partial correlation removes confounded indirect changes |
| More than two conditions | CoDiNA | n-way comparison with edge classification |
| Multi-omics rewiring | iDINGO | chain-graph respects the biological hierarchy |
| Just want mean-expression changes | -> differential-expression/de-results | that is DE, not rewiring |
| Build the per-condition networks first | -> coexpression-networks | rewiring compares already-built networks |
## DiffCorr: Pairwise Differential Correlation (R)
**Goal:** Find gene pairs whose correlation differs significantly between two conditions.
**Approach:** Fisher z-transform each correlation per condition and test the z-difference with FDR; classify surviving edges as gained, lost, or reversed.
```r
library(DiffCorr)
expr_all <- read.csv('normalized_counts.csv', row.names = 1) # genes x samples
info <- read.csv('sample_info.csv', row.names = 1)
# Filter to top variable genes first: p^2/2 edge tests make the full matrix intractable.
gene_vars <- apply(expr_all, 1, var)
top <- names(sort(gene_vars, decreasing = TRUE))[1:3000]
d1 <- expr_all[top, info$condition == 'control']
d2 <- expr_all[top, info$condition == 'disease']
# Returns the differential correlations directly (threshold filters exported pairs by lfdr).
# It only writes the file when save = TRUE, so use the returned data.frame. Columns carry
# spaces ('molecule X', 'molecule Y', 'r1', 'r2', 'lfdr (difference)') -- index with [[ ]].
res <- comp.2.cc.fdr(data1 = d1, data2 = d2, threshold = 0.05, save = TRUE,
output.file = 'diffcorr.txt')
```
## DINGO: Direct Differential Rewiring (R)
**Goal:** Detect rewiring at the conditional-independence (direct edge) level rather than marginal correlation.
**Approach:** Estimate a group-specific Gaussian graphical model and bootstrap an edge-wise differential score.
```r
library(iDINGO)
# dingo(dat, x, ...): dat = samples x genes; x = the binary group covariate (length n).
fit <- dingo(dat = expr_mat, x = group, B = 100, cores = 8) # B = bootstrap reps
# fit$diff.score / fit$p.val give edge-wise differential connectivity (direct edges).
```
## Python: Fisher z Differential Network
**Goal:** Compare correlation networks between two conditions in a Python-native workflow.
**Approach:** Compute per-condition correlation matrices, test each pair with Fisher's z, apply BH FDR (explicitly), and classify edges.
```python
import numpy as np, pandas as pd
from scipy import stats
from statsmodels.stats.multitest import multipletests
def fisher_z(r1, n1, r2, n2):
z1, z2 = np.arctanh(np.clip([r1, r2], -0.9999, 0.9999))
se = np.sqrt(1 / (n1 - 3) + 1 / (n2 - 3))
z = (z1 - z2) / se
return z, 2 * stats.norm.sf(abs(z))
def differential_network(e1, e2, fdr=0.05):
genes = e1.columns.tolist()
n1, n2 = len(e1), len(e2)
c1, c2 = e1.corr().values, e2.corr().values
rows = []
for i in range(len(genes)):
for j in range(i + 1, len(genes)):
z, p = fisher_z(c1[i, j], n1, c2[i, j], n2)
rows.append((genes[i], genes[j], c1[i, j], c2[i, j], z, p))
df = pd.DataFrame(rows, columns=['g1', 'g2', 'r1', 'r2', 'z', 'p'])
# statsmodels default is Holm-Sidak ('hs'); BH must be requested explicitly.
df['padj'] = multipletests(df['p'], method='fdr_bh')[1]
return df
```
## Per-Method Failure Modes
### Underpowered rewiring claims
**Trigger:** declaring rewired hubs from a small cohort. **Mechanism:** the variance of a correlation difference is large; rewiring needs more samples than DE. **Symptom:** few or no edges survive FDR, or unstable results across resampling. **Fix:** require adequate n per group; treat low-power results as exploratory.
### Pairwise multiple-testing explosion
**Trigger:** testing all gene pairs with weak/no FDR. **Mechanism:** p genes -> ~p^2/2 tests. **Symptom:** thousands of "significant" edges, irreproducible. **Fix:** pre-filter to variable genes, apply strict FDR, or use a module-level Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.