{"data":{"slug":"github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-cibersort-immune-infiltration-analysis-c6cbd262c607","title":"CIBERSORT Immune Infiltration Analysis","summary":"Estimate immune cell infiltration from bulk RNA-seq data using a CIBERSORT-style nu-SVR deconvolution workflow. Generate structured tables, immune-fraction plots, and compare case and control groups using an LM22 signature matrix.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-cibersort-immune-infiltration-analysis-c6cbd262c607","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-cibersort-immune-infiltration-analysis-c6cbd262c607","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-cibersort-immune-infiltration-analysis-c6cbd262c607.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-cibersort-immune-infiltration-analysis-c6cbd262c607\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"The workflow requires an expression matrix with genes as rows and samples as columns, a group file with sample and group annotations, and a signature matrix. The default signature matrix is `tests\/data\/LM22.txt`. Ensure the input files are in CSV or TSV format, with the first column containing gene identifiers and remaining columns containing numeric expression values. The `--auto_unlog` flag applies `2^x` transformation only if the matrix passes a conservative log-scale heuristic.","instructions":"---\nname: cibersort-immune-infiltration-analysis\ndescription: Use when estimating relative immune cell infiltration from a bulk expression matrix with a CIBERSORT-style nu-SVR deconvolution workflow based on an LM22 signature matrix, comparing one case group against one control group, and generating structured tables plus immune-fraction plots. NOT for single-cell RNA-seq, spatial data, clinical diagnosis, or workflows that require the original hosted CIBERSORT web service.\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n# CIBERSORT Immune Infiltration Analysis\n\n## When to Use\n\n- Estimate relative immune cell fractions from a bulk expression matrix.\n- Compare one case group against one control group after deconvolution.\n- Generate structured tables, a serialized result object, and optional PDF plots.\n\n## When Not to Use\n\n- Single-cell RNA-seq, spatial transcriptomics, or clustering tasks.\n- Absolute clinical interpretation or treatment recommendation.\n- Workflows that require the original online CIBERSORT service instead of a local R implementation.\n\n## Workflow\n\n1. Confirm that the expression matrix, group file, and signature matrix are available.\n2. Run `scripts\/main.R` with the case and control groups.\n3. Review the full result table, derived summary tables, and optional plots.\n4. Inspect `run_record.txt` and `output_manifest.txt` after each run, including failed validation attempts.\n\n## When to Read External Files\n\n| Situation | File to Read | Purpose |\n|-----------|--------------|---------|\n| Need to run the analysis | `scripts\/main.R` | CLI entry point |\n| Need algorithm details | `references\/algorithm.md` | HQ reference workflow and result interpretation |\n| Encounter an error | `references\/troubleshooting.md` | Error codes and environment fixes |\n| Need CLI examples or the baseline record | `references\/cli-guide.md` | Example commands and validation notes |\n| Need packaged test inputs | `tests\/data\/` | Demo expression matrix, group file, and LM22 file |\n\n## Usage\n\n```bash\nRscript scripts\/main.R \\\n  --input_file .\/expression_matrix.csv \\\n  --group_file .\/group_info.csv \\\n  --signature_file .\/LM22.txt \\\n  --case_group treatment \\\n  --control_group control \\\n  --output_dir .\/output \\\n  --qn false \\\n  --seed 42\n```\n\n## Arguments\n\n| Short | Long | Type | Default | Description |\n|-------|------|------|---------|-------------|\n| `-i` | `--input_file` | file | required | Expression matrix with genes as rows and samples as columns |\n| `-g` | `--group_file` | file | required | Group annotation table |\n| `-a` | `--case_group` | string | required | Case group label |\n| `-b` | `--control_group` | string | required | Control group label |\n| `-o` | `--output_dir` | dir | `.\/output` | Output directory |\n|  | `--signature_file` | file | `tests\/data\/LM22.txt` when present | Signature matrix file |\n|  | `--sample_col` | string\/int | none | Optional sample column name or 1-based index |\n|  | `--group_col` | string\/int | none | Optional group column name or 1-based index |\n|  | `--gene_id_case` | string | `upper` | Gene ID normalization: `asis`, `upper`, or `lower` |\n|  | `--auto_unlog` | boolean | `true` | Apply `2^x` only if the expression matrix passes a conservative log-scale heuristic |\n|  | `--min_mean_expression` | numeric | `1` | Minimum mean expression before deconvolution |\n|  | `--perm` | integer | `1000` | Permutation count for empirical p-value estimation; `0` keeps the run lightweight but records `P-value` as `NA` |\n|  | `--qn` | boolean | `true` | Apply quantile normalization to the mixture matrix |\n|  | `--svm_cores` | integer | `1` | Worker count for the nu-SVR model selection step |\n|  | `--make_plots` | boolean | `true` | Generate PDF plots |\n|  | `--plot_width` | numeric | `16` | Default plot width in inches |\n|  | `--plot_height` | numeric | `10` | Default plot height in inches |\n| `-s` | `--seed` | integer | `42` | Random seed |\n| `-t` | `--timeout_seconds` | integer | `0` | Optional timeout in seconds; `0` disables it |\n|  | `--verbose` | boolean | `true` | Print progress logs |\n\n## Input Format\n\n### Expression Matrix\n\nCSV or TSV. The first column must contain gene identifiers. Remaining columns must be numeric sample-level expression values.\n\nWhen `--auto_unlog=true`, the workflow reports summary statistics and applies `2^x` only if the matrix passes a conservative log-scale heuristic. If the matrix is ambiguous, the values are left unchanged and the startup log explains why.\n\nIf duplicate gene identifiers are present, they are consolidated after gene-ID normalization by taking the per-sample maximum before downstream filtering and deconvolution.\n\n```csv\ngene,Sample1,Sample2,Sample3\nTP53,10.2,8.5,9.1\nCXCL9,4.3,6.1,5.7\n```\n\n### Group File\n\nCSV or TSV with one sample column and one group column.\n\n```csv\nsample,group\nSample1,control\nSample2,treatment\nSample3,treatment\n```\n\n### Signature Matrix\n\nThe packaged default is `tests\/data\/LM22.txt`. A custom signature matrix must contain one gene column followed by immune-cell signature columns.\n\nAll immune-cell signature columns must be numeric and finite. If duplicate gene identifiers are present, they are consolidated by taking the per-cell-type maximum before gene intersection.\n\n## Output Files\n\n| File | Description |\n|------|-------------|\n| `data\/cibersort_input.rds` | Serialized aligned input matrices used by the local algorithm |\n| `data\/cibersort_null_distribution.rds` | Serialized permutation null distribution |\n| `data\/cibersort_result.rds` | Serialized result object with cell fractions, metrics, runtime settings, and heatmap rendering metadata |\n| `table\/CIBERSORT_Results.csv` | Full result table in CSV format |\n| `table\/CIBERSORT-Results.txt` | Full result table in tab-delimited text format |\n| `table\/cibersort_cell_fractions_wide.csv` | Wide-format immune cell fraction table |\n| `table\/cibersort_cell_fractions_long.csv` | Long-format immune cell fraction table |\n| `table\/cibersort_group_compare.csv` | Case-vs-control comparison summary |\n| `table\/cibersort_quality_metrics.csv` | Sample-level `P-value`, `Correlation`, and `RMSE` table |\n| `table\/immune_cell_correlation_matrix.csv` | Spearman correlation matrix across immune cell types |\n| `table\/immune_cell_correlation_pvalue.csv` | P-value matrix aligned to the correlation matrix |\n| `plot\/immune_cell_composition_sample.pdf` | Sample-level stacked composition plot when `--make_plots=true` |\n| `plot\/immune_group_boxplot.pdf` | Group comparison boxplot when `--make_plots=true` |\n| `plot\/immune_correlation_heatmap.pdf` | Immune-cell correlation heatmap when `--make_plots=true` |\n| `session_info.txt` | R session information |\n| `output_manifest.txt` | Append-only output manifest for successful and failed runs |\n| `run_record.txt` | Append-only structured run record, including runtime notes and failed-run summaries |\n\nWhen `--make_plots=false`, the `plot\/` directory may still exist as part of the standard output layout, but no PDF plot files are written.\n\nWhen `--perm=0`, the workflow logs a warning and completes without empirical permutation testing, so the `P-value` column is recorded as `NA`.\n\nWhen a rerun targets an existing `--output_dir` and then fails validation or execution, the previous successful payload is preserved and the failure is appended to `run_record.txt` and `output_manifest.txt`.\n\n## Error Handling\n\n| Error Code | Meaning | Solution |\n|------------|---------|----------|\n| `SKILL_FILE_NOT_FOUND` | An input file or signature matrix was not found | Check the file path and rerun |\n| `SKILL_MISSING_COLUMNS` | A required column is missing | Fix the input schema |\n| `SKILL_EMPTY_DATA` | No usable genes, samples, or deconvolution outputs remain | Check the data, filtering, or signature overlap |\n| `SKILL_INVALID_PARAMETER` | A CLI parameter is missing or invalid | Review the argument table and input values |\n| `SKILL_SAMPLE_MISMATCH` | Expression samples and group annotations do not align | Harmonize sample identifiers |\n| `SKILL_PACKAGE_NOT_FOUND` | A required R package is missing | Install the missing package |\n| `SKILL_TIMEOUT` | The configured time limit was exceeded | Increase `--timeout_seconds` or set it to `0` |\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 one gene column and numeric sample columns.\n- A group annotation file in CSV or TSV format with one sample column and one group column.\n- Exactly one case group label and one control group label for comparison.\n- An optional custom signature matrix compatible with the documented LM22-style schema.\n\nDo not use this skill for:\n\n- Single-cell RNA-seq, spatial transcriptomics, or cell clustering workflows.\n- Clinical diagnosis, treatment recommendation, or patient-level medical decision making.\n- Requests that need the hosted CIBERSORT web service rather than this local R implementation.\n- Multi-group study designs that require more than one case group versus one control group in a single run.\n\nIf the user's request is outside this scope, do not proceed with the workflow. Instead respond:\n\n> \"cibersort-immune-infiltration-analysis is designed for local CIBERSORT-style immune deconvolution from a bulk expression matrix with one case group and one control group. Your request appears to be outside this scope. Please provide compatible bulk-expression inputs and group labels, or use a more appropriate tool for your task.\"\n\n## Testing\n\n```bash\nRscript scripts\/main.R --help\n\nRscript tests\/run_tests.R\n\nRscript tests\/test_skill.R\n```\n\nValidated packaged test path:\n\n```bash\nRscript scripts\/main.R \\\n  --input_file tests\/data\/expression_matrix.csv \\\n  --group_file tests\/data\/group_info.csv \\\n  --signature_file tests\/data\/LM22.txt \\\n  --case_group Tumor \\\n  --control_group Healthy \\\n  --output_dir tests\/output \\\n  --perm 25 \\\n  --qn false \\\n  --svm_cores 1 \\\n  --seed 42\n```\n\nContainer note:\n\n- The packaged test path uses `--qn false` because `preprocessCore::normalize.quantiles()` may trigger environment-level thread failures in some containers.\n- If you need a quantile-normalized run, validate that environment first and record the result in `references\/cli-guide.md`.\n- `tests\/run_tests.R` also checks that a failed rerun does not erase an existing successful payload directory.\n","use_cases":["Estimate immune cell fractions from bulk expression matrix","Compare immune infiltration between case and control groups","Generate structured tables and immune-fraction plots"],"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\/cibersort-immune-infiltration-analysis\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T06:56:12.000000Z","updated_at":"2026-11-24T07:13:04.000000Z","seo_title":"CIBERSORT Immune Infiltration Analysis Tool","seo_description":"Estimate immune cell infiltration from bulk RNA-seq data using CIBERSORT-style deconvolution. Compare case and control groups with structured tables and immune-fractional","seo_keywords":["CIBERSORT immune infiltration analysis","bulk RNA-seq immune cell deconvolution","case vs control immune comparison","immune infiltration analysis tool","CIBERSORT deconvolution workflow"]}}