{"data":{"slug":"github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gsva-analysis-and-visualization-eb6353195913","title":"GSVA Pathway Analysis and Heatmap Generation","summary":"Run GSVA or ssGSEA pathway-level analysis on bulk RNA-seq expression data and generate heatmaps for pathway enrichment. Requires a gene expression matrix and sample group file. Outputs pathway scores, differential results, and a heatmap in PDF format.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gsva-analysis-and-visualization-eb6353195913","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gsva-analysis-and-visualization-eb6353195913","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gsva-analysis-and-visualization-eb6353195913.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gsva-analysis-and-visualization-eb6353195913\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure the input file has numeric values with no missing data and the first column contains gene identifiers. The group file must include a sample column and a group column with matching sample names. Run `--mode analyze` or `--mode full` first if `GSVA_list.rda` is missing in the output directory.","instructions":"---\nname: gsva-analysis-and-visualization\ndescription: \"Use this skill to run GSVA or ssGSEA pathway-level differential analysis from a bulk expression matrix and a sample group file, then generate a heatmap from the saved GSVA result object. Trigger keywords: GSVA, ssGSEA, pathway enrichment, KEGG pathway analysis, MSigDB. NOT for: gene-level differential expression, single-cell analysis, methylation analysis, clinical diagnosis.\"\nlicense: MIT\nskill-author: AIPOCH\n---\n\n# GSVA Analysis And Visualization\n\n## When to Use\n\nUse this skill when the user wants one of the following:\n\n- Pathway-level GSVA or ssGSEA analysis from a bulk expression matrix plus a sample group file\n- Case-vs-control or treatment-vs-control pathway enrichment comparison using GSVA plus limma\n- KEGG or MSigDB pathway analysis for bulk RNA-seq or microarray-like expression data\n- Heatmap generation from an existing `data\/GSVA_list.rda` result object\n- A reproducible CLI-backed GSVA workflow with saved tables, an `.rda` object, and a PDF heatmap\n\nTypical request patterns:\n\n- \"Run GSVA on my bulk RNA-seq matrix and compare case vs control\"\n- \"Use ssGSEA to score pathways and save the pathway differential results\"\n- \"Generate a KEGG pathway heatmap from my saved GSVA result\"\n- \"Do pathway enrichment with GSVA for these grouped bulk samples\"\n\n## Execution Model\n\nThis is a hybrid skill.\n\n1. Use `SKILL.md` to verify that the request is in scope.\n2. Use `scripts\/main.R` for real execution.\n3. Use `--mode analyze` to compute pathway scores and differential results.\n4. Use `--mode visualize` to reuse an existing `data\/GSVA_list.rda` and generate a heatmap. In visualize mode, `GSVA_list.rda` must exist in `output_dir\/data\/`; run `analyze` or `full` mode first if it is missing (`SKILL_FILE_NOT_FOUND` will be raised otherwise).\n5. Use `--mode full` to run analysis and visualization in one pass.\n6. Read reference files only when you need algorithm details, troubleshooting, or additional CLI examples.\n\n## When to Read External Files\n\n| Situation | File to Read | Purpose |\n|-----------|--------------|---------|\n| Need algorithm details | `references\/algorithm.md` | Understand GSVA, limma, and heatmap generation logic |\n| Need to run analysis or plotting | `scripts\/main.R` | Execute the CLI entry point |\n| Encounter errors | `references\/troubleshooting.md` | Find standard error codes and fixes |\n| Need more CLI examples or the baseline execution record | `references\/cli-guide.md` | Copy ready-to-run commands and review the recorded test run |\n| Need sample input files | `tests\/data\/` | Use the bundled demo matrix and group file |\n\n## When Not to Use\n\n- Gene-level differential expression: use `differential-expression-analysis` instead\n- Single-cell RNA-seq clustering or communication analysis: use `sc-clustering` or `cellchat`\n- Immune infiltration scoring rather than pathway enrichment: use `ssgsea-r` or `ssgsea_immune`\n- Clinical diagnosis, treatment selection, or patient-specific interpretation: do not use this skill; ask for a validated clinical workflow or human expert review\n\nIf the request falls outside these boundaries, stop and tell the user that this skill only covers bulk expression pathway-level GSVA\/ssGSEA analysis plus downstream heatmap visualization.\n\n## Method Selection Guide\n\nChoose `--method` based on your data characteristics:\n\n- `gsva`: kernel-based enrichment scores suitable for continuous expression data with moderate-to-large sample sizes (\u2265 10 samples per group recommended).\n- `ssgsea`: rank-based enrichment scores; less sensitive to outliers and more suitable for noisy data or smaller sample sizes.\n\nFor detailed methodological comparison, READ: `references\/algorithm.md`\n\n## Usage\n\n```bash\nRscript scripts\/main.R \\\n  --mode full \\\n  --input_file tests\/data\/expr_matrix.csv \\\n  --group_file tests\/data\/group.csv \\\n  --case_group Tumor \\\n  --control_group Healthy \\\n  --species \"Homo sapiens\" \\\n  --category C2 \\\n  --subcategory KEGG \\\n  --output_dir .\/output \\\n  --seed 42\n```\n\n## Arguments\n\n| Short | Long | Type | Default | Description |\n|-------|------|------|---------|-------------|\n| `-m` | `--mode` | character | `analyze` | Run mode: `analyze`, `visualize`, or `full` |\n| `-i` | `--input_file` | character | required for `analyze`\/`full` | Expression matrix file (CSV or TSV, genes as rows, samples as columns) |\n| `-g` | `--group_file` | character | required for `analyze`\/`full` | Sample group file (CSV or TSV with sample and group columns) |\n| `-a` | `--case_group` | character | required for `analyze`\/`full` | Case or treatment group label |\n| `-c` | `--control_group` | character | required for `analyze`\/`full` | Control group label |\n| `-o` | `--output_dir` | character | `.\/output\/` | Output directory |\n| `-s` | `--species` | character | `Homo sapiens` | MSigDB species |\n| `-C` | `--category` | character | `C2` | MSigDB category |\n| `-S` | `--subcategory` | character | `KEGG` | MSigDB subcategory |\n|  | `--method` | character | `gsva` | GSVA method: `gsva` or `ssgsea` (see Method Selection Guide above) |\n|  | `--kcdf` | character | `Gaussian` | GSVA kernel: `Gaussian`, `Poisson`, or `none` |\n|  | `--min_sz` | integer | `2` | Minimum gene set size |\n|  | `--max_sz` | integer | `10000` | Maximum gene set size |\n|  | `--parallel_sz` | integer | `1` | Parallel worker count passed to GSVA |\n|  | `--mx_diff` | logical | `TRUE` | GSVA `mx.diff` flag |\n|  | `--tau` | double | `1` | GSVA `tau` value |\n|  | `--fdr_threshold` | double | `0.05` | FDR threshold used to select top pathways |\n|  | `--top_n` | integer | `20` | Number of pathways exported to the top score matrix |\n|  | `--seed` | integer | `42` | Random seed |\n|  | `--timeout_seconds` | integer | `0` | Optional timeout in seconds; `0` disables it |\n|  | `--plot_file` | character | `GSVA_heatmap.pdf` | Heatmap file name under `plot\/` (file name only; no path separators) |\n|  | `--plot_title` | character | `GSVA Enrichment Heatmap` | Heatmap title |\n|  | `--width` | double | `14` | Heatmap width in inches |\n|  | `--height` | double | `8` | Heatmap height in inches |\n|  | `--colors` | character | `#91bfdb,#ffffbf,#fc8d59` | Comma-separated heatmap colors |\n|  | `--scale` | character | `none` | Heatmap scale mode: `none`, `row`, or `column` |\n|  | `--cluster_rows` | logical | `TRUE` | Cluster heatmap rows |\n|  | `--cluster_cols` | logical | `FALSE` | Cluster heatmap columns |\n|  | `--show_rownames` | logical | `TRUE` | Show pathway names on the heatmap |\n|  | `--show_colnames` | logical | `FALSE` | Show sample names on the heatmap |\n|  | `--fontsize` | double | `10` | Base heatmap font size |\n|  | `--fontsize_row` | double | `8` | Row label font size |\n|  | `--fontsize_col` | double | `9` | Column label font size |\n|  | `--legend_cex` | double | `1` | Legend text scaling factor |\n|  | `--top_up` | integer | optional | Number of up-regulated pathways retained for plotting |\n|  | `--top_down` | integer | optional | Number of down-regulated pathways retained for plotting |\n|  | `--top_mode` | character | `both` | Heatmap subset mode: `both`, `up`, `down`, or `total` |\n|  | `--sort_by` | character | `FDR` | Pathway ranking: `FDR`, `absLFC`, or `LFC` |\n|  | `--append_stats` | logical | `FALSE` | Append `FDR` and `logFC` to heatmap labels |\n|  | `--label_max_chars` | integer | `80` | Maximum heatmap label length |\n\n## Input Format\n\n### Expression Matrix\n\n- CSV or TSV file\n- First column contains gene identifiers\n- Remaining columns are sample names\n- Values must be numeric and contain no missing values\n\nExample:\n\n```csv\ngene,S1,S2,S3,S4\nTP53,8.1,7.9,6.5,6.3\nEGFR,5.2,5.0,4.2,4.1\n```\n\nThe bundled `tests\/data\/expr_matrix.csv` is derived from the public GEO series `GSE44076` after probe-to-gene collapsing and contains the `Tumor` versus `Healthy` subset.\n\n### Group File\n\n- CSV or TSV file with a header row\n- One sample column: `sample`, `sample_name`, or `sample_id`\n- One group column: `group`, `condition`, `cluster`, or `class`\n- Sample names must match the expression matrix columns\n\nExample:\n\n```csv\nsample,group\nGSM1077746,Tumor\nGSM1077747,Tumor\nGSM1077598,Healthy\nGSM1077599,Healthy\n```\n\n## Output Files\n\n| File | Description |\n|------|-------------|\n| `table\/GSVA_diff.csv` | limma differential pathway results with `logFC`, `P.Value`, and `adj.P.Val` |\n| `table\/GSVA_enrichment_results.csv` | Full GSVA score matrix |\n| `table\/GSVA_enrichment_results_topN.csv` | Top pathway score matrix selected by `--top_n` and `--fdr_threshold` |\n| `data\/GSVA_list.rda` | Saved `gsva_result` object for downstream visualization |\n| `plot\/GSVA_heatmap.pdf` | Heatmap PDF generated in `visualize` or `full` mode |\n| `session_info.txt` | R session and package version information |\n| `output_manifest.txt` | Append-only manifest of generated outputs across runs in the same `output_dir` |\n| `run_record.txt` | Append-only run log with parameters, runtime, and output summaries across runs in the same `output_dir` |\n\n### table\/GSVA_diff.csv\n\n| Column | Type | Description |\n|--------|------|-------------|\n| `logFC` | numeric | limma-estimated pathway score difference between case and control |\n| `AveExpr` | numeric | Average pathway score across all samples |\n| `t` | numeric | Moderated t statistic from limma |\n| `P.Value` | numeric | Raw p-value from limma |\n| `adj.P.Val` | numeric | Benjamini-Hochberg adjusted p-value |\n| `B` | numeric | Log-odds that the pathway is differentially enriched |\n| `geneset` | character | Pathway identifier used in the GSVA run |\n\n## Workflow\n\n### Step 1: Validate Input\n\n- Check that the expression matrix and group file exist\n- Validate supported columns and matching sample names\n- Validate CLI ranges and mode-specific required parameters\n\n### Step 2: Run Pathway Analysis\n\n- Load MSigDB gene sets for the requested species and collection\n- Compute GSVA or ssGSEA scores for each sample\n- Fit a limma model for the case-vs-control pathway comparison\n\n### Step 3: Generate Output\n\n- Save the full score matrix, top pathway subset, and differential results to `table\/`\n- Save the reusable `gsva_result` object to `data\/GSVA_list.rda`\n- Generate the heatmap PDF in `plot\/` when running `visualize` or `full`\n- Append a new section to `output_manifest.txt` and `run_record.txt` for each invocation so earlier provenance is preserved when reusing one `output_dir`\n\n## Examples\n\n### Basic Usage\n\n```bash\nRscript scripts\/main.R \\\n  --mode full \\\n  --input_file .\/expression_matrix.csv \\\n  --group_file .\/group_info.csv \\\n  --case_group treatment \\\n  --control_group control \\\n  --output_dir .\/output\n```\n\n### With ssGSEA and Custom Parameters\n\n```bash\nRscript scripts\/main.R \\\n  --mode analyze \\\n  --input_file .\/expression_matrix.csv \\\n  --group_file .\/group_info.csv \\\n  --case_group treatment \\\n  --control_group control \\\n  --method ssgsea \\\n  --top_n 30 \\\n  --fdr_threshold 0.1 \\\n  --output_dir .\/ssgsea_output \\\n  --seed 123\n```\n\n### Reuse a Saved Result Object\n\n```bash\nRscript scripts\/main.R \\\n  --mode visualize \\\n  --output_dir .\/output \\\n  --plot_file custom_heatmap.pdf \\\n  --top_up 10 \\\n  --top_down 10 \\\n  --top_mode both\n```\n\nFor the bundled real-data baseline record, READ: `references\/cli-guide.md`\n\n## Error Handling\n\n| Error Code | Meaning | Solution |\n|------------|---------|----------|\n| `SKILL_FILE_NOT_FOUND` | Input file or saved result file is missing; in visualize mode, `GSVA_list.rda` must exist in `output_dir\/data\/` \u2014 run analyze or full mode first | Check the path and rerun with the correct file |\n| `SKILL_MISSING_COLUMNS` | Group file lacks a valid sample or group column | Rename the columns to a supported name |\n| `SKILL_SAMPLE_MISMATCH` | Sample names do not match between files | Align sample names before running the skill |\n| `SKILL_EMPTY_DATA` | Input matrix, gene set query, or plotting matrix is empty | Verify the input matrix and MSigDB settings |\n| `SKILL_INVALID_PARAMETER` | A CLI argument is missing or out of range | Review the parameter table and rerun |\n| `SKILL_PACKAGE_NOT_FOUND` | Required R packages are not installed | Install the missing packages listed in `references\/cli-guide.md` |\n\nIf the error persists, READ: `references\/troubleshooting.md`\n\n## Input Validation\n\nThis skill accepts:\n\n- A bulk expression matrix file in CSV or TSV format with genes as rows and samples as columns\n- A sample group file with one supported sample column and one supported group column\n- A valid case\/control comparison for pathway-level GSVA or ssGSEA analysis\n- Optional heatmap customization parameters for visualization of a saved `GSVA_list.rda`\n\nPrivacy and data-handling note:\n\n- If your matrix or group file can be linked to patients or protected records, anonymize it before use\n- This workflow writes result tables, a saved R object, plots, and session metadata to the local `output_dir`\n- Review local output retention practices before using sensitive material\n\nIf the user's request does not involve bulk expression pathway enrichment analysis or GSVA heatmap generation \u2014 for example, asking for single-cell analysis, gene-level DE testing, methylation analysis, or clinical diagnosis \u2014 do not proceed with this workflow. Instead respond:\n\n> \"gsva-analysis-and-visualization is designed for bulk expression pathway-level GSVA\/ssGSEA analysis and saved-result heatmap visualization. Your request appears to be outside this scope. Please provide a bulk expression matrix plus sample group file for GSVA\/ssGSEA analysis, or use a more appropriate skill for your task.\"\n\n## Testing\n\n```bash\nRscript scripts\/main.R --help\n\nRscript tests\/run_tests.R\n\nRscript scripts\/main.R \\\n  --mode full \\\n  --input_file tests\/data\/expr_matrix.csv \\\n  --group_file tests\/data\/group.csv \\\n  --case_group Tumor \\\n  --control_group Healthy \\\n  --species \"Homo sapiens\" \\\n  --category C2 \\\n  --subcategory KEGG \\\n  --output_dir tests\/output \\\n  --seed 42\n```\n\nExpected outputs:\n\n- `tests\/output\/table\/GSVA_diff.csv`\n- `tests\/output\/table\/GSVA_enrichment_results.csv`\n- `tests\/output\/table\/GSVA_enrichment_results_topN.csv`\n- `tests\/output\/data\/GSVA_list.rda`\n- `tests\/output\/plot\/GSVA_heatmap.pdf`\n- `tests\/output\/session_info.txt`\n- `tests\/output\/output_manifest.txt`\n- `tests\/output\/run_record.txt`\n\nOptional post-check:\n\n```bash\nRscript tests\/test_skill.R tests\/output\n```\n\n`tests\/run_tests.R` executes the full demo workflow, validates the expected output files, then reruns `visualize` in the same `output_dir` to confirm that `output_manifest.txt` and `run_record.txt` preserve both run sections.\n\n## References\n\n1. Hanzelmann S, Castelo R, Guinney J. (2013) GSVA: gene set variation analysis for microarray and RNA-seq data. *BMC Bioinformatics*. doi:10.1186\/1471-2105-14-7\n2. Ritchie ME, Phipson B, Wu D, et al. (2015) limma powers differential expression analyses for RNA-sequencing and microarray studies. *Nucleic Acids Research*. doi:10.1093\/nar\/gkv007\n3. Liberzon A, Birger C, Thorvaldsdottir H, et al. (2015) The Molecular Signatures Database Hallmark Gene Set Collection. *Cell Systems*. doi:10.1016\/j.cels.2015.12.004\n\nFor detailed algorithm notes, READ: `references\/algorithm.md`\n\n## Implementation Checklist\n\n- [x] CLI parsing with `optparse`\n- [x] `set.seed()` for reproducibility\n- [x] Only CRAN\/Bioconductor packages\n- [x] Documented parameters match script\n- [x] `get_script_dir()` defined before any call to it\n- [x] File reading instructions in `SKILL.md`\n- [x] Test data provided in `tests\/data\/`\n- [x] Error handling implemented with `SKILL_*` messages\n- [x] `Rscript scripts\/main.R --help` works\n","use_cases":["Run GSVA on bulk RNA-seq matrix and compare case vs control","Use ssGSEA to score pathways and save pathway differential results","Generate a KEGG pathway heatmap from saved GSVA result","Do pathway enrichment with GSVA for grouped bulk samples"],"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\/gsva-analysis-and-visualization\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T07:12:59.000000Z","updated_at":"2026-11-24T07:13:04.000000Z","seo_title":"GSVA pathway analysis and heatmap generation","seo_description":"Run GSVA or ssGSEA pathway analysis on bulk RNA-seq data and generate heatmaps for pathway enrichment. Supports KEGG and MSigDB pathways.","seo_keywords":["GSVA pathway analysis","ssGSEA pathway enrichment","KEGG pathway heatmap","bulk RNA-seq pathway analysis","MSigDB pathway scoring"]}}