-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
302 lines (214 loc) · 7.57 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
OBO = http://purl.obolibrary.org/obo
RUN = poetry run
VERSION = $(shell git tag | tail -1)
SRC_DIR = src/semsql/linkml
BUILDER_DIR = src/semsql/builder
DDL_DIR = $(BUILDER_DIR)/sql_schema
YAML_DIR = src/semsql/linkml
SQLA_DIR = src/semsql/sqla
ONT_REGISTRY = src/semsql/builder/registry/ontologies.yaml
PREFIX_DIR = $(BUILDER_DIR)/prefixes
ALL_OBO_ONTS := $(shell cat reports/obo.tsv)
SELECTED_ONTS = obi mondo go envo ro hp mp zfa wbphenotype ecto upheno uberon_cm doid chebi pr wbphenotype fbbt dron
# EXTRA_ONTOLOGIES is defined in ontologies.Makefile
ALL_ONTS = $(ALL_OBO_ONTS) $(EXTRA_ONTOLOGIES)
STAGED_ONTOLOGIES = $(patsubst %, stage/%.db.gz, $(ALL_ONTS))
TEST_ONTOLOGIES = go-nucleus robot-example
# environment variables
include config.env
GEN_PARGS =
ifdef LINKML_GENERATORS_PROJECT_ARGS
GEN_PARGS = ${LINKML_GENERATORS_PROJECT_ARGS}
endif
GEN_DARGS =
ifdef LINKML_GENERATORS_MARKDOWN_ARGS
GEN_DARGS = ${LINKML_GENERATORS_MARKDOWN_ARGS}
endif
include ontologies.Makefile
all: build_all stage_all
build_all: $(patsubst %, all-%, $(ALL_ONTS))
echo building $(ALL_ONTS)
stats_all: $(patsubst %, statistics/%.statistics.yaml, $(ALL_ONTS))
echo building $(ALL_ONTS)
validate_all: $(patsubst %, validation/%.validate.tsv, $(ALL_ONTS))
echo building $(ALL_ONTS)
stage_all: $(STAGED_ONTOLOGIES)
echo done $(STAGED_ONTOLOGIES)
selected: $(patsubst %,all-%,$(SELECTED_ONTS))
all-%: db/%.db
sqlite3 $< "SELECT COUNT(*) FROM statements"
stage/%.db.gz: STAMP
gzip -c db/$*.db > [email protected] && mv [email protected] $@
#stage/%.db.gz:
# gzip -c db/$*.db > [email protected] && mv [email protected] $@
.PRECIOUS: stage/%.db.gz
list-onts:
echo $(ALL_ONTS)
list-extra:
echo $(EXTRA_ONTOLOGIES)
list-staged:
ls -alt $(STAGED_ONTOLOGIES)
# INSTALL
include install.Makefile
#include ontologies.Makefile
# ---
# tests
# ---
#test: test_build unittest
test: unittest
unittest:
$(RUN) python -s -m unittest tests/test_*/test_*.py
cp-%: tests/inputs/%.owl
cp $< owl/
test_build: setup_tests $(patsubst %, test-build-%,$(TEST_ONTOLOGIES))
test-build-%: inferences/%-inf.tsv
./utils/create-semsql-db.sh -v -f -r -d db/$*.db owl/$*.owl && cp db/$*.db tests/inputs/
# copy from tests/input to staging area
setup_tests: $(patsubst %, cp-%,$(TEST_ONTOLOGIES))
realclean-%:
rm target/$*.* ;
rm db/$*.db
# ---
# Prefixes
# ---
build_prefixes: $(PREFIX_DIR)/prefixes.csv $(PREFIX_DIR)/prefixes.yaml
$(PREFIX_DIR)/obo_prefixes.owl: $(STAMP)
robot convert -I http://purl.obolibrary.org/meta/obo_prefixes.ttl -o $@
$(PREFIX_DIR)/obo_prefixes.db: $(PREFIX_DIR)/obo_prefixes.owl
sqlite3 $@ < $(PREFIX_DIR)/prefix_ddl.sql && rdftab $@ < $<
$(PREFIX_DIR)/obo_prefixes.csv: $(PREFIX_DIR)/obo_prefixes.db
sqlite3 $< -cmd ".separator ','" "SELECT p.value AS prefix, ns.value AS base FROM statements AS p JOIN statements AS ns ON (p.subject=ns.subject) WHERE p.predicate='<http://www.w3.org/ns/shacl#prefix>' AND ns.predicate='<http://www.w3.org/ns/shacl#namespace>'" > $@
$(PREFIX_DIR)/prefixes.csv: $(PREFIX_DIR)/prefixes_curated.csv $(PREFIX_DIR)/prefixes_local.csv $(PREFIX_DIR)/obo_prefixes.csv
cat $^ > $@
# see https://github.com/INCATools/relation-graph/issues/168
$(PREFIX_YAML_PATH): $(PREFIX_CSV_PATH)
grep -v ^prefix, $< | grep -v ^obo, | perl -npe 's@,(.*)@: "$$1"@' > [email protected] && mv [email protected] $@
# ---
# sqlite db creation and loading
# ---
db/%.db: db/%.owl
$(RUN) semsql make $@
.PRECIOUS: db/%.db
statistics/%.statistics.yaml: db/%.db
runoak -i $< statistics --group-by-prefix -o $@
validation/%.validate.tsv: db/%.db
runoak -i $< validate -o $@
# ---
# OBO Registry
# ---
# fetch list of ontologies from OBO registry
# first fetch ontology list in rdf/owl;
db/obo-ontologies.owl:
robot convert -I http://purl.obolibrary.org/meta/ontologies.ttl -o $@
# depends on .db build of rdf/owl - then export to TSV
# NOTE: currently there is a checked in copy of obo.tsv; use this, as we have pre-filtered ontologies that do not load
reports/obo.tsv: db/obo-ontologies.db
sqlite3 $< "SELECT subject FROM ontology_status_statement WHERE value = 'active'" | perl -npe 's@^obo:@@' > $@
# ---
# Reports
# ---
reports/%.problems.tsv: db/%.db target/%.views
sqlite3 $< "SELECT * FROM problems" > $@
# ---
# Downloads
# ---
STAMP:
touch $@
## Additional ontologies
src/semsql/builder/registry/registry_schema.py: src/semsql/builder/registry/registry_schema.yaml
$(RUN) gen-python $< > $@
ontologies.Makefile: $(ONT_REGISTRY)
$(RUN) semsql generate-makefile -P src/semsql/builder/prefixes/prefixes_local.csv $< > [email protected] && mv [email protected] $@
include ontologies.Makefile
#fma.owl:#
# http://purl.org/sig/ont/fma.owl
# ---
# Schema
# ---
# the section below here is only required for when changes to the schema is made;
# changing the yaml triggers changes in
# - derived SQL DDL
# - SQL Alchemy objects
# - Docs
MODULES = rdf owl obo omo relation_graph semsql
GENDOC_ARGS = -d docs --template-directory docgen-templates
# TODO: markdown gen should make modular output
markdown-%: $(YAML_DIR)/%.yaml
$(RUN) gen-doc $(GENDOC_ARGS) $< && mv docs/index.md docs/$*_index.md
markdown: $(patsubst %, markdown-%, $(MODULES))
$(RUN) gen-doc $(GENDOC_ARGS) $(YAML_DIR)/semsql.yaml
gendoc: markdown
gen-project: $(YAML_DIR)/semsql.yaml
$(RUN) gen-project ${GEN_PARGS} $< -d project
# Create SQL Create Table statements from linkml
# 1. first use generic ddl generation
# 2. Add views
GENDDL = $(RUN) gen-sqlddl --dialect sqlite --no-use-foreign-keys
gen-ddl: $(patsubst %, $(DDL_DIR)/%.sql, $(MODULES))
$(DDL_DIR)/%.sql: $(YAML_DIR)/%.yaml
$(GENDDL) $< > [email protected] && \
$(RUN) gen-semsql-views $< >> [email protected] && \
mv [email protected] $@
reports/query-%.sql: $(YAML_DIR)/%.yaml
$(RUN) python src/semsql/sqlutils/reportgen.py $< > $@
# Generate SQL Alchemy
gen-sqla: $(patsubst %, $(SQLA_DIR)/%.py, $(MODULES))
# make SQL Alchemy models
# requires linkml 1.2.5
$(SQLA_DIR)/%.py: $(YAML_DIR)/%.yaml
$(RUN) gen-sqla --no-use-foreign-keys $< > $@
# -- makes bin/semsql --
# this is useful for core developers of semsql -
# this will create a one line bash script that
# can be added to your $PATH that will execute the
# version of semsql used in github
bin/%:
echo `poetry run which $*` '$$*' > $@ && chmod +x $@
### DEPLOY
DATE = $(shell date -u +"%Y-%m-%d")
s3-deploy:
aws s3 sync stage s3://bbop-sqlite --acl public-read
s3-version:
aws s3 sync stage s3://bbop-sqlite/releases/$(DATE) --acl public-read
s3-deploy-%: stage/%.db.gz
aws s3 cp $< s3://bbop-sqlite/$*.db.gz --acl public-read
# Test documentation locally
serve: mkd-serve
# Python datamodel
$(PYMODEL):
mkdir -p $@
$(DOCDIR):
mkdir -p $@
testdoc: gendoc serve
MKDOCS = $(RUN) mkdocs
mkd-%:
$(MKDOCS) $*
################################################
#### Commands for building the Docker image ####
################################################
IM=linkml/semantic-sql
docker-build-no-cache:
@docker build --no-cache -t $(IM):$(VERSION) . \
&& docker tag $(IM):$(VERSION) $(IM):latest
docker-build:
@docker build -t $(IM):$(VERSION) . \
&& docker tag $(IM):$(VERSION) $(IM):latest
docker-build-use-cache-dev:
@docker build -t $(DEV):$(VERSION) . \
&& docker tag $(DEV):$(VERSION) $(DEV):latest
docker-clean:
docker kill $(IM) || echo not running ;
docker rm $(IM) || echo not made
docker-publish-no-build:
@docker push $(IM):$(VERSION) \
&& docker push $(IM):latest
docker-publish-dev-no-build:
@docker push $(DEV):$(VERSION) \
&& docker push $(DEV):latest
docker-publish: docker-build
@docker push $(IM):$(VERSION) \
&& docker push $(IM):latest
docker-run:
@docker run -v $(PWD):/work -w /work -ti $(IM):$(VERSION)
test-docker-run:
cd docker-test && docker run -v `pwd`/db:/semsql/db -w /semsql -ti $(IM):$(VERSION) make -k all RUN=