bulk-rnaseq-counts-to-de-deseq2listed
Install: claude install-skill hossainlab/omics-skills
# DESeq2 Comprehensive Reference
Complete code patterns for DESeq2 differential expression analysis. Adapt these
examples to your experimental design.
**Decision-making:** see `decision-guide.md` | **Errors:** see `troubleshooting.md`
## Complete Standard Workflow
```r
library(DESeq2)
library(apeglm)
# 1. Create DESeqDataSet
dds <- DESeqDataSetFromMatrix(countData = counts, colData = coldata, design = ~ condition)
# 2. Pre-filter low counts
keep <- rowSums(counts(dds)) >= 10
dds <- dds[keep,]
# 3. Set reference level
dds$condition <- relevel(dds$condition, ref = 'control')
# 4. Run DESeq2 pipeline
dds <- DESeq(dds)
# 5. Extract results
res <- results(dds)
# 6. Apply LFC shrinkage
resLFC <- lfcShrink(dds, coef = 'condition_treated_vs_control', type = 'apeglm')
# 7. Get significant genes
sig <- subset(res, padj < 0.05 & abs(log2FoldChange) > 1)
```
## Design Formulas
### Simple Two-Group
```r
design = ~ condition
```
Use: Single factor, no batch effects, most common starting point.
### Batch Correction
```r
design = ~ batch + condition
```
Use: Multiple sequencing runs, PCA shows batch clustering. Requirement: each
condition must have samples in each batch (not confounded).
### Paired Samples
```r
design = ~ individual + condition
```
Use: Before/after treatment, tumor vs normal from same patient. Benefit: controls
individual variation, increases power.
### Interaction
```r
design = ~ genotype * treatment
# Expands to: ~ genotype + treatment + genotype:tr