$npx -y skills add anthropics/knowledge-work-plugins --skill instrument-data-to-allotropeConvert laboratory instrument output files (PDF, CSV, Excel, TXT) to Allotrope Simple Model (ASM) JSON format or flattened 2D CSV. Use this skill when scientists need to standardize instrument data for LIMS systems, data lakes, or downstream analysis. Supports auto-detection of i
| 1 | # Instrument Data to Allotrope Converter |
| 2 | |
| 3 | Convert instrument files into standardized Allotrope Simple Model (ASM) format for LIMS upload, data lakes, or handoff to data engineering teams. |
| 4 | |
| 5 | > **Note: This is an Example Skill** |
| 6 | > |
| 7 | > This skill demonstrates how skills can support your data engineering tasks—automating schema transformations, parsing instrument outputs, and generating production-ready code. |
| 8 | > |
| 9 | > **To customize for your organization:** |
| 10 | > - Modify the `references/` files to include your company's specific schemas or ontology mappings |
| 11 | > - Use an MCP server to connect to systems that define your schemas (e.g., your LIMS, data catalog, or schema registry) |
| 12 | > - Extend the `scripts/` to handle proprietary instrument formats or internal data standards |
| 13 | > |
| 14 | > This pattern can be adapted for any data transformation workflow where you need to convert between formats or validate against organizational standards. |
| 15 | |
| 16 | ## Workflow Overview |
| 17 | |
| 18 | 1. **Detect instrument type** from file contents (auto-detect or user-specified) |
| 19 | 2. **Parse file** using allotropy library (native) or flexible fallback parser |
| 20 | 3. **Generate outputs**: |
| 21 | - ASM JSON (full semantic structure) |
| 22 | - Flattened CSV (2D tabular format) |
| 23 | - Python parser code (for data engineer handoff) |
| 24 | 4. **Deliver** files with summary and usage instructions |
| 25 | |
| 26 | > **When Uncertain:** If you're unsure how to map a field to ASM (e.g., is this raw data or calculated? device setting or environmental condition?), ask the user for clarification. Refer to `references/field_classification_guide.md` for guidance, but when ambiguity remains, confirm with the user rather than guessing. |
| 27 | |
| 28 | ## Quick Start |
| 29 | |
| 30 | ```python |
| 31 | # Install requirements first |
| 32 | pip install allotropy pandas openpyxl pdfplumber --break-system-packages |
| 33 | |
| 34 | # Core conversion |
| 35 | from allotropy.parser_factory import Vendor |
| 36 | from allotropy.to_allotrope import allotrope_from_file |
| 37 | |
| 38 | # Convert with allotropy |
| 39 | asm = allotrope_from_file("instrument_data.csv", Vendor.BECKMAN_VI_CELL_BLU) |
| 40 | ``` |
| 41 | |
| 42 | ## Output Format Selection |
| 43 | |
| 44 | **ASM JSON (default)** - Full semantic structure with ontology URIs |
| 45 | - Best for: LIMS systems expecting ASM, data lakes, long-term archival |
| 46 | - Validates against Allotrope schemas |
| 47 | |
| 48 | **Flattened CSV** - 2D tabular representation |
| 49 | - Best for: Quick analysis, Excel users, systems without JSON support |
| 50 | - Each measurement becomes one row with metadata repeated |
| 51 | |
| 52 | **Both** - Generate both formats for maximum flexibility |
| 53 | |
| 54 | ## Calculated Data Handling |
| 55 | |
| 56 | **IMPORTANT:** Separate raw measurements from calculated/derived values. |
| 57 | |
| 58 | - **Raw data** → `measurement-document` (direct instrument readings) |
| 59 | - **Calculated data** → `calculated-data-aggregate-document` (derived values) |
| 60 | |
| 61 | Calculated values MUST include traceability via `data-source-aggregate-document`: |
| 62 | |
| 63 | ```json |
| 64 | "calculated-data-aggregate-document": { |
| 65 | "calculated-data-document": [{ |
| 66 | "calculated-data-identifier": "SAMPLE_B1_DIN_001", |
| 67 | "calculated-data-name": "DNA integrity number", |
| 68 | "calculated-result": {"value": 9.5, "unit": "(unitless)"}, |
| 69 | "data-source-aggregate-document": { |
| 70 | "data-source-document": [{ |
| 71 | "data-source-identifier": "SAMPLE_B1_MEASUREMENT", |
| 72 | "data-source-feature": "electrophoresis trace" |
| 73 | }] |
| 74 | } |
| 75 | }] |
| 76 | } |
| 77 | ``` |
| 78 | |
| 79 | **Common calculated fields by instrument type:** |
| 80 | | Instrument | Calculated Fields | |
| 81 | |------------|-------------------| |
| 82 | | Cell counter | Viability %, cell density dilution-adjusted values | |
| 83 | | Spectrophotometer | Concentration (from absorbance), 260/280 ratio | |
| 84 | | Plate reader | Concentrations from standard curve, %CV | |
| 85 | | Electrophoresis | DIN/RIN, region concentrations, average sizes | |
| 86 | | qPCR | Relative quantities, fold change | |
| 87 | |
| 88 | See `references/field_classification_guide.md` for detailed guidance on raw vs. calculated classification. |
| 89 | |
| 90 | ## Validation |
| 91 | |
| 92 | Always validate ASM output before delivering to the user: |
| 93 | |
| 94 | ```bash |
| 95 | python scripts/validate_asm.py output.json |
| 96 | python scripts/validate_asm.py output.json --reference known_good.json # Compare to reference |
| 97 | python scripts/validate_asm.py output.json --strict # Treat warnings as errors |
| 98 | ``` |
| 99 | |
| 100 | **Validation Rules:** |
| 101 | - Based on Allotrope ASM specification (December 2024) |
| 102 | - Last updated: 2026-01-07 |
| 103 | - Source: https://gitlab.com/allotrope-public/asm |
| 104 | |
| 105 | **Soft Validation Approach:** |
| 106 | Unknown techniques, units, or sample roles generate **warnings** (not errors) to allow for forward co |