|
| 1 | +# refua-data |
| 2 | + |
| 3 | +`refua-data` is the Refua data layer for drug discovery. It provides a curated dataset catalog, intelligent local caching, and parquet materialization optimized for downstream modeling and campaign workflows. |
| 4 | + |
| 5 | +## What it provides |
| 6 | + |
| 7 | +- A built-in catalog of useful drug-discovery datasets. |
| 8 | +- Dataset-aware download pipeline with cache reuse and metadata tracking. |
| 9 | +- Pluggable cache backend architecture (filesystem cache by default). |
| 10 | +- API dataset ingestion for paginated JSON endpoints (for example ChEMBL and UniProt). |
| 11 | +- HTTP conditional refresh support (`ETag` / `Last-Modified`) when enabled. |
| 12 | +- Incremental parquet materialization (chunked processing + partitioned parquet parts). |
| 13 | +- CLI for listing, fetching, and materializing datasets. |
| 14 | +- Source health checks via `validate-sources` for CI and environment diagnostics. |
| 15 | +- Rich dataset metadata snapshots (description + usage notes) persisted in cache metadata. |
| 16 | + |
| 17 | +## Included datasets |
| 18 | + |
| 19 | +The default catalog includes local-file/HTTP datasets plus API presets useful in drug discovery, including **ZINC**, **ChEMBL**, and **UniProt**. |
| 20 | + |
| 21 | +1. `zinc15_250k` (ZINC) |
| 22 | +2. `zinc15_tranche_druglike_instock` (ZINC tranche) |
| 23 | +3. `zinc15_tranche_druglike_agent` (ZINC tranche) |
| 24 | +4. `zinc15_tranche_druglike_wait_ok` (ZINC tranche) |
| 25 | +5. `zinc15_tranche_druglike_boutique` (ZINC tranche) |
| 26 | +6. `zinc15_tranche_druglike_annotated` (ZINC tranche) |
| 27 | +7. `tox21` |
| 28 | +8. `bbbp` |
| 29 | +9. `bace` |
| 30 | +10. `clintox` |
| 31 | +11. `sider` |
| 32 | +12. `hiv` |
| 33 | +13. `muv` |
| 34 | +14. `esol` |
| 35 | +15. `freesolv` |
| 36 | +16. `lipophilicity` |
| 37 | +17. `pcba` |
| 38 | +18. `chembl_activity_ki_human` |
| 39 | +19. `chembl_activity_ic50_human` |
| 40 | +20. `chembl_assays_binding_human` |
| 41 | +21. `chembl_targets_human_single_protein` |
| 42 | +22. `chembl_molecules_phase3plus` |
| 43 | +23. `uniprot_human_reviewed` |
| 44 | +24. `uniprot_human_kinases` |
| 45 | +25. `uniprot_human_gpcr` |
| 46 | +26. `uniprot_human_ion_channels` |
| 47 | +27. `uniprot_human_transporters` |
| 48 | + |
| 49 | +Most of these are distributed through MoleculeNet/DeepChem mirrors and retain upstream licensing terms. |
| 50 | +ChEMBL and UniProt presets are fetched through their public REST APIs and cached locally as JSONL. |
| 51 | +ZINC tranche presets aggregate multiple tranche files per dataset (drug-like MW B-K and logP A-K bins, |
| 52 | +reactivity A/B/C/E) into one cached tabular source during fetch. |
| 53 | + |
| 54 | +## Install |
| 55 | + |
| 56 | +```bash |
| 57 | +cd refua-data |
| 58 | +pip install -e . |
| 59 | +``` |
| 60 | + |
| 61 | +## CLI quickstart |
| 62 | + |
| 63 | +List datasets: |
| 64 | + |
| 65 | +```bash |
| 66 | +refua-data list |
| 67 | +``` |
| 68 | + |
| 69 | +Validate all dataset sources: |
| 70 | + |
| 71 | +```bash |
| 72 | +refua-data validate-sources |
| 73 | +``` |
| 74 | + |
| 75 | +Validate a subset and fail CI on probe failures: |
| 76 | + |
| 77 | +```bash |
| 78 | +refua-data validate-sources chembl_activity_ki_human uniprot_human_kinases --fail-on-error |
| 79 | +``` |
| 80 | + |
| 81 | +JSON output for automation: |
| 82 | + |
| 83 | +```bash |
| 84 | +refua-data validate-sources --json --fail-on-error |
| 85 | +``` |
| 86 | + |
| 87 | +For datasets with multiple mirrors, source validation succeeds when at least one configured source |
| 88 | +is reachable. Failed fallback attempts are included in the result details. |
| 89 | + |
| 90 | +Fetch raw data with cache: |
| 91 | + |
| 92 | +```bash |
| 93 | +refua-data fetch zinc15_250k |
| 94 | +``` |
| 95 | + |
| 96 | +Fetch API-based presets: |
| 97 | + |
| 98 | +```bash |
| 99 | +refua-data fetch chembl_activity_ki_human |
| 100 | +refua-data fetch uniprot_human_kinases |
| 101 | +``` |
| 102 | + |
| 103 | +Materialize parquet: |
| 104 | + |
| 105 | +```bash |
| 106 | +refua-data materialize zinc15_250k |
| 107 | +``` |
| 108 | + |
| 109 | +Refresh against remote metadata: |
| 110 | + |
| 111 | +```bash |
| 112 | +refua-data fetch zinc15_250k --refresh |
| 113 | +``` |
| 114 | + |
| 115 | +For API datasets, `--refresh` re-runs the API query (with conditional headers on first page when available). |
| 116 | + |
| 117 | +## Cache layout |
| 118 | + |
| 119 | +By default, cache root is: |
| 120 | + |
| 121 | +- `~/.cache/refua-data` |
| 122 | + |
| 123 | +Override with: |
| 124 | + |
| 125 | +- `REFUA_DATA_HOME=/custom/path` |
| 126 | + |
| 127 | +Layout: |
| 128 | + |
| 129 | +- `raw/<dataset>/<version>/...` downloaded source files |
| 130 | +- `_meta/raw/<dataset>/<version>/...json` raw metadata (`etag`, `sha256`, API request signature, rows/pages, dataset description/usage metadata) |
| 131 | +- `parquet/<dataset>/<version>/part-*.parquet` materialized parquet parts |
| 132 | +- `_meta/parquet/<dataset>/<version>/manifest.json` parquet manifest metadata with dataset snapshot |
| 133 | + |
| 134 | +## Python API |
| 135 | + |
| 136 | +```python |
| 137 | +from refua_data import DatasetManager |
| 138 | + |
| 139 | +manager = DatasetManager() |
| 140 | +manager.fetch("zinc15_250k") |
| 141 | +manager.fetch("chembl_activity_ki_human") |
| 142 | +result = manager.materialize("zinc15_250k") |
| 143 | +print(result.parquet_dir) |
| 144 | +``` |
| 145 | + |
| 146 | +`DataCache` is the default cache backend. You can pass a custom backend object that implements |
| 147 | +the same interface (`ensure`, `raw_file`, `raw_meta`, `parquet_dir`, `parquet_manifest`, |
| 148 | +`read_json`, `write_json`) to make storage pluggable. |
| 149 | + |
| 150 | +## Licensing notes |
| 151 | + |
| 152 | +- `refua-data` package code is MIT licensed. |
| 153 | +- Dataset content licenses are dataset-specific and controlled by upstream providers. |
| 154 | +- Always verify dataset licensing and allowed use before redistribution or commercial deployment. |
0 commit comments