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
|
# File 'lib/bel/translator/plugins/jgf/translator.rb', line 24
def write(objects, writer = StringIO.new, options = {})
graph = {
:type => 'BEL-V1.0',
:nodes => [],
:edges => []
}
objects.each do |nanopub|
unless nanopub.bel_statement.is_a?(::BEL::Nanopub::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
|