{"data":{"slug":"github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gsea-17849b331776","title":"Run GSEA Analysis and Generate Enrichment Plots","summary":"Perform Gene Set Enrichment Analysis (GSEA) on a ranked gene list and generate enrichment plots using Rscript with CSV input files.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gsea-17849b331776","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gsea-17849b331776","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gsea-17849b331776.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gsea-17849b331776\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure the input CSV file contains at least a gene column (default name `name`) and a ranking-statistic column (default name `logFC`). If using `HALLMARKS` as the gene-set type, a preloaded RDS file with the asset key `Hallmarks` must be available.","instructions":"---\nname: gsea\ndescription: Run GSEA on a ranked gene list and produce the enrichment table, running-score table, and enrichment plots.\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n## When to read external files\n\n| Situation | Read | Purpose |\n|---|---|---|\n| Need algorithm details | `references\/algorithm.md` | Statistical method and formulas |\n| Need to run an analysis | `scripts\/main.R` | Full command reference |\n| Hit an error | `references\/troubleshooting.md` | Look up error codes and fixes |\n| Need CLI examples | `references\/cli-guide.md` | Worked argument examples |\n\n## Scope\n\nUse this skill for:\n- Running GSEA on a gene list ranked by a statistic\n- Generating enrichment curve plots from existing `enrichGSEA.csv` and `gsea_running_scores.csv`\n- Smoke-testing the pipeline with `tests\/data\/sample_deg_results.csv`\n\nDo not use it for:\n- Differential expression on raw expression matrices\n- Single-sample ssGSEA\n- Network analysis or multi-omics integration\n\n## Usage\n\nAnalysis mode:\n`Rscript scripts\/main.R --input tests\/data\/sample_deg_results.csv --outdir .\/GSEA_analysis --type KEGG --species human --seed 42 --timeout 300`\n\nPlot mode:\n`Rscript scripts\/main.R --running_file .\/GSEA_analysis\/Table\/gsea_running_scores.csv --enrich_file .\/GSEA_analysis\/Table\/enrichGSEA.csv --plot_output .\/GSEA_analysis\/plot\/gsea_plot.pdf --top_n 5 --plot_format pdf --seed 42 --timeout 300`\n\nSee `references\/cli-guide.md` for more.\n\nMode selection:\n- Passing only `--input` runs analysis mode\n- Passing both `--running_file` and `--enrich_file` runs plot mode\n- If both sets of arguments are provided, plot mode takes precedence; analysis mode is skipped and a warning is logged\n\n## Arguments\n\n### Analysis-mode arguments\n\n| Short | Long | Type | Default | Required | Description |\n|---|---|---|---|---|---|\n| `-i` | `--input` | character | `NULL` | yes | Input CSV file |\n| `-o` | `--outdir` | character | `GSEA_analysis` | no | Output directory |\n| `-g` | `--gene_col` | character | `name` | no | Gene column name |\n| `-f` | `--fc_col` | character | `logFC` | no | Ranking-statistic column name |\n| `-t` | `--type` | character | `KEGG` | no | Gene-set type: `KEGG`, `HALLMARKS`, `GO_BP`, `GO_MF`, `GO_CC`. With a preloaded RDS, `HALLMARKS` is automatically mapped to the asset key `Hallmarks` |\n| `-s` | `--species` | character | `human` | no | Species: `human`, `mouse`, `rat` |\n| `-p` | `--pvalue_cutoff` | numeric | `0.05` | no | Significance threshold |\n| `-m` | `--method` | character | `fgsea` | no | GSEA backend: `fgsea` or `DOSE` |\n| `-c` | `--chunk_size` | numeric | `1000` | no | Chunk size for large gene-set conversion |\n| `-r` | `--rds_path` | character | `NULL` | no | Path to a pre-stored gene-set RDS |\n| `-v` | `--verbose` | logical | `FALSE` | no | Verbose logging |\n|  | `--seed` | integer | `42` | no | Random seed |\n|  | `--timeout` | integer | `300` | no | Timeout in seconds; `<=0` disables it |\n| `-h` | `--help` | logical | `FALSE` | no | Show help |\n\n### Plot-mode arguments\n\n| Short | Long | Type | Default | Required | Description |\n|---|---|---|---|---|---|\n|  | `--running_file` | character | `NULL` | yes | Path to `gsea_running_scores.csv` |\n|  | `--enrich_file` | character | `NULL` | yes | Path to `enrichGSEA.csv` |\n|  | `--plot_output` | character | `gsea_plot.pdf` | no | Output plot path |\n|  | `--plot_width` | numeric | `8` | no | Plot width |\n|  | `--plot_height` | numeric | `6` | no | Plot height |\n|  | `--plot_format` | character | `pdf` | no | Output format: `pdf` or `png` |\n|  | `--top_n` | numeric | `1` | no | Number of top pathways to plot when `geneSetID` is not given |\n|  | `--rank_by` | character | `p.adjust` | no | Column used to rank pathways |\n|  | `--geneSetID` | character | `\"\"` | no | Comma-separated pathway IDs |\n|  | `--plot_title` | character | `\"\"` | no | Plot title |\n|  | `--colors` | character | `#4DBBD5,#E64B35,#00A087,#F39B7F,#3C5488,#8491B4` | no | Color list |\n|  | `--base_size` | numeric | `11` | no | Base font size |\n|  | `--subplots` | character | `1,2,3` | no | Sub-panel indices to display |\n|  | `--rel_heights` | character | `1.5,0.8,1` | no | Relative panel heights |\n|  | `--NES_table` | logical | `TRUE` | no | Show NES annotation |\n|  | `--no_NES_table` | logical | `FALSE` | no | Disable NES annotation |\n|  | `--NES_label_size` | numeric | `4` | no | NES label font size |\n|  | `--NES_label_x` | numeric | `0.75` | no | NES label x position |\n|  | `--NES_label_y` | numeric | `0.75` | no | NES label y position |\n|  | `--NES_label_color` | character | `black` | no | NES label color |\n|  | `--NES_label_hjust` | numeric | `0` | no | NES label horizontal justification |\n|  | `--NES_label_vjust` | numeric | `1` | no | NES label vertical justification |\n|  | `--line_width` | numeric | `1` | no | ES line width |\n|  | `--dot_size` | numeric | `1.2` | no | ES dot size |\n|  | `--legend_position` | character | `auto` | no | Legend position |\n|  | `--legend_x` | numeric | `0.02` | no | Inset legend x coordinate |\n|  | `--legend_y` | numeric | `0.02` | no | Inset legend y coordinate |\n|  | `--legend_just_x` | numeric | `0` | no | Legend horizontal justification |\n|  | `--legend_just_y` | numeric | `0` | no | Legend vertical justification |\n|  | `--legend_text_size` | numeric | `9` | no | Legend text size |\n|  | `--legend_key_size` | numeric | `0.6` | no | Legend key size |\n|  | `--legend_bg_alpha` | numeric | `0` | no | Legend background alpha |\n|  | `--grid_major_color` | character | `grey92` | no | Major grid color |\n|  | `--grid_minor_color` | character | `grey92` | no | Minor grid color |\n|  | `--ylab_es` | character | `Enrichment Score` | no | ES panel y-axis title |\n|  | `--ylab_rank` | character | `Ranked List Metric` | no | Rank panel y-axis title |\n|  | `--xlab_rank` | character | `Rank in Ordered Dataset` | no | Rank panel x-axis title |\n|  | `--hit_height` | numeric | `1` | no | Hit-bar height |\n|  | `--hit_gap` | numeric | `0` | no | Hit-bar gap |\n|  | `--hit_linewidth` | numeric | `0.5` | no | Hit-bar line width |\n|  | `--rank_bar_alpha` | numeric | `0.9` | no | Rank-bar alpha |\n|  | `--rank_bar_height_ratio` | numeric | `0.3` | no | Rank-bar height ratio |\n|  | `--rank_metric_segment_color` | character | `grey` | no | Rank-line color |\n|  | `--rank_metric_segment_width` | numeric | `0.3` | no | Rank-line width |\n|  | `--rank_metric_segment_alpha` | numeric | `1` | no | Rank-line alpha |\n|  | `--pvalue_table` | logical | `FALSE` | no | Show p-value table |\n|  | `--ES_geom` | character | `line` | no | ES geometry: `line` or `dot` |\n|  | `--verbose` | logical | `FALSE` | no | Verbose logging |\n|  | `--seed` | integer | `42` | no | Random seed |\n|  | `--timeout` | integer | `300` | no | Timeout in seconds; `<=0` disables it |\n| `-h` | `--help` | logical | `FALSE` | no | Show help |\n\n## Input format\n\nAnalysis-mode input is a CSV with at least:\n- a gene column (default name `name`)\n- a ranking-statistic column (default name `logFC`)\n\nExample:\n```csv\nname,logFC,pvalue,padj\nTP53,2.5,0.001,0.01\nBRCA1,1.8,0.005,0.02\nEGFR,-1.2,0.01,0.05\n```\n\nValue constraints:\n- `type` accepts `KEGG`, `HALLMARKS`, `GO_BP`, `GO_MF`, `GO_CC`\n- When using a preloaded RDS, `HALLMARKS` is automatically matched to the asset key `Hallmarks`\n- `species` accepts `human`, `mouse`, `rat`\n\n## Output files\n\n| File | Format | Description |\n|---|---|---|\n| `data\/GSEA_list.rda` | RDA | Full GSEA result object |\n| `Table\/enrichGSEA.csv` | CSV | Enrichment result table |\n| `Table\/gsea_running_scores.csv` | CSV | Running-score table; if no enrichment passes, a header-only file is still written |\n| `plot\/` | directory | Plot output directory |\n| `session_info.txt` | TXT | R version and package versions |\n\n`enrichGSEA.csv` mainly contains: `ID`, `Description`, `NES`, `pvalue`, `p.adjust`, `core_enrichment`.\n\n## Error handling\n\nCommon error codes:\n- `SKILL_FILE_NOT_FOUND`: input file does not exist\n- `SKILL_MISSING_COLUMNS`: required columns are missing\n- `SKILL_EMPTY_DATA`: input is empty, or empty after filtering\n- `SKILL_INVALID_PARAMETER`: an argument has an invalid value\n- `SKILL_PACKAGE_NOT_FOUND`: a required package is not installed\n- `SKILL_ANALYSIS_FAILED`: GSEA still failed after retries\n\nTriage doc: `references\/troubleshooting.md`\n\nExit codes:\n- `0`: success\n- `1`: failure\n\n## Testing\n\nMinimal test dataset: `tests\/data\/sample_deg_results.csv`\n\nMinimal command:\n`Rscript scripts\/main.R --input tests\/data\/sample_deg_results.csv --outdir .\/test_output --type KEGG --species human --seed 42 --timeout 300 --verbose`\n\nExpected output:\n- `.\/test_output\/data\/GSEA_list.rda`\n- `.\/test_output\/Table\/enrichGSEA.csv`\n- `.\/test_output\/Table\/gsea_running_scores.csv`\n- `.\/test_output\/session_info.txt`\n- If no significant enrichment is found, `gsea_running_scores.csv` is still written but contains only the header\n- Exit code `0`\n","use_cases":["Run GSEA analysis on a differential expression results file","Generate enrichment plots from existing GSEA output files","Test the GSEA pipeline with sample data"],"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\/gsea\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T07:11:39.000000Z","updated_at":"2026-11-24T07:13:04.000000Z","seo_title":"Run GSEA Analysis and Generate Enrichment Plots","seo_description":"Run GSEA on a ranked gene list and generate enrichment plots using Rscript with CSV input files.","seo_keywords":["Run GSEA analysis","Generate GSEA plots","Enrichment analysis","GSEA pipeline","GSEA enrichment plot"]}}