-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault_rules.ttl
More file actions
420 lines (407 loc) · 13.3 KB
/
Copy pathdefault_rules.ttl
File metadata and controls
420 lines (407 loc) · 13.3 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix csvw: <http://www.w3.org/ns/csvw#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix vcfc: <https://w3id.org/vcf-core/vocab#> .
# Default VCF-RDFizer RML rules, targeting the VCF Core vocabulary.
#
# Namespace
# ---------
# The target is https://w3id.org/vcf-core/vocab# (prefix vcfc:), which replaces
# the retired https://w3id.org/vcf-rdfizer/vocab# (prefix vcfr:). The retired
# namespace is not redirected: it serves a deprecation document in which every
# former term is linked to its successor. No version IRI is pinned; these rules
# target the namespace, whose release cadence is independent of the converter's.
#
# Expected TSV inputs produced by src/vcf_as_tsv.sh:
# - /data/tsv/<sample>.file_metadata.tsv
# - /data/tsv/<sample>.header_lines.tsv
# - /data/tsv/<sample>.records.tsv
# - /data/tsv/<sample>.sample_calls.tsv (header-only compatibility source)
# - /data/tsv/<sample>.sample_format_values.tsv (header-only compatibility source)
# The wrapper rewrites the template paths below for each input sample.
#
# What is here and what is not
# ----------------------------
# The division is a single rule: this mapping carries every field whose RDF
# datatype is the same for every row, and the wrapper's direct N-Triples
# emitters carry everything else. RML cannot choose an object datatype per row,
# and it cannot decompose one source cell into several resources without a
# materialized helper table whose size is the product of its dimensions.
#
# Emitted by the wrapper, not here:
# - ID, ALT, QUAL, FILTER and INFO. Each may be the VCF missing token, which the
# vocabulary requires as "."^^vcfc:Null rather than a plain string, so the
# datatype depends on the row.
# - fileDate. The published shape requires xsd:date, but ##fileDate has no
# mandated format in the VCF specification, so the value must be inspected.
# - The structured header representation: header-line subclasses, the
# vcfc:HeaderAttribute resources that vcfc:StructuredHeaderLineShape requires
# on every ##INFO/##FORMAT/##FILTER/##ALT/##contig/##META/##SAMPLE/##PEDIGREE
# line, and the INFO/FORMAT/FILTER/ALT/contig/META declaration properties.
# These all live inside one angle-bracketed cell.
# - The allele layer: vcfc:ReferenceAllele and vcfc:AltAllele resources with
# their index, kind, symbolic type and breakend components, parsed out of the
# REF and ALT columns.
# - The structured INFO representation, its vcfc:FieldValueItem decomposition,
# and the SV carriers derived from reserved INFO keys.
# - Genotype data. The wrapper selects exactly one direct sample emitter:
# expanded SampleCall / FormatFieldValue / Genotype triples, or condensed
# SampleSet / CohortCallMatrix / FormatValueVector triples. The helper tables
# stay header-only in either mode.
#
# Ordinals
# --------
# vcfc:lineIndex and vcfc:recordIndex are typed xsd:integer, not
# xsd:positiveInteger. The SHACL profiles constrain every ordinal with
# sh:datatype xsd:integer plus a sh:minInclusive bound, and a SHACL datatype
# constraint compares the datatype IRI exactly. An xsd:integer literal
# satisfies both the shape and the ontology's xsd:positiveInteger range, since
# the value 1 belongs to that value space however it is written.
#
# VCF versions
# ------------
# VCF Core supplies one SHACL overlay per VCF version, each scoped by the file's
# vcfc:fileFormat. Most of this mapping is version-neutral, because the fixed
# columns and the header-line structure do not change between 4.1 and 4.5. The
# one version-dependent thing RML can carry is the optional vcfc:VCF4xFile
# subclass on the file subject, which is the sentinel in <#VCFFileMap> below.
#
# The version-dependent *semantics* -- which INFO keys flatten a tuple, whether
# that tuple repeats per ALT allele, and whether the local-allele and
# base-modification FORMAT families exist -- are decompositions of one source
# cell, so they live in the wrapper's emitters like every other decomposition.
#
# Output format:
# - The default conversion targets triples (N-Triples) without named graph terms.
<#VCFFileMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/file_metadata.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}" ;
rr:class vcfc:VCFFile ;
# Version overlay. The wrapper rewrites this sentinel per input to the
# optional subclass for the version the file's ##fileformat line declares
# -- vcfc:VCF41File through vcfc:VCF45File -- which activates that version's
# SHACL gate. When the version has no conformance overlay (VCFv4.0, or a
# missing or malformed line) the sentinel is rewritten to vcfc:VCFFile,
# which is already asserted above, so the graph never claims a version gate
# it cannot support and never gains an undefined term.
rr:class vcfc:VCFVersionFile
] ;
rr:predicateObjectMap [
rr:predicate vcfc:hasHeader ;
rr:objectMap [ rr:template "file://{SOURCE_FILE}#header" ]
] ;
rr:predicateObjectMap [
rr:predicate vcfc:fileFormat ;
rr:objectMap [ rml:reference "FILE_FORMAT" ]
] ;
rr:predicateObjectMap [
rr:predicate vcfc:sourceSoftware ;
rr:objectMap [ rml:reference "SOURCE_SOFTWARE" ]
] ;
rr:predicateObjectMap [
rr:predicate vcfc:referenceGenome ;
rr:objectMap [ rml:reference "REFERENCE_GENOME" ]
] .
<#VCFHeaderMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/file_metadata.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}#header" ;
rr:class vcfc:VCFHeader
] ;
rr:predicateObjectMap [
rr:predicate vcfc:hasColumnHeader ;
rr:objectMap [ rr:template "file://{SOURCE_FILE}#header/columns" ]
] .
# The mandatory #CHROM line. Its ordered sample columns are attached by the
# wrapper with vcfc:hasGenotypeColumns, because they live in the records TSV
# header rather than in a row of any source table.
<#ColumnHeaderLineMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/file_metadata.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}#header/columns" ;
rr:class vcfc:ColumnHeaderLine
] .
# NOTE:
# Use explicit link maps (template-based) instead of parentTriplesMap joins.
# In distributed RMLStreamer execution, joins can duplicate parent map triples.
<#VCFFileToRecordLinkMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/records.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}"
] ;
rr:predicateObjectMap [
rr:predicate vcfc:hasRecord ;
rr:objectMap [
rr:template "file://{SOURCE_FILE}#record/{ROW_ID}"
]
] .
<#VCFHeaderToHeaderLineLinkMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/header_lines.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}#header"
] ;
rr:predicateObjectMap [
rr:predicate vcfc:hasHeaderLine ;
rr:objectMap [
rr:template "file://{SOURCE_FILE}#header/line/{HEADER_INDEX}"
]
] .
# Every '##' line as a base vcfc:HeaderLine. The wrapper adds the subclass, the
# ordered vcfc:HeaderAttribute resources and the declaration properties.
# vcfc:lineIndex is what the SPARQL SHACL profile uses to check that header
# indices are unique and that ##fileformat is line 1.
<#HeaderLineMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/header_lines.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}#header/line/{HEADER_INDEX}" ;
rr:class vcfc:HeaderLine
] ;
rr:predicateObjectMap [
rr:predicate vcfc:headerKey ;
rr:objectMap [ rml:reference "HEADER_KEY" ]
] ;
rr:predicateObjectMap [
rr:predicate vcfc:headerValue ;
rr:objectMap [ rml:reference "HEADER_VALUE" ]
] ;
rr:predicateObjectMap [
rr:predicate vcfc:lineIndex ;
rr:objectMap [ rml:reference "HEADER_INDEX" ; rr:datatype xsd:integer ]
] .
# CHROM, POS and REF are the three fixed fields VCF 4.5 forbids from being the
# missing token, so their datatype is fixed for every row and they belong here.
# ID and ALT may be missing and are emitted by the wrapper.
<#VCFRecordMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/records.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}#record/{ROW_ID}" ;
rr:class vcfc:VCFRecord
] ;
rr:predicateObjectMap [
rr:predicate vcfc:chrom ;
rr:objectMap [ rml:reference "CHROM" ]
] ;
rr:predicateObjectMap [
rr:predicate vcfc:pos ;
rr:objectMap [ rml:reference "POS" ; rr:datatype xsd:integer ]
] ;
rr:predicateObjectMap [
rr:predicate vcfc:ref ;
rr:objectMap [ rml:reference "REF" ]
] ;
rr:predicateObjectMap [
rr:predicate vcfc:recordIndex ;
rr:objectMap [ rml:reference "ROW_ID" ; rr:datatype xsd:integer ]
] ;
rr:predicateObjectMap [
rr:predicate vcfc:hasCall ;
rr:objectMap [ rr:template "file://{SOURCE_FILE}#call/{ROW_ID}" ]
] .
# FORMAT is the only call-level column whose datatype is fixed: VCF 4.5 defines
# it as a colon-separated key list with no missing form. QUAL, FILTER and INFO
# are emitted by the wrapper.
<#VariantCallMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/records.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}#call/{ROW_ID}" ;
rr:class vcfc:VariantCall
] ;
rr:predicateObjectMap [
rr:predicate vcfc:formatRaw ;
rr:objectMap [ rml:reference "FORMAT" ]
] .
<#VariantCallToSampleLinkMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/sample_calls.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}#call/{ROW_ID}"
] ;
rr:predicateObjectMap [
rr:predicate vcfc:hasSampleCall ;
rr:objectMap [
rr:template "file://{SOURCE_FILE}#sample/{ROW_ID}/{SAMPLE_URI_ID}"
]
] .
<#SampleCallMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/sample_calls.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}#sample/{ROW_ID}/{SAMPLE_URI_ID}" ;
rr:class vcfc:SampleCall
] ;
rr:predicateObjectMap [
rr:predicate vcfc:sampleId ;
rr:objectMap [ rml:reference "SAMPLE_ID" ]
] ;
rr:predicateObjectMap [
rr:predicate vcfc:forSample ;
rr:objectMap [
rr:template "file://{SOURCE_FILE}#samples/{SAMPLE_URI_ID}"
]
] .
<#SampleCallToFormatValueLinkMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/sample_format_values.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}#sample/{ROW_ID}/{SAMPLE_URI_ID}"
] ;
rr:predicateObjectMap [
rr:predicate vcfc:hasFormatValue ;
rr:objectMap [
rr:template "file://{SOURCE_FILE}#sample/{ROW_ID}/{SAMPLE_URI_ID}/fmt/{FORMAT_KEY}"
]
] .
<#FormatFieldValueMap>
a rr:TriplesMap ;
rml:logicalSource [
rml:source [
a csvw:Table ;
csvw:url "/data/tsv/sample_format_values.tsv" ;
csvw:dialect [
a csvw:Dialect ;
csvw:delimiter "\t" ;
csvw:headerRowCount 1
]
] ;
rml:referenceFormulation ql:CSV
] ;
rr:subjectMap [
rr:template "file://{SOURCE_FILE}#sample/{ROW_ID}/{SAMPLE_URI_ID}/fmt/{FORMAT_KEY}" ;
rr:class vcfc:FormatFieldValue
] ;
rr:predicateObjectMap [
rr:predicate vcfc:fieldValue ;
rr:objectMap [ rml:reference "FORMAT_VALUE" ]
] .