wirthal1990-tech commited on
Commit
8ee220b
·
verified ·
1 Parent(s): 440e19a

upload: quickstart.ipynb (RUN_005 HF1)

Browse files
Files changed (1) hide show
  1. quickstart.ipynb +233 -0
quickstart.ipynb ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 5,
4
+ "metadata": {
5
+ "kernelspec": {
6
+ "display_name": "Python 3",
7
+ "language": "python",
8
+ "name": "python3"
9
+ },
10
+ "language_info": {
11
+ "name": "python",
12
+ "version": "3.12.0"
13
+ }
14
+ },
15
+ "cells": [
16
+ {
17
+ "cell_type": "markdown",
18
+ "id": "cell-01",
19
+ "metadata": {},
20
+ "source": [
21
+ "# USDA Phytochemical & Ethnobotanical Database — Enriched v2.0\n",
22
+ "\n",
23
+ "**104,388 records · 24,771 compounds · 2,315 species · 4 enrichment layers**\n",
24
+ "\n",
25
+ "| Tier | Price | Includes |\n",
26
+ "|------|-------|----------|\n",
27
+ "| **Single Entity** | €699 | JSON + Parquet + SHA-256 Manifest |\n",
28
+ "| **Team** | €1,349 | + `duckdb_queries.sql` (20 queries) + `compound_priority_score.py` + 4 Pre-computed Views |\n",
29
+ "| **Enterprise** | €1,699 | + `snowflake_load.sql` + `chromadb_ingest.py` + `pinecone_ingest.py` + `embedding_guide.md` + Opportunity Matrix |\n",
30
+ "\n",
31
+ "**Full dataset:** [ethno-api.com](https://ethno-api.com) · ",
32
+ "**This notebook runs on the free 400-row sample.**\n"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "id": "cell-02",
38
+ "metadata": {},
39
+ "outputs": [],
40
+ "execution_count": null,
41
+ "source": [
42
+ "import pandas as pd\n",
43
+ "import duckdb\n",
44
+ "\n",
45
+ "# Load the free 400-row sample\n",
46
+ "# To use full dataset: replace path with 'ethno_dataset_2026_v2.json'\n",
47
+ "SAMPLE = 'ethno_sample_400.json'\n",
48
+ "\n",
49
+ "df = pd.read_json(SAMPLE)\n",
50
+ "print(f'Shape: {df.shape}')\n",
51
+ "print(f'Columns: {list(df.columns)}')\n",
52
+ "df.head(3)"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "id": "cell-03",
58
+ "metadata": {},
59
+ "outputs": [],
60
+ "execution_count": null,
61
+ "source": [
62
+ "# Dataset statistics\n",
63
+ "print(f'Unique compounds: {df[\"chemical\"].nunique():,}')\n",
64
+ "print(f'Unique species: {df[\"plant_species\"].nunique():,}')\n",
65
+ "print(f'Application coverage: {df[\"application\"].notna().mean()*100:.1f}%')\n",
66
+ "print(f'Dosage coverage: {df[\"dosage\"].notna().mean()*100:.1f}%')\n",
67
+ "print(f'\\nTop compound by PubMed evidence:')\n",
68
+ "print(df.groupby(\"chemical\")[\"pubmed_mentions_2026\"].max().sort_values(ascending=False).head(5).to_string())"
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "id": "cell-04",
74
+ "metadata": {},
75
+ "outputs": [],
76
+ "execution_count": null,
77
+ "source": [
78
+ "# Q05: Composite evidence score (weighted: PubMed 30% | Trials 35% | ChEMBL 20% | Patents 15%)\n",
79
+ "# Source: duckdb_queries.sql — available in Team + Enterprise tier\n",
80
+ "result = duckdb.sql(f\"\"\"\n",
81
+ " SELECT\n",
82
+ " chemical,\n",
83
+ " MAX(pubmed_mentions_2026) AS pubmed,\n",
84
+ " MAX(clinical_trials_count_2026) AS trials,\n",
85
+ " MAX(chembl_bioactivity_count) AS bioassays,\n",
86
+ " MAX(patent_count_since_2020) AS patents,\n",
87
+ " ROUND(\n",
88
+ " (MAX(pubmed_mentions_2026) * 0.30) +\n",
89
+ " (MAX(clinical_trials_count_2026) * 0.35) +\n",
90
+ " (MAX(chembl_bioactivity_count) * 0.20) +\n",
91
+ " (MAX(patent_count_since_2020) * 0.15),\n",
92
+ " 2) AS composite_score\n",
93
+ " FROM read_json_auto('{SAMPLE}')\n",
94
+ " GROUP BY chemical\n",
95
+ " ORDER BY composite_score DESC\n",
96
+ " LIMIT 10\n",
97
+ "\"\"\").df()\n",
98
+ "print('Top 10 by composite evidence score:')\n",
99
+ "result"
100
+ ]
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "id": "cell-05",
105
+ "metadata": {},
106
+ "outputs": [],
107
+ "execution_count": null,
108
+ "source": [
109
+ "# Q17: IP whitespace candidates — high research signal, low patent activity\n",
110
+ "# Use case: freedom-to-operate screening\n",
111
+ "# Source: duckdb_queries.sql (Team + Enterprise tier)\n",
112
+ "whitespace = duckdb.sql(f\"\"\"\n",
113
+ " SELECT\n",
114
+ " chemical,\n",
115
+ " MAX(pubmed_mentions_2026) AS pubmed,\n",
116
+ " MAX(patent_count_since_2020) AS patents_since_2020,\n",
117
+ " ROUND(MAX(pubmed_mentions_2026)::DOUBLE / NULLIF(MAX(patent_count_since_2020),0), 1)\n",
118
+ " AS research_to_patent_ratio\n",
119
+ " FROM read_json_auto('{SAMPLE}')\n",
120
+ " GROUP BY chemical\n",
121
+ " HAVING MAX(pubmed_mentions_2026) > 50 AND MAX(patent_count_since_2020) < 5\n",
122
+ " ORDER BY research_to_patent_ratio DESC\n",
123
+ " LIMIT 10\n",
124
+ "\"\"\").df()\n",
125
+ "print('IP Whitespace Candidates (high research, low patents):')\n",
126
+ "whitespace"
127
+ ]
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ "id": "cell-06",
132
+ "metadata": {},
133
+ "outputs": [],
134
+ "execution_count": null,
135
+ "source": [
136
+ "# Q06: Evidence tier classification (PLATINUM / GOLD / SILVER / BRONZE)\n",
137
+ "# Source: duckdb_queries.sql (Team + Enterprise tier)\n",
138
+ "tiers = duckdb.sql(f\"\"\"\n",
139
+ " SELECT evidence_tier, COUNT(*) AS compound_count\n",
140
+ " FROM (\n",
141
+ " SELECT chemical,\n",
142
+ " CASE\n",
143
+ " WHEN MAX(pubmed_mentions_2026)>5000 AND MAX(clinical_trials_count_2026)>100 THEN 'PLATINUM'\n",
144
+ " WHEN MAX(pubmed_mentions_2026)>1000 AND MAX(clinical_trials_count_2026)>20 THEN 'GOLD'\n",
145
+ " WHEN MAX(pubmed_mentions_2026)>100 THEN 'SILVER'\n",
146
+ " ELSE 'BRONZE'\n",
147
+ " END AS evidence_tier\n",
148
+ " FROM read_json_auto('{SAMPLE}')\n",
149
+ " GROUP BY chemical\n",
150
+ " ) sub\n",
151
+ " GROUP BY evidence_tier\n",
152
+ " ORDER BY evidence_tier\n",
153
+ "\"\"\").df()\n",
154
+ "print('Evidence tier distribution:')\n",
155
+ "tiers"
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "markdown",
160
+ "id": "cell-07",
161
+ "metadata": {},
162
+ "source": [
163
+ "## What's Included in Each Tier\n",
164
+ "\n",
165
+ "### Team License (€1,349) — adds to Single:\n",
166
+ "| File | Description |\n",
167
+ "|------|-------------|\n",
168
+ "| `duckdb_queries.sql` | 20 production-ready queries across 5 categories (compound discovery, evidence scoring, species analysis, application intelligence, IP/pipeline) |\n",
169
+ "| `compound_priority_score.py` | Combined evidence score calculator across all 4 layers |\n",
170
+ "| `top500_by_pubmed.parquet` | Pre-computed Top 500 compounds by PubMed score |\n",
171
+ "| `top500_by_trials.parquet` | Pre-computed Top 500 by ClinicalTrials count |\n",
172
+ "| `top500_by_patent_density.parquet` | Pre-computed Top 500 by patent density |\n",
173
+ "| `anti_inflammatory_panel.parquet` | All anti-inflammatory application records |\n",
174
+ "\n",
175
+ "### Enterprise License (€1,699) — adds to Team:\n",
176
+ "| File | Description |\n",
177
+ "|------|-------------|\n",
178
+ "| `snowflake_load.sql` | Drop-in Snowflake import script (Stage + COPY INTO + Verify) |\n",
179
+ "| `chromadb_ingest.py` | ChromaDB vector ingest with batch upload, --resume, verification |\n",
180
+ "| `pinecone_ingest.py` | Pinecone ingest supporting OpenAI, sentence-transformers, Pinecone inference |\n",
181
+ "| `embedding_guide.md` | ClinicalBERT, RAG pipeline templates, cost benchmarks |\n",
182
+ "| `compound_opportunity_matrix.csv` | Ranked compound candidates: high bioactivity × low patent density |\n",
183
+ "| `clinical_pipeline_gaps.csv` | High-PubMed, low-trial compounds: drug discovery pipeline gaps |\n",
184
+ "| `ethno_rag_chunks.jsonl` | Pre-chunked JSONL for direct LLM embedding (ChromaDB / Pinecone) |\n",
185
+ "\n",
186
+ "→ **Purchase full dataset:** [ethno-api.com](https://ethno-api.com)\n"
187
+ ]
188
+ },
189
+ {
190
+ "cell_type": "code",
191
+ "id": "cell-08",
192
+ "metadata": {},
193
+ "outputs": [],
194
+ "execution_count": null,
195
+ "source": [
196
+ "# Load via HuggingFace Datasets\n",
197
+ "# from datasets import load_dataset\n",
198
+ "# ds = load_dataset(\n",
199
+ "# 'wirthal1990-tech/USDA-Phytochemical-Database-JSON',\n",
200
+ "# split='sample',\n",
201
+ "# trust_remote_code=False\n",
202
+ "# )\n",
203
+ "# df_hf = ds.to_pandas()\n",
204
+ "# print(f'Records: {len(df_hf)} | Columns: {list(df_hf.columns)}')\n",
205
+ "print('HuggingFace repo: https://huggingface.co/datasets/wirthal1990-tech/USDA-Phytochemical-Database-JSON')"
206
+ ]
207
+ },
208
+ {
209
+ "cell_type": "markdown",
210
+ "id": "cell-09",
211
+ "metadata": {},
212
+ "source": [
213
+ "## Citation\n",
214
+ "\n",
215
+ "```bibtex\n",
216
+ "@misc{ethno_api_v2_2026,\n",
217
+ " title = {USDA Phytochemical \\& Ethnobotanical Database --- Enriched v2.0},\n",
218
+ " author = {Wirth, Alexander},\n",
219
+ " year = {2026},\n",
220
+ " publisher = {Ethno-API},\n",
221
+ " url = {https://ethno-api.com},\n",
222
+ " note = {104,388 records, 24,771 unique chemicals, 2,315 plant species,\n",
223
+ " 8-column schema with PubMed, ClinicalTrials, ChEMBL, and PatentsView enrichment}\n",
224
+ "}\n",
225
+ "```\n",
226
+ "\n",
227
+ "**Links:** [ethno-api.com](https://ethno-api.com) · ",
228
+ "[GitHub](https://github.com/wirthal1990-tech/USDA-Phytochemical-Database-JSON) · ",
229
+ "[HuggingFace](https://huggingface.co/datasets/wirthal1990-tech/USDA-Phytochemical-Database-JSON)\n"
230
+ ]
231
+ }
232
+ ]
233
+ }