Skip to content

Commit bc1fc2b

Browse files
feat: Add Claude skill for generating Allotropy parsers (#1160)
## Summary - Adds a Claude skill to help developers quickly generate complete Allotropy instrument parsers from example input files - The skill analyzes files, suggests appropriate schemas, and generates all necessary boilerplate code - Includes three main scripts: analyze_file.py, list_schemas.py, and create_parser.py ## Features - **File Analysis**: Automatically detects file format and suggests appropriate Allotrope schema based on content - **Schema Discovery**: Lists all available schemas with filtering and shows example parsers - **Parser Generation**: Creates complete parser structure with reader, structure, tests, and all required files - **Smart Detection**: Recognizes measurement types (absorbance, CT values, pH, etc.) to suggest the right schema ## Files Added - `.claude/skills/parser-generator/skill.md` - Main skill definition for Claude - `.claude/skills/parser-generator/README.md` - Documentation for using the skill - `.claude/skills/parser-generator/scripts/analyze_file.py` - Analyzes input files and suggests schemas - `.claude/skills/parser-generator/scripts/list_schemas.py` - Lists available Allotrope schemas - `.claude/skills/parser-generator/scripts/create_parser.py` - Generates complete parser structure - `.claude/.ruff.toml` - Ruff configuration for Claude skill scripts ## Usage 1. Analyze a file: `python .claude/skills/parser-generator/scripts/analyze_file.py <file>` 2. List schemas: `python .claude/skills/parser-generator/scripts/list_schemas.py [filter]` 3. Generate parser: `python .claude/skills/parser-generator/scripts/create_parser.py <name> "<Display Name>"` ## Test Plan - [x] Tested file analysis on Excel files (Exp6.xlsx) - [x] Tested schema listing with filtering - [x] All linting checks pass - [x] Scripts are executable This skill will significantly speed up the process of adding new instrument parsers to the allotropy library. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.1 <noreply@anthropic.com>
1 parent 1e48cc8 commit bc1fc2b

6 files changed

Lines changed: 1260 additions & 0 deletions

File tree

.claude/.ruff.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ruff configuration for Claude skills
2+
# These are CLI scripts, so print statements are allowed
3+
4+
extend-ignore = ["T201", "T203", "E501"] # Allow print, pprint, and long lines in skills
5+
6+
[per-file-ignores]
7+
"skills/*/scripts/*.py" = ["T201", "T203", "FBT001", "FBT002"] # Allow print and boolean args in skill scripts
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Allotropy Parser Generator Skill
2+
3+
This Claude skill helps you generate complete Allotropy instrument parsers from example input files. It analyzes file structure, auto-detects appropriate Allotrope schemas, and generates fully functional parser code.
4+
5+
## Installation
6+
7+
This skill is already installed in the `.claude/skills/parser-generator/` directory.
8+
9+
## Usage with Claude
10+
11+
When working with Claude in this repository, you can invoke the parser generator skill by saying:
12+
13+
- "Use the parser-generator skill to create a new parser"
14+
- "Analyze this file and suggest a schema" (with a file path)
15+
- "Generate a parser for [instrument name]"
16+
- "/parser-generator" (if configured as a slash command)
17+
18+
## Manual Usage
19+
20+
You can also run the scripts directly:
21+
22+
### 1. Analyze an Input File
23+
24+
```bash
25+
python .claude/skills/parser-generator/scripts/analyze_file.py <path_to_file>
26+
```
27+
28+
This will analyze the file and suggest an appropriate schema based on the content.
29+
30+
### 2. List Available Schemas
31+
32+
```bash
33+
# List all schemas
34+
python .claude/skills/parser-generator/scripts/list_schemas.py
35+
36+
# Filter schemas
37+
python .claude/skills/parser-generator/scripts/list_schemas.py plate
38+
39+
# Verbose output with paths
40+
python .claude/skills/parser-generator/scripts/list_schemas.py --verbose
41+
```
42+
43+
### 3. Generate a Parser
44+
45+
```bash
46+
python .claude/skills/parser-generator/scripts/create_parser.py \
47+
<parser_name> \
48+
"<Display Name>" \
49+
--schema <schema_path> \
50+
--example <example_file>
51+
```
52+
53+
Example:
54+
```bash
55+
python .claude/skills/parser-generator/scripts/create_parser.py \
56+
beckman_pharmspec \
57+
"Beckman Coulter PharmSpec" \
58+
--schema adm/plate_reader/BENCHLING/2024/06/plate_reader \
59+
--example ~/Downloads/pharmspec_data.xlsx
60+
```
61+
62+
## Generated Files
63+
64+
The skill creates a complete parser structure:
65+
66+
```
67+
src/allotropy/parsers/{parser_name}/
68+
├── __init__.py # Module exports
69+
├── {parser_name}_parser.py # Main parser class
70+
├── {parser_name}_reader.py # File reading logic
71+
└── {parser_name}_structure.py # Data structures
72+
73+
tests/parsers/{parser_name}/
74+
├── __init__.py
75+
├── test_{parser_name}_parser.py # Test file
76+
└── testdata/
77+
└── example.xlsx # Test data
78+
```
79+
80+
## Workflow
81+
82+
1. **Analyze** your example file to detect the schema
83+
2. **List** available schemas if you need to override
84+
3. **Generate** the parser with the create script
85+
4. **Implement** the TODO sections in the generated code
86+
5. **Test** the parser with your example data
87+
6. **Register** the parser in `parser_factory.py`
88+
89+
## Supported File Formats
90+
91+
- Excel files (.xlsx, .xls)
92+
- CSV files (.csv)
93+
- Tab-delimited files (.txt, .tsv)
94+
- Text files with sections
95+
96+
## Schema Detection
97+
98+
The skill detects schemas based on keywords in the file:
99+
100+
- **plate-reader**: absorbance, fluorescence, luminescence, well, plate
101+
- **pcr**: ct, cq, cycle, amplification, target
102+
- **cell-counting**: viability, cell count, density
103+
- **spectrophotometry**: wavelength, spectrum, nm
104+
- **solution-analyzer**: pH, osmolality, particle size
105+
- **binding-affinity**: ka, kd, kon, koff, resonance
106+
107+
## Tips
108+
109+
- Always start with `analyze_file.py` to understand your input format
110+
- Look at similar existing parsers for patterns
111+
- Use the existing utility functions in `allotropy.parsers.utils`
112+
- Test with real data files early and often
113+
- Start with `WORKING_DRAFT` release state
114+
115+
## Troubleshooting
116+
117+
- **Schema not detected**: Manually specify with `list_schemas.py`
118+
- **Parser already exists**: Choose a different name or delete existing
119+
- **Import errors**: Make sure you're in the allotropy repository
120+
- **Test failures**: Check that your Data structure matches the schema

0 commit comments

Comments
 (0)