Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DrOn from RxNorm_full_01022024 #30

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ontology/catalog-v001.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<!-- <uri name="http://purl.obolibrary.org/obo/dron/dron-upper.owl" uri="components/dron-upper.owl"/>-->


<uri name="http://purl.obolibrary.org/obo/dron/dron-obsolete.owl" uri="components/dron-obsolete.owl"/>

</group>
</catalog>
</catalog>
3 changes: 2 additions & 1 deletion src/ontology/dron-edit.owl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Ontology(<http://purl.obolibrary.org/obo/dron.owl>
Import(<http://purl.obolibrary.org/obo/dron/dron-ingredient.owl>)
Import(<http://purl.obolibrary.org/obo/dron/dron-ndc.owl>)
Import(<http://purl.obolibrary.org/obo/dron/dron-rxnorm.owl>)
Import(<http://purl.obolibrary.org/obo/dron/dron-obsolete.owl>)
Import(<http://purl.obolibrary.org/obo/dron/imports/apollo_sv_import.owl>)
Import(<http://purl.obolibrary.org/obo/dron/imports/bfo_import.owl>)
Import(<http://purl.obolibrary.org/obo/dron/imports/chebi_import.owl>)
Expand Down Expand Up @@ -2160,4 +2161,4 @@ AnnotationAssertion(<http://purl.obolibrary.org/obo/IAO_0000412> <http://purl.ob


AnnotationAssertion(<http://purl.obolibrary.org/obo/IAO_0000117> <http://purl.obolibrary.org/obo/DRON_00723856> "ciara lusnia")
)
)
27 changes: 21 additions & 6 deletions src/ontology/dron.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# In essence we merge rxnorm, dron-ingredient, all imports and the edit file
# (no NDC) and the run a regular full release.

LITE_ARTEFACTS=$(COMPONENTSDIR)/dron-rxnorm.owl $(COMPONENTSDIR)/dron-ingredient.owl $(IMPORT_OWL_FILES)
LITE_ARTEFACTS=$(COMPONENTSDIR)/dron-rxnorm.owl $(COMPONENTSDIR)/dron-ingredient.owl $(COMPONENTSDIR)/dron-obsolete.owl $(IMPORT_OWL_FILES)
$(TMPDIR)/dron-edit_lite.owl: $(SRC) $(LITE_ARTEFACTS)
$(ROBOT) remove --input $(SRC) --select imports \
merge $(patsubst %, -i %, $(LITE_ARTEFACTS)) --output [email protected] && mv [email protected] $@
Expand All @@ -33,13 +33,14 @@ $(TMPDIR)/ldtab.jar: | $(TMPDIR)
LDTAB := java -jar $(TMPDIR)/ldtab.jar

# Load DrOn templates into SQLite.
$(TMPDIR)/dron.db: $(SCRIPTSDIR)/create-dron-tables.sql $(SCRIPTSDIR)/load-dron-tables.sql
$(TMPDIR)/dron.db: $(SCRIPTSDIR)/create-dron-tables.sql $(SCRIPTSDIR)/load-dron-tables.sql $(SCRIPTSDIR)/index-dron-tables.sql
rm -f $@
sqlite3 $@ < $<
sqlite3 $@ < $(word 2,$^)
sqlite3 $@ < $(word 3,$^)

# Load ChEBI into SQLite using LDTab.
$(TMPDIR)/chebi.db: $(SCRIPTSDIR)/prefix.tsv $(TMPDIR)/mirror-chebi.owl | $(TMPDIR)/ldtab.jar
$(TMPDIR)/chebi.db: $(SCRIPTSDIR)/prefix.tsv $(TMPDIR)/mirror-chebi.owl $(SCRIPTSDIR)/collect-chebi-labels.sql | $(TMPDIR)/ldtab.jar
$(eval DB=$@)
rm -f $@
$(LDTAB) init $(DB) --table chebi
Expand All @@ -48,6 +49,8 @@ $(TMPDIR)/chebi.db: $(SCRIPTSDIR)/prefix.tsv $(TMPDIR)/mirror-chebi.owl | $(TMPD
sqlite3 $(DB) "CREATE INDEX idx_chebi_subject ON chebi(subject)"
sqlite3 $(DB) "CREATE INDEX idx_chebi_predicate ON chebi(predicate)"
sqlite3 $(DB) "CREATE INDEX idx_chebi_object ON chebi(object)"
sqlite3 $(DB) "ANALYZE"
sqlite3 $(DB) < $(word 3,$^)

# Create a SQLite database for RxNorm and load data from tmp/rxnorm/*.RRF.
$(TMPDIR)/rxnorm.db: $(SCRIPTSDIR)/create-rxnorm-tables.sql $(SCRIPTSDIR)/load-rxnorm-tables.sql $(SCRIPTSDIR)/index-rxnorm-tables.sql | $(TMPDIR)/
Expand All @@ -61,13 +64,23 @@ update-labels: $(TMPDIR)/dron.db $(TMPDIR)/chebi.db $(TMPDIR)/rxnorm.db $(SCRIPT
sqlite3 < $(word 4,$^)
cd $(TEMPLATEDIR) && sqlite3 ../ontology/$< < ../ontology/$(word 5,$^)

.PHONY: update-rxnorm
update-rxnorm: $(TMPDIR)/dron.db $(TMPDIR)/chebi.db $(TMPDIR)/rxnorm.db $(SCRIPTSDIR)/update-dron-from-rxnorm.sql $(SCRIPTSDIR)/save-dron-tables.sql
sqlite3 < $(word 4,$^)
cd $(TEMPLATEDIR) && sqlite3 ../ontology/$< < ../ontology/$(word 5,$^)

# Report common problems.
$(TMPDIR)/problems.db: $(TMPDIR)/dron.db $(TMPDIR)/chebi.db $(TMPDIR)/rxnorm.db $(SCRIPTSDIR)/report-problems.sql
sqlite3 $@ < $(word 4,$^)

# Convert DrOn template tables to LDTab format tables.
$(TMPDIR)/ldtab.db: $(TMPDIR)/dron.db $(SCRIPTSDIR)/prefix.tsv $(SCRIPTSDIR)/convert-dron-ldtab.sql | $(TMPDIR)/ldtab.jar
$(eval DB=$@)
rm -f $@
$(LDTAB) init $(DB) --table dron_ingredient
$(LDTAB) init $(DB) --table dron_rxnorm
$(LDTAB) init $(DB) --table dron_ndc
$(LDTAB) init $(DB) --table dron_obsolete
$(LDTAB) prefix $@ $(word 2,$^)
sqlite3 $@ < $(word 3,$^)

Expand All @@ -81,7 +94,7 @@ $(COMPONENTSDIR)/%.owl: $(COMPONENTSDIR)/%.ttl
$(ROBOT) convert -i $< -o $@

# Override the all_components task.
all_components: $(COMPONENTSDIR)/dron-ingredient.ttl $(COMPONENTSDIR)/dron-rxnorm.ttl $(COMPONENTSDIR)/dron-ndc.ttl $(COMPONENTSDIR)/dron-ingredient.owl $(COMPONENTSDIR)/dron-rxnorm.owl $(COMPONENTSDIR)/dron-ndc.owl
all_components: $(COMPONENTSDIR)/dron-ingredient.ttl $(COMPONENTSDIR)/dron-rxnorm.ttl $(COMPONENTSDIR)/dron-ndc.ttl $(COMPONENTSDIR)/dron-obsolete.ttl $(COMPONENTSDIR)/dron-ingredient.owl $(COMPONENTSDIR)/dron-rxnorm.owl $(COMPONENTSDIR)/dron-ndc.owl $(COMPONENTSDIR)/dron-obsolete.owl

###################################
#### Create templates from OWL ####
Expand All @@ -99,17 +112,19 @@ $(TMPDIR)/reverse/:
$(TMPDIR)/reverse/dron-%.owl: components.bk/dron-%.owl | $(TMPDIR)/reverse/
$(ROBOT) convert -i $< -o $@

$(TMPDIR)/reverse.db: $(SCRIPTSDIR)/prefix.tsv $(SCRIPTSDIR)/create-dron-tables.sql $(SCRIPTSDIR)/convert-ldtab-dron.sql $(TMPDIR)/reverse/dron-ingredient.owl $(TMPDIR)/reverse/dron-rxnorm.owl $(TMPDIR)/reverse/dron-ndc.owl | $(TMPDIR)/ldtab.jar
$(TMPDIR)/reverse.db: $(SCRIPTSDIR)/prefix.tsv $(SCRIPTSDIR)/create-dron-tables.sql $(SCRIPTSDIR)/convert-ldtab-dron.sql $(TMPDIR)/reverse/dron-ingredient.owl $(TMPDIR)/reverse/dron-rxnorm.owl $(TMPDIR)/reverse/dron-ndc.owl $(TMPDIR)/reverse/dron-obsolete.owl | $(TMPDIR)/ldtab.jar
$(eval DB=$@)
rm -f $(DB)
$(LDTAB) init $(DB) --table dron_ingredient
$(LDTAB) init $(DB) --table dron_rxnorm
$(LDTAB) init $(DB) --table dron_ndc
$(LDTAB) init $(DB) --table dron_obsolete
$(LDTAB) prefix $(DB) $<
sqlite3 $(DB) < $(word 2,$^)
$(LDTAB) import $(DB) --table dron_ingredient $(TMPDIR)/reverse/dron-ingredient.owl
$(LDTAB) import $(DB) --table dron_rxnorm $(TMPDIR)/reverse/dron-rxnorm.owl
$(LDTAB) import $(DB) --table dron_ndc $(TMPDIR)/reverse/dron-ndc.owl
$(LDTAB) import $(DB) --table dron_obsolete $(TMPDIR)/reverse/dron-obsolete.owl

.PHONY: reverse
reverse: $(TMPDIR)/reverse.db $(SCRIPTSDIR)/save-dron-tables.sql
Expand Down Expand Up @@ -143,4 +158,4 @@ $(TMPDIR)/%.owl.diff: $(TMPDIR)/reverse/%.owl $(COMPONENTSDIR)/%.owl
-diff -u $^ > $@

.PHONY: roundtrip
roundtrip: $(COMPONENTSDIR)/dron-ingredient.ttl $(COMPONENTSDIR)/dron-rxnorm.ttl $(COMPONENTSDIR)/dron-ndc.ttl $(TMPDIR)/dron-ingredient.owl.diff $(TMPDIR)/dron-ingredient.tsv.diff $(TMPDIR)/dron-rxnorm.owl.diff $(TMPDIR)/dron-rxnorm.tsv.diff $(TMPDIR)/dron-ndc.owl.diff $(TMPDIR)/dron-ndc.tsv.diff
roundtrip: $(COMPONENTSDIR)/dron-ingredient.ttl $(COMPONENTSDIR)/dron-rxnorm.ttl $(COMPONENTSDIR)/dron-ndc.ttl $(COMPONENTSDIR)/dron-obsolete.ttl $(TMPDIR)/dron-ingredient.owl.diff $(TMPDIR)/dron-ingredient.tsv.diff $(TMPDIR)/dron-rxnorm.owl.diff $(TMPDIR)/dron-rxnorm.tsv.diff $(TMPDIR)/dron-ndc.owl.diff $(TMPDIR)/dron-ndc.tsv.diff $(TMPDIR)/dron-obsolete.owl.diff $(TMPDIR)/dron-obsolete.tsv.diff
20 changes: 20 additions & 0 deletions src/scripts/collect-chebi-labels.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Collect labels from ChEBI terms that are not deprecated.
DROP TABLE IF EXISTS label;
CREATE TABLE label (
curie TEXT PRIMARY KEY,
label TEXT UNIQUE
);

INSERT OR IGNORE INTO label
SELECT
subject AS curie,
object AS label
FROM chebi
WHERE predicate = 'rdfs:label'
AND subject NOT IN (
SELECT subject
FROM chebi
WHERE predicate = 'owl:deprecated'
);
CREATE INDEX idx_label_label ON label(label);
ANALYZE label;
35 changes: 35 additions & 0 deletions src/scripts/convert-dron-ldtab.sql
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,38 @@ FROM (
UNION
SELECT curie, clinical_drug AS drug FROM dron.ndc_clinical_drug
);


-- ## Obsolete Terms

INSERT OR IGNORE INTO dron_obsolete(subject, predicate, object)
SELECT
curie AS subject,
'rdf:type' AS predicate,
type AS object
FROM obsolete;

INSERT OR IGNORE INTO dron_obsolete(subject, predicate, object, datatype)
SELECT
curie AS subject,
'rdfs:label' AS predicate,
label AS object,
'xsd:string' AS datatype
FROM obsolete;

INSERT OR IGNORE INTO dron_obsolete(subject, predicate, object, datatype)
SELECT
curie AS subject,
'owl:deprecated' AS predicate,
'true' AS object,
'xsd:boolean' AS datatype
FROM obsolete;

INSERT OR IGNORE INTO dron_obsolete(subject, predicate, object)
SELECT
curie AS subject,
'IAO:0100001' AS predicate,
replaced_by AS object
FROM obsolete
WHERE replaced_by IS NOT NULL
AND replaced_by != '';
19 changes: 19 additions & 0 deletions src/scripts/convert-ldtab-dron.sql
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,22 @@ UNION
SELECT rxcui FROM clinical_drug
UNION
SELECT rxcui FROM branded_drug;


-- ## dron-obsolete

INSERT OR IGNORE INTO obsolete(curie, label, type)
SELECT
a.subject AS curie,
b.object AS label,
a.object AS type
FROM dron_obsolete AS a
LEFT JOIN dron_obsolete AS b ON a.subject = b.subject
WHERE a.predicate = 'rdf:type'
AND b.predicate = 'rdfs:label';

UPDATE obsolete
SET replaced_by = object
FROM dron_obsolete
WHERE obsolete.curie = dron_obsolete.subject
AND dron_obsolete.predicate = 'IAO:0100001';
70 changes: 41 additions & 29 deletions src/scripts/create-dron-tables.sql
Original file line number Diff line number Diff line change
@@ -1,104 +1,116 @@
-- Create the DrOn tables.

CREATE TABLE rxcui (
rxcui INT PRIMARY KEY,
rxcui INTEGER PRIMARY KEY NOT NULL,
replaced_by INTEGER
);

CREATE TABLE disposition (
curie TEXT PRIMARY KEY,
label TEXT UNIQUE
label TEXT UNIQUE NOT NULL
);

CREATE TABLE ingredient (
curie TEXT PRIMARY KEY,
label TEXT, -- UNIQUE,
rxcui INTEGER,
label TEXT NOT NULL,
rxcui INTEGER NOT NULL,
FOREIGN KEY (rxcui) REFERENCES rxcui(rxcui)
);

CREATE TABLE ingredient_disposition (
ingredient TEXT,
disposition TEXT,
ingredient TEXT NOT NULL,
disposition TEXT NOT NULL,
FOREIGN KEY (ingredient) REFERENCES ingredient(curie),
FOREIGN KEY (disposition) REFERENCES disposition(curie)
);

CREATE TABLE clinical_drug_form (
curie TEXT PRIMARY KEY,
label TEXT, -- UNIQUE,
label TEXT NOT NULL, -- UNIQUE,
parent TEXT,
rxcui INTEGER,
rxcui INTEGER NOT NULL,
FOREIGN KEY (rxcui) REFERENCES rxcui(rxcui)
);

CREATE TABLE clinical_drug_form_ingredient (
clinical_drug_form TEXT,
ingredient TEXT,
clinical_drug_form TEXT NOT NULL,
ingredient TEXT NOT NULL,
PRIMARY KEY (clinical_drug_form, ingredient),
FOREIGN KEY (clinical_drug_form) REFERENCES clinical_drug_form(curie),
FOREIGN KEY (ingredient) REFERENCES ingredient(curie)
);

CREATE TABLE clinical_drug_form_disposition (
clinical_drug_form TEXT,
disposition TEXT,
clinical_drug_form TEXT NOT NULL,
disposition TEXT NOT NULL,
PRIMARY KEY (clinical_drug_form, disposition),
FOREIGN KEY (clinical_drug_form) REFERENCES clinical_drug_form(curie),
FOREIGN KEY (disposition) REFERENCES disposition(curie)
);

CREATE TABLE clinical_drug (
curie TEXT PRIMARY KEY,
label TEXT, -- UNIQUE,
clinical_drug_form TEXT,
rxcui INTEGER,
label TEXT NOT NULL, -- UNIQUE,
clinical_drug_form TEXT NOT NULL,
rxcui INTEGER NOT NULL,
FOREIGN KEY (clinical_drug_form) REFERENCES clinical_drug_form(curie),
FOREIGN KEY (rxcui) REFERENCES rxcui(rxcui)
);

CREATE TABLE clinical_drug_strength (
clinical_drug TEXT,
ingredient TEXT,
strength TEXT,
unit TEXT,
clinical_drug TEXT NOT NULL,
ingredient TEXT NOT NULL,
strength TEXT NOT NULL,
unit TEXT NOT NULL,
-- WARN: There are some clinical drugs in RxNorm
-- with the same ingredient but multiple strengths.
PRIMARY KEY (clinical_drug, ingredient, strength, unit),
FOREIGN KEY (clinical_drug) REFERENCES clinical_drug(curie),
FOREIGN KEY (ingredient) REFERENCES ingredient(curie)
);

CREATE TABLE branded_drug (
curie TEXT PRIMARY KEY,
label TEXT, -- UNIQUE,
clinical_drug TEXT,
rxcui INTEGER,
label TEXT NOT NULL, -- UNIQUE,
clinical_drug TEXT NOT NULL,
rxcui INTEGER NOT NULL,
FOREIGN KEY (clinical_drug) REFERENCES clinical_drug(curie),
FOREIGN KEY (rxcui) REFERENCES rxcui(rxcui)
);

CREATE TABLE branded_drug_excipient (
branded_drug TEXT,
ingredient TEXT,
branded_drug TEXT NOT NULL,
ingredient TEXT NOT NULL,
PRIMARY KEY (branded_drug, ingredient),
FOREIGN KEY (branded_drug) REFERENCES branded_drug(curie),
FOREIGN KEY (ingredient) REFERENCES ingredient(curie)
);

CREATE TABLE ndc_branded_drug (
curie TEXT PRIMARY KEY,
ndc TEXT,
branded_drug TEXT,
ndc TEXT UNIQUE NOT NULL,
branded_drug TEXT NOT NULL,
FOREIGN KEY (branded_drug) REFERENCES branded_drug(curie)
);

CREATE TABLE ndc_clinical_drug (
curie TEXT PRIMARY KEY,
ndc TEXT,
clinical_drug TEXT,
ndc TEXT UNIQUE NOT NULL,
clinical_drug TEXT NOT NULL,
FOREIGN KEY (clinical_drug) REFERENCES clinical_drug(curie)
);

CREATE TABLE obsolete (
curie TEXT PRIMARY KEY NOT NULL,
label TEXT NOT NULL, -- UNIQUE,
type TEXT NOT NULL,
replaced_by TEXT
);

-- Create triggers for automatically assigning DRON IDs.
-- First create a table with one row to track the current ID.
CREATE TABLE current_dron_id ( id INTEGER );
INSERT INTO current_dron_id VALUES (1000000); -- TODO: check this!
-- INSERT INTO current_dron_id VALUES (1003000);

-- Then create a trigger for each row where a CURIE can be assigned:
-- When a row is inserted into the table,
Expand Down
36 changes: 36 additions & 0 deletions src/scripts/index-dron-tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- Index main DrOn tables.

CREATE INDEX IF NOT EXISTS idx_ingredient_curie ON ingredient(curie);
CREATE INDEX IF NOT EXISTS idx_ingredient_label ON ingredient(label);
CREATE INDEX IF NOT EXISTS idx_ingredient_rxcui ON ingredient(rxcui);

CREATE INDEX IF NOT EXISTS idx_clinical_drug_form_curie ON clinical_drug_form(curie);
CREATE INDEX IF NOT EXISTS idx_clinical_drug_form_label ON clinical_drug_form(label);
CREATE INDEX IF NOT EXISTS idx_clinical_drug_form_rxcui ON clinical_drug_form(rxcui);

CREATE INDEX IF NOT EXISTS idx_clinical_drug_form_ingredient_clinical_drug_form ON clinical_drug_form_ingredient(clinical_drug_form);
CREATE INDEX IF NOT EXISTS idx_clinical_drug_form_ingredient_ingredient ON clinical_drug_form_ingredient(ingredient);

CREATE INDEX IF NOT EXISTS idx_clinical_drug_curie ON clinical_drug(curie);
CREATE INDEX IF NOT EXISTS idx_clinical_drug_label ON clinical_drug(label);
CREATE INDEX IF NOT EXISTS idx_clinical_drug_rxcui ON clinical_drug(rxcui);

CREATE INDEX IF NOT EXISTS idx_clinical_drug_strength_clinical_drug ON clinical_drug_strength(clinical_drug);
CREATE INDEX IF NOT EXISTS idx_clinical_drug_strength_ingredient ON clinical_drug_strength(ingredient);

CREATE INDEX IF NOT EXISTS idx_branded_drug_curie ON branded_drug(curie);
CREATE INDEX IF NOT EXISTS idx_branded_drug_label ON branded_drug(label);
CREATE INDEX IF NOT EXISTS idx_branded_drug_rxcui ON branded_drug(rxcui);

CREATE INDEX IF NOT EXISTS idx_branded_drug_excipient_branded_drug ON branded_drug_excipient(branded_drug);
CREATE INDEX IF NOT EXISTS idx_branded_drug_excipient_ingredient ON branded_drug_excipient(ingredient);

CREATE INDEX IF NOT EXISTS idx_ndc_clinical_drug_curie ON ndc_clinical_drug(curie);
CREATE INDEX IF NOT EXISTS idx_ndc_clinical_drug_ndc ON ndc_clinical_drug(ndc);
CREATE INDEX IF NOT EXISTS idx_ndc_clinical_drug_clinical_drug ON ndc_clinical_drug(clinical_drug);

CREATE INDEX IF NOT EXISTS idx_ndc_branded_drug_curie ON ndc_branded_drug(curie);
CREATE INDEX IF NOT EXISTS idx_ndc_branded_drug_ndc ON ndc_branded_drug(ndc);
CREATE INDEX IF NOT EXISTS idx_ndc_branded_drug_branded_drug ON ndc_branded_drug(branded_drug);

ANALYZE;
Loading
Loading