Class: BEL::Translator::Plugins::Jgf::JgfTranslator
- Inherits:
-
Object
- Object
- BEL::Translator::Plugins::Jgf::JgfTranslator
show all
- Includes:
- Namespace, BEL::Translator
- Defined in:
- lib/bel/translator/plugins/jgf/translator.rb
Constant Summary
Constants included
from Namespace
Namespace::DEFAULT_NAMESPACES, Namespace::DEFAULT_URI, Namespace::LATEST_PREFIX, Namespace::NAMESPACE_BELNS, Namespace::NAMESPACE_LATEST
Instance Method Summary
collapse
Instance Method Details
#read(data, options = {}) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/bel/translator/plugins/jgf/translator.rb', line 13
def read(data, options = {})
default_resource_index = options.fetch(:default_resource_index) {
ResourceIndex.openbel_published_index('20131211')
}
::BEL::JSON.read(data, options).lazy.select { |obj|
obj.include?(:nodes) && obj.include?(:edges)
}.flat_map { |graph|
unwrap(graph, default_resource_index)
}
end
|
#write(objects, writer = StringIO.new, options = {}) ⇒ Object
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
|
# File 'lib/bel/translator/plugins/jgf/translator.rb', line 25
def write(objects, writer = StringIO.new, options = {})
graph = {
:type => 'BEL-V1.0',
:nodes => [],
:edges => []
}
objects.each do |nanopub|
unless nanopub.bel_statement.is_a?(BELParser::Expression::Model::Statement)
nanopub.bel_statement = ::BEL::Nanopub::Nanopub.parse_statement(nanopub)
end
stmt = nanopub.bel_statement
subject = stmt.subject.to_bel
graph[:nodes] << {
:id => subject,
:label => subject
}
if stmt.object
object = stmt.object.to_bel
graph[:nodes] << {
:id => object,
:label => object
}
graph[:edges] << {
:source => subject,
:relation => stmt.relationship,
:target => object
}
end
end
graph[:nodes].uniq!
::BEL::JSON.write({:graph => graph}, writer, options)
writer
end
|