bel 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{bel.gemspec → .gemspec} +8 -4
- data/README.md +3 -3
- data/VERSION +1 -0
- data/bin/bel +8 -8
- data/bin/bel2rdf.rb +1 -1
- data/bin/bel_summarize.rb +4 -4
- data/bin/bel_upgrade.rb +6 -6
- data/lib/bel.rb +3 -2
- data/lib/bel/completion.rb +13 -10
- data/lib/bel/completion_rule.rb +29 -21
- data/lib/bel/dsl.rb +75 -0
- data/lib/bel/gen.rb +2 -2
- data/lib/bel/gen/annotation.rb +2 -2
- data/lib/bel/gen/citation.rb +6 -6
- data/lib/bel/gen/document_header.rb +1 -1
- data/lib/bel/gen/{evidence.rb → nanopub.rb} +15 -15
- data/lib/bel/gen/parameter.rb +6 -6
- data/lib/bel/gen/sample_resources.rb +4 -4
- data/lib/bel/gen/statement.rb +1 -1
- data/lib/bel/gen/term.rb +1 -1
- data/lib/bel/language.rb +0 -20
- data/lib/bel/namespace.rb +7 -3
- data/lib/bel/nanopub.rb +15 -0
- data/lib/bel/{evidence_model/buffering_evidence_combiner.rb → nanopub/buffering_nanopub_combiner.rb} +39 -45
- data/lib/bel/{evidence_model → nanopub}/citation.rb +2 -2
- data/lib/bel/{evidence_model → nanopub}/experiment_context.rb +7 -1
- data/lib/bel/{evidence_model → nanopub}/hash_map_references.rb +1 -1
- data/lib/bel/{evidence_model → nanopub}/map_references.rb +1 -1
- data/lib/bel/nanopub/map_references_combiner.rb +30 -0
- data/lib/bel/nanopub/metadata.rb +102 -0
- data/lib/bel/nanopub/nanopub.rb +122 -0
- data/lib/bel/{evidence_model → nanopub}/references.rb +50 -38
- data/lib/bel/{evidence_model/streaming_evidence_combiner.rb → nanopub/streaming_nanopub_combiner.rb} +8 -8
- data/lib/bel/{evidence_model/summary_text.rb → nanopub/support.rb} +8 -2
- data/lib/bel/{evidence_model → nanopub}/util.rb +10 -10
- data/lib/bel/resource/annotation.rb +15 -24
- data/lib/bel/resource/annotation_value.rb +24 -20
- data/lib/bel/resource/annotations.rb +12 -11
- data/lib/bel/resource/concept.rb +62 -0
- data/lib/bel/resource/concept_scheme.rb +49 -0
- data/lib/bel/resource/namespace.rb +15 -24
- data/lib/bel/resource/namespace_value.rb +26 -23
- data/lib/bel/resource/namespaces.rb +11 -11
- data/lib/bel/script.rb +367 -367
- data/lib/bel/translate.rb +7 -7
- data/lib/bel/translator.rb +10 -10
- data/lib/bel/translator/plugins/bnj.rb +37 -0
- data/lib/bel/translator/plugins/{json_evidence → bnj}/translator.rb +17 -34
- data/lib/bel/translator/plugins/jgf.rb +1 -1
- data/lib/bel/translator/plugins/jgf/translator.rb +10 -10
- data/lib/bel/translator/plugins/jsonld.rb +1 -1
- data/lib/bel/translator/plugins/nquads.rb +1 -1
- data/lib/bel/translator/plugins/ntriples.rb +1 -1
- data/lib/bel/translator/plugins/rdf/bel_schema.rb +134 -126
- data/lib/bel/translator/plugins/rdf/graph_translator.rb +6 -6
- data/lib/bel/translator/plugins/rdf/monkey_patch.rb +50 -49
- data/lib/bel/translator/plugins/rdf/reader.rb +42 -42
- data/lib/bel/translator/plugins/rdf/translator.rb +6 -6
- data/lib/bel/translator/plugins/rdf/writer.rb +4 -4
- data/lib/bel/translator/plugins/rdf2/belv2_0.rb +416 -0
- data/lib/bel/translator/plugins/rdf2/converter.rb +13 -0
- data/lib/bel/translator/plugins/rdf2/namespace_converter.rb +24 -0
- data/lib/bel/translator/plugins/rdf2/nanopub_converter.rb +82 -0
- data/lib/bel/translator/plugins/rdf2/parameter_converter.rb +50 -0
- data/lib/bel/translator/plugins/rdf2/rdf_converter.rb +13 -0
- data/lib/bel/translator/plugins/rdf2/rdf_writer.rb +63 -0
- data/lib/bel/translator/plugins/rdf2/reader.rb +172 -0
- data/lib/bel/translator/plugins/rdf2/relationship_converter.rb +49 -0
- data/lib/bel/translator/plugins/rdf2/statement_converter.rb +65 -0
- data/lib/bel/translator/plugins/rdf2/term_converter.rb +262 -0
- data/lib/bel/translator/plugins/rdf2/translator.rb +51 -0
- data/lib/bel/translator/plugins/rdf2/uuid.rb +20 -0
- data/lib/bel/translator/plugins/rdf2/writer.rb +53 -0
- data/lib/bel/translator/plugins/rdfa.rb +1 -1
- data/lib/bel/translator/plugins/rdfxml.rb +1 -1
- data/lib/bel/translator/plugins/rj.rb +1 -1
- data/lib/bel/translator/plugins/trig.rb +1 -1
- data/lib/bel/translator/plugins/trix.rb +1 -1
- data/lib/bel/translator/plugins/turtle.rb +3 -6
- data/lib/bel/translator/plugins/xbel.rb +5 -6
- data/lib/bel/translator/plugins/xbel/nanopub_handler.rb +625 -0
- data/lib/bel/translator/plugins/xbel/{evidence_yielder.rb → nanopub_yielder.rb} +3 -3
- data/lib/bel/translator/plugins/xbel/translator.rb +2 -5
- data/lib/bel/translator/plugins/xbel/xbel_yielder.rb +135 -74
- data/lib/bel/version.rb +31 -1
- metadata +81 -33
- data/lib/bel/evidence_model.rb +0 -15
- data/lib/bel/evidence_model/bel_parameter.rb +0 -56
- data/lib/bel/evidence_model/bel_statement.rb +0 -97
- data/lib/bel/evidence_model/bel_term.rb +0 -87
- data/lib/bel/evidence_model/evidence.rb +0 -127
- data/lib/bel/evidence_model/map_references_combiner.rb +0 -30
- data/lib/bel/evidence_model/metadata.rb +0 -49
- data/lib/bel/parser.rb +0 -39
- data/lib/bel/translator/plugins/bel_script.rb +0 -36
- data/lib/bel/translator/plugins/bel_script/bel_citation_serialization.rb +0 -125
- data/lib/bel/translator/plugins/bel_script/bel_discrete_serialization.rb +0 -109
- data/lib/bel/translator/plugins/bel_script/bel_top_down_serialization.rb +0 -100
- data/lib/bel/translator/plugins/bel_script/bel_yielder.rb +0 -180
- data/lib/bel/translator/plugins/bel_script/evidence_serialization.rb +0 -79
- data/lib/bel/translator/plugins/bel_script/evidence_yielder.rb +0 -87
- data/lib/bel/translator/plugins/bel_script/translator.rb +0 -35
- data/lib/bel/translator/plugins/json_evidence.rb +0 -38
- data/lib/bel/translator/plugins/xbel/evidence_handler.rb +0 -495
data/lib/bel/parser.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require_relative 'libbel'
|
2
|
-
|
3
|
-
module BEL
|
4
|
-
module Parser
|
5
|
-
|
6
|
-
# Parses BEL expressions to a {BEL::LibBEL::BelAst}.
|
7
|
-
#
|
8
|
-
# If +bel_expression+ is +nil+ then +nil+ is returned.
|
9
|
-
#
|
10
|
-
# @param bel_expression [responds to #to_s] the bel expression to parse
|
11
|
-
# @return [BEL::LibBEL::BelAst]
|
12
|
-
def self.parse(bel_expression, options = {})
|
13
|
-
if !bel_expression
|
14
|
-
return nil
|
15
|
-
end
|
16
|
-
|
17
|
-
LibBEL.parse_statement(
|
18
|
-
ensure_newline(bel_expression.to_s)
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
# Ensures a newline (e.g. +\n+) is the last character in +string+.
|
25
|
-
#
|
26
|
-
# +Pure function+ but returns the +string+ reference if it already ends
|
27
|
-
# with a newline.
|
28
|
-
#
|
29
|
-
# @param string [String] the string which must have a newline
|
30
|
-
# @return [String]
|
31
|
-
def self.ensure_newline(string)
|
32
|
-
if string[-1] != "\n"
|
33
|
-
string + "\n"
|
34
|
-
else
|
35
|
-
string
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module BEL::Translator::Plugins
|
2
|
-
|
3
|
-
module BelScript
|
4
|
-
|
5
|
-
ID = :bel
|
6
|
-
NAME = 'BEL Script Translator'
|
7
|
-
DESCRIPTION = 'A translator that can read and write evidence to BEL Script (version 1.0).'
|
8
|
-
MEDIA_TYPES = %i(application/bel)
|
9
|
-
EXTENSIONS = %i(bel)
|
10
|
-
|
11
|
-
def self.create_translator(options = {})
|
12
|
-
require_relative 'bel_script/translator'
|
13
|
-
BelScriptTranslator.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.id
|
17
|
-
ID
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.name
|
21
|
-
NAME
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.description
|
25
|
-
DESCRIPTION
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.media_types
|
29
|
-
MEDIA_TYPES
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.file_extensions
|
33
|
-
EXTENSIONS
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,125 +0,0 @@
|
|
1
|
-
require_relative 'evidence_serialization.rb'
|
2
|
-
|
3
|
-
# BEL Script evidence serialization that groups evidence by citation scoped to
|
4
|
-
# individual statement groups (i.e. BEL Script's +SET STATEMENT_GROUP+ and
|
5
|
-
# +UNSET STATEMENT_GROUP+).
|
6
|
-
#
|
7
|
-
# @example Citation serialization for a group of evidence
|
8
|
-
# SET STATEMENT_GROUP = 12857727
|
9
|
-
# SET Citation = {"PubMed", "Journal...", "12857727", "2003-08-11", "", ""}
|
10
|
-
# SET Evidence = "USF1 and USF2 bound the IGF2R promoter in vitro, ..."
|
11
|
-
# SET CellLine = "MCF 10A"
|
12
|
-
# SET TextLocation = Abstract
|
13
|
-
# complex(p(HGNC:USF1),g(HGNC:IGF2R))
|
14
|
-
#
|
15
|
-
# complex(p(HGNC:USF2),g(HGNC:IGF2R))
|
16
|
-
#
|
17
|
-
# tscript(p(HGNC:USF2)) directlyIncreases r(HGNC:IGF2R)
|
18
|
-
#
|
19
|
-
# tscript(p(HGNC:USF1)) causesNoChange r(HGNC:IGF2R)
|
20
|
-
#
|
21
|
-
# SET Evidence = "c-Myc was present on the CDK4 promoter to the ..."
|
22
|
-
# complex(p(HGNC:MYC),g(HGNC:CDK4))
|
23
|
-
# UNSET STATEMENT_GROUP
|
24
|
-
module BEL::Translator::Plugins::BelScript::BelCitationSerialization
|
25
|
-
include BEL::Translator::Plugins::BelScript::EvidenceSerialization
|
26
|
-
|
27
|
-
# Serialize the {BEL::Model::Evidence evidence} to a BEL Script string.
|
28
|
-
#
|
29
|
-
# Includes +SET AnnotationName+ and +UNSET AnnotationName+ where needed in
|
30
|
-
# order to remove duplicating annotations.
|
31
|
-
#
|
32
|
-
# @param [BEL::Model::Evidence] evidence the evidence to serialize
|
33
|
-
# @return [String] the BEL Script string
|
34
|
-
def to_bel(evidence)
|
35
|
-
bel = ''
|
36
|
-
|
37
|
-
citation = citation_value(evidence)
|
38
|
-
summary_text = summary_text_value(evidence)
|
39
|
-
annotations = annotation_values(evidence)
|
40
|
-
|
41
|
-
current_annotations = {}.merge(annotations)
|
42
|
-
current_annotations[:Citation] = citation if citation
|
43
|
-
current_annotations[:Evidence] = summary_text if summary_text
|
44
|
-
|
45
|
-
if !evidence.citation.id || evidence.citation.id.empty?
|
46
|
-
citation_id = quote('')
|
47
|
-
else
|
48
|
-
citation_id = quote_if_needed(evidence.citation.id)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Reset cumulative annotations if new citation.
|
52
|
-
if cumulative_citation == nil
|
53
|
-
bel << %Q{SET STATEMENT_GROUP = #{citation_id}\n}
|
54
|
-
cumulative_annotations.clear
|
55
|
-
elsif evidence.citation != cumulative_citation
|
56
|
-
bel << %Q{UNSET STATEMENT_GROUP\n}
|
57
|
-
bel << "\n\n"
|
58
|
-
bel << %Q{SET STATEMENT_GROUP = #{citation_id}\n}
|
59
|
-
cumulative_annotations.clear
|
60
|
-
end
|
61
|
-
|
62
|
-
# Hang on to the last citation.
|
63
|
-
self.cumulative_citation = evidence.citation
|
64
|
-
|
65
|
-
# UNSET unused annotations from previous evidence.
|
66
|
-
(cumulative_annotations.keys - current_annotations.keys).each do |unset_key|
|
67
|
-
bel << "UNSET #{unset_key}\n"
|
68
|
-
cumulative_annotations.delete(unset_key)
|
69
|
-
end
|
70
|
-
|
71
|
-
# Remove annotation if key/value was SET by a previous evidence.
|
72
|
-
Hash[
|
73
|
-
cumulative_annotations.to_a & current_annotations.to_a
|
74
|
-
].each do |same_k, _|
|
75
|
-
current_annotations.delete(same_k)
|
76
|
-
end
|
77
|
-
|
78
|
-
# Retain the current evidence's annotation in cumulative set.
|
79
|
-
cumulative_annotations.merge!(current_annotations)
|
80
|
-
|
81
|
-
# SET Citation
|
82
|
-
citation = current_annotations.delete(:Citation)
|
83
|
-
if citation
|
84
|
-
bel << "SET Citation = {#{citation}}\n"
|
85
|
-
end
|
86
|
-
|
87
|
-
# SET Evidence
|
88
|
-
summary_text = current_annotations.delete(:Evidence)
|
89
|
-
if summary_text
|
90
|
-
bel << %Q{SET Evidence = "#{summary_text}"\n}
|
91
|
-
end
|
92
|
-
|
93
|
-
# SET new or modified annotations
|
94
|
-
current_annotations.sort.each do |(name, value)|
|
95
|
-
bel << "SET #{name} = #{value}\n"
|
96
|
-
end
|
97
|
-
|
98
|
-
# Assert BEL statement
|
99
|
-
bel << "#{evidence.bel_statement}\n"
|
100
|
-
|
101
|
-
# Separate evidence by new line.
|
102
|
-
bel << "\n"
|
103
|
-
|
104
|
-
bel
|
105
|
-
end
|
106
|
-
|
107
|
-
private
|
108
|
-
|
109
|
-
# The cumulative citation that is active for the current evidence. This is
|
110
|
-
# tracked in order to decide when to begin a new statement group.
|
111
|
-
attr_accessor :cumulative_citation
|
112
|
-
|
113
|
-
# Returns the cumulative +Hash+ of annotations. This *state* is used to keep
|
114
|
-
# track of the active, scoped annotations as evidence is serialized.
|
115
|
-
def cumulative_annotations
|
116
|
-
@cumulative_annotations ||= {}
|
117
|
-
end
|
118
|
-
|
119
|
-
# Return BEL Script syntax that should completes the BEL Script document.
|
120
|
-
# For Citation serialization we will always end with the unset of a
|
121
|
-
# statement group.
|
122
|
-
def epilogue
|
123
|
-
%Q{UNSET STATEMENT_GROUP\n}
|
124
|
-
end
|
125
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
require_relative 'evidence_serialization'
|
2
|
-
|
3
|
-
# BEL Script evidence serialization that writes each evidence with their full
|
4
|
-
# set of annotations (i.e. includes all `SET` and necessary `UNSET` records).
|
5
|
-
# This style is more readable because it groups all set annotations near the
|
6
|
-
# BEL statement.
|
7
|
-
#
|
8
|
-
# @example Discrete serialization for a group of evidence
|
9
|
-
# SET Citation = {"PubMed", "Journal...", "12857727", "2003-08-11", "", ""}
|
10
|
-
# SET Evidence = "USF1 and USF2 bound the IGF2R promoter in vitro, ..."
|
11
|
-
# SET CellLine = "MCF 10A"
|
12
|
-
# SET TextLocation = Abstract
|
13
|
-
# complex(p(HGNC:USF1),g(HGNC:IGF2R))
|
14
|
-
#
|
15
|
-
# SET Citation = {"PubMed", "Journal...", "12857727", "2003-08-11", "", ""}
|
16
|
-
# SET Evidence = "USF1 and USF2 bound the IGF2R promoter in vitro, ..."
|
17
|
-
# SET CellLine = "MCF 10A"
|
18
|
-
# SET TextLocation = Abstract
|
19
|
-
# complex(p(HGNC:USF2),g(HGNC:IGF2R))
|
20
|
-
#
|
21
|
-
# SET Citation = {"PubMed", "Journal...", "12857727", "2003-08-11", "", ""}
|
22
|
-
# SET Evidence = "USF1 and USF2 bound the IGF2R promoter in vitro, ..."
|
23
|
-
# SET CellLine = "MCF 10A"
|
24
|
-
# SET TextLocation = Abstract
|
25
|
-
# tscript(p(HGNC:USF2)) directlyIncreases r(HGNC:IGF2R)
|
26
|
-
#
|
27
|
-
# SET Citation = {"PubMed", "Journal...", "12857727", "2003-08-11", "", ""}
|
28
|
-
# SET Evidence = "USF1 and USF2 bound the IGF2R promoter in vitro, ..."
|
29
|
-
# SET CellLine = "MCF 10A"
|
30
|
-
# SET TextLocation = Abstract
|
31
|
-
# tscript(p(HGNC:USF1)) causesNoChange r(HGNC:IGF2R)
|
32
|
-
#
|
33
|
-
# SET Citation = {"PubMed", "Journal...", "12857727", "2003-08-11", "", ""}
|
34
|
-
# SET Evidence = "c-Myc was present on the CDK4 promoter to the ..."
|
35
|
-
# SET CellLine = "MCF 10A"
|
36
|
-
# SET TextLocation = Abstract
|
37
|
-
# complex(p(HGNC:MYC),g(HGNC:CDK4))
|
38
|
-
#
|
39
|
-
# UNSET CellLine
|
40
|
-
module BEL::Translator::Plugins::BelScript::BelDiscreteSerialization
|
41
|
-
include BEL::Translator::Plugins::BelScript::EvidenceSerialization
|
42
|
-
|
43
|
-
# Serialize the {BEL::Model::Evidence evidence} to a BEL Script string.
|
44
|
-
# Includes all necessary +SET AnnotationName+ and +UNSET AnnotationName+
|
45
|
-
# records around the BEL statement.
|
46
|
-
#
|
47
|
-
# @param [BEL::Model::Evidence] evidence the evidence to serialize
|
48
|
-
# @return [String] the BEL Script string
|
49
|
-
def to_bel(evidence)
|
50
|
-
bel = ''
|
51
|
-
|
52
|
-
citation = citation_value(evidence)
|
53
|
-
summary_text = summary_text_value(evidence)
|
54
|
-
annotations = annotation_values(evidence)
|
55
|
-
|
56
|
-
current_annotations = {}.merge(annotations)
|
57
|
-
current_annotations[:Citation] = citation if citation
|
58
|
-
current_annotations[:Evidence] = summary_text if summary_text
|
59
|
-
|
60
|
-
# UNSET unused annotations from previous evidence.
|
61
|
-
(cumulative_annotations.keys - current_annotations.keys).each do |unset_key|
|
62
|
-
bel << "UNSET #{unset_key}\n"
|
63
|
-
cumulative_annotations.delete(unset_key)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Retain the current evidence's annotation in cumulative set.
|
67
|
-
cumulative_annotations.merge!(current_annotations)
|
68
|
-
|
69
|
-
# SET Citation
|
70
|
-
citation = current_annotations.delete(:Citation)
|
71
|
-
if citation
|
72
|
-
bel << "SET Citation = {#{citation}}\n"
|
73
|
-
end
|
74
|
-
|
75
|
-
# SET Evidence
|
76
|
-
summary_text = current_annotations.delete(:Evidence)
|
77
|
-
if summary_text
|
78
|
-
bel << %Q{SET Evidence = "#{summary_text}"\n}
|
79
|
-
end
|
80
|
-
|
81
|
-
# SET new or modified annotations
|
82
|
-
current_annotations.sort.each do |(name, value)|
|
83
|
-
bel << "SET #{name} = #{value}\n"
|
84
|
-
end
|
85
|
-
|
86
|
-
# Assert BEL statement
|
87
|
-
bel << "#{evidence.bel_statement}\n"
|
88
|
-
|
89
|
-
# Separate evidence by new line.
|
90
|
-
bel << "\n"
|
91
|
-
|
92
|
-
bel
|
93
|
-
end
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
# Returns the cumulative +Hash+ of annotations. This *state* is used to keep
|
98
|
-
# track of the active, scoped annotations as evidence is serialized.
|
99
|
-
def cumulative_annotations
|
100
|
-
@cumulative_annotations ||= {}
|
101
|
-
end
|
102
|
-
|
103
|
-
# Return BEL Script syntax that completes the BEL Script document.
|
104
|
-
# The empty string is returned since no ending syntax is necessary when
|
105
|
-
# serializing each evidence discretely.
|
106
|
-
def epilogue
|
107
|
-
""
|
108
|
-
end
|
109
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require_relative 'evidence_serialization.rb'
|
2
|
-
|
3
|
-
# BEL Script evidence serialization that writes evidence sequentially while
|
4
|
-
# including only the necessary unsetting of annotations (i.e. BEL Script's
|
5
|
-
# +UNSET AnnotationName+ syntax).
|
6
|
-
#
|
7
|
-
# @example Top-down serialization for a group of evidence
|
8
|
-
# SET Citation = {"PubMed", "Journal...", "12857727", "2003-08-11", "", ""}
|
9
|
-
# SET Evidence = "USF1 and USF2 bound the IGF2R promoter in vitro, ..."
|
10
|
-
# SET CellLine = "MCF 10A"
|
11
|
-
# SET TextLocation = Abstract
|
12
|
-
# complex(p(HGNC:USF1),g(HGNC:IGF2R))
|
13
|
-
#
|
14
|
-
# complex(p(HGNC:USF2),g(HGNC:IGF2R))
|
15
|
-
#
|
16
|
-
# tscript(p(HGNC:USF2)) directlyIncreases r(HGNC:IGF2R)
|
17
|
-
#
|
18
|
-
# tscript(p(HGNC:USF1)) causesNoChange r(HGNC:IGF2R)
|
19
|
-
#
|
20
|
-
# SET Evidence = "c-Myc was present on the CDK4 promoter to the ..."
|
21
|
-
# complex(p(HGNC:MYC),g(HGNC:CDK4))
|
22
|
-
#
|
23
|
-
# UNSET CellLine
|
24
|
-
module BEL::Translator::Plugins::BelScript::BelTopDownSerialization
|
25
|
-
include BEL::Translator::Plugins::BelScript::EvidenceSerialization
|
26
|
-
|
27
|
-
# Serialize the {BEL::Model::Evidence evidence} to a BEL Script string.
|
28
|
-
# Includes all necessary +SET AnnotationName+ and +UNSET AnnotationName+
|
29
|
-
# records within the scope of a citation's statement group.
|
30
|
-
#
|
31
|
-
# @param [BEL::Model::Evidence] evidence the evidence to serialize
|
32
|
-
# @return [String] the BEL Script string
|
33
|
-
def to_bel(evidence)
|
34
|
-
bel = ''
|
35
|
-
|
36
|
-
citation = citation_value(evidence)
|
37
|
-
summary_text = summary_text_value(evidence)
|
38
|
-
annotations = annotation_values(evidence)
|
39
|
-
|
40
|
-
current_annotations = {}.merge(annotations)
|
41
|
-
current_annotations[:Citation] = citation if citation
|
42
|
-
current_annotations[:Evidence] = summary_text if summary_text
|
43
|
-
|
44
|
-
# UNSET unused annotations from previous evidence.
|
45
|
-
(cumulative_annotations.keys - current_annotations.keys).each do |unset_key|
|
46
|
-
bel << "UNSET #{unset_key}\n"
|
47
|
-
cumulative_annotations.delete(unset_key)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Remove annotation if key/value was SET by a previous evidence.
|
51
|
-
Hash[
|
52
|
-
cumulative_annotations.to_a & current_annotations.to_a
|
53
|
-
].each do |same_k, _|
|
54
|
-
current_annotations.delete(same_k)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Retain the current evidence's annotation in cumulative set.
|
58
|
-
cumulative_annotations.merge!(current_annotations)
|
59
|
-
|
60
|
-
# SET Citation
|
61
|
-
citation = current_annotations.delete(:Citation)
|
62
|
-
if citation
|
63
|
-
bel << "SET Citation = {#{citation}}\n"
|
64
|
-
end
|
65
|
-
|
66
|
-
# SET Evidence
|
67
|
-
summary_text = current_annotations.delete(:Evidence)
|
68
|
-
if summary_text
|
69
|
-
bel << %Q{SET Evidence = "#{summary_text}"\n}
|
70
|
-
end
|
71
|
-
|
72
|
-
# SET new or modified annotations
|
73
|
-
current_annotations.sort.each do |(name, value)|
|
74
|
-
bel << "SET #{name} = #{value}\n"
|
75
|
-
end
|
76
|
-
|
77
|
-
# Assert BEL statement
|
78
|
-
bel << "#{evidence.bel_statement}\n"
|
79
|
-
|
80
|
-
# Separate evidence by new line.
|
81
|
-
bel << "\n"
|
82
|
-
|
83
|
-
bel
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
# Returns the cumulative +Hash+ of annotations. This *state* is used to keep
|
89
|
-
# track of the active, scoped annotations as evidence is serialized.
|
90
|
-
def cumulative_annotations
|
91
|
-
@cumulative_annotations ||= {}
|
92
|
-
end
|
93
|
-
|
94
|
-
# Return BEL Script syntax that completes the BEL Script document.
|
95
|
-
# The empty string is returned since no ending syntax is necessary when
|
96
|
-
# serializing in a top-down manner.
|
97
|
-
def epilogue
|
98
|
-
""
|
99
|
-
end
|
100
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
require_relative 'bel_citation_serialization'
|
2
|
-
require_relative 'bel_discrete_serialization'
|
3
|
-
require_relative 'bel_top_down_serialization'
|
4
|
-
require 'bel'
|
5
|
-
|
6
|
-
module BEL::Translator::Plugins
|
7
|
-
|
8
|
-
module BelScript
|
9
|
-
|
10
|
-
class BelYielder
|
11
|
-
|
12
|
-
# Create a {BelYielder} object that serializes {BEL::Model::Evidence} to
|
13
|
-
# BEL Script.
|
14
|
-
#
|
15
|
-
# @param [Enumerator<BEL::Model::Evidence>] data evidence data iterated
|
16
|
-
# using +each+
|
17
|
-
# @option options [Boolean] :write_header +true+ to write the BEL Script
|
18
|
-
# document header; +false+ to not write the BEL Script document
|
19
|
-
# header
|
20
|
-
# @option options [Symbol,Module] :serialization the serialization
|
21
|
-
# technique to use for evidence; a +Module+ type will be used as
|
22
|
-
# is; a +Symbol+ type will be mapped as
|
23
|
-
# +:discrete+ => {BelDiscreteSerialization},
|
24
|
-
# +:topdown+ => {BelTopDownSerialization},
|
25
|
-
# +:citation+ => {BelCitationSerialization}; otherwise the default
|
26
|
-
# of {BelCitationSerialization} is used
|
27
|
-
def initialize(data, options = {})
|
28
|
-
@data = data
|
29
|
-
@streaming = options.fetch(:streaming, false)
|
30
|
-
@write_header = options.fetch(:write_header, true)
|
31
|
-
@annotation_reference_map = options.fetch(:annotation_reference_map, nil)
|
32
|
-
@namespace_reference_map = options.fetch(:namespace_reference_map, nil)
|
33
|
-
|
34
|
-
# augment self with BEL serialization stategy.
|
35
|
-
serialization = options[:serialization]
|
36
|
-
serialization_module =
|
37
|
-
case serialization
|
38
|
-
when Module
|
39
|
-
serialization
|
40
|
-
when String, Symbol
|
41
|
-
serialization_refs = {
|
42
|
-
:discrete => BelDiscreteSerialization,
|
43
|
-
:topdown => BelTopDownSerialization,
|
44
|
-
:citation => BelCitationSerialization,
|
45
|
-
}
|
46
|
-
serialization_module = serialization_refs[serialization.to_sym]
|
47
|
-
unless serialization_module
|
48
|
-
raise %Q{No BEL serialization strategy for "#{serialization}"}
|
49
|
-
end
|
50
|
-
serialization_module
|
51
|
-
else
|
52
|
-
# Default to citation serialization.
|
53
|
-
BelCitationSerialization
|
54
|
-
end
|
55
|
-
|
56
|
-
self_eigenclass = (class << self; self; end)
|
57
|
-
self_eigenclass.send(:include, serialization_module)
|
58
|
-
end
|
59
|
-
|
60
|
-
def each
|
61
|
-
if block_given?
|
62
|
-
combiner =
|
63
|
-
if @streaming
|
64
|
-
BEL::Model::StreamingEvidenceCombiner.new(@data)
|
65
|
-
elsif @annotation_reference_map && @namespace_reference_map
|
66
|
-
BEL::Model::MapReferencesCombiner.new(
|
67
|
-
@data,
|
68
|
-
BEL::Model::HashMapReferences.new(
|
69
|
-
@annotation_reference_map,
|
70
|
-
@namespace_reference_map
|
71
|
-
)
|
72
|
-
)
|
73
|
-
else
|
74
|
-
BEL::Model::BufferingEvidenceCombiner.new(@data)
|
75
|
-
end
|
76
|
-
|
77
|
-
header_flag = true
|
78
|
-
combiner.each { |evidence|
|
79
|
-
|
80
|
-
# serialize evidence
|
81
|
-
bel = to_bel(evidence)
|
82
|
-
|
83
|
-
if @write_header && header_flag
|
84
|
-
yield document_header(evidence.metadata.document_header)
|
85
|
-
yield namespaces(combiner.namespace_references)
|
86
|
-
yield annotations(combiner.annotation_references)
|
87
|
-
|
88
|
-
yield <<-COMMENT.gsub(/^\s+/, '')
|
89
|
-
###############################################
|
90
|
-
# Statements Section
|
91
|
-
COMMENT
|
92
|
-
header_flag = false
|
93
|
-
end
|
94
|
-
|
95
|
-
yield bel
|
96
|
-
}
|
97
|
-
|
98
|
-
yield epilogue
|
99
|
-
else
|
100
|
-
to_enum(:each)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
def document_header(header)
|
107
|
-
return "" unless header
|
108
|
-
|
109
|
-
bel = <<-COMMENT.gsub(/^\s+/, '')
|
110
|
-
###############################################
|
111
|
-
# Document Properties Section
|
112
|
-
COMMENT
|
113
|
-
|
114
|
-
header.each { |name, value|
|
115
|
-
name_s = name.to_s
|
116
|
-
value_s =
|
117
|
-
if value.respond_to?(:each)
|
118
|
-
value.join('|')
|
119
|
-
else
|
120
|
-
value.to_s
|
121
|
-
end
|
122
|
-
|
123
|
-
# handle casing for document properties (special case, contactinfo)
|
124
|
-
name_s = (name_s.downcase == 'contactinfo') ?
|
125
|
-
'ContactInfo' :
|
126
|
-
name_s.capitalize
|
127
|
-
|
128
|
-
bel << %Q{SET DOCUMENT #{name_s} = "#{value_s}"\n}
|
129
|
-
}
|
130
|
-
|
131
|
-
bel << "\n"
|
132
|
-
bel
|
133
|
-
end
|
134
|
-
|
135
|
-
def annotations(annotation_references)
|
136
|
-
bel = <<-COMMENT.gsub(/^\s+/, '')
|
137
|
-
###############################################
|
138
|
-
# Annotation Definitions Section
|
139
|
-
COMMENT
|
140
|
-
|
141
|
-
return bel unless annotation_references
|
142
|
-
|
143
|
-
annotation_references.reduce(bel) { |bel, ref|
|
144
|
-
keyword, type, domain = ref.values_at(:keyword, :type, :domain)
|
145
|
-
bel << "DEFINE ANNOTATION #{keyword} AS "
|
146
|
-
|
147
|
-
case type.to_sym
|
148
|
-
when :uri
|
149
|
-
bel << %Q{URL "#{domain}"\n}
|
150
|
-
when :pattern
|
151
|
-
regex = domain.respond_to?(:source) ? domain.source : domain
|
152
|
-
bel << %Q{PATTERN "#{regex}"\n}
|
153
|
-
when :list
|
154
|
-
bel << %Q|LIST {#{domain.inspect[1...-1]}}\n|
|
155
|
-
end
|
156
|
-
bel
|
157
|
-
}
|
158
|
-
bel << "\n"
|
159
|
-
bel
|
160
|
-
end
|
161
|
-
|
162
|
-
def namespaces(namespace_references)
|
163
|
-
bel = <<-COMMENT.gsub(/^\s+/, '')
|
164
|
-
###############################################
|
165
|
-
# Namespace Definitions Section
|
166
|
-
COMMENT
|
167
|
-
|
168
|
-
return bel unless namespace_references
|
169
|
-
|
170
|
-
namespace_references.reduce(bel) { |bel, ref|
|
171
|
-
keyword, url = ref.values_at(:keyword, :uri)
|
172
|
-
bel << %Q{DEFINE NAMESPACE #{keyword} AS URL "#{url}"\n}
|
173
|
-
bel
|
174
|
-
}
|
175
|
-
bel << "\n"
|
176
|
-
bel
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|