Turingdb graph

From ClawBio/ClawBio · View interactive version

Turingdb graph is an AI agent skill from the GitHub repository ClawBio/ClawBio. Build, query, and analyse biomedical knowledge graphs in TuringDB, a columnar graph database with git-like versioning.

How to use this skill

Skill file

🕸 TuringDB Graph

You are TuringDB Graph, a specialised ClawBio agent for building, querying, and analysing biomedical knowledge graphs in TuringDB — a columnar graph database with git-like versioning.

Trigger

Fire this skill when the user says any of:

Do NOT fire when:

Why This Exists

Core Capabilities

  1. Build (--build): ingest CSV/TSV/GML/JSONL into a named TuringDB graph with automatic numeric type wrapping and commit tracking.
  2. Query (--query): run an arbitrary Cypher query against a graph and return results as Markdown, JSON, or TSV.
  3. Analyse cohort (--analyse-cohort): run a fixed set of descriptive clinical-cohort analyses (demographics, top conditions & medications, comorbidities, comedications) on a patient-centric graph.
  4. Demo (--demo): run an end-to-end example against one of three shipped synthetic datasets (cohort, pathway, antibody).

Scope

One skill, four operations. This skill builds graphs, queries them, and runs descriptive cohort analytics. It does not perform statistical inference, vocabulary normalisation, or clinical decision support. For custom Cypher beyond the fixed analyses, point an agent at the reference/ docs.

Input Formats

| Format | Extension | Required Flags | Notes |

|--------|-----------|----------------|-------|

| CSV | .csv | --node-label | One node per row; columns become properties; integer/float columns auto-wrapped via toInteger()/toFloat() |

| TSV | .tsv | --node-label | Treated as CSV with tab separator |

| GML | .gml | — | All nodes become GMLNode, all edges GMLEdge, all properties strings. Properties stored with type suffix (e.g. displayName (String)) |

| JSONL | .jsonl | — | Typed labels and properties preserved (Neo4j APOC export-compatible) |

Workflow

When the user asks to build and analyse a graph:

  1. Connect: reach TuringDB at --host (default localhost:6666); auto-start the daemon if unreachable.
  2. Ingest: load the input file via LOAD CSV + CREATE, LOAD GML, or LOAD JSONL inside a versioned change.
  3. Commit: submit the change and record the commit hash for audit.
  4. Analyse (if --analyse-cohort or --demo cohort): run 8 fixed Cypher queries for demographics, conditions, medications, comorbidities, and comedications; aggregate results in pandas.
  5. Report: write report.md + summary.json to the output directory. Every report ends with the ClawBio research disclaimer.

CLI Reference

Note for ClawBio reviewers: this skill uses mutually exclusive subcommand

flags (--build, --query, --analyse-cohort, --demo, --stop-server)

rather than the standard --input/--output pattern. This is because it

handles four distinct operations that do not share a single input/output

contract. --out serves the role of --output.

# Build a graph from CSV
python skills/turingdb-graph/turingdb_graph.py \
  --build --input data.csv --graph my_graph --node-label PatientRow \
  --out /tmp/build-output

# Build from GML
python skills/turingdb-graph/turingdb_graph.py \
  --build --input pathway.gml --graph my_pathway --out /tmp/build-output

# Run a Cypher query
python skills/turingdb-graph/turingdb_graph.py \
  --query --graph my_graph \
  --cypher "MATCH (p:Patient)-[:HAS]->(c:MedicalCondition) RETURN p.displayName, c.displayName LIMIT 10" \
  --out /tmp/query-output

# Analyse a patient cohort
python skills/turingdb-graph/turingdb_graph.py \
  --analyse-cohort --graph my_graph --top-n 10 --out /tmp/analysis-output

# Run a demo (auto-starts TuringDB if needed)
python skills/turingdb-graph/turingdb_graph.py --demo cohort --out /tmp/demo
python skills/turingdb-graph/turingdb_graph.py --demo pathway --out /tmp/demo
python skills/turingdb-graph/turingdb_graph.py --demo antibody --out /tmp/demo

# Stop the TuringDB daemon
python skills/turingdb-graph/turingdb_graph.py --stop-server

Global flags

| Flag | Default | Description |

|------|---------|-------------|

| --host | http://localhost:6666 | TuringDB host URL |

| --data-dir | ~/.turing | TuringDB data directory |

| --no-auto-start | off | Fail fast if the server is not running |

| --out | ./output | Output directory for reports |

Demo

python skills/turingdb-graph/turingdb_graph.py --demo cohort --out /tmp/demo

Expected output: a patient-centric graph with 50 nodes (20 patients, 6 conditions, 7 medications, 4 doctors, 3 hospitals, 8 blood types, 2 genders) and 120 edges, plus a cohort analysis report showing demographics (ages 14-73, mean 48.6), top conditions (Hypertension: 6, Diabetes Type 2: 4), and top medications (Metformin: 4).

All three demos (cohort, pathway, antibody) use synthetic data with no PHI.

Example Queries

Example Output

# Cohort analysis: `demo_cohort`

- **Patients**: 20
- **Ages** (n=20): min 14, max 73, mean 48.6, median 51.0
- **Under 18**: 3
- **Over 65**: 6

## Top 10 conditions

| condition | patients |
|---|---|
| Hypertension | 6 |
| Diabetes Type 2 | 4 |
| Arthritis | 3 |
| Asthma | 3 |
| Cancer | 2 |
| Migraine | 2 |

---

*ClawBio is a research and educational tool. Not a medical device.
This output must not be used for clinical decision-making.*

Output Structure

output_directory/
├── report.md              # Markdown report (build summary, cohort analysis, or query results)
├── summary.json           # Structured JSON (counts, stats, query metadata)
├── result.json            # Query results as JSON (--query only)
├── result.tsv             # Query results as TSV (--query only)
└── analysis/              # Subdirectory for cohort analysis (--demo cohort only)
    ├── report.md
    └── summary.json

Algorithm / Methodology

Cohort analyses

All cohort analyses run as fixed Cypher queries that return raw rows, with aggregation performed in pandas. This avoids TuringDB's current GROUP BY limitation and keeps the aggregation logic auditable in Python.

  1. Patient demographics: count, age min/max/mean/median via pd.to_numeric. Missing ages excluded, not imputed.
  2. Top conditions: MATCH (p:Patient)-[:HAS]->(c:MedicalCondition) returns (patient, condition) pairs; pandas groupby().nunique() counts distinct patients per condition.
  3. Top medications: same pattern via :TOOK_MEDICATION edges.
  4. Comorbidities: cartesian self-join on conditions per patient; self-pairs filtered, pairs normalised via min()/max() to avoid double-counting, then filtered to pairs co-occurring in >= 2 patients.
  5. Comedications: same pattern on medications.
  6. Junior/senior split: WHERE p.age < 18 and WHERE p.age > 65.

CSV type inference

LOAD CSV values arrive as strings. The skill reads the first 200 rows with pandas dtype detection and wraps integer-like columns with toInteger() and float-like columns with toFloat() at ingest time.

GML property name convention

TuringDB's LOAD GML stores properties with a type suffix: displayName becomes displayName (String). Access via backtick-escaped Cypher: ` n.displayName (String) `.

Dependencies

Required:

Optional (HTTP endpoint only):

Gotchas

Safety

Domain Decisions

Graph modelling conventions

Versioning

Every --build run executes inside a fresh TuringDB change. After load, the skill issues CHANGE SUBMIT and returns the resulting commit hash in the JSON summary. This makes every build auditable via CALL db.history().

Indexing

The skill does not create indexes automatically. Users who repeatedly run --query against the same graph should create indexes manually — see reference/writing.md.

Agent Boundary

In scope

Out of scope

Agent role

The agent (LLM) dispatches this skill and interprets its outputs. It must not rewrite the cohort-analysis Cypher, invent new subcommands, or skip the safety disclaimer. For custom Cypher, point the agent at reference/querying.md, reference/writing.md, and reference/biomedical.md.

Integration with Bio Orchestrator

Trigger conditions: the orchestrator routes here when:

Chaining partners:

Maintenance

Citations

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.