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

OBA-EFO alignment pipeline (not ready) #1660

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions src/ontology/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,11 @@ components/gwas_template.owl: $(SRC) iri_dependencies/gwas_terms.tsv
components/gwas_import.owl: components/gwas_template.owl
$(ROBOT) annotate -i $< -O "http://www.ebi.ac.uk/efo/components/gwas_import.owl" -o $@
rm components/gwas_template.owl

# ----------------------------------------
# OBA alignment Measurment Branch
# -----------------------------------------

align_oba:
make -f measurement.Makefile download_all
make -f measurement.Makefile reclassify.owl tmp/lost.owl
111 changes: 111 additions & 0 deletions src/ontology/measurement.Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
##################################
### Cancer Mapping Pipeline ######
##################################
ROBOT=robot --catalog catalog-v001.xml
#MAPPING_EFO_OBA=https://raw.githubusercontent.com/EBISPOT/efo/master/src/ontology/components/oba_efo_mappings.tsv
MAPPING_OBA_EFO=https://raw.githubusercontent.com/obophenotype/bio-attribute-ontology/master/src/mappings/oba-efo.sssom.tsv
#MAPPING_AUGMENTED_EFO_OBA=https://docs.google.com/spreadsheets/d/e/2PACX-1vQb6EtOFekjNUAfnnQLfm6KDFY3DH8WPV2Gjb_2WXLofZ87HvmR2m0wchNxplpDGwzucsWy6BGfaILp/pub?gid=2147444170&single=true&output=tsv
UNMAPPED_TERMS=https://docs.google.com/spreadsheets/d/e/2PACX-1vQb6EtOFekjNUAfnnQLfm6KDFY3DH8WPV2Gjb_2WXLofZ87HvmR2m0wchNxplpDGwzucsWy6BGfaILp/pub?gid=665705711&single=true&output=tsv
OBA=http://purl.obolibrary.org/obo/oba.owl

O1=efo-edit-tmp.owl
O2=tmp/oba.owl
MAP=tmp/oba_efo.tsv

UNMAPPED_TERMS_FILTERED=tmp/keep_unmapped.owl
TERMLIST=tmp/measurement_branch.tsv
UNMAPPED=tmp/unmapped.tsv
SPARQL_TERMLIST=sparql/efo_measurement.sparql
SPARQL_LABELS=sparql/efo-original-labels.ru
MIR=false

tmp/ metadata/:
mkdir -p $@

#tmp/efo_oba.tsv: | tmp/
# if [ $(MIR) = true ]; then wget "$(MAPPING_AUGMENTED_EFO_OBA)" -O [email protected] &&\
# cut -f 1,2 [email protected] > $@ && rm [email protected]; fi

# sed -i '1s/^/o1\to2\n/' [email protected]

tmp/oba_efo.tsv: | tmp/
if [ $(MIR) = true ]; then wget "$(MAPPING_OBA_EFO)" -O $@; fi

tmp/unmapped.tsv: | tmp/
if [ $(MIR) = true ]; then echo "EFO:0001444" > $@; fi

$(O1):
cp efo-edit.owl $@

MON=false
tmp/oba.owl:
if [ $(MON) = true ]; then wget $(OBA) -O $@; fi

download_all: tmp/oba_efo.tsv $(O1) tmp/oba.owl

metadata/%_synonyms.tsv: | metadata/
$(ROBOT) query -i tmp/$*.owl --query sparql/synonyms.sparql $@

metadata/%_labels.tsv: | metadata/
$(ROBOT) query -i tmp/$*.owl --query sparql/labels.sparql $@

extract_metadata: metadata/oba_synonyms.tsv metadata/efo_synonyms.tsv
extract_metadata: metadata/oba_labels.tsv metadata/efo_labels.tsv

$(TERMLIST): $(O1) $(SPARQL_TERMLIST)
$(ROBOT) query -i $(O1) --query $(SPARQL_TERMLIST) $@
sed -i 's/[<>]//g' $@

tmp/original_labels.ttl: $(O1) $(SPARQL_LABELS)
$(ROBOT) query -i $(O1) --query $(SPARQL_LABELS) $@

# filter trim true will omit axioms in the measurement branch that mention entities
# outside the measurement branch, in particular A sub R some C (where R, or C, are not in the measurement branch)
tmp/reclassified.owl: $(O2) $(MAP) $(TERMLIST)
$(ROBOT) merge -i $(O2) \
query --update sparql/oba-labels-to-synonym.ru \
rename --mappings $(MAP) --allow-missing-entities true \
filter -T $(TERMLIST) --select "self annotations" -o $@

$(UNMAPPED_TERMS_FILTERED): $(O1) $(UNMAPPED)
$(ROBOT) filter -i $< -T $(UNMAPPED) --trim false -o $@

reclassify.owl: $(O1) tmp/reclassified.owl tmp/original_labels.ttl $(UNMAPPED_TERMS_FILTERED) $(TERMLIST)
$(ROBOT) remove -i $(O1) -T $(TERMLIST) \
merge -i tmp/reclassified.owl -i $(UNMAPPED_TERMS_FILTERED) -i tmp/original_labels.ttl -i tmp/lost_illegal.owl --collapse-import-closure false -o $@

tmp/diff.txt: $(O1) reclassify.owl
$(ROBOT) diff --left $(O1) --right reclassify.owl -o $@

tmp/diff2.txt: o1_merged.owl reclassify_merged.owl
$(ROBOT) diff --left o1_merged.owl --right reclassify_merged.owl -o $@


# I want to get everything that has been lost for a wrong reason.
reclassify_merged.owl: reclassify.owl
$(ROBOT) remove -i reclassify.owl --select imports -o $@

o1_merged.owl: $(O1)
$(ROBOT) remove -i $(O1) --select imports -o $@

tmp/types.owl: $(O1)
$(ROBOT) query -i $(O1) --query sparql/efo-types.ru $@

unmerged.owl: tmp/types.owl reclassify_merged.owl o1_merged.owl
$(ROBOT) unmerge -i o1_merged.owl -i reclassify_merged.owl \
merge -i tmp/types.owl -o $@

tmp/lost.owl: unmerged.owl
$(ROBOT) filter -i $< -T $(TERMLIST) --select complement --select classes --trim false \
convert -f ofn -o $@

mv_efo:
$(ROBOT) convert -i reclassify.owl -f ofn -o efo-edit.owl

sed:
sed -i 's/obo1:/obo2:/g' efo-edit.owl
sed -i 's/chebi5:/chebi6:/g' efo-edit.owl
sed -i 's/chebi4:/chebi5:/g' efo-edit.owl
sed -i 's/chebi3:/chebi4:/g' efo-edit.owl
sed -i 's/chebi2:/chebi3:/g' efo-edit.owl

14 changes: 14 additions & 0 deletions src/ontology/sparql/efo_measurement.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX replaced_by: <http://purl.obolibrary.org/obo/IAO_0100001>
prefix oboInOwl: <http://www.geneontology.org/formats/oboInOwl#>
PREFIX EFO: <http://www.ebi.ac.uk/efo/EFO_>

SELECT ?cls WHERE {
?cls a owl:Class .
?cls rdfs:subClassOf* EFO:0001444 .
FILTER NOT EXISTS {?cls owl:deprecated ?dep}
FILTER (!isBlank(?cls))
}
ORDER BY ?cls
36 changes: 36 additions & 0 deletions src/ontology/sparql/oba-labels-to-synonym.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX replaced_by: <http://purl.obolibrary.org/obo/IAO_0100001>
prefix oboInOwl: <http://www.geneontology.org/formats/oboInOwl#>
PREFIX EFO: <http://www.ebi.ac.uk/efo/EFO_>

DELETE {
?cls rdfs:label ?label .
?cls oboInOwl:id ?oid .
}

INSERT {
?cls a owl:Class .
?cls oboInOwl:hasExactSynonym ?label .
?cls oboInOwl:hasDbXref ?curie .
[] a owl:Axiom ;
owl:annotatedSource ?cls ;
owl:annotatedProperty oboInOwl:hasExactSynonym ;
owl:annotatedTarget ?label ;
rdfs:comment "OBA preferred label 06.07.2022." ;
oboInOwl:hasDbXref ?curie .

}

WHERE {
?cls a owl:Class .
?cls rdfs:label ?label .
OPTIONAL {
?cls oboInOwl:id ?oid .
}
FILTER NOT EXISTS {?cls owl:deprecated ?dep}
FILTER (isIRI(?cls) && regex(str(?cls), "^http://purl.obolibrary.org/obo/OBA_"))
FILTER (!isBlank(?cls))
BIND(REPLACE(?cls, "http://purl.obolibrary.org/obo/OBA_", "OBA:", "i") AS ?curie)
}