Agent skill

Knn Imputation

by aipoch in aipoch/medical-research-skills

A skill your agent uses when filtering genes with high missingness and then imputing missing values in a bulk expression matrix with group-aware KNN through DMwR2, where donor samples are restricted…

MITAuto-check passedResearch & Science

Install Knn Imputation

skills CLI
$ npx skills add aipoch/medical-research-skills --skill knn-imputation -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install aipoch/medical-research-skills knn-imputation --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/aipoch/medical-research-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/'awesome-med-research-skills/Data Analysis/knn-imputation' .claude/skills/knn-imputation && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
knn-imputation
GitHub stars
2k
Token cost
~2.5k tokens
SKILL.md length
976 words
Files
14 (incl. scripts, references)
Skills in repo
578
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when filtering genes with high missingness and then imputing missing values in a bulk expression matrix with group-aware KNN through DMwR2, where donor samples are restricted…

  • Works in 5 steps: Validate Input → Filter Genes → Build Strata → …
  • Filtering genes with high missingness and then imputing missing values in a bulk expression matrix with group-aware KNN through DMwR2
  • SKILL.md covers When to Use, When to Read External Files, Input Validation and Prerequisites, plus 10 more sections
  • Runs R scripts from its folder

What it does

Knn Imputation is an agent skill from aipoch/medical-research-skills. Use when filtering genes with high missingness and then imputing missing values in a bulk expression matrix with group-aware KNN through DMwR2, where donor samples are restricted by one annotation column before imputation. For strata with 10 or fewer samples, the script falls back to row-wise direct filling with mean or median. NOT for: single-cell data, multi-column stratification, non-tabular inputs, network access, or interactive workflows.

Its SKILL.md is about 2.5k tokens, which your agent loads only when the skill is triggered. The skill folder holds 17 other files, including scripts and reference files (for example `eval_report_knn-imputation_result.json`, `references/algorithm.md` and `references/cli-guide.md`).

It sits in Research & Science, covering Bioinformatics and Data cleaning. The repository describes itself as: Hundreds of agent skills for medical research, including protocol design, data analysis, evidence insights, and academic writing. The licence is MIT.

When your agent uses it

  • Filtering genes with high missingness and then imputing missing values in a bulk expression matrix with group-aware KNN through DMwR2
  • Where donor samples are restricted by one annotation column before imputation

Example prompts

  • “/knn-imputation”

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Validate Input
  2. Filter Genes
  3. Build Strata
  4. Run Imputation
  5. Save Results

What it can do on your machine

Read from SKILL.md and the folder at commit 686e09d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 6 files in scripts/ (R), which the agent can run.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Knn Imputation loads about 2.5k tokens when it runs, and up to ~5.2k if it reads all its reference files. Until then it costs about 116 tokens; SKILL.md has 976 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~116
When it runs · the whole SKILL.md, loaded when a task matches
~2.5k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~5.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from aipoch/medical-research-skills at commit 686e09d, republished under its MIT licence (© aipoch). 976 words, ~2,494 tokens.

Download SKILL.mdSave it as .claude/skills/knn-imputation/SKILL.md (or your agent's skills folder). This skill also uses 13 other files; get the full folder from GitHub.
name
knn-imputation
description
Use when filtering genes with high missingness and then imputing missing values in a bulk expression matrix with group-aware KNN through DMwR2, where donor samples are restricted by one annotation column before imputation. For strata with 10 or fewer samples, the script falls back to row-wise direct filling with mean or median. NOT for: single-cell data, multi-column stratification, non-tabular inputs, network access, or interactive workflows.
license
MIT
skill-author
AIPOCH

KNN Imputation

When to Use

Use this skill when you need to remove genes with more than 50% missing values from a bulk expression matrix and then run group-aware KNN imputation, with the donor pool restricted by one grouping column.

Do not use this skill for:

  • single-cell data
  • multi-column stratification
  • non-tabular inputs
  • network-dependent workflows
  • interactive analysis sessions

When to Read External Files

SituationFile to ReadPurpose
Need algorithm detailsreferences/algorithm.mdGroup-stratified KNN method, fallback rules, and assumptions
Need to run analysisscripts/main.RExecute: Rscript scripts/main.R --input_file ... --group_file ...
Encounter errorsreferences/troubleshooting.mdCommon errors and solutions
Need CLI examplesreferences/cli-guide.mdDetailed CLI usage examples
Need sample input fixturestests/data/Repository fixtures for local validation and examples

Input Validation

This skill accepts: a bulk expression matrix CSV (features × samples) and a sample annotation CSV file with a single grouping column for KNN stratification.

If the user's request does not involve imputing missing values in a bulk expression matrix — for example, asking to impute single-cell data, use multi-column stratification, or run network-dependent workflows — do not proceed with the workflow. Instead respond:

"knn-imputation is designed to filter and impute missing values in bulk expression matrices using group-aware KNN with DMwR2. Your request appears to be outside this scope. Please provide a bulk expression matrix with a single grouping column, or use a more appropriate tool for your task."

Prerequisites

DMwR2 is not available on CRAN. Install it from GitHub before running:

r
install.packages("remotes")
remotes::install_github("cran/DMwR2")

If SKILL_DEPENDENCY_MISSING is raised, use the command above to install DMwR2 before retrying. Standard install.packages("DMwR2") will not work.


Usage

bash
Rscript scripts/main.R \
  --input_file tests/data/sample_expression_matrix.csv \
  --group_file tests/data/sample_groups.csv \
  --output_dir tests/output/basic_run \
  --sample_column sample \
  --group_column group \
  --k 10 \
  --small_strata_fill_method mean \
  --overwrite \
  --timeout_seconds 0 \
  --seed 42

If re-running into an existing output_dir, pass --overwrite. Otherwise use a fresh output directory.


Arguments

ShortLongTypeDefaultDescription
-i--input_filecharacterrequiredExpression matrix CSV file with features in rows and samples in columns
-g--group_filecharacterrequiredSample annotation CSV file
-o--output_dircharacter./output/Output directory
-c--sample_columncharactersampleSample ID column in the group file
-l--group_columncharactergroupSingle grouping column used to define imputation strata
-k--kinteger10Number of nearest neighbors used inside each stratum
-m--small_strata_fill_methodcharactermeanFill method for strata with 10 or fewer samples: mean or median
--overwriteflagFALSEOverwrite existing output files in output_dir
-t--timeout_secondsinteger0Optional elapsed timeout in seconds, 0 disables timeout
-s--seedinteger42Random seed for reproducibility

Input Format

Expression Matrix (input_file)

Features as rows, samples as columns, CSV format with feature ID in the first column.

csv
,Sample01,Sample02,Sample03
TSPAN6,1.84,1.83,3.82
SEMA3F,4.83,4.04,5.28

Requirements:

  • The first column stores feature IDs.
  • All remaining columns must be numeric or empty.
  • Missing values must be encoded as empty cells or NA.
Group File (group_file)

CSV with one sample ID column and one grouping column.

csv
sample,group
Sample01,case
Sample02,control
Sample03,case

Requirements:

  • sample_column must match the expression matrix sample names exactly.
  • The column named in group_column must exist in the group file.
  • sample_column and the selected grouping column must be non-missing.
  • KNN only runs for strata with at least 11 samples.
  • Strata with 10 or fewer samples use row-wise direct filling with --small_strata_fill_method.

Output Files

FileFormatDescription
imputed_expression_matrix.csvCSVComplete imputed expression matrix
session_info.txtTXTR session and package version information

Workflow

Step 1: Validate Input
  • Check file existence.
  • Validate sample matching between expression matrix and group file.
  • Verify that the requested grouping column exists.
Step 2: Filter Genes
  • Remove genes whose missing-value fraction across all samples is at least 50%.
  • Stop if all genes are removed by this filter.
Step 3: Build Strata
  • Construct one stratum per unique value in group_column.
  • Keep strata even when they are small; only strata with at least 11 samples run KNN.
Show full SKILL.md (384 more words)Show less
Step 4: Run Imputation
  • Run group-stratified KNN imputation only within strata that contain at least 11 samples.
  • Within each stratum, skip imputation for any gene whose missing-value fraction in that stratum is at least 50%; leave those values as NA.
  • For strata with 10 or fewer samples, fill missing values by the row-wise mean or median within that stratum.
  • If a small stratum has an all-missing gene row that is still imputable, fall back to the global row-wise mean or median.
Step 5: Save Results
  • Write the imputed matrix.
  • Save session_info.txt to the output directory.

Methods

Missingness Filter + Group-Stratified DMwR2 KNN

Genes with at least 50% missing values are removed first. KNN imputation is then applied within user-defined strata built from one grouping column when the stratum contains at least 11 samples.

If the chosen grouping scheme splits the data into strata of 10 samples or fewer, the command falls back to row-wise direct filling by mean or median inside that stratum. Genes that reach at least 50% missingness within a stratum are skipped in that stratum and remain NA. If another small-stratum row is fully missing but still below that threshold, the script falls back to the corresponding global row summary.

For implementation details, assumptions, and skip behavior for small strata, read references/algorithm.md.


Examples

Basic Usage
bash
Rscript scripts/main.R \
  -i tests/data/sample_expression_matrix.csv \
  -g tests/data/sample_groups.csv \
  -o tests/output/basic_run
Smaller Neighborhood
bash
Rscript scripts/main.R \
  -i tests/data/sample_expression_matrix.csv \
  -g tests/data/sample_groups.csv \
  -o tests/output/k5_run \
  -k 5
Small Strata Fallback
bash
Rscript scripts/main.R \
  -i tests/data/sample_expression_matrix.csv \
  -g tests/data/sample_groups.csv \
  -o tests/output/small_strata_run \
  -l sample \
  -m median \
  --overwrite

Error Handling

Common Errors
ErrorCauseSolution
SKILL_FILE_NOT_FOUNDInput file does not existCheck the file path
SKILL_EMPTY_FILEInput file exists but is emptyReplace it with a valid non-empty CSV file
SKILL_OUTPUT_EXISTSOutput files already existRe-run with --overwrite or change --output_dir
SKILL_SAMPLE_MISMATCHSample names do not match between filesVerify exact sample name matching
SKILL_MISSING_COLUMNSRequested grouping column is absentAdd that column to the group file or change --group_column
SKILL_INVALID_PARAMETERMultiple grouping columns were suppliedPass exactly one grouping column in --group_column
SKILL_INVALID_DATAMatrix or group file structure is invalidCheck input format, duplicated IDs, and group completeness
SKILL_DEPENDENCY_MISSINGDMwR2 not installedInstall with: Rscript -e "install.packages('remotes'); remotes::install_github('cran/DMwR2')" — note: DMwR2 is not on CRAN
SKILL_TIMEOUTTimeout limit was exceededIncrease --timeout_seconds or reduce data size

IF error persists, READ: references/troubleshooting.md


Local Validation

Validate the CLI Entrypoint
bash
# Check help
Rscript scripts/main.R --help

# Run with sample data
Rscript scripts/main.R \
  -i tests/data/sample_expression_matrix.csv \
  -g tests/data/sample_groups.csv \
  -o tests/output/basic_run \
  --overwrite

# Run forced small-strata fallback
Rscript scripts/main.R \
  -i tests/data/sample_expression_matrix.csv \
  -g tests/data/sample_groups.csv \
  -o tests/output/small_strata_run \
  -l sample \
  -m median \
  --overwrite
Output Checks
bash
# Count lines in output
wc -l tests/output/basic_run/imputed_expression_matrix.csv

# Check output files exist
ls -la tests/output/basic_run

Reference Files

FilePurpose
references/algorithm.mdGroup-stratified KNN method, fallback rules, and assumptions
references/troubleshooting.mdCommon errors and solutions
references/cli-guide.mdCLI usage examples

© aipoch, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 13 other files (scripts, references) in awesome-med-research-skills/Data Analysis/knn-imputation of aipoch/medical-research-skills.

  • SKILL.md
  • eval_report_knn-imputation_result.json
  • references/algorithm.md
  • references/cli-guide.md
  • references/troubleshooting.md
  • scripts/functions.R
  • scripts/imputation_functions.R
  • scripts/imputation_helpers.R
  • scripts/main.R
  • scripts/run_analysis.R
  • scripts/utils.R
  • tests/data/sample_expression_matrix.csv
  • tests/data/sample_groups.csv
  • tests/data/sample_groups_custom.csv

Open the folder on GitHubat commit 686e09d

Compare with similar skills

Knn Imputation next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Knn Imputation compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Knn Imputation this skillaipoch/medical-research-skills2k—~2.5kAutomated safety check: PassMIT
Bio Outlier Splicing DetectionGPTomics/bioSkills1.2k2 repos~5.1kAutomated safety check: PassMIT
Bio Proteomics Data ImportFreedomIntelligence/OpenClaw-Medical-Skills3.1k1 repos~1.2kAutomated safety check: PassNone
Rare Disease RnaseqClawBio/ClawBio1.2k1 repos~1.2kAutomated safety check: PassMIT
Bio Splicing QcGPTomics/bioSkills1.2k2 repos~6.2kAutomated safety check: PassMIT
Bio Proteomics Proteomics QcFreedomIntelligence/OpenClaw-Medical-Skills3.1k1 repos~1.8kAutomated safety check: PassNone

Similar skills

  • Detects aberrant splicing in single rare-disease patients vs a control panel using FRASER 2.0 (Bioconductor; Beta-binomial autoencoder on Intron Jaccard Index, default delta cutoff 0.1, q…

    1.2k GitHub starsUsed in 2 repos~5.1k tokens
    Research & ScienceAuto-check passed
  • Bio Proteomics Data Import

    FreedomIntelligence/OpenClaw-Medical-Skills

    Load and parse mass spectrometry data formats including mzML, mzXML, and quantification tool outputs like MaxQuant proteinGroups.txt.

    3.1k GitHub starsUsed in 1 repo~1.2k tokens
    Research & ScienceAuto-check passed
  • Rare Disease Rnaseq

    ClawBio/ClawBio

    Blood RNA-seq expression-outlier detection for rare-disease diagnostics.

    1.2k GitHub starsUsed in 1 repo~1.2k tokens
    Research & ScienceAuto-check passed
  • Bio Splicing Qc

    GPTomics/bioSkills

    Assesses RNA-seq data quality specifically for alternative splicing analysis.

    1.2k GitHub starsUsed in 2 repos~6.2k tokens
    Research & ScienceAuto-check passed
  • Bio Proteomics Proteomics Qc

    FreedomIntelligence/OpenClaw-Medical-Skills

    Quality control and assessment for proteomics data. An agent skill from FreedomIntelligence/OpenClaw-Medical-Skills.

    3.1k GitHub starsUsed in 1 repo~1.8k tokens
    Data & AnalyticsAuto-check passed
  • Orchestrates the end-to-end bisulfite/EM-seq methylation pipeline from FASTQ to differentially methylated regions, chaining Trim Galore/fastp QC, Bismark alignment + deduplication, methylation…

    1.2k GitHub starsUsed in 1 repo~3.7k tokens
    Data & AnalyticsAuto-check passed

More from aipoch/medical-research-skills

All 578 skills in this repo
  • Academic Poster Generator

    aipoch/medical-research-skills

    Complete workflow for generating academic research posters from PDF literature; use when you need to extract paper content from PDFs and produce a LaTeX-based poster…

    2k GitHub stars~2.2k tokensUpdated 22 days ago
    Auto-check passed
  • Diagnostic Study Quality Assessment Quadas

    aipoch/medical-research-skills

    Analyzes clinical diagnostic accuracy studies for bias using the QUADAS-2 tool.

    2k GitHub stars~1.4k tokensUpdated 22 days ago
    Auto-check passed
  • Exploratory Data Analysis

    aipoch/medical-research-skills

    Perform comprehensive exploratory data analysis on scientific data files across 200+ file formats.

    2k GitHub stars~3.7k tokensUpdated 22 days ago
    Auto-check passed
  • Iso Certification

    aipoch/medical-research-skills

    A toolkit for preparing ISO 13485:2016 certification documentation for medical device QMS.

    2k GitHub stars~1.8k tokensUpdated 22 days ago
    Auto-check passed
  • Journal Skills

    aipoch/medical-research-skills

    Recommends target journals for manuscript submission by analyzing the paper topic/abstract and the journal distribution of similar PubMed literature; use when users ask for journal…

    2k GitHub stars~1.7k tokensUpdated 22 days ago
    Auto-check passed
  • Latex Posters

    aipoch/medical-research-skills

    Creates academic-poster writing packages for LaTeX using beamerposter, tikzposter, or baposter.

    2k GitHub stars~1.3k tokensUpdated 22 days ago
    Auto-check passed

Questions about Knn Imputation

What does Knn Imputation do?

A skill your agent uses when filtering genes with high missingness and then imputing missing values in a bulk expression matrix with group-aware KNN through DMwR2, where donor samples are restricted…. Knn Imputation is an agent skill from aipoch/medical-research-skills. Use when filtering genes with high missingness and then imputing missing values in a bulk expression matrix with group-aware KNN through DMwR2, where donor samples are restricted by one annotation column before imputation.

When should I use Knn Imputation?

Knn Imputation fits situations like: filtering genes with high missingness and then imputing missing values in a bulk expression matrix with group-aware KNN through DMwR2; where donor samples are restricted by one annotation column before imputation.

How do I install Knn Imputation in Claude Code?

Run `npx skills add aipoch/medical-research-skills --skill knn-imputation -a claude-code`. Or copy the skill folder (awesome-med-research-skills/Data Analysis/knn-imputation in aipoch/medical-research-skills) into .claude/skills/knn-imputation in your project. Claude Code loads it when a task matches its description.

How do I install Knn Imputation in Codex?

Run `npx skills add aipoch/medical-research-skills --skill knn-imputation -a codex`. Or copy the skill folder (awesome-med-research-skills/Data Analysis/knn-imputation in aipoch/medical-research-skills) into .agents/skills/knn-imputation in your project. Codex loads it when a task matches its description.

Can I use Knn Imputation in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add aipoch/medical-research-skills --skill knn-imputation -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/knn-imputation, .gemini/skills/knn-imputation, .github/skills/knn-imputation and .opencode/skills/knn-imputation in your project.

What does Knn Imputation need to run?

Going by SKILL.md and its folder, Knn Imputation needs R for the scripts in its folder.

Does Knn Imputation access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Knn Imputation safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Knn Imputation use?

Knn Imputation is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Knn Imputation use?

About 2.5k tokens (SKILL.md is roughly 10k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 2.7k tokens, read only when the agent opens those files.

What are the alternatives to Knn Imputation?

Skills that share tags, products or a category with Knn Imputation: Bio Outlier Splicing Detection (GPTomics/bioSkills, 1.2k stars), Bio Proteomics Data Import (FreedomIntelligence/OpenClaw-Medical-Skills, 3.1k stars), Rare Disease Rnaseq (ClawBio/ClawBio, 1.2k stars) and Bio Splicing Qc (GPTomics/bioSkills, 1.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Knn Imputation?

aipoch (a GitHub organization) maintains it in aipoch/medical-research-skills, which has 1,978 GitHub stars. The repository holds 578 skills in this directory. The repository was last updated on September 17, 2026.

Source: aipoch/medical-research-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.