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
|
# File 'lib/bel/translator/plugins/rdf/monkey_patch.rb', line 116
def to_rdf(graph_name = nil, remap = nil)
uri = to_uri
statements = []
type = rdf_type
statements << ::RDF::Statement.new(uri, BELRDF::RDF.type, BELRDF::BELV.Term, :graph_name => graph_name)
statements << ::RDF::Statement.new(uri, BELRDF::RDF.type, type, :graph_name => graph_name)
fx = @fx.respond_to?(:short_form) ? @fx.short_form : @fx.to_s.to_sym
if BELRDF::ACTIVITY_TYPE.include? fx
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasActivityType, BELRDF::ACTIVITY_TYPE[fx], :graph_name => graph_name)
end
statements << ::RDF::Statement.new(uri, BELRDF::RDFS.label, to_s.force_encoding('UTF-8'), :graph_name => graph_name)
if [:p, :proteinAbundance].include?(fx)
pmod =
@arguments.find{ |x|
if x.is_a? ::BEL::Nanopub::Term
arg_fx = x.fx
arg_fx = arg_fx.respond_to?(:short_form) ? arg_fx.short_form : arg_fx.to_s.to_sym
[:pmod, :proteinModification].include?(arg_fx)
else
false
end
}
if pmod
mod_string = pmod.arguments.map(&:to_s).join(',')
mod_type = BELRDF::MODIFICATION_TYPE.find {|k,v| mod_string.start_with? k}
mod_type = (mod_type ? mod_type[1] : BELRDF::BELV.Modification)
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasModificationType, mod_type, :graph_name => graph_name)
last = pmod.arguments.last.to_s
if last.match(/^\d+$/)
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasModificationPosition, last.to_i, :graph_name => graph_name)
end
root_param = @arguments.find{|x| x.is_a? ::BEL::Nanopub::Parameter}
(root_id, root_statements) = ::BEL::Nanopub::Term.new(:p, [root_param]).to_rdf(graph_name, remap)
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, root_id, :graph_name => graph_name)
statements.concat(root_statements)
return [uri, statements]
elsif @arguments.find{|x| x.is_a? ::BEL::Nanopub::Term and BELRDF::PROTEIN_VARIANT.include? x.fx}
root_param = @arguments.find{|x| x.is_a? ::BEL::Nanopub::Parameter}
(root_id, root_statements) = ::BEL::Nanopub::Term.new(:p, [root_param]).to_rdf(graph_name, remap)
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, root_id, :graph_name => graph_name)
statements.concat(root_statements)
return [uri, statements]
end
end
@arguments.find_all{ |x|
x.is_a? ::BEL::Nanopub::Parameter and x.ns != nil
}.each do |param|
param_uri, encoding_statements = param.to_rdf(graph_name, remap)
statements.concat(encoding_statements)
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasConcept, param_uri, :graph_name => graph_name)
end
@arguments.find_all{|x| x.is_a? ::BEL::Nanopub::Term}.each do |child|
(child_id, child_statements) = child.to_rdf(graph_name, remap)
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, child_id, :graph_name => graph_name)
statements.concat(child_statements)
end
[uri, statements]
end
|