{"data":{"slug":"github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gene-protein-expression-matrix-normalization-6fc2df8a83ca","title":"Normalize Gene or Protein Expression Matrices","summary":"Normalize gene or protein expression matrices using log2, z-score, or min-max scaling for downstream analysis. Outputs include normalized data, feature and sample summaries, and run metadata in CSV and RDS formats.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gene-protein-expression-matrix-normalization-6fc2df8a83ca","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gene-protein-expression-matrix-normalization-6fc2df8a83ca","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gene-protein-expression-matrix-normalization-6fc2df8a83ca.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-gene-protein-expression-matrix-normalization-6fc2df8a83ca\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"The input matrix must have the first column as feature identifiers and remaining columns as finite numeric sample values. Missing or non-finite values (e.g., NA, NaN, Inf) are not accepted and will cause errors.","instructions":"---\nname: gene-protein-expression-matrix-normalization\ndescription: Use when normalizing bulk gene or protein expression matrices with log2 transform, z-score standardization, or min-max scaling before downstream visualization or exploratory analysis. NOT for count-model normalization such as TPM\/DESeq2 size factors, batch correction, or single-cell preprocessing.\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n# Gene Protein Expression Matrix Normalization\n\n## When to Use\n\nUse this skill when the user wants to normalize a numeric expression matrix before plotting, clustering, or exploratory comparison.\n\nTypical requests:\n\n- \"Normalize this gene expression matrix with log2\"\n- \"Do z-score scaling across samples\"\n- \"Map protein abundance values into 0 to 1\"\n\n## When Not to Use\n\nDo not use this skill for:\n\n- Count-model normalization such as CPM, TPM, TMM, or DESeq2 size factors\n- Batch correction or covariate adjustment\n- Single-cell preprocessing workflows\n- Matrices that contain missing, `Inf`, or `NaN` values unless they are cleaned first\n\n## When to Read External Files\n\nWhen executing the analysis, run:\n\n```bash\nRscript scripts\/main.R --input_file <matrix.csv> --output_dir <output_dir> --method <log2|zscore|minmax>\n```\n\n| Situation | File to Read | Purpose |\n|-----------|--------------|---------|\n| Need to execute the workflow | `scripts\/main.R` | CLI entry point |\n| Need algorithm details | `references\/algorithm.md` | Method definitions and assumptions |\n| Encounter an error | `references\/troubleshooting.md` | Standard error codes and fixes |\n| Need examples or baseline run details | `references\/cli-guide.md` | Ready-to-run commands and test record |\n| Need dependency declarations | `DESCRIPTION` | Runtime package list |\n\n## Usage\n\n```bash\nRscript scripts\/main.R \\\n  --input_file tests\/data\/expression_matrix.csv \\\n  --output_dir .\/output \\\n  --method log2 \\\n  --pseudo_count 1 \\\n  --seed 42\n```\n\n## Arguments\n\n| Short | Long | Type | Default | Description |\n|-------|------|------|---------|-------------|\n| `-i` | `--input_file` | file | required | Expression matrix in CSV or TSV format |\n| `-o` | `--output_dir` | dir | `.\/output` | Output directory |\n| `-m` | `--method` | string | `log2` | Normalization method: `log2`, `zscore`, `minmax` |\n| `-r` | `--margin` | string | `column` | Apply normalization by `row` or `column` |\n| `-p` | `--pseudo_count` | numeric | `1` | Added before log2 transformation |\n| `-c` | `--center` | boolean | `true` | Center values for z-score |\n| `-s` | `--scale_values` | boolean | `true` | Scale values for z-score |\n| `-t` | `--timeout_seconds` | integer | `0` | Optional timeout; `0` disables it |\n| `-d` | `--delimiter` | string | `auto` | Input delimiter: `auto`, `csv`, or `tsv` |\n|  | `--seed` | integer | `42` | Random seed |\n|  | `--verbose` | boolean | `true` | Print progress logs |\n\n## Input Format\n\nThe first column must contain feature identifiers. Remaining columns must be finite numeric sample values.\n\nMissing values and non-finite values such as `NA`, `NaN`, `Inf`, and `-Inf` are rejected.\n\n```csv\nfeature,S1,S2,S3\nTP53,10,20,30\nEGFR,3,5,9\n```\n\nThis skill accepts gene or protein expression matrices. It does not infer count-model normalization such as CPM, TPM, TMM, or DESeq2 size factors.\n\n## Output Files\n\nIf `--output_dir` already exists, result files with the same names are overwritten. When `--verbose=true`, the workflow prints a warning before writing into a non-empty output directory.\n\nFor single-sample inputs, `feature_summary.csv` reports per-feature standard deviations as `0` by design because each feature contributes one observed value.\n\n| File | Description |\n|------|-------------|\n| `table\/normalized_matrix.csv` | Normalized matrix with the original feature column preserved |\n| `table\/feature_summary.csv` | Per-feature min, max, mean, and SD before and after normalization |\n| `table\/sample_summary.csv` | Per-sample min, max, mean, and SD before and after normalization |\n| `data\/normalized_matrix.rds` | Serialized normalized matrix and run metadata |\n| `run_record.txt` | Structured execution record |\n| `output_manifest.txt` | Output file manifest |\n| `session_info.txt` | R session information |\n\n## Methods\n\n### `log2`\n\nComputes `log2(x + pseudo_count)` for each numeric value.\n\n### `zscore`\n\nCenters and scales along the selected margin. `margin=column` standardizes each sample; `margin=row` standardizes each feature.\n\nWhen `center=false` and `scale_values=true`, the workflow divides by standard deviation without subtracting the mean first.\n\n### `minmax`\n\nRescales values to `[0, 1]` along the selected margin. Constant vectors are returned as zeros to avoid division-by-zero errors.\n\n## Error Handling\n\n| Error | Cause | Solution |\n|-------|-------|----------|\n| `SKILL_FILE_NOT_FOUND` | Input file path is invalid | Check the input path |\n| `SKILL_MISSING_COLUMNS` | Matrix has fewer than two columns | Provide one feature column and at least one sample column |\n| `SKILL_INVALID_PARAMETER` | CLI value is unsupported or malformed, or the matrix contains non-finite values | Review the argument table and inspect the matrix values |\n| `SKILL_TIMEOUT` | The run exceeded `--timeout_seconds` | Increase the timeout or simplify the input size |\n| `SKILL_EMPTY_DATA` | No usable rows or columns remain | Check the input matrix |\n\n## Testing\n\n```bash\nRscript scripts\/main.R --help\n\nRscript tests\/run_tests.R\n\nRscript tests\/run_tests.R audit_output_check\n\nRscript tests\/test_skill.R\n\nRscript tests\/test_skill.R audit_output_check --skip-prepare\n```\n\n`tests\/run_tests.R` executes bundled `log2`, `zscore`, and `minmax` runs and writes their outputs under `tests\/output\/`.\n\nWhen you pass a relative directory name such as `audit_output_check`, the test runner writes outputs under `tests\/output\/audit_output_check\/`.\n\nRun `tests\/run_tests.R` before `tests\/test_skill.R` when you want to validate pre-generated outputs explicitly. The validation script can also prepare missing outputs on its own.\n","use_cases":["Normalize gene expression matrix with log2 transformation","Z-score scale protein abundance values across samples","Rescale expression values to 0-1 range for visualization"],"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\/gene-protein-expression-matrix-normalization\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T07:08:34.000000Z","updated_at":"2026-11-24T07:13:04.000000Z","seo_title":"Normalize Gene Expression Matrix with Log2, Z-Score, or Min-Max","seo_description":"Normalize gene or protein expression matrices using log2, z-score, or min-max scaling for downstream analysis. Supports CSV\/TSV input and outputs normalized data, feature","seo_keywords":["normalize gene expression matrix","log2 transform expression data","z-score scale protein values","minmax rescale expression matrix","normalize expression data for analysis"]}}