$npx -y skills add QSong-github/DrugClaw --skill drugprotQuery drug/chemical and gene/protein entities in the BioCreative VII DrugProt dataset. Returns annotated relations (e.g., INHIBITOR, ACTIVATOR, SUBSTRATE) between chemicals and genes/proteins from biomedical literature.
| 1 | # 31_DrugProt — Drug-Protein Relation Query |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Query drug/chemical and gene/protein entities in the **BioCreative VII DrugProt** dataset. Returns annotated relations (e.g., INHIBITOR, ACTIVATOR, SUBSTRATE) between chemicals and genes/proteins from biomedical literature. |
| 6 | |
| 7 | - **Source**: <https://zenodo.org/records/5119892> |
| 8 | - **Paper**: <https://pmc.ncbi.nlm.nih.gov/articles/PMC10683943/> |
| 9 | - **Coverage**: 15,000 PubMed abstracts (3,500 training + 750 development + 10,750 test-background), 13 relation types |
| 10 | |
| 11 | ## Data Location |
| 12 | |
| 13 | ``` |
| 14 | DrugClaw/ |
| 15 | ├── skills/drug_nlp/drugprot/ |
| 16 | │ └── example.py ← helper script |
| 17 | └── resources_metadata/drug_nlp/DrugProt/ |
| 18 | └── drugprot-gs-training-development/ |
| 19 | ├── training/ |
| 20 | │ ├── drugprot_training_abstracs.tsv |
| 21 | │ ├── drugprot_training_entities.tsv |
| 22 | │ └── drugprot_training_relations.tsv |
| 23 | ├── development/ |
| 24 | │ ├── drugprot_development_abstracs.tsv |
| 25 | │ ├── drugprot_development_entities.tsv |
| 26 | │ └── drugprot_development_relations.tsv |
| 27 | └── test-background/ |
| 28 | ├── test_background_abstracts.tsv |
| 29 | └── test_background_entities.tsv |
| 30 | ``` |
| 31 | |
| 32 | Use the repo-local `resources_metadata/drug_nlp/DrugProt/drugprot-gs-training-development` path, or override it with the `DRUGPROT_DIR` environment variable if your dataset lives elsewhere. |
| 33 | |
| 34 | All three splits are loaded by default. Note: `test-background` has no relations file (relations are the prediction target). |
| 35 | |
| 36 | ## Quick Start |
| 37 | |
| 38 | ```python |
| 39 | from importlib.util import spec_from_file_location, module_from_spec |
| 40 | |
| 41 | # Load module |
| 42 | spec = spec_from_file_location("drugprot", "/path/to/skills/drug_nlp/drugprot/example.py") |
| 43 | dp = module_from_spec(spec) |
| 44 | spec.loader.exec_module(dp) |
| 45 | |
| 46 | # Load dataset (one-time, ~2 s) |
| 47 | ds = dp.load_dataset("/path/to/drugprot-gs-training-development") |
| 48 | |
| 49 | # Query single entity |
| 50 | results = dp.query_entities(ds, "aspirin") |
| 51 | print(dp.format_results(results)) |
| 52 | |
| 53 | # Query multiple entities |
| 54 | results = dp.query_entities(ds, ["metformin", "insulin", "EGFR"]) |
| 55 | print(dp.format_results(results)) |
| 56 | ``` |
| 57 | |
| 58 | ## API |
| 59 | |
| 60 | ### `load_dataset(base_dir, splits=["training","development","test-background"]) -> dict` |
| 61 | |
| 62 | Loads and indexes all TSV files. Returns a dict with keys: `abstracts`, `entities`, `relations`, `name_index`. |
| 63 | |
| 64 | ### `query_entities(dataset, names, case_sensitive=False) -> list[dict]` |
| 65 | |
| 66 | | Parameter | Type | Description | |
| 67 | |---|---|---| |
| 68 | | `dataset` | `dict` | Output of `load_dataset()` | |
| 69 | | `names` | `str` or `list[str]` | Entity name(s) to query | |
| 70 | | `case_sensitive` | `bool` | Default `False`; falls back to substring match if exact match fails | |
| 71 | |
| 72 | **Returns** a list of result dicts, one per query name: |
| 73 | |
| 74 | ```json |
| 75 | [ |
| 76 | { |
| 77 | "query": "aspirin", |
| 78 | "matches": [ |
| 79 | { |
| 80 | "pmid": "12345678", |
| 81 | "entity_id": "T3", |
| 82 | "entity_type": "CHEMICAL", |
| 83 | "entity_text": "aspirin", |
| 84 | "relations": [ |
| 85 | { |
| 86 | "relation_type": "INHIBITOR", |
| 87 | "partner_id": "T12", |
| 88 | "partner_text": "COX-2", |
| 89 | "partner_type": "GENE-Y", |
| 90 | "role": "arg1(chemical)" |
| 91 | } |
| 92 | ], |
| 93 | "article_title": "Effects of aspirin on ..." |
| 94 | } |
| 95 | ] |
| 96 | } |
| 97 | ] |
| 98 | ``` |
| 99 | |
| 100 | ### `format_results(results, max_matches=5) -> str` |
| 101 | |
| 102 | Formats query results into a concise, LLM-readable plain-text summary. |
| 103 | |
| 104 | ## Relation Types |
| 105 | |
| 106 | | Type | Description | |
| 107 | |---|---| |
| 108 | | INHIBITOR | Chemical inhibits gene/protein | |
| 109 | | ACTIVATOR | Chemical activates gene/protein | |
| 110 | | AGONIST | Chemical is an agonist | |
| 111 | | ANTAGONIST | Chemical is an antagonist | |
| 112 | | SUBSTRATE | Chemical is a substrate | |
| 113 | | PRODUCT-OF | Chemical is a product of enzyme | |
| 114 | | INDIRECT-DOWNREGULATOR | Chemical indirectly downregulates | |
| 115 | | INDIRECT-UPREGULATOR | Chemical indirectly upregulates | |
| 116 | | DIRECT-REGULATOR | Chemical directly regulates | |
| 117 | | PART-OF | Chemical is part of protein complex | |
| 118 | | COFACTOR | Chemical acts as cofactor | |
| 119 | | NOT | Negative relation | |
| 120 | | UNDEFINED | Undefined relation | |
| 121 | |
| 122 | ## CLI Usage |
| 123 | |
| 124 | ```bash |
| 125 | export DRUGPROT_DIR=/path/to/drugprot-gs-training-development |
| 126 | python 31_DrugProt.py aspirin insulin p53 |
| 127 | ``` |