{"data":{"slug":"github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-differential-expression-analysis-4685eb43ac37","title":"Differential Expression Analysis for RNA-seq Data","summary":"Identify differentially expressed genes between biological groups using RNA-seq or microarray data, with volcano plots and heatmaps as deliverables.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-differential-expression-analysis-4685eb43ac37","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-differential-expression-analysis-4685eb43ac37","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-differential-expression-analysis-4685eb43ac37.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-differential-expression-analysis-4685eb43ac37\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure the input file exists and matches the group file's sample names. Install required R packages if encountering `SKILL_DEPENDENCY_MISSING`.","instructions":"---\nname: differential-expression-analysis\ndescription: Use when analyzing bulk RNA-seq or microarray expression data to identify differentially expressed genes between two biological groups (case vs control), with volcano plots and heatmap visualization. NOT for:single-cell RNA-seq, methylation analysis, non-expression data.\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n# Differential Expression Analysis\n\n## When to Read External Files\n\n| Situation | File to Read | Purpose |\n|-----------|--------------|---------|\n| **Need algorithm details** | `references\/algorithm.md` | Statistical methods, formulas, assumptions |\n| **Need to run analysis** | `scripts\/main.R` | Execute: `Rscript scripts\/main.R --input_file ... --group_file ...` |\n| **Encounter errors** | `references\/troubleshooting.md` | Common errors and solutions |\n| **Need CLI examples** | `references\/cli-guide.md` | Detailed CLI usage examples |\n| **Need test data** | `tests\/data\/` | Sample input files for testing |\n\n---\n\n## Usage\n\n```bash\nRscript scripts\/main.R \\\n  --input_file .\/expression_matrix.csv \\\n  --group_file .\/group_info.csv \\\n  --output_dir .\/output\/ \\\n  --diff_method limma \\\n  --p_threshold 0.05 \\\n  --logfc_threshold 0.1 \\\n  --seed 42\n```\n\n---\n\n## Arguments\n\n| Short | Long | Type | Default | Description |\n|-------|------|------|---------|-------------|\n| `-i` | `--input_file` | character | **required** | Expression matrix file (genes as rows, samples as columns) |\n| `-g` | `--group_file` | character | **required** | Group information file (sample ID + group columns) |\n| `-o` | `--output_dir` | character | `.\/output\/` | Output directory |\n| `-m` | `--diff_method` | character | `limma` | Method: limma, deseq2, edger, t, wilcox |\n| `-n` | `--norm_method` | character | `TMM` | Normalization for edgeR: TMM, RLE, upperquartile |\n| `-p` | `--p_threshold` | numeric | `0.05` | P-value threshold |\n| `-f` | `--logfc_threshold` | numeric | `0.1` | Log fold change threshold |\n| `-s` | `--seed` | integer | `42` | Random seed for reproducibility |\n\n---\n\n## Input Format\n\n### Expression Matrix (input_file)\n\nGenes as rows, samples as columns, CSV format with gene ID in first column.\n\n```csv\n\"\",\"GSM1442228\",\"GSM1442229\",\"GSM1442230\"\n\"0610006L08Rik\",3.438,3.237,3.265\n\"0610007P14Rik\",6.734,7.017,6.807\n```\n\n### Group File (group_file)\n\nCSV with sample ID and group columns.\n\n```csv\n\"ID\",\"group\"\n\"GSM1442228\",\"Control\"\n\"GSM1442229\",\"Control\"\n\"GSM1442230\",\"DIC\"\n```\n\n---\n\n## Output Files\n\n| File | Description |\n|------|-------------|\n| `Diffanalysis.csv` | Complete DE results with gene_id, logFC, Pvalue, Padj |\n| `volcano_plot.pdf` | Volcano plot with significance thresholds |\n| `heatmap.pdf` | Heatmap of top upregulated\/downregulated genes |\n| `session_info.txt` | R session and package version info |\n| `temp\/rdegs.csv` | Significant differentially expressed genes |\n| `temp\/Diffanalysis_filtered.csv` | Full results with group annotations |\n\n---\n\n## Workflow\n\n### Step 1: Validate Input\n- Check file existence\n- Validate sample matching between expression matrix and group file\n- Verify at least 2 samples per group\n\n### Step 2: Run Differential Expression\n- Choose method: limma, DESeq2, edgeR, t-test, or Wilcoxon\n- Calculate logFC and p-values\n- Apply multiple testing correction (Benjamini-Hochberg)\n\n### Step 3: Filter Results\n- Filter by p-value and logFC thresholds\n- Classify genes as Up, Down, or Not significant\n\n### Step 4: Generate Visualizations\n- Volcano plot showing significance vs fold change\n- Heatmap of top differential genes\n\n---\n\n## Methods\n\n### limma\nLinear models for microarray and RNA-seq with empirical Bayes moderation. Recommended for normalized expression data (FPKM, TPM).\n\n### DESeq2\nNegative binomial GLM with variance stabilization. Recommended for raw count data.\n\n### edgeR\nEmpirical Bayes methods with TMM normalization. Supports robust dispersion estimation.\n\n### t-test \/ Wilcoxon\nSimple pairwise statistical tests. t-test for parametric, Wilcoxon for non-parametric.\n\n---\n\n## Examples\n\n### Basic Usage (limma)\n```bash\nRscript scripts\/main.R \\\n  -i expression_matrix.csv \\\n  -g group_info.csv \\\n  -o .\/output \\\n  -m limma\n```\n\n### With DESeq2 for Count Data\n```bash\nRscript scripts\/main.R \\\n  -i count_matrix.csv \\\n  -g group_info.csv \\\n  -o .\/output \\\n  -m deseq2\n```\n\n### Custom Thresholds\n```bash\nRscript scripts\/main.R \\\n  -i expression_matrix.csv \\\n  -g group_info.csv \\\n  -o .\/output \\\n  -p 0.01 \\\n  -f 0.5\n```\n\n---\n\n## Error Handling\n\n### Common Errors\n\n| Error | Cause | Solution |\n|-------|-------|----------|\n| `SKILL_FILE_NOT_FOUND` | Input file doesn't exist | Check file path |\n| `SKILL_SAMPLE_MISMATCH` | Sample names don't match | Verify group file matches expression matrix columns |\n| `SKILL_INVALID_DATA` | Less than 2 groups or samples per group | Check group file |\n| `SKILL_FILTER_ERROR` | No significant genes found | Relax thresholds or check data quality |\n| `SKILL_DEPENDENCY_MISSING` | R package not installed | Install required packages |\n\n**IF error persists**, READ: `references\/troubleshooting.md`\n\n---\n\n## Testing\n\n### Test with Sample Data\n\n```bash\n# Check help\nRscript scripts\/main.R --help\n\n# Run with sample data\nRscript scripts\/main.R \\\n  -i tests\/data\/Combined_Datasets_Matrix_mus.csv \\\n  -g tests\/data\/Combined_Datasets_mus_Group.csv \\\n  -o tests\/output\/\n```\n\n### Validation Commands\n\n```bash\n# Count lines in output\nwc -l output\/Diffanalysis.csv\n\n# Check volcano plot exists\nls -la output\/volcano_plot.pdf\n```\n\n---\n\n## Implementation Checklist\n\n- [x] CLI parsing with `optparse`\n- [x] `set.seed()` for reproducibility\n- [x] `requireNamespace()` dependency checks\n- [x] Session info recording\n- [x] Temp file cleanup\n- [x] File reading instructions in SKILL.md\n- [x] Modular script structure (<100 lines per file)\n- [x] Test data provided\n- [x] Error handling with SKILL_* codes\n- [x] Scripts in `scripts\/` directory\n- [x] References in `references\/` directory\n\n---\n\n*Last updated: 2026-04-01 | Version: 2.0.0*\n","use_cases":["Identify differentially expressed genes between case and control groups in RNA-seq data","Generate volcano plots and heatmaps for gene expression analysis","Compare gene expression levels across experimental conditions"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/aipoch\/medical-research-skills\/blob\/686e09dfdb45d9fa1a08664f06bb93769b3c9d91\/awesome-med-research-skills\/Data%20Analysis\/differential-expression-analysis\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T07:03:08.000000Z","updated_at":"2026-11-24T07:13:04.000000Z","seo_title":"Differential Expression Analysis for RNA-seq Data","seo_description":"Perform differential expression analysis on RNA-seq or microarray data to identify significant gene expression differences between biological groups.","seo_keywords":["differential expression analysis","RNA-seq gene analysis","volcano plot generation","gene expression comparison","microarray data analysis"]}}