Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
hkir-dev committed Aug 22, 2023
1 parent a528fa6 commit 2d96987
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 10 deletions.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pandas
ruamel.yaml
linkml-owl
39 changes: 39 additions & 0 deletions src/config/db_graph_atlas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
dhba:
species: human dev
graph: 16
atlases:
-
name: Human, 34 years, Cortex - Gyral
id: 138322605
-
name: Human, 34 years, Cortex - Mod. Brodmann
id: 265297126
-
name: Human, 21 pcw
id: 3
-
name: 287730656
id: 138322603

mba:
species: mouse
graph: 1
atlases:
-
id: 602630314
name: Adult Mouse, 3D Coronal
-
id: 1
name: Mouse, P56, Coronal

- id: 2
name: Mouse, P56, Sagittal

hba:
species: human
graph: 10
atlases:
-
id: 265297125
name: Human Brain Atlas Guide

Empty file added src/linkml/data/.gitignore
Empty file.
44 changes: 44 additions & 0 deletions src/linkml/structure_graph_schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
id: http://purl.obolibrary.org/obo/ABA_Uberon
name: structure_graph
prefixes:
UBERON: 'http://purl.obolibrary.org/obo/UBERON_'

default_curi_maps:
- semweb_context
- obo_context

types:
string:
base: str
uri: xsd:string

classes:
Class:
slots:
- id
- name
- acronym
- parent_structure_id
- subclass_of
class_uri: owl:Class

slots:
id:
identifier: true
# range: uriorcurie
name:
slot_uri: rdfs:label
annotations:
owl: AnnotationAssertion
acronym:
slot_uri: oboInOwl:hasExactSynonym
annotations:
owl: AnnotationAssertion
parent_structure_id:
slot_uri: BFO:0000050
annotations:
owl: SubClassOf, ObjectSomeValuesFrom
subclass_of:
slot_uri: rdfs:subclass_of
annotations:
owl: SubClassOf
2 changes: 1 addition & 1 deletion src/ontology/catalog-v001.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<uri name="https://purl.brain-bican.org/ontology/dhbao/imports/ncbitaxon_import.owl" uri="imports/ncbitaxon_import.owl"/>
<uri name="https://purl.brain-bican.org/ontology/dhbao/imports/ncbitaxon_import.obo" uri="imports/ncbitaxon_import.obo"/>


<uri name="https://purl.brain-bican.org/ontology/dhbao/imports/merged_import.owl" uri="imports/merged_import.owl"/>


<uri name="https://purl.brain-bican.org/ontology/dhbao/components/all_templates.owl" uri="components/all_templates.owl"/>
Expand Down
12 changes: 5 additions & 7 deletions src/ontology/dhbao-edit.owl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ Prefix(dcterms:=<http://purl.org/dc/terms/>)

Ontology(<https://purl.brain-bican.org/ontology/dhbao.owl>

Import(<https://purl.brain-bican.org/ontology/dhbao/imports/uberon_import.owl>)
# Import(<https://purl.brain-bican.org/ontology/dhbao/imports/uberon_import.owl>)
# Import(<https://purl.brain-bican.org/ontology/dhbao/imports/ncbitaxon_import.owl>)

Import(<https://purl.brain-bican.org/ontology/dhbao/imports/merged_import.owl>)
Import(<https://purl.brain-bican.org/ontology/dhbao/components/all_templates.owl>)

Import(<https://purl.brain-bican.org/ontology/dhbao/imports/ncbitaxon_import.owl>)


Import(<https://purl.brain-bican.org/ontology/dhbao/patterns/definitions.owl>)
Annotation(dcterms:description "None")
Annotation(dcterms:license <https://creativecommons.org/licenses/unspecified>)
Annotation(dcterms:title "Developing Human Brain Atlas Ontology")

Expand All @@ -39,10 +41,6 @@ AnnotationAssertion(rdfs:label dcterms:title "title")
# Classes
############################

# Class: <https://purl.brain-bican.org/ontology/DHBAO_0000000> (root node)

AnnotationAssertion(rdfs:label <https://purl.brain-bican.org/ontology/DHBAO_0000000> "root node"@en)


)

164 changes: 162 additions & 2 deletions src/ontology/dhbao.Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,166 @@
## Customize Makefile settings for dhbao
##
## Customize Makefile settings for mbao
##
## If you need to customize your Makefile, make
## changes here rather than in the main Makefile
#
# sh ./run.sh make clean
# sh ./run.sh make prepare_release
#
# MBA : 1
# DMBA : 17
# HBA : 10
# DHBA : 16
# PBA : 8

URIBASE = https://purl.brain-bican.org/ontology

JOBS = 16 # 1 17 10 8
BRIDGES = aba dhba
TARGETS = dhba

LINKML = linkml-data2owl

STRUCTURE_GRAPHS = $(patsubst %, sources/%.json, $(JOBS))
ALL_GRAPH_ONTOLOGIES = $(patsubst sources/%.json,sources/%.ofn,$(STRUCTURE_GRAPHS))
ALL_BRIDGES = $(patsubst %, sources/uberon-bridge-to-%.owl, $(BRIDGES))
SOURCE_TEMPLATES = $(patsubst %, ../robot_templates/%_CCF_to_UBERON_source.tsv, $(TARGETS))
NEW_BRIDGES = $(patsubst %, new-bridges/new-uberon-bridge-to-%.owl, $(TARGETS))


.PHONY: $(COMPONENTSDIR)/all_templates.owl
$(COMPONENTSDIR)/all_templates.owl: clean_files dependencies $(COMPONENTSDIR)/linkouts.owl $(COMPONENTSDIR)/sources_merged.owl
$(ROBOT) merge -i $(COMPONENTSDIR)/linkouts.owl -i $(COMPONENTSDIR)/sources_merged.owl annotate --ontology-iri $(URIBASE)/$@ convert -f ofn -o $@
.PRECIOUS: $(COMPONENTSDIR)/all_templates.owl

# Installing depedencies so it can run in ODK container
.PHONY: dependencies
dependencies:
pip3 install -r ../../requirements.txt


LOCAL_CLEAN_FILES = $(ALL_GRAPH_ONTOLOGIES) $(ALL_BRIDGES) $(TMPDIR)/tmp.json $(TMPDIR)/tmp.owl $(COMPONENTSDIR)/sources_merged.owl $(COMPONENTSDIR)/linkouts.owl $(TEMPLATEDIR)/linkouts.tsv

# clean previous build files
.PHONY: clean_files
clean_files:
rm -f $(LOCAL_CLEAN_FILES)

sources/%.json:
curl -o $@ $(subst %,$(subst sources/,,$@),"http://api.brain-map.org/api/v2/structure_graph_download/%")

../linkml/data/template_%.tsv: sources/%.json
python3 $(SCRIPTSDIR)/structure_graph_template.py -i $< -o $@
.PRECIOUS: ../linkml/data/template_%.tsv:
# TODO delete

sources/%.ofn: ../linkml/data/template_%.tsv
$(LINKML) -C Class -s ../linkml/structure_graph_schema.yaml $< -o $@
.PRECIOUS: sources/%.ofn

# download bridges
sources/uberon-bridge-to-aba.owl:
curl -o sources/uberon-bridge-to-aba.obo "https://raw.githubusercontent.com/obophenotype/uberon/master/src/ontology/bridge/uberon-bridge-to-aba.obo"
$(ROBOT) convert -i sources/uberon-bridge-to-aba.obo --format owl -o $@
sed -i 's|http://purl.obolibrary.org/obo/ABA_|https://purl.brain-bican.org/ontology/mbao/ABA_|g' $@

sources/uberon-bridge-to-dhba.owl:
curl -o sources/uberon-bridge-to-dhba.obo "https://raw.githubusercontent.com/obophenotype/uberon/master/src/ontology/bridge/uberon-bridge-to-dhba.obo"
$(ROBOT) convert -i sources/uberon-bridge-to-dhba.obo --format owl -o $@
sed -i 's|http://purl.obolibrary.org/obo/DHBA_|https://purl.brain-bican.org/ontology/mbao/DHBA_|g' $@

sources/uberon-bridge-to-dmba.owl:
curl -o sources/uberon-bridge-to-dmba.obo "https://raw.githubusercontent.com/obophenotype/uberon/master/src/ontology/bridge/uberon-bridge-to-dmba.obo"
$(ROBOT) convert -i sources/uberon-bridge-to-dmba.obo --format owl -o $@
sed -i 's|http://purl.obolibrary.org/obo/DMBA_|https://purl.brain-bican.org/ontology/mbao/DMBA_|g' $@

sources/uberon-bridge-to-hba.owl:
curl -o sources/uberon-bridge-to-hba.obo "https://raw.githubusercontent.com/obophenotype/uberon/master/src/ontology/bridge/uberon-bridge-to-hba.obo"
$(ROBOT) convert -i sources/uberon-bridge-to-hba.obo --format owl -o $@
sed -i 's|http://purl.obolibrary.org/obo/HBA_|https://purl.brain-bican.org/ontology/mbao/HBA_|g' $@

sources/uberon-bridge-to-mba.owl:
curl -o sources/uberon-bridge-to-mba.obo "https://raw.githubusercontent.com/obophenotype/uberon/master/src/ontology/bridge/uberon-bridge-to-mba.obo"
$(ROBOT) convert -i sources/uberon-bridge-to-mba.obo --format owl -o $@
sed -i 's|http://purl.obolibrary.org/obo/MBA_|https://purl.brain-bican.org/ontology/mbao/MBA_|g' $@

sources/uberon-bridge-to-pba.owl:
curl -o sources/uberon-bridge-to-pba.obo "https://raw.githubusercontent.com/obophenotype/uberon/master/src/ontology/bridge/uberon-bridge-to-pba.obo"
$(ROBOT) convert -i sources/uberon-bridge-to-pba.obo --format owl -o $@
sed -i 's|http://purl.obolibrary.org/obo/PBA_|https://purl.brain-bican.org/ontology/mbao/PBA_|g' $@

# TODO handle legacy mapings

#all_bridges:
# make sources/uberon-bridge-to-aba.obo sources/uberon-bridge-to-dmba.obo -B

# Merge sources. # crudely listing dependencies for now - but could switch to using pattern expansion
#sources_merged.owl: all_bridges
# robot merge --input sources/1.ofn --input sources/17.ofn --input sources/10.ofn --input sources/16.ofn --input sources/8.ofn --input sources/uberon-bridge-to-aba.obo --input sources/uberon-bridge-to-dhba.obo --input sources/uberon-bridge-to-dmba.obo --input sources/uberon-bridge-to-hba.obo --input sources/uberon-bridge-to-mba.obo --input sources/uberon-bridge-to-pba.obo annotate --ontology-iri $(URIBASE)/$@ -o $@

$(COMPONENTSDIR)/sources_merged.owl: $(ALL_GRAPH_ONTOLOGIES) $(ALL_BRIDGES)
$(ROBOT) merge $(patsubst %, -i %, $^) relax annotate --ontology-iri $(URIBASE)/$@ -o $@

# merge uberon + sources, reason & relax (EC -> SC)
$(TMPDIR)/tmp.owl: $(SRC) $(COMPONENTSDIR)/sources_merged.owl
robot merge $(patsubst %, -i %, $^) relax annotate --ontology-iri $(URIBASE)/$@ -o $@

# Make a json file for use in generating ROBOT template
$(TMPDIR)/tmp.json: $(TMPDIR)/tmp.owl
$(ROBOT) convert --input $< -f json -o $@

# Build robot template - with linkouts and prefLabels
$(TEMPLATEDIR)/linkouts.tsv: $(TMPDIR)/tmp.json
python $(SCRIPTSDIR)/gen_linkout_template.py $<

# generate OWL from template
$(COMPONENTSDIR)/linkouts.owl: $(TMPDIR)/tmp.owl $(TEMPLATEDIR)/linkouts.tsv
$(ROBOT) template --template $(word 2, $^) --input $< --add-prefixes template_prefixes.json -o $@




## ONTOLOGY: uberon (remove disjoint classes and properties, they are causing inconsistencies when merged with dhba bridge)
.PHONY: mirror-uberon
.PRECIOUS: $(MIRRORDIR)/uberon.owl
mirror-uberon: | $(TMPDIR)
if [ $(MIR) = true ] && [ $(IMP) = true ]; then curl -L $(OBOBASE)/uberon/uberon-base.owl --create-dirs -o $(MIRRORDIR)/uberon.owl --retry 4 --max-time 200 &&\
$(ROBOT) convert -i $(MIRRORDIR)/uberon.owl -o $@.tmp.owl && \
$(ROBOT) remove -i $@.tmp.owl --axioms disjoint -o $@.tmp.owl && \
mv $@.tmp.owl $(TMPDIR)/$@.owl; fi
# if [ $(MIR) = true ] && [ $(IMP) = true ]; then $(ROBOT) convert -I http://purl.obolibrary.org/obo/uberon/subsets/human-view.owl -o [email protected] &&\
# $(ROBOT) remove -i [email protected] --axioms disjoint -o [email protected] && \
# mv [email protected] $(TMPDIR)/[email protected]; fi


## Disable '--equivalent-classes-allowed asserted-only' due to DHBA inconsistencies
.PHONY: reason_test
reason_test: $(EDIT_PREPROCESSED)
# $(ROBOT) explain --input $< --reasoner ELK -M unsatisfiability --unsatisfiable all --explanation explanation.md
# $(ROBOT) reason --input $< --reasoner ELK --equivalent-classes-allowed asserted-only \
# --exclude-tautologies structural --output test.owl && rm test.owl
$(ROBOT) reason --input $< --reasoner ELK \
--exclude-tautologies structural --output test.owl && rm test.owl

## Disable '--equivalent-classes-allowed asserted-only' due to DHBA inconsistencies
# Full: The full artefacts with imports merged, reasoned.
$(ONT)-full.owl: $(EDIT_PREPROCESSED) $(OTHER_SRC) $(IMPORT_FILES)
$(ROBOT_RELEASE_IMPORT_MODE) \
reason --reasoner ELK --exclude-tautologies structural \
relax \
reduce -r ELK \
$(SHARED_ROBOT_COMMANDS) annotate --ontology-iri $(ONTBASE)/$@ $(ANNOTATE_ONTOLOGY_VERSION) --output $@.tmp.owl && mv $@.tmp.owl $@

## Disable '--equivalent-classes-allowed asserted-only' due to DHBA inconsistencies
# foo-simple: (edit->reason,relax,reduce,drop imports, drop every axiom which contains an entity outside the "namespaces of interest")
# drop every axiom: filter --term-file keep_terms.txt --trim true
# remove --select imports --trim false
$(ONT)-simple.owl: $(EDIT_PREPROCESSED) $(OTHER_SRC) $(SIMPLESEED) $(IMPORT_FILES)
$(ROBOT_RELEASE_IMPORT_MODE) \
reason --reasoner ELK --exclude-tautologies structural \
relax \
remove --axioms equivalent \
relax \
filter --term-file $(SIMPLESEED) --select "annotations ontology anonymous self" --trim true --signature true \
reduce -r ELK \
query --update ../sparql/inject-subset-declaration.ru --update ../sparql/inject-synonymtype-declaration.ru \
$(SHARED_ROBOT_COMMANDS) annotate --ontology-iri $(ONTBASE)/$@ $(ANNOTATE_ONTOLOGY_VERSION) --output $@.tmp.owl && mv $@.tmp.owl $@
Empty file.
7 changes: 7 additions & 0 deletions src/ontology/template_prefixes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"@context": {
"UBERON": "http://purl.obolibrary.org/obo/UBERON_",
"OboInOwl": "http://www.geneontology.org/formats/oboInOwl#",
"DHBA": "https://purl.brain-bican.org/ontology/mbao/DHBA_"
}
}
3 changes: 3 additions & 0 deletions src/ontology/template_prefixes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UBERON: http://purl.obolibrary.org/obo/UBERON_
OboInOwl: http://www.geneontology.org/formats/oboInOwl#
DHBA: https://purl.brain-bican.org/ontology/mbao/DHBA_
51 changes: 51 additions & 0 deletions src/scripts/gen_linkout_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import json
from ruamel.yaml import YAML
from string import Template
import pandas as pd
import argparse

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('filepath',
help='Path to json version of ontology for input')
args = parser.parse_args()

f = open(args.filepath, 'r')
j = json.loads(f.read())
g = j['graphs'][0]
conf = open('../config/db_graph_atlas.yaml', 'r')
yaml = YAML(typ='safe')
mapping = yaml.load(conf.read())
link = Template("http://atlas.brain-map.org/atlas?atlas="
"$atlas_id#structure=$structure_id")

seed = {'ID': 'ID',
'xref': 'A OboInOwl:hasDbXref',
'prefLabel': 'A skos:prefLabel'}

tab = [seed]

for n in g['nodes']:
if 'type' in n.keys() and n['type'] == 'CLASS':
lstat = True
for k, v in mapping.items():
if str(n['id']).lower().startswith('http://purl.obolibrary.org/obo/%s' % k) and 'lbl' in n:
for a in v['atlases']:
try:
tab.append({'ID': n['id'],
'xref': link.substitute(atlas_id=a['id'],
structure_id=str(n['id']).rsplit('_', 1)[-1]),
'prefLabel': ' '.join([n['lbl'],
' (',
v['species'],
')'])})
except Exception as e:
print("ERROR: Exception occurred while processing: " + n['id'])
raise e
lstat = False
if lstat and 'lbl' in n.keys():
tab.append({'ID': n['id'], 'xref': '', 'prefLabel': n['lbl']})


r_temp = pd.DataFrame.from_records(tab)
r_temp.to_csv('../templates/linkouts.tsv', sep='\t', index=False)

22 changes: 22 additions & 0 deletions src/scripts/structure_graph_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import argparse
import pandas as pd
import csv

from structure_graph_utils import read_structure_graph


def generate_template(graph_json, output):
data_list = read_structure_graph(graph_json)

data_template = pd.DataFrame.from_records(data_list)
data_template.to_csv(output, sep="\t", index=False, quoting=csv.QUOTE_NONE)


parser = argparse.ArgumentParser(description='Cli interface structure graph linkml template generation.')

parser.add_argument('-i', '--input', help="Path to input JSON file")
parser.add_argument('-o', '--output', help="Path to output TSV file")

args = parser.parse_args()

generate_template(args.input, args.output)
Loading

0 comments on commit 2d96987

Please sign in to comment.