{"data":{"slug":"github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-immune-pathway-analysis-fb673568f030","title":"Immune Pathway Analysis for Bulk RNA-seq Data","summary":"Quantify immune pathway activity from bulk expression data and compare pathway enrichment between two sample groups using GSVA or ssGSEA methods. Output includes differential pathway results and a heatmap.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-immune-pathway-analysis-fb673568f030","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-immune-pathway-analysis-fb673568f030","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-immune-pathway-analysis-fb673568f030.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-immune-pathway-analysis-fb673568f030\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure the input files are in CSV or TSV format, with the first column containing gene identifiers and numeric values. The sample group file must contain two comparison groups and use supported column names such as `sample` or `group`. The gene-set file must be in long format with a `pathway` and `gene` column.","instructions":"---\nname: immune-pathway-analysis\ndescription: Run immune pathway GSVA or ssGSEA analysis from a bulk expression matrix, a sample group file, and a local immune Reactome gene-set table, then export differential pathway results and a heatmap for two-group comparison.\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n# Immune Pathway Analysis\n\n## When to Use\n\nUse this skill when the goal is to quantify immune-related pathway activity from bulk expression data and compare pathway enrichment between two sample groups.\n\nTypical requests:\n\n- \"Run immune pathway GSVA for these samples.\"\n- \"Score immune Reactome pathways and compare case versus control.\"\n- \"Generate an immune pathway heatmap from a saved result.\"\n- \"Use a local immune gene-set table for pathway scoring.\"\n\nThis skill is appropriate for:\n\n- Bulk RNA-seq or microarray-like expression matrices\n- Local immune Reactome gene-set tables prepared in advance\n- Two-group pathway differential analysis with `limma`\n- Reproducible CLI execution with append-only provenance files\n\n## Execution Model\n\nThis is a hybrid skill.\n\n1. Confirm the request is in scope with this `SKILL.md`.\n2. Ask only for missing file paths or missing group labels.\n3. Run `scripts\/main.R` with the appropriate mode.\n4. Use `--mode analyze` to score pathways and export tables.\n5. Use `--mode visualize` to regenerate a heatmap from a saved result object.\n6. Use `--mode full` to run analysis and visualization in one pass.\n7. Read reference files only when you need deeper algorithm, troubleshooting, or CLI details.\n8. After execution, report the output directory, scoring method, comparison groups, and the primary output files.\n\n## Completion Format\n\nAfter a successful run, summarize the outcome in 3 short parts:\n\n1. Mode and method used, plus the compared groups.\n2. Output directory and key files written.\n3. Important warnings that affect interpretation, such as no pathways meeting `fdr_threshold` and fallback to `|t|` ranking.\n\nExample completion summary:\n\n> Completed immune pathway analysis in `.\/output\/run_001` using `gsva` for `Case` versus `Control`. Key outputs: `table\/immune_pathway_diff.csv`, `table\/immune_pathway_scores.csv`, `data\/immune_pathway_result.rds`, and `plot\/immune_pathway_heatmap.pdf`. No pathways passed `FDR <= 0.05`, so the workflow used the documented fallback ranking by `|t|` for the top-pathway export and heatmap subset.\n\n## When to Read External Files\n\n| Situation | File to Read | Purpose |\n|-----------|--------------|---------|\n| Need method details or interpretation guidance | `references\/algorithm.md` | Review GSVA logic, limma comparison, and interpretation guidance |\n| Need runnable commands or dependency setup | `references\/cli-guide.md` | Reuse CLI examples, fixture notes, and validated baseline records |\n| Need error remediation | `references\/troubleshooting.md` | Map error codes, fallback behavior, and common fixes |\n| Need the executable workflow | `scripts\/main.R` | Use the CLI entry point |\n| Need minimal demo inputs | `tests\/data\/` | Use the bundled example expression, group, and gene-set files |\n\n## When Not to Use\n\n- Immune cell fraction estimation or deconvolution\n- Gene-level differential expression without pathway scoring\n- Single-cell clustering, annotation, or communication analysis\n- Clinical diagnosis or treatment selection\n\nIf the request falls outside these boundaries, stop and state that this skill only covers bulk immune pathway GSVA or ssGSEA analysis from a local immune gene-set table.\n\n## Input Validation\n\nThis skill accepts:\n\n- A bulk expression matrix in CSV or TSV format\n- A sample group file with exactly two comparison groups for analysis mode\n- A local immune gene-set table in long format\n- An existing output directory containing `data\/immune_pathway_result.rds` for visualize mode\n\nIf the user's request does not involve bulk immune pathway scoring from local files, do not proceed with the workflow. Instead respond:\n\n> \"Immune Pathway Analysis is designed for bulk immune pathway GSVA or ssGSEA analysis from a local gene-set table. Your request appears to be outside this scope. Please provide a bulk expression matrix, a two-group sample file, and a local pathway table, or use a more appropriate skill for deconvolution, differential expression, or single-cell analysis.\"\n\nIf the request is in scope but required inputs are missing, ask only for the missing file paths or group labels before running `scripts\/main.R`.\n\n## Usage\n\n```bash\nRscript scripts\/main.R \\\n  --mode full \\\n  --input_file .\/expression_matrix.csv \\\n  --group_file .\/group_info.csv \\\n  --geneset_file .\/immune_genesets.csv \\\n  --case_group Case \\\n  --control_group Control \\\n  --output_dir .\/output\/run_001 \\\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` or `full` | Expression matrix file in CSV or TSV format |\n| `-g` | `--group_file` | character | required for `analyze` or `full` | Sample group file in CSV or TSV format |\n|  | `--geneset_file` | character | required for `analyze` or `full` | Local immune gene-set table in long format |\n|  | `--geneset_column` | character | `gs_name` | Pathway column in the gene-set table |\n|  | `--gene_column` | character | `gene_symbol` | Gene symbol column in the gene-set table |\n|  | `--focus_genesets` | character | optional | Comma-separated pathway names to prioritize in the heatmap |\n| `-a` | `--case_group` | character | required for `analyze` or `full` | Case group label |\n| `-c` | `--control_group` | character | required for `analyze` or `full` | Control group label |\n| `-o` | `--output_dir` | character | `.\/output` | Output directory inside this skill folder |\n|  | `--method` | character | `gsva` | Scoring method: `gsva` or `ssgsea` |\n|  | `--kcdf` | character | `Gaussian` | GSVA kernel: `Gaussian`, `Poisson`, or `none` |\n|  | `--min_sz` | integer | `2` | Minimum gene-set size |\n|  | `--max_sz` | integer | `5000` | Maximum gene-set size |\n|  | `--parallel_sz` | integer | `1` | Worker count passed to `GSVA::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 for significance summaries |\n|  | `--top_n` | integer | `20` | Maximum 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 timeout |\n|  | `--plot_file` | character | `immune_pathway_heatmap.pdf` | Heatmap file name stored under `plot\/` |\n|  | `--plot_title` | character | `Immune Pathway GSVA 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` | Heatmap row font size |\n|  | `--fontsize_col` | double | `9` | Heatmap column font size |\n|  | `--legend_cex` | double | `1` | Legend text scaling factor |\n|  | `--top_up` | integer | optional | Number of up-regulated pathways kept for plotting |\n|  | `--top_down` | integer | optional | Number of down-regulated pathways kept 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 | `90` | Maximum heatmap label length |\n\n## Input Format\n\n### Expression Matrix\n\n- CSV or TSV file\n- The first column contains gene identifiers\n- Remaining columns are sample names\n- Values must be numeric\n- Missing values are not allowed\n\n### Group File\n\n- CSV or TSV file with a header\n- Supported sample column names: `sample`, `sample_name`, `sample_id`, `sampleid`\n- Supported group column names: `group`, `condition`, `class`, `cluster`\n- Sample names must match the expression matrix columns\n\n### Gene-Set Table\n\n- CSV or TSV file in long format\n- One row per gene-to-pathway mapping\n- Must contain a pathway column and a gene column\n- Default column names are `gs_name` and `gene_symbol`\n- Alternate schemas are supported through `--geneset_column` and `--gene_column`\n\n## Output Files\n\n| File | Description |\n|------|-------------|\n| `table\/immune_pathway_diff.csv` | Differential pathway results from `limma` |\n| `table\/immune_pathway_scores.csv` | Full GSVA or ssGSEA score matrix |\n| `table\/immune_pathway_scores_top.csv` | Top pathway score matrix selected from the differential results |\n| `table\/immune_gene_set_summary.csv` | Per-pathway gene counts after table parsing |\n| `data\/immune_pathway_result.rds` | Saved analysis object used by visualize mode |\n| `plot\/immune_pathway_heatmap.pdf` | Heatmap PDF generated in `visualize` or `full` mode |\n| `session_info.txt` | R session and package version record |\n| `output_manifest.txt` | Append-only output manifest |\n| `run_record.txt` | Append-only run record |\n\nWhen no pathways pass the selected `fdr_threshold`, the workflow logs a warning and falls back to ranking pathways by `|t|`. In that case, `table\/immune_pathway_scores_top.csv` can still be populated for downstream plotting and review.\n\n## Error Handling\n\n| Error Code | Meaning | Solution |\n|------------|---------|----------|\n| `SKILL_FILE_NOT_FOUND` | An input file or saved result object does not exist | Check the path and rerun |\n| `SKILL_MISSING_COLUMNS` | The group file or gene-set table lacks required columns | Rename the columns or export the correct table |\n| `SKILL_EMPTY_DATA` | The matrix, gene-set list, or plotting matrix is empty | Check the input content, gene overlap, and selected gene-set columns |\n| `SKILL_INVALID_PARAMETER` | A CLI value is missing, invalid, or unsafe | Review the argument table and rerun |\n| `SKILL_SAMPLE_MISMATCH` | Samples do not align between the matrix and group file | Align sample names before rerunning |\n| `SKILL_PACKAGE_NOT_FOUND` | Required R packages are missing | Install the packages listed in `references\/cli-guide.md` |\n| `SKILL_VERSION_INCOMPATIBLE` | Installed package versions are a known incompatible combination | Follow the version guidance in `references\/cli-guide.md` and rerun |\n\nRead `references\/troubleshooting.md` if the error persists.\n\n## Testing\n\n- Minimal runnable files are bundled in `tests\/data\/`.\n- The bundled smoke-test dataset is intended to validate execution and the fallback path. It may legitimately produce zero pathways with `FDR <= 0.05`.\n- `tests\/data\/immune_genesets_minimal.csv` is a unit-test fixture, not a drop-in full-workflow demo with `tests\/data\/expression_matrix.csv` unless you prepare a matching matrix with overlapping genes.\n- Use `Rscript tests\/run_unit_tests.R` to run boundary checks, helper-function checks, and validation tests without the full GSVA workflow.\n- Use `Rscript tests\/run_tests.R` to execute the unit checks plus the full smoke-test workflow.\n- Use `Rscript tests\/test_skill.R tests\/output` to validate the expected outputs.\n- The validated test baseline, package versions, fixture notes, and custom-column CLI examples are documented in `references\/cli-guide.md`.\n","use_cases":["Run immune pathway GSVA for these samples.","Score immune Reactome pathways and compare case versus control.","Generate an immune pathway heatmap from a saved result."],"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\/immune-pathway-analysis\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T07:15:26.000000Z","updated_at":"2026-11-24T07:13:04.000000Z","seo_title":"Immune Pathway Analysis for Bulk RNA-seq Data","seo_description":"Run immune pathway GSVA or ssGSEA analysis from bulk expression matrices and sample group files to compare pathway enrichment between two groups.","seo_keywords":["immune pathway analysis","bulk RNA-seq pathway scoring","GSVA pathway enrichment","Reactome pathway comparison","two-group pathway analysis"]}}