Skip to content

Commit

Permalink
Now produces spreadsheet report.
Browse files Browse the repository at this point in the history
  • Loading branch information
dosumis committed Apr 16, 2020
1 parent f9b128c commit 6f53c60
Show file tree
Hide file tree
Showing 10 changed files with 100,297 additions and 2,674 deletions.
43,040 changes: 41,708 additions & 1,332 deletions aba_uberon.owl

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandas
openpyxl
26 changes: 17 additions & 9 deletions src/ontology/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ROBOT = robot
URIBASE = http://purl.obolibrary.org/obo

all: aba-uberon.owl.gz
all: aba_uberon.owl report.xlsx

IMP=true # Global parameter to bypass import generation
MIR=true # Global parameter to bypass mirror generation

# Pulling full Uberon for now and using
mirror/uberon.owl:
mirror/uberon.owl:
@if [ $(MIR) = true ] && [ $(IMP) = true ]; then $(ROBOT) convert -I $(URIBASE)/uberon.owl -o $@.tmp.owl && mv $@.tmp.owl $@; fi

# TODO: move to making uberon slice.
Expand All @@ -19,17 +19,19 @@ sources_merged.owl:

# Generate seed for pulling relevant subset of Uberon
terms.txt: sources_merged.owl
$(ROBOT) query --use-graphs true -f csv -i $< --query ../sparql/terms.sparql $@
$(ROBOT) query --use-graphs true -f tsv -i $< --query ../sparql/terms.sparql $@

# Generate slice of uberon.
# Generate slice of uberon, removing disjoints
# Using BOT for now - but this could potentially be more minimal

uberon_slice.owl: mirror/uberon.owl terms.txt
$(ROBOT) extract --method BOT -i mirror/uberon.owl -T terms.txt -o $@
$(ROBOT) extract --method BOT -i mirror/uberon.owl -T terms.txt remove --axioms disjoint -o $@


# merge uberon + sources, reason & relax (EC -> SC)

tmp.owl: uberon_slice.owl sources_merged.owl
robot merge --input uberon_slice.owl --input sources_merged.owl annotate --ontology-iri $(URIBASE)/$@ -o $@
robot merge --input uberon_slice.owl --input sources_merged.owl reason relax annotate --ontology-iri $(URIBASE)/$@ -o $@

# Make a json file for use in geneating ROBOT template
tmp.json: tmp.owl
Expand All @@ -38,7 +40,7 @@ tmp.json: tmp.owl
# Build robot template - with linkouts and prefLabels

../robot_templates/linkouts.tsv: tmp.json
python ../scripts/gen_linkout_template.py
python ../scripts/gen_linkout_template.py $<

# generate OWL from template

Expand All @@ -49,9 +51,15 @@ linkouts.owl: tmp.owl ../robot_templates/linkouts.tsv
aba_uberon.owl: linkouts.owl
robot merge --input $< --input tmp.owl annotate --ontology-iri $(URIBASE)/$@ convert -f ofn -o $@

report.tsv: aba_uberon.owl
robot query -i $< -f tsv -q ../sparql/aba_mapping_report.sparql $@

report.xlsx: report.tsv
python3 ../scripts/mapping_spreadsheet_gen.py $< $@

# Compress for release to get below GitHub file size restrictions.
aba-uberon.owl.gz: aba_uberon.owl
gzip $<
# aba-uberon.owl.gz: aba_uberon.owl
# gzip $<

prepare_release: aba_uberon.owl
cp $< ../../.
Expand Down
43,040 changes: 41,708 additions & 1,332 deletions src/ontology/aba_uberon.owl

Large diffs are not rendered by default.

16,803 changes: 16,803 additions & 0 deletions src/ontology/report.tsv

Large diffs are not rendered by default.

Binary file added src/ontology/report.xlsx
Binary file not shown.
1 change: 1 addition & 0 deletions src/robot_templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add robot templates here
8 changes: 7 additions & 1 deletion src/scripts/gen_linkout_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
from ruamel.yaml import YAML
from string import Template
import pandas as pd
import argparse

f = open('../ontology/tmp.json', 'r')
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')
Expand Down
35 changes: 35 additions & 0 deletions src/scripts/mapping_spreadsheet_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pandas as pd
import argparse

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('infile',
help='Path to csv for input')
parser.add_argument('outfile', help='Path to output ')
args = parser.parse_args()

df = pd.read_csv(args.infile, sep='\t')

# remove rows with generic classification (regional part of brain)
unwanted_uberon_mappings = ['<http://purl.obolibrary.org/obo/UBERON_0002616>']
df.rename(columns={'?sup': 'superclass_iri', '?supname': 'superclass_name',
'?sub': 'subclass_iri', '?subname': 'subclass_name'}, inplace=True)
filtered_df = df[~df.superclass_iri.isin(unwanted_uberon_mappings)]


def gen_ols_xls_link(row):
ont_name = 'uberon'
link = 'https://www.ebi.ac.uk/ols/ontologies/%s/terms?iri=%s' \
'' % (ont_name,
row['superclass_iri'].replace('>', '').replace('<', ''))
return'=HYPERLINK("%s","%s")' % (link, row['superclass_name'])
#urllib.parse.quote()

filtered_df.insert(0, 'superclass_name_linked',
value=filtered_df.apply(
lambda row: gen_ols_xls_link(row), axis=1))

filtered_df.drop(columns=['superclass_name'], inplace=True)

filtered_df.to_excel(args.outfile, header=True, index=False)


16 changes: 16 additions & 0 deletions src/sparql/aba_mapping_report.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?supname ?sup ?subname ?sub
WHERE {
{ ?sub rdfs:subClassOf ?sup .
?sub rdfs:label ?subname .
?sup rdfs:label ?supname .
}
FILTER (STRSTARTS(STR(?sup), "http://purl.obolibrary.org/obo/UBERON_"))
# Can't get double filter to work!
# FILTER (!STRENDS(STR(?sup), "UBERON_0002616")) # ignore generic uberon classification
FILTER (!STRSTARTS(STR(?sub), "http://purl.obolibrary.org/obo/UBERON_"))
}
ORDER BY ?supname

0 comments on commit 6f53c60

Please sign in to comment.