Module: BEL::Translator::Plugins::BelScript::BelTopDownSerialization

Includes:
NanopubSerialization
Defined in:
lib/bel/translator/plugins/bel_script/bel_top_down_serialization.rb

Overview

BEL Script nanopub serialization that writes nanopubs sequentially while including only the necessary unsetting of annotations (i.e. BEL Script’s UNSET AnnotationName syntax).

Examples:

Top-down serialization for a group of nanopubs

SET Citation = {"PubMed", "Journal...", "12857727", "2003-08-11", "", ""}
SET Support = "USF1 and USF2 bound the IGF2R promoter in vitro, ..."
SET CellLine = "MCF 10A"
SET TextLocation = Abstract
complex(p(HGNC:USF1),g(HGNC:IGF2R))

complex(p(HGNC:USF2),g(HGNC:IGF2R))

tscript(p(HGNC:USF2)) directlyIncreases r(HGNC:IGF2R)

tscript(p(HGNC:USF1)) causesNoChange r(HGNC:IGF2R)

SET Support = "c-Myc was present on the CDK4 promoter to the ..."
complex(p(HGNC:MYC),g(HGNC:CDK4))

UNSET CellLine

Instance Method Summary collapse

Instance Method Details

#to_bel(nanopub) ⇒ String

Serialize the nanopub to a BEL Script string. Includes all necessary SET AnnotationName and UNSET AnnotationName records within the scope of a citation’s statement group.



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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bel/translator/plugins/bel_script/bel_top_down_serialization.rb', line 33

def to_bel(nanopub)
  bel = ''

  citation     = citation_value(nanopub)
  support = support_value(nanopub)
  annotations  = annotation_values(nanopub)

  current_annotations            = {}.merge(annotations)
  current_annotations[:Citation] = citation if citation
  current_annotations[:Support]  = support if support

  # UNSET unused annotations from previous nanopub.
  (cumulative_annotations.keys - current_annotations.keys).each do |unset_key|
    bel << "UNSET #{unset_key}\n"
    cumulative_annotations.delete(unset_key)
  end

  # Remove annotation if key/value was SET by a previous nanopub.
  Hash[
    cumulative_annotations.to_a & current_annotations.to_a
  ].each do |same_k, _|
    current_annotations.delete(same_k)
  end

  # Retain the current nanopub's annotation in cumulative set.
  cumulative_annotations.merge!(current_annotations)

  # SET Citation
  citation = current_annotations.delete(:Citation)
  if citation
    bel << "SET Citation = {#{citation}}\n"
  end

  # SET Support
  support = current_annotations.delete(:Support)
  if support
    bel << %Q{SET Support = "#{support}"\n}
  end

  # SET new or modified annotations
  current_annotations.sort.each do |(name, value)|
    bel << "SET #{name} = #{value}\n"
  end

  # Assert BEL statement
  bel << "#{nanopub.bel_statement}\n"

  # Separate nanopub by new line.
  bel << "\n"

  bel
end