Lab unit harmonization

From XuShuwenn/RedAct · View interactive version

Lab unit harmonization is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Harmonize clinical lab data from multiple sources with different units, handling scientific notation and decimal format issues.

How to use this skill

Skill file

Clinical Lab Unit Harmonization

When to Use

Task-Specific Protocol

Input Files

Before coding, inspect both files beyond the header. Read enough of ckd_lab_data.csv to see actual numeric encodings/issues, and read ckd_feature_descriptions.csv completely enough to cover every feature you will claim to harmonize. If any read is truncated, returns only headers, or errors, continue with smaller reads, targeted searches, chunked inspection, or column extraction until you confirm the relevant columns, feature presence, documented units, and ranges. Read representative rows from across the lab file for each feature you may convert. Do not invent dataset-wide conversion rules, unit mappings, or physiological ranges from partial reference information.

Data Quality Issues

  1. Missing values → remove patient rows
  2. Scientific notation → convert 1.23e2 to 123.00
  3. Decimal commas → 12,34 → 12.34
  4. Mixed units → convert alternative units to standard (e.g., µmol/L → mg/dL)

Harmonization Steps

  1. Inspect the full schema, complete feature descriptions, and representative raw values before defining cleaning or conversion rules; if any metadata or data view is truncated, keep reading/searching until coverage is complete for every feature you will harmonize
  2. Record the input header, feature count, and row count early so you can preserve schema and verify that final row-count changes come only from removed missing/unparsable rows
  3. Build the harmonization as one reusable script/pipeline for the whole table, and load lab columns as raw strings first so decimal commas, scientific notation, whitespace, and empty-like tokens are normalized intentionally before numeric coercion
  4. Extract or tabulate per-feature documented units and expected ranges from ckd_feature_descriptions.csv before finalizing conversion logic; maintain one authoritative per-feature conversion map (feature, source unit, target unit, factor, direction, evidence)
  5. Normalize raw numeric text first: scientific notation, decimal commas, whitespace, and other non-canonical numeric strings
  6. Convert normalized values to numeric and mark unparsable entries as missing
  7. Remove rows with missing values only after parsing/normalization has converted malformed numeric text into missing values; base completeness checks on parsed numeric values, not the raw string dataframe
  8. Detect mixed-unit candidates per feature using observed distributions plus fixed physiological/reference expectations after parsing: keep values already plausible in the target unit unchanged, and only consider supported alternate-unit conversions for values implausible in the target unit. Do not hard-code thresholds from feature names alone, use convert-only-extreme-outliers heuristics as the sole detector, or widen ranges just to silence warnings
  9. Apply conversion factors only when supported by feature metadata, explicit units, or clear dataset-wide evidence; confirm the source→target direction and analyte-specific factor before bulk conversion, sanity-check multiply/divide direction with representative raw→converted examples, and do not reuse a guessed pattern across analytes
  10. Re-check plausibility after conversion using the same fixed per-feature acceptance criteria and summarize remaining below-range/above-range counts by feature; if values remain implausible, investigate the logic and refine only the justified analyte-specific rule or treat unresolved values as missing and remove those rows per task requirements rather than leaving known bad values in place, clamping values, or forcing a pass
  11. Round all values to 2 decimal places (X.XX) and write them with string-preserving formatting so trailing zeros are kept in the saved CSV
  12. Validate the final saved CSV across the entire dataset before declaring success, and do not claim dataset-wide harmonization, conversion coverage, converted-row counts, supported units, or physiological compliance unless you explicitly computed or inspected evidence for each relevant feature from the final saved output

Output

/root/ckd_lab_data_harmonized.csv:

Verification requirements before finishing:

Output

Validation and Completion

Tips

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.