bel 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +3 -3
- data/bel.gemspec +1 -0
- data/bin/bel +91 -24
- data/bin/bel2rdf.rb +24 -2
- data/lib/bel/examples/remap-file-example.yml +50 -0
- data/lib/bel/quoting.rb +0 -2
- data/lib/bel/translator/plugins/bel_script/bel_citation_serialization.rb +8 -2
- data/lib/bel/translator/plugins/rdf/config/default_prefixes.yml +6 -0
- data/lib/bel/translator/plugins/rdf/monkey_patch.rb +53 -18
- data/lib/bel/translator/plugins/rdf/translator.rb +27 -1
- data/lib/bel/translator/plugins/xbel/xbel_yielder.rb +1 -0
- data/lib/bel/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f60c8d511672752ce1913092b9c8f11bce1afcf7
|
4
|
+
data.tar.gz: 7af3edc1edfb6d481168297a4799af8c7c9e0128
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea8b5f5950c41e93faae0dc4e22868e6234703bfbd8721f278653b4eb47e62815a034b5baa1d74f08908c80cd335aeeb91f3e6394fbdccfcf2ad9ba7f4ca93bc
|
7
|
+
data.tar.gz: f10f81d5c54a55d2c359c30b62af642de45ff3b479db9b81f096def42c881abd76271efe5b00dfbbfec862805fea34111ffb22634a6a337703076eba729008eb
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,14 @@ All notable changes to bel.rb will be documented in this file. The curated log b
|
|
3
3
|
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [0.7.0][0.7.0] - 2016-04-12
|
7
|
+
### Fixed
|
8
|
+
- RDF translation allows for RDF prefixes to be used. Default RDF prefixes are provided ([Issue #69][69]).
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- Annotation and Namespace definitions can now be remapped using a YAML file ([Issue #92][92]).
|
12
|
+
- An example remap file can be obtained from the command `bel remapfile` ([Issue #92][92]).
|
13
|
+
|
6
14
|
## [0.6.0][0.6.0] - 2016-03-15
|
7
15
|
### Fixed
|
8
16
|
- Serialization of BEL Script / XBEL can produce incorrect annotation and namespaces references ([Issue #111][111]).
|
@@ -91,6 +99,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
91
99
|
### Added
|
92
100
|
- Development gem dependencies (i.e. byebug, pry, pry-byebug) for debugging.
|
93
101
|
|
102
|
+
[0.7.0]: https://github.com/OpenBEL/bel.rb/compare/0.6.0...0.7.0
|
94
103
|
[0.6.0]: https://github.com/OpenBEL/bel.rb/compare/0.5.0...0.6.0
|
95
104
|
[0.5.0]: https://github.com/OpenBEL/bel.rb/compare/0.4.2...0.5.0
|
96
105
|
[0.4.2]: https://github.com/OpenBEL/bel.rb/compare/0.4.1...0.4.2
|
@@ -108,12 +117,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
108
117
|
[64]: https://github.com/OpenBEL/bel.rb/issues/64
|
109
118
|
[66]: https://github.com/OpenBEL/bel.rb/issues/66
|
110
119
|
[68]: https://github.com/OpenBEL/bel.rb/issues/68
|
120
|
+
[69]: https://github.com/OpenBEL/bel.rb/issues/69
|
111
121
|
[71]: https://github.com/OpenBEL/bel.rb/issues/71
|
112
122
|
[82]: https://github.com/OpenBEL/bel.rb/issues/82
|
113
123
|
[85]: https://github.com/OpenBEL/bel.rb/issues/85
|
114
124
|
[86]: https://github.com/OpenBEL/bel.rb/pull/86
|
115
125
|
[90]: https://github.com/OpenBEL/bel.rb/issues/90
|
116
126
|
[91]: https://github.com/OpenBEL/bel.rb/issues/91
|
127
|
+
[92]: https://github.com/OpenBEL/bel.rb/issues/92
|
117
128
|
[93]: https://github.com/OpenBEL/bel.rb/issues/93
|
118
129
|
[94]: https://github.com/OpenBEL/bel.rb/issues/94
|
119
130
|
[95]: https://github.com/OpenBEL/bel.rb/issues/95
|
data/README.md
CHANGED
@@ -71,7 +71,6 @@ the root of the bel.rb tree:
|
|
71
71
|
export BR_ISOLATE="yes"
|
72
72
|
```
|
73
73
|
|
74
|
-
|
75
74
|
## branches
|
76
75
|
|
77
76
|
- master branch
|
@@ -108,10 +107,12 @@ the root of the bel.rb tree:
|
|
108
107
|
translate
|
109
108
|
upgrade
|
110
109
|
plugins
|
110
|
+
generate
|
111
|
+
remapfile
|
111
112
|
|
112
113
|
|
113
114
|
bel
|
114
|
-
Copyright (C)
|
115
|
+
Copyright (C) 2016 OpenBEL
|
115
116
|
Apache License, Version 2.0, January 2004
|
116
117
|
http://www.apache.org/licenses/
|
117
118
|
|
@@ -121,7 +122,6 @@ the root of the bel.rb tree:
|
|
121
122
|
-h, --help Show this message
|
122
123
|
```
|
123
124
|
|
124
|
-
|
125
125
|
**bel2rdf.rb**: Converts BEL to RDF.
|
126
126
|
|
127
127
|
```bash
|
data/bel.gemspec
CHANGED
data/bin/bel
CHANGED
@@ -7,7 +7,7 @@ require 'bel/vendor/trollop'
|
|
7
7
|
|
8
8
|
VERSION_BANNER = <<-VERSION
|
9
9
|
bel #{BEL::VERSION}
|
10
|
-
Copyright (C)
|
10
|
+
Copyright (C) #{Time.now.year} OpenBEL
|
11
11
|
Apache License, Version 2.0, January 2004
|
12
12
|
http://www.apache.org/licenses/
|
13
13
|
VERSION
|
@@ -64,27 +64,41 @@ Subcommands:
|
|
64
64
|
synopsis "Converts BEL to RDF."
|
65
65
|
usage "[OPTIONS]... bel2rdf [OPTIONS]"
|
66
66
|
|
67
|
-
opt :bel,
|
68
|
-
:type
|
69
|
-
:long
|
70
|
-
:short
|
71
|
-
:default
|
72
|
-
|
73
|
-
opt :format,
|
74
|
-
:type
|
75
|
-
:long
|
76
|
-
:short
|
77
|
-
:default
|
78
|
-
|
79
|
-
opt :schema,
|
80
|
-
:long
|
81
|
-
:short
|
82
|
-
:default
|
67
|
+
opt :bel, 'The BEL script to parse and output (Defaults to STDIN).',
|
68
|
+
:type => String,
|
69
|
+
:long => :bel,
|
70
|
+
:short => :b,
|
71
|
+
:default => nil
|
72
|
+
|
73
|
+
opt :format, 'The RDF format to output.',
|
74
|
+
:type => String,
|
75
|
+
:long => :format,
|
76
|
+
:short => :f,
|
77
|
+
:default => 'ntriples'
|
78
|
+
|
79
|
+
opt :schema, 'Includes the BEL RDFS schema in RDF output.',
|
80
|
+
:long => :schema,
|
81
|
+
:short => :s,
|
82
|
+
:default => false
|
83
|
+
|
84
|
+
opt :'rdf-prefix-file', "A YAML file mapping prefix containing key/value pairs. The key is an RDF prefix to use in the RDF output; the value is the RDF URI for that prefix. For example, belv: 'http://www.openbel.org/vocabulary/'",
|
85
|
+
:type => String,
|
86
|
+
:long => :'rdf-prefix-file',
|
87
|
+
:short => :p,
|
88
|
+
:default => nil
|
89
|
+
|
90
|
+
opt :'remap-file', 'A YAML file that remaps annotation and namespace definitions. Run "bel remapfile" to get an example of the YAML format.',
|
91
|
+
:type => String,
|
92
|
+
:long => :'remap-file',
|
93
|
+
:short => :r,
|
94
|
+
:default => nil
|
83
95
|
end
|
84
96
|
|
85
|
-
ARGV.concat(['--bel',
|
86
|
-
ARGV.concat(['--format',
|
87
|
-
ARGV.concat(['--schema',
|
97
|
+
ARGV.concat(['--bel', parsed_options[:bel]]) if parsed_options[:bel]
|
98
|
+
ARGV.concat(['--format', parsed_options[:format]]) if parsed_options[:format]
|
99
|
+
ARGV.concat(['--schema', parsed_options[:schema]]) if parsed_options[:schema]
|
100
|
+
ARGV.concat(['--rdf-prefix-file', parsed_options[:'rdf-prefix-file']]) if parsed_options[:'rdf-prefix-file']
|
101
|
+
ARGV.concat(['--remap-file', parsed_options[:'remap-file']]) if parsed_options[:'remap-file']
|
88
102
|
|
89
103
|
require_relative 'bel2rdf'
|
90
104
|
end
|
@@ -234,7 +248,32 @@ Subcommands:
|
|
234
248
|
parsed_options =
|
235
249
|
Trollop::options do
|
236
250
|
synopsis "Translates BEL evidence between formats using translator plugins."
|
237
|
-
usage
|
251
|
+
usage <<-DOC.gsub(/^ {14}/, '')
|
252
|
+
[OPTIONS]... translate [OPTIONS] FROM_TRANSLATOR TO_TRANSLATOR
|
253
|
+
|
254
|
+
From options:
|
255
|
+
None
|
256
|
+
To options:
|
257
|
+
streaming=true|false
|
258
|
+
Set to "true" to enable streaming writes for translators that support it.
|
259
|
+
Set to "false" to disable streaming.
|
260
|
+
serialization=discrete|topdown|citation [BEL Script translator]
|
261
|
+
Set to "discrete" to render each statement with its annotations.
|
262
|
+
Set to "topdown" to set/unset annotations as needed.
|
263
|
+
Set to "citation" to use statement groups for each citation.
|
264
|
+
write_schema=true|false
|
265
|
+
Set to "true" to write RDFS schema for RDF-based translators.
|
266
|
+
Set to "false" to omit RDFS schema for RDF-based translators.
|
267
|
+
void_dataset_uri=URI
|
268
|
+
The VoID dataset URI to use for the dataset of an RDF-based translation.
|
269
|
+
rdf_prefix_file=FILE
|
270
|
+
A YAML file mapping prefix containing key/value pairs. The key is an
|
271
|
+
RDF prefix to use in the RDF output; the value is the RDF URI for that
|
272
|
+
prefix. For example, belv: 'http://www.openbel.org/vocabulary/'.
|
273
|
+
remap_file=FILE
|
274
|
+
A YAML file that remaps annotation and namespace definitions.
|
275
|
+
Run "bel remapfile" to get an example of the YAML format.
|
276
|
+
DOC
|
238
277
|
|
239
278
|
opt :'input-file', 'The file containing evidence data to translate. If not specified the default is to read from STDIN.',
|
240
279
|
:type => String,
|
@@ -297,8 +336,10 @@ Subcommands:
|
|
297
336
|
Trollop::educate
|
298
337
|
end
|
299
338
|
|
300
|
-
|
301
|
-
|
339
|
+
# XXX Merge conflicts.
|
340
|
+
options = {}.
|
341
|
+
merge(map_kv_options(parsed_options, :'from-option')).
|
342
|
+
merge(map_kv_options(parsed_options, :'to-option'))
|
302
343
|
|
303
344
|
begin
|
304
345
|
BEL.translate(
|
@@ -306,7 +347,7 @@ Subcommands:
|
|
306
347
|
from_format,
|
307
348
|
to_format,
|
308
349
|
$stdout,
|
309
|
-
|
350
|
+
options
|
310
351
|
)
|
311
352
|
ensure
|
312
353
|
$stdout.close
|
@@ -490,6 +531,32 @@ Subcommands:
|
|
490
531
|
translator.write(random_data, $stdout)
|
491
532
|
end
|
492
533
|
end
|
534
|
+
|
535
|
+
class RemapfileCommand
|
536
|
+
|
537
|
+
def initialize(global_options)
|
538
|
+
@global_options = global_options
|
539
|
+
end
|
540
|
+
|
541
|
+
def run
|
542
|
+
options = Trollop::options do
|
543
|
+
synopsis "Writes an example resource remap YAML file."
|
544
|
+
usage "[OPTIONS]... remapfile [OPTIONS]"
|
545
|
+
end
|
546
|
+
|
547
|
+
example_file_path =
|
548
|
+
File.join(
|
549
|
+
File.expand_path(File.dirname(__FILE__)),
|
550
|
+
'..',
|
551
|
+
'lib',
|
552
|
+
'bel',
|
553
|
+
'examples',
|
554
|
+
'remap-file-example.yml')
|
555
|
+
File.open(example_file_path) do |f|
|
556
|
+
$stdout.write(f.read)
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|
493
560
|
end
|
494
561
|
end
|
495
562
|
|
data/bin/bel2rdf.rb
CHANGED
@@ -46,15 +46,35 @@ OptionParser.new do |opts|
|
|
46
46
|
options[:format] = format.downcase
|
47
47
|
end
|
48
48
|
|
49
|
+
|
50
|
+
opts.on('-p', '--rdf-prefix-file FILE', "A YAML file mapping prefix containing key/value pairs. The key is an RDF prefix to use in the RDF output; the value is the RDF URI for that prefix. For example, belv: 'http://www.openbel.org/vocabulary/'.") do |prefix_file|
|
51
|
+
options[:rdf_prefix_file] = prefix_file
|
52
|
+
end
|
53
|
+
|
49
54
|
opts.on('-s', '--[no-]schema', 'Write BEL RDF schema? The default is to include the schema in the output.') do |schema|
|
50
55
|
options[:schema] = schema
|
51
56
|
end
|
57
|
+
|
58
|
+
opts.on('-r', '--remap-file FILE', 'A YAML file that remaps annotation and namespace definitions. Run "bel remapfile" to get an example of the YAML format.') do |remap_file|
|
59
|
+
options[:remap_file] = remap_file
|
60
|
+
end
|
52
61
|
end.parse!
|
53
62
|
|
54
63
|
if options[:bel] and not File.exists? options[:bel]
|
55
64
|
$stderr.puts "No file for bel, #{options[:bel]}"
|
56
65
|
exit 1
|
57
66
|
end
|
67
|
+
|
68
|
+
if options[:rdf_prefix_file] and not File.exists? options[:rdf_prefix_file]
|
69
|
+
$stderr.puts "No file for rdf_prefix_file, #{options[:rdf_prefix_file]}"
|
70
|
+
exit 1
|
71
|
+
end
|
72
|
+
|
73
|
+
if options[:remap_file] and not File.exist? options[:remap_file]
|
74
|
+
$stderr.puts "No file for remap_file, #{options[:remap_file]}"
|
75
|
+
exit 1
|
76
|
+
end
|
77
|
+
|
58
78
|
unless RDF_TRANSLATORS.include? options[:format]
|
59
79
|
$stderr.puts "Format must be one of: #{RDF_TRANSLATORS.join(', ')}"
|
60
80
|
exit 1
|
@@ -77,7 +97,7 @@ end
|
|
77
97
|
# read bel content
|
78
98
|
input_io =
|
79
99
|
if options[:bel]
|
80
|
-
File.open(options[:bel], :
|
100
|
+
File.open(options[:bel], external_encoding: 'UTF-8')
|
81
101
|
else
|
82
102
|
$stdin
|
83
103
|
end
|
@@ -87,7 +107,9 @@ validate_translator!(options[:format])
|
|
87
107
|
begin
|
88
108
|
BEL.translate(input_io, :bel, options[:format], $stdout,
|
89
109
|
{
|
90
|
-
:
|
110
|
+
write_schema: options[:schema],
|
111
|
+
rdf_prefix_file: options[:rdf_prefix_file],
|
112
|
+
remap_file: options[:remap_file]
|
91
113
|
}
|
92
114
|
)
|
93
115
|
ensure
|
@@ -0,0 +1,50 @@
|
|
1
|
+
namespaces:
|
2
|
+
- remap:
|
3
|
+
from:
|
4
|
+
prefix: "CHEBI"
|
5
|
+
url: "http://resource.belframework.org/belframework/20131211/namespace/chebi.belns"
|
6
|
+
to:
|
7
|
+
prefix: "HGNC"
|
8
|
+
url: "http://resource.belframework.org/belframework/20150611/namespace/hgnc-human-genes.belns"
|
9
|
+
rdf_uri: "http://identifiers.org/hgnc/"
|
10
|
+
- remap:
|
11
|
+
from:
|
12
|
+
prefix: "EGID"
|
13
|
+
url: "http://resource.belframework.org/belframework/20150611/namespace/entrez-gene-ids.belns"
|
14
|
+
to:
|
15
|
+
prefix: "EGID"
|
16
|
+
url: "http://resource.belframework.org/belframework/20150611/namespace/entrez-gene-ids.belns"
|
17
|
+
rdf_uri: "http://identifiers.org/ncbigene/"
|
18
|
+
- remap:
|
19
|
+
from:
|
20
|
+
prefix: "MESHD"
|
21
|
+
url: "http://resource.belframework.org/belframework/20131211/namespace/mesh-diseases.belns"
|
22
|
+
to:
|
23
|
+
prefix: "MESHD"
|
24
|
+
url: "http://resource.belframework.org/belframework/20131211/namespace/mesh-diseases.belns"
|
25
|
+
rdf_uri: "http://identifiers.org/meshd/"
|
26
|
+
annotations:
|
27
|
+
- remap:
|
28
|
+
from:
|
29
|
+
keyword: "Anatomy"
|
30
|
+
type: "url"
|
31
|
+
domain: "http://resource.belframework.org/belframework/20131211/annotation/anatomy.belanno"
|
32
|
+
to:
|
33
|
+
keyword: "Anatomy"
|
34
|
+
type: "url"
|
35
|
+
domain: "http://resource.belframework.org/belframework/20131211/annotation/anatomy.belanno"
|
36
|
+
rdf_uri: "http://identifiers.org/anatomy/"
|
37
|
+
- remap:
|
38
|
+
from:
|
39
|
+
keyword: "TextLocation"
|
40
|
+
type: "list"
|
41
|
+
domain:
|
42
|
+
- Abstract
|
43
|
+
- Results
|
44
|
+
- Legend
|
45
|
+
- Review
|
46
|
+
to:
|
47
|
+
keyword: "TextLocation"
|
48
|
+
type: "pattern"
|
49
|
+
domain: "Value[0-9]+"
|
50
|
+
rdf_uri: "http://identifiers.org/text-location/"
|
data/lib/bel/quoting.rb
CHANGED
@@ -42,14 +42,20 @@ module BEL::Translator::Plugins::BelScript::BelCitationSerialization
|
|
42
42
|
current_annotations[:Citation] = citation if citation
|
43
43
|
current_annotations[:Evidence] = summary_text if summary_text
|
44
44
|
|
45
|
+
if !evidence.citation.id || evidence.citation.id.empty?
|
46
|
+
citation_id = quote('')
|
47
|
+
else
|
48
|
+
citation_id = quote_if_needed(evidence.citation.id)
|
49
|
+
end
|
50
|
+
|
45
51
|
# Reset cumulative annotations if new citation.
|
46
52
|
if cumulative_citation == nil
|
47
|
-
bel << %Q{SET STATEMENT_GROUP = #{
|
53
|
+
bel << %Q{SET STATEMENT_GROUP = #{citation_id}\n}
|
48
54
|
cumulative_annotations.clear
|
49
55
|
elsif evidence.citation != cumulative_citation
|
50
56
|
bel << %Q{UNSET STATEMENT_GROUP\n}
|
51
57
|
bel << "\n\n"
|
52
|
-
bel << %Q{SET STATEMENT_GROUP = #{
|
58
|
+
bel << %Q{SET STATEMENT_GROUP = #{citation_id}\n}
|
53
59
|
cumulative_annotations.clear
|
54
60
|
end
|
55
61
|
|
@@ -12,7 +12,9 @@ module BELRDF
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_rdf_vocabulary
|
15
|
-
|
15
|
+
uri = @rdf_uri
|
16
|
+
uri << '/' unless uri.end_with?('/')
|
17
|
+
::RDF::Vocabulary.new(uri)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -33,11 +35,27 @@ module BELRDF
|
|
33
35
|
@ns.to_rdf_vocabulary[URI::encode(@value)]
|
34
36
|
end
|
35
37
|
|
36
|
-
def to_rdf(graph_name = nil)
|
38
|
+
def to_rdf(graph_name = nil, remap = nil)
|
37
39
|
# resolve encoding to make rdf:type assertions
|
38
40
|
if !@enc && @ns.is_a?(BEL::Namespace::NamespaceDefinition)
|
39
41
|
@enc = @ns[@value].enc
|
40
42
|
end
|
43
|
+
|
44
|
+
# update namespace resource
|
45
|
+
if remap && remap['namespaces']
|
46
|
+
ro_ind = remap['namespaces'].index { |mapping|
|
47
|
+
mapping['remap'] && mapping['remap'].is_a?(Hash) &&
|
48
|
+
mapping['remap']['from'] && mapping['remap']['from'].is_a?(Hash) &&
|
49
|
+
mapping['remap']['from']['prefix'] == @ns.prefix.to_s &&
|
50
|
+
mapping['remap']['from']['url'] == @ns.url
|
51
|
+
}
|
52
|
+
if ro_ind
|
53
|
+
@ns.prefix = remap['namespaces'][ro_ind]['remap']['to']['prefix']
|
54
|
+
@ns.url = remap['namespaces'][ro_ind]['remap']['to']['url']
|
55
|
+
@ns.rdf_uri = remap['namespaces'][ro_ind]['remap']['to']['rdf_uri']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
41
59
|
uri = to_uri
|
42
60
|
encodings = ['A'].concat(@enc.to_s.each_char.to_a).uniq
|
43
61
|
encodings.map! { |enc| concept_statement(enc, uri, graph_name)}
|
@@ -94,7 +112,7 @@ module BELRDF
|
|
94
112
|
end
|
95
113
|
end
|
96
114
|
|
97
|
-
def to_rdf(graph_name = nil)
|
115
|
+
def to_rdf(graph_name = nil, remap = nil)
|
98
116
|
uri = to_uri
|
99
117
|
statements = []
|
100
118
|
|
@@ -133,14 +151,14 @@ module BELRDF
|
|
133
151
|
end
|
134
152
|
# link root protein abundance as hasChild
|
135
153
|
root_param = @arguments.find{|x| x.is_a? ::BEL::Model::Parameter}
|
136
|
-
(root_id, root_statements) = ::BEL::Model::Term.new(:p, [root_param]).to_rdf(graph_name)
|
154
|
+
(root_id, root_statements) = ::BEL::Model::Term.new(:p, [root_param]).to_rdf(graph_name, remap)
|
137
155
|
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, root_id, :graph_name => graph_name)
|
138
156
|
statements.concat(root_statements)
|
139
157
|
return [uri, statements]
|
140
158
|
elsif @arguments.find{|x| x.is_a? ::BEL::Model::Term and BELRDF::PROTEIN_VARIANT.include? x.fx}
|
141
159
|
# link root protein abundance as hasChild
|
142
160
|
root_param = @arguments.find{|x| x.is_a? ::BEL::Model::Parameter}
|
143
|
-
(root_id, root_statements) = ::BEL::Model::Term.new(:p, [root_param]).to_rdf(graph_name)
|
161
|
+
(root_id, root_statements) = ::BEL::Model::Term.new(:p, [root_param]).to_rdf(graph_name, remap)
|
144
162
|
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, root_id, :graph_name => graph_name)
|
145
163
|
statements.concat(root_statements)
|
146
164
|
return [uri, statements]
|
@@ -151,14 +169,14 @@ module BELRDF
|
|
151
169
|
@arguments.find_all{ |x|
|
152
170
|
x.is_a? ::BEL::Model::Parameter and x.ns != nil
|
153
171
|
}.each do |param|
|
154
|
-
param_uri, encoding_statements = param.to_rdf(graph_name)
|
172
|
+
param_uri, encoding_statements = param.to_rdf(graph_name, remap)
|
155
173
|
statements.concat(encoding_statements)
|
156
174
|
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasConcept, param_uri, :graph_name => graph_name)
|
157
175
|
end
|
158
176
|
|
159
177
|
# BELRDF::BELV.hasChild]
|
160
178
|
@arguments.find_all{|x| x.is_a? ::BEL::Model::Term}.each do |child|
|
161
|
-
(child_id, child_statements) = child.to_rdf(graph_name)
|
179
|
+
(child_id, child_statements) = child.to_rdf(graph_name, remap)
|
162
180
|
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, child_id, :graph_name => graph_name)
|
163
181
|
statements.concat(child_statements)
|
164
182
|
end
|
@@ -205,20 +223,20 @@ module BELRDF
|
|
205
223
|
end
|
206
224
|
end
|
207
225
|
|
208
|
-
def to_rdf(graph_name = nil)
|
226
|
+
def to_rdf(graph_name = nil, remap = nil)
|
209
227
|
uri = to_uri
|
210
228
|
statements = []
|
211
229
|
|
212
230
|
case
|
213
231
|
when subject_only?
|
214
|
-
(sub_uri, sub_statements) = @subject.to_rdf(graph_name)
|
232
|
+
(sub_uri, sub_statements) = @subject.to_rdf(graph_name, remap)
|
215
233
|
statements << ::RDF::Statement(uri, BELRDF::BELV.hasSubject, sub_uri, :graph_name => graph_name)
|
216
234
|
statements.concat(sub_statements)
|
217
235
|
when simple?
|
218
|
-
(sub_uri, sub_statements) = @subject.to_rdf(graph_name)
|
236
|
+
(sub_uri, sub_statements) = @subject.to_rdf(graph_name, remap)
|
219
237
|
statements.concat(sub_statements)
|
220
238
|
|
221
|
-
(obj_uri, obj_statements) = @object.to_rdf(graph_name)
|
239
|
+
(obj_uri, obj_statements) = @object.to_rdf(graph_name, remap)
|
222
240
|
statements.concat(obj_statements)
|
223
241
|
|
224
242
|
rel = BELRDF::RELATIONSHIP_TYPE[@relationship.to_s]
|
@@ -226,9 +244,9 @@ module BELRDF
|
|
226
244
|
statements << ::RDF::Statement(uri, BELRDF::BELV.hasObject, obj_uri, :graph_name => graph_name)
|
227
245
|
statements << ::RDF::Statement(uri, BELRDF::BELV.hasRelationship, rel, :graph_name => graph_name)
|
228
246
|
when nested?
|
229
|
-
(sub_uri, sub_statements) = @subject.to_rdf(graph_name)
|
230
|
-
(nsub_uri, nsub_statements) = @object.subject.to_rdf(graph_name)
|
231
|
-
(nobj_uri, nobj_statements) = @object.object.to_rdf(graph_name)
|
247
|
+
(sub_uri, sub_statements) = @subject.to_rdf(graph_name, remap)
|
248
|
+
(nsub_uri, nsub_statements) = @object.subject.to_rdf(graph_name, remap)
|
249
|
+
(nobj_uri, nobj_statements) = @object.object.to_rdf(graph_name, remap)
|
232
250
|
statements.concat(sub_statements)
|
233
251
|
statements.concat(nsub_statements)
|
234
252
|
statements.concat(nobj_statements)
|
@@ -278,8 +296,25 @@ module BELRDF
|
|
278
296
|
@annotations.each do |_, anno|
|
279
297
|
name = anno.name.gsub('"', '')
|
280
298
|
|
281
|
-
|
282
|
-
|
299
|
+
# update annotations resource
|
300
|
+
anno_rdf_uri = nil
|
301
|
+
if remap && remap['annotations']
|
302
|
+
ro_ind = remap['annotations'].index { |mapping|
|
303
|
+
mapping['remap'] && mapping['remap'].is_a?(Hash) &&
|
304
|
+
mapping['remap']['from'] && mapping['remap']['from'].is_a?(Hash) &&
|
305
|
+
mapping['remap']['from']['keyword'] == name && (mapping['remap']['from']['type'] == 'url' ||
|
306
|
+
mapping['remap']['from']['type'] == 'list' &&
|
307
|
+
mapping['remap']['from']['domain'] && mapping['remap']['from']['domain'].is_a?(Array) &&
|
308
|
+
mapping['remap']['from']['domain'].include?(anno.value))
|
309
|
+
}
|
310
|
+
if ro_ind
|
311
|
+
anno_rdf_uri = remap['annotations'][ro_ind]['remap']['to']['rdf_uri']
|
312
|
+
anno_rdf_uri << '/' unless anno_rdf_uri.end_with?('/')
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
if anno_rdf_uri or BELRDF::const_defined? name
|
317
|
+
annotation_scheme = anno_rdf_uri ? anno_rdf_uri : BELRDF::const_get(name)
|
283
318
|
[anno.value].flatten.map{|x| x.gsub('"', '')}.each do |val|
|
284
319
|
value_uri = BELRDF::RDF::URI(URI.encode(annotation_scheme + val.to_s))
|
285
320
|
statements << ::RDF::Statement.new(evidence, BELRDF::BELV.hasAnnotation, value_uri, :graph_name => graph_name)
|
@@ -307,7 +342,7 @@ module BELRDF
|
|
307
342
|
BELRDF::BELE[BELRDF.generate_uuid]
|
308
343
|
end
|
309
344
|
|
310
|
-
def to_rdf
|
345
|
+
def to_rdf(remap = nil)
|
311
346
|
uri = to_uri
|
312
347
|
|
313
348
|
# parse BEL statement if necessary
|
@@ -316,7 +351,7 @@ module BELRDF
|
|
316
351
|
end
|
317
352
|
|
318
353
|
# convert BEL statement to RDF
|
319
|
-
statement_uri, statements = bel_statement.to_rdf(uri)
|
354
|
+
statement_uri, statements = bel_statement.to_rdf(uri, remap)
|
320
355
|
|
321
356
|
statements << ::RDF::Statement.new(uri, BELRDF::RDF.type, BELRDF::BELV.Evidence, :graph_name => uri)
|
322
357
|
statements << ::RDF::Statement.new(statement_uri, BELRDF::BELV.hasEvidence, uri, :graph_name => uri)
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'rdf'
|
2
|
+
require 'pathname'
|
3
|
+
require 'yaml'
|
2
4
|
|
3
5
|
require_relative 'uuid'
|
4
6
|
require_relative 'bel_schema'
|
@@ -55,6 +57,11 @@ module BELRDF
|
|
55
57
|
|
56
58
|
wrote_dataset = false
|
57
59
|
|
60
|
+
# read remap file
|
61
|
+
if options[:remap_file]
|
62
|
+
remap = YAML::load_file(options[:remap_file])
|
63
|
+
end
|
64
|
+
|
58
65
|
rdf_statement_enum = Enumerator.new do |yielder|
|
59
66
|
# enumerate BEL schema
|
60
67
|
@rdf_schema.each do |schema_statement|
|
@@ -73,7 +80,7 @@ module BELRDF
|
|
73
80
|
wrote_dataset = true
|
74
81
|
end
|
75
82
|
|
76
|
-
evidence_uri, statements = evidence.to_rdf
|
83
|
+
evidence_uri, statements = evidence.to_rdf(remap)
|
77
84
|
statements.each do |statement|
|
78
85
|
yielder << statement
|
79
86
|
end
|
@@ -94,6 +101,12 @@ module BELRDF
|
|
94
101
|
:stream => true
|
95
102
|
)
|
96
103
|
|
104
|
+
# load RDF prefixes
|
105
|
+
prefixes = load_prefixes(options)
|
106
|
+
prefixes.each do |prefix, uri|
|
107
|
+
rdf_writer.prefix prefix.to_sym, RDF::URI(uri)
|
108
|
+
end
|
109
|
+
|
97
110
|
rdf_writer.write_prologue
|
98
111
|
rdf_statement_enum.each do |statement|
|
99
112
|
rdf_writer << statement
|
@@ -103,5 +116,18 @@ module BELRDF
|
|
103
116
|
|
104
117
|
io
|
105
118
|
end
|
119
|
+
|
120
|
+
def load_prefixes(options)
|
121
|
+
prefix_file = options[:rdf_prefix_file] || default_prefix_file
|
122
|
+
YAML::load_file(prefix_file)
|
123
|
+
end
|
124
|
+
|
125
|
+
def default_prefix_file
|
126
|
+
File.join(
|
127
|
+
File.expand_path(File.dirname(__FILE__)),
|
128
|
+
'config',
|
129
|
+
'default_prefixes.yml'
|
130
|
+
)
|
131
|
+
end
|
106
132
|
end
|
107
133
|
end
|
@@ -11,6 +11,7 @@ module BEL::Translator::Plugins
|
|
11
11
|
|
12
12
|
def initialize(data, options = {})
|
13
13
|
@data = data
|
14
|
+
@streaming = options.fetch(:streaming, false)
|
14
15
|
@annotation_reference_map = options.fetch(:annotation_reference_map, nil)
|
15
16
|
@namespace_reference_map = options.fetch(:namespace_reference_map, nil)
|
16
17
|
end
|
data/lib/bel/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Bargnesi
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: ffi
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/bel/evidence_model/streaming_evidence_combiner.rb
|
95
95
|
- lib/bel/evidence_model/summary_text.rb
|
96
96
|
- lib/bel/evidence_model/util.rb
|
97
|
+
- lib/bel/examples/remap-file-example.yml
|
97
98
|
- lib/bel/gen.rb
|
98
99
|
- lib/bel/gen/annotation.rb
|
99
100
|
- lib/bel/gen/citation.rb
|
@@ -172,6 +173,7 @@ files:
|
|
172
173
|
- lib/bel/translator/plugins/nquads.rb
|
173
174
|
- lib/bel/translator/plugins/ntriples.rb
|
174
175
|
- lib/bel/translator/plugins/rdf/bel_schema.rb
|
176
|
+
- lib/bel/translator/plugins/rdf/config/default_prefixes.yml
|
175
177
|
- lib/bel/translator/plugins/rdf/graph_translator.rb
|
176
178
|
- lib/bel/translator/plugins/rdf/monkey_patch.rb
|
177
179
|
- lib/bel/translator/plugins/rdf/reader.rb
|