Skip to content

Commit

Permalink
Obsolete-and-replace DrOn ingredients with non-obsolete labels in ChEBI
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesaoverton committed Jun 17, 2024
1 parent 31a8b07 commit 4e8a376
Show file tree
Hide file tree
Showing 8 changed files with 502 additions and 426 deletions.
29 changes: 29 additions & 0 deletions src/scripts/obsolete-dron-ingredients.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
#
# Add DRON ingredients to obsolete.tsv
# if they match ChEBI labels.

fail() {
echo "ERROR: " "$@"
exit 1
}

ROOT=$(git rev-parse --show-toplevel) || fail "Not a git repository"
DIR="${ROOT}/src/ontology"
SCRIPTSDIR="${ROOT}/src/scripts"
TEMPLATEDIR="${ROOT}/src/templates"
DB="${DIR}/tmp/dron.db"

# Load template TSVs into SQLite.
cd "${DIR}" || fail "Could not cd to ${DIR}"
make tmp/dron.db || fail "Could not make tmp/dron.db"
make tmp/chebi.db || fail "Could not make tmp/chebi.db"

# Find DRON ingredients matching ChEBI labels.
sqlite3 "${DB}" < "${SCRIPTSDIR}/obsolete-dron-ingredients.sql" \
|| fail "Could not run query for ingredients"

# Save obsolete.tsv.
cd "${TEMPLATEDIR}" \
&& sqlite3 "${DB}" < "${SCRIPTSDIR}/save-dron-tables.sql" \
|| fail "Could not save updated obsolete.tsv"
23 changes: 23 additions & 0 deletions src/scripts/obsolete-dron-ingredients.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ATTACH 'tmp/dron.db' AS dron;
ATTACH 'tmp/chebi.db' AS chebi;

CREATE INDEX IF NOT EXISTS dron.idx_ingredient_label ON ingredient(label);
WITH labels AS (
SELECT subject, object AS label
FROM chebi.chebi
WHERE predicate = 'rdfs:label'
AND subject NOT IN (
SELECT subject
FROM chebi.chebi
WHERE predicate = 'owl:deprecated'
)
)
INSERT OR IGNORE INTO dron.obsolete
SELECT
i.curie AS curie,
'obsolete ' || i.label AS label,
'owl:Class' AS type,
l.subject AS replaced_by
FROM dron.ingredient AS i
JOIN labels AS l ON l.label = i.label
WHERE i.curie LIKE 'DRON:%';
5 changes: 5 additions & 0 deletions src/scripts/report-problems.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ WITH labels AS (
SELECT subject, object AS label
FROM chebi.chebi
WHERE predicate = 'rdfs:label'
AND subject NOT IN (
SELECT subject
FROM chebi.chebi
WHERE predicate = 'owl:deprecated'
)
)
INSERT INTO problem
SELECT
Expand Down
Loading

0 comments on commit 4e8a376

Please sign in to comment.