-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from EBISPOT/hett
Hett
- Loading branch information
Showing
26 changed files
with
521 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import sqlite3 | ||
import json | ||
import sys | ||
|
||
def export_tables_to_jsonl(sqlite_file): | ||
conn = sqlite3.connect(sqlite_file) | ||
cursor = conn.cursor() | ||
|
||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") | ||
tables = cursor.fetchall() | ||
|
||
for table in tables: | ||
table_name = table[0] | ||
|
||
cursor.execute(f"PRAGMA table_info({table_name});") | ||
columns_info = cursor.fetchall() | ||
primary_key = None | ||
for column_info in columns_info: | ||
if column_info[5] == 1: # PK column | ||
primary_key = column_info[1] | ||
break | ||
|
||
cursor.execute(f"SELECT * FROM {table_name};") | ||
rows = cursor.fetchall() | ||
column_names = [description[0] for description in cursor.description] | ||
|
||
for row in rows: | ||
row_dict = dict(zip(column_names, row)) | ||
row_dict = {f"chembl:{key}": value for key, value in row_dict.items()} | ||
if primary_key: | ||
row_dict["id"] = row_dict["chembl:"+primary_key] | ||
row_dict["grebi:type"] = f"chembl:{table_name}" | ||
print(json.dumps(row_dict)) | ||
|
||
conn.close() | ||
|
||
export_tables_to_jsonl('chembl_34/chembl_34_sqlite/chembl_34.db') | ||
|
||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
wget https://www3.epa.gov/pesticides/appril/apprildatadump_public.xlsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
wget https://www.hse.gov.uk/pesticides/assets/docs/active-substance-register.xlsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import json | ||
import argparse | ||
import pandas as pd | ||
import io | ||
import re | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--datasource-name', required=True) | ||
parser.add_argument('--filename', required=False) | ||
args = parser.parse_args() | ||
|
||
df = pd.read_excel(io.BytesIO(sys.stdin.buffer.read()), dtype=str) | ||
df.rename(columns={col: 'grebi:name' for col in df.columns if col == 'PRODUCT_NAME'}, inplace=True) | ||
df['id'] = 'appril:'+df['REG_NUM'] | ||
df['grebi:type'] = 'hett:PesticideProduct' | ||
df['grebi:datasource'] = args.datasource_name | ||
|
||
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x) | ||
|
||
for obj in df.to_dict(orient='records'): | ||
obj = {k: v for k, v in obj.items() if pd.notna(v)} | ||
|
||
if 'PESTS' in obj: | ||
obj['PESTS'] = list(map(lambda p: p.strip(), obj['PESTS'].split(','))) | ||
if 'SITES' in obj: | ||
obj['SITES'] = list(map(lambda p: p.strip(), obj['SITES'].split(','))) | ||
|
||
if 'AIS' in obj: | ||
cas = list(map(lambda cas: 'cas:'+cas, re.findall(r'\d{1,7}-\d{2}-\d', obj['AIS']))) | ||
for c in cas: | ||
print(json.dumps({'id': c, 'grebi:type': 'grebi:Chemical', 'grebi:datasource': args.datasource_name})) | ||
obj['hett:hasActiveIngredient'] = cas | ||
|
||
if 'INERTS' in obj: | ||
cas = list(map(lambda cas: 'cas:'+cas, re.findall(r'\d{1,7}-\d{2}-\d', obj['INERTS']))) | ||
for c in cas: | ||
print(json.dumps({'id': c, 'grebi:type': 'grebi:Chemical', 'grebi:datasource': args.datasource_name})) | ||
obj['hett:hasInertIngredient'] = cas | ||
|
||
print(json.dumps(obj)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import json | ||
import argparse | ||
import pandas as pd | ||
import io | ||
import re | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--datasource-name', required=True) | ||
parser.add_argument('--filename', required=False) | ||
args = parser.parse_args() | ||
|
||
df = pd.read_excel(io.BytesIO(sys.stdin.buffer.read()), skiprows=3, dtype=str) | ||
df.rename(columns={col: 'Category' for col in df.columns if col.startswith('Category')}, inplace=True) | ||
|
||
df['id'] = df['Substance Name'] | ||
df.rename(columns={col: 'grebi:name' for col in df.columns if col == 'Substance Name'}, inplace=True) | ||
|
||
df['grebi:type'] = 'hett:AgroSubstance' | ||
df['grebi:datasource'] = args.datasource_name | ||
|
||
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x) | ||
|
||
for obj in df.to_dict(orient='records'): | ||
obj = {k: v for k, v in obj.items() if pd.notna(v)} | ||
|
||
if 'Category' in obj: | ||
obj['Category'] = obj['Category'].split(',') | ||
|
||
if 'CAS Number' in obj: | ||
# match cas numbers by regex | ||
cas = list(map(lambda cas: 'cas:'+cas, re.findall(r'\d{1,7}-\d{2}-\d', obj['CAS Number']))) | ||
for c in cas: | ||
print(json.dumps({'id': c, 'grebi:type': 'grebi:Chemical', 'grebi:datasource': args.datasource_name})) | ||
obj['CAS Number'] = cas | ||
|
||
if 'IUPAC Name' in obj: | ||
iupac = list(map(lambda iupac: iupac.strip(), re.split(r', | or |;', obj['IUPAC Name']))) | ||
iupac = list(map(lambda i: i.strip(), iupac)) | ||
iupac = list(filter(lambda i: not i.lower().startswith('not '), iupac)) | ||
obj['grebi:equivalentTo'] = iupac | ||
|
||
print(json.dumps(obj)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import json | ||
import argparse | ||
import pandas as pd | ||
import io | ||
import re | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--datasource-name', required=True) | ||
parser.add_argument('--filename', required=False) | ||
args = parser.parse_args() | ||
|
||
df = pd.read_excel(io.BytesIO(sys.stdin.buffer.read()), skiprows=2, dtype=str) | ||
# df.rename(columns={col: 'Status' for col in df.columns if col.startswith('Category')}, inplace=True) | ||
|
||
df['id'] = df['Substance'] | ||
df.rename(columns={col: 'grebi:name' for col in df.columns if col == 'Substance'}, inplace=True) | ||
|
||
df['grebi:type'] = 'hett:AgroSubstance' | ||
df['grebi:datasource'] = args.datasource_name | ||
|
||
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x) | ||
|
||
for obj in df.to_dict(orient='records'): | ||
obj = {k: v for k, v in obj.items() if pd.notna(v)} | ||
|
||
if 'Authorised' in obj: | ||
obj['Authorised'] = list(map(lambda p: p.strip(), obj['Authorised'].split(','))) | ||
|
||
if 'CAS Number' in obj: | ||
# match cas numbers by regex | ||
cas = list(map(lambda cas: 'cas:'+cas, re.findall(r'\d{1,7}-\d{2}-\d', obj['CAS Number']))) | ||
for c in cas: | ||
print(json.dumps({'id': c, 'grebi:type': 'grebi:Chemical', 'grebi:datasource': args.datasource_name})) | ||
obj['CAS Number'] = cas | ||
|
||
print(json.dumps(obj)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.