Class: BEL::Nanopub::Nanopub
- Inherits:
-
Object
- Object
- BEL::Nanopub::Nanopub
- Defined in:
- lib/bel/nanopub/nanopub.rb,
lib/bel/translator/plugins/rdf/monkey_patch.rb
Overview
Nanopub represents an asserted biological interaction with associated constituents:
-
BEL Statement
-
Citation
-
Support
-
Experiment Context
-
References
-
Metadata
Class Method Summary collapse
Instance Method Summary collapse
- #bel_statement ⇒ Object
- #bel_statement=(bel_statement) ⇒ Object
- #citation ⇒ Object
- #citation=(citation) ⇒ Object
- #experiment_context ⇒ Object
- #experiment_context=(experiment_context) ⇒ Object
- #metadata ⇒ Object
- #metadata=(metadata) ⇒ Object
- #references ⇒ Object
- #references=(references) ⇒ Object
- #support ⇒ Object
- #support=(support) ⇒ Object
- #to_h(hash = {}) ⇒ Object
- #to_rdf(remap = nil) ⇒ Object
- #to_uri ⇒ Object
- #to_void_dataset(void_dataset_uri) ⇒ Object
Class Method Details
.create(hash) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bel/nanopub/nanopub.rb', line 23 def self.create(hash) nanopub = Nanopub.new # Order-dependent; metadata/references must be set first in order for # _parse_statement to reference specification and namespaces. nanopub. = Metadata.new(hash[:metadata] || {}) nanopub.references = References.new(hash[:references] || {}) nanopub.bel_statement = hash[:bel_statement] || nil nanopub.citation = Citation.new(hash[:citation] || {}) nanopub.support.value = hash[:support] || nil nanopub.experiment_context = ExperimentContext.new(hash[:experiment_context] || []) nanopub end |
Instance Method Details
#bel_statement ⇒ Object
36 37 38 |
# File 'lib/bel/nanopub/nanopub.rb', line 36 def bel_statement @bel_statement end |
#bel_statement=(bel_statement) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bel/nanopub/nanopub.rb', line 40 def bel_statement=(bel_statement) @bel_statement = case bel_statement when String _parse_statement(bel_statement) when BELParser::Expression::Model::Statement bel_statement when nil nil else raise ArgumentError, %(expected String, Statement, actual: #{bel_statement.class}) end end |
#citation ⇒ Object
54 55 56 |
# File 'lib/bel/nanopub/nanopub.rb', line 54 def citation (@citation ||= Citation.new) end |
#citation=(citation) ⇒ Object
58 59 60 |
# File 'lib/bel/nanopub/nanopub.rb', line 58 def citation=(citation) @citation = citation end |
#experiment_context ⇒ Object
70 71 72 |
# File 'lib/bel/nanopub/nanopub.rb', line 70 def experiment_context (@experiment_context ||= ExperimentContext.new) end |
#experiment_context=(experiment_context) ⇒ Object
74 75 76 |
# File 'lib/bel/nanopub/nanopub.rb', line 74 def experiment_context=(experiment_context) @experiment_context = experiment_context end |
#metadata ⇒ Object
86 87 88 |
# File 'lib/bel/nanopub/nanopub.rb', line 86 def (@metadata ||= Metadata.new) end |
#metadata=(metadata) ⇒ Object
90 91 92 |
# File 'lib/bel/nanopub/nanopub.rb', line 90 def () @metadata = end |
#references ⇒ Object
78 79 80 |
# File 'lib/bel/nanopub/nanopub.rb', line 78 def references (@references ||= References.new) end |
#references=(references) ⇒ Object
82 83 84 |
# File 'lib/bel/nanopub/nanopub.rb', line 82 def references=(references) @references = references end |
#support ⇒ Object
62 63 64 |
# File 'lib/bel/nanopub/nanopub.rb', line 62 def support (@support ||= Support.new) end |
#support=(support) ⇒ Object
66 67 68 |
# File 'lib/bel/nanopub/nanopub.rb', line 66 def support=(support) @support = support end |
#to_h(hash = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bel/nanopub/nanopub.rb', line 94 def to_h(hash = {}) hash.merge!( { :bel_statement => bel_statement, :citation => citation.to_h, :support => support.value, :experiment_context => experiment_context.values, :references => references.to_h, :metadata => .to_a } ) hash end |
#to_rdf(remap = nil) ⇒ Object
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 |
# File 'lib/bel/translator/plugins/rdf/monkey_patch.rb', line 346 def to_rdf(remap = nil) uri = to_uri # parse BEL statement if necessary unless self.bel_statement.is_a?(::BEL::Nanopub::Statement) self.bel_statement = self.class.parse_statement(self) end # convert BEL statement to RDF statement_uri, statements = bel_statement.to_rdf(uri, remap) statements << ::RDF::Statement.new(uri, BELRDF::RDF.type, BELRDF::BELV.Nanopub, :graph_name => uri) statements << ::RDF::Statement.new(statement_uri, BELRDF::BELV.hasNanopub, uri, :graph_name => uri) statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasStatement, statement_uri, :graph_name => uri) annotations = bel_statement.annotations # citation citation = annotations.delete('Citation') if citation value = citation.value.map{|x| x.gsub('"', '')} if citation and value[0] == 'PubMed' pid = value[2] statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasCitation, BELRDF::PUBMED[pid], :graph_name => uri) end end # support support = annotations.delete('Support') if support value = support.value.gsub('"', '').force_encoding('UTF-8') statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasSupport, value, :graph_name => uri) end # annotations annotations.each do |_, anno| name = anno.name.gsub('"', '') if BELRDF::const_defined? name annotation_scheme = BELRDF::const_get name [anno.value].flatten.map{|x| x.gsub('"', '')}.each do |val| value_uri = BELRDF::RDF::URI(URI.encode(annotation_scheme + val.to_s)) statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasAnnotation, value_uri, :graph_name => uri) end end end [uri, statements] end |
#to_uri ⇒ Object
342 343 344 |
# File 'lib/bel/translator/plugins/rdf/monkey_patch.rb', line 342 def to_uri BELRDF::BELE[BELRDF.generate_uuid] end |
#to_void_dataset(void_dataset_uri) ⇒ Object
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 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/bel/translator/plugins/rdf/monkey_patch.rb', line 396 def to_void_dataset(void_dataset_uri) document_header = self.[:document_header] return nil if !document_header || !document_header.is_a?(Hash) triples = ::RDF::Repository.new triples << ::RDF::Statement.new(void_dataset_uri, ::RDF.type, BELRDF::VOID.Dataset) name = version = nil document_header.each do |property, value| case property when /name/i name = value.to_s triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.title, name) when /description/i triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.description, value.to_s) when /version/i version = value.to_s when /copyright/i waiver = RDF::Vocabulary.new('http://vocab.org/waiver/terms/').waiver value = value.to_s uri = RDF::URI(value) value = if uri.valid? uri else value end triples << ::RDF::Statement.new(void_dataset_uri, waiver, value) when /authors/i if value.respond_to?(:each) value.each do |v| triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.creator, v.to_s) end else triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.creator, value.to_s) end when /licenses/i value = value.to_s uri = RDF::URI(value) value = if uri.valid? uri else value end triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.license, value) when /contactinfo/i triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.publisher, :publisher) triples << ::RDF::Statement.new(:publisher, ::RDF.type, BELRDF::FOAF.Person) triples << ::RDF::Statement.new(:publisher, BELRDF::FOAF.mbox, value.to_s) end end if name && version identifier = "#{name}/#{version}" triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.identifier, identifier) end triples end |