bel_parser 1.0.0.alpha.12 → 1.0.0.alpha.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.gemspec +1 -1
  3. data/VERSION +1 -1
  4. data/bin/bel2_validator +35 -8
  5. data/lib/bel_parser/expression/validator.rb +3 -2
  6. data/lib/bel_parser/language/apply_namespace_encoding.rb +96 -0
  7. data/lib/bel_parser/language/base_specification.rb +82 -0
  8. data/lib/bel_parser/language/expression_validator.rb +6 -2
  9. data/lib/bel_parser/language/relationship.rb +1 -1
  10. data/lib/bel_parser/language/semantics/signature_mapping.rb +26 -32
  11. data/lib/bel_parser/language/semantics_ast.rb +285 -149
  12. data/lib/bel_parser/language/semantics_ast_warnings.rb +180 -0
  13. data/lib/bel_parser/language/semantics_result.rb +11 -2
  14. data/lib/bel_parser/language/semantics_type_warning.rb +22 -0
  15. data/lib/bel_parser/language/semantics_warning.rb +8 -0
  16. data/lib/bel_parser/language/specification.rb +38 -55
  17. data/lib/bel_parser/language/syntax/undefined_namespace_value.rb +43 -0
  18. data/lib/bel_parser/language/syntax_error.rb +8 -0
  19. data/lib/bel_parser/language/syntax_result.rb +8 -0
  20. data/lib/bel_parser/language/syntax_warning.rb +9 -4
  21. data/lib/bel_parser/language/version1_0/functions/abundance.rb +5 -6
  22. data/lib/bel_parser/language/version1_0/functions/biological_process.rb +5 -6
  23. data/lib/bel_parser/language/version1_0/functions/complex_abundance.rb +6 -7
  24. data/lib/bel_parser/language/version1_0/functions/fusion.rb +39 -60
  25. data/lib/bel_parser/language/version1_0/functions/gene_abundance.rb +9 -12
  26. data/lib/bel_parser/language/version1_0/functions/list.rb +5 -6
  27. data/lib/bel_parser/language/version1_0/functions/micro_rna_abundance.rb +5 -6
  28. data/lib/bel_parser/language/version1_0/functions/pathology.rb +5 -6
  29. data/lib/bel_parser/language/version1_0/functions/protein_abundance.rb +16 -30
  30. data/lib/bel_parser/language/version1_0/functions/protein_modification.rb +15 -27
  31. data/lib/bel_parser/language/version1_0/functions/rna_abundance.rb +8 -11
  32. data/lib/bel_parser/language/version1_0/functions/substitution.rb +6 -12
  33. data/lib/bel_parser/language/version1_0/functions/translocation.rb +9 -12
  34. data/lib/bel_parser/language/version1_0/functions/truncation.rb +2 -4
  35. data/lib/bel_parser/language/version1_0/value_encodings/abundance.rb +21 -0
  36. data/lib/bel_parser/language/version1_0/value_encodings/any.rb +74 -0
  37. data/lib/bel_parser/language/version1_0/value_encodings/biological_process.rb +21 -0
  38. data/lib/bel_parser/language/version1_0/value_encodings/complex_abundance.rb +21 -0
  39. data/lib/bel_parser/language/version1_0/value_encodings/gene_abundance.rb +21 -0
  40. data/lib/bel_parser/language/version1_0/value_encodings/micro_rna_abundance.rb +21 -0
  41. data/lib/bel_parser/language/version1_0/value_encodings/pathology.rb +21 -0
  42. data/lib/bel_parser/language/version1_0/value_encodings/protein_abundance.rb +21 -0
  43. data/lib/bel_parser/language/version1_0/value_encodings/rna_abundance.rb +21 -0
  44. data/lib/bel_parser/language/version1_0.rb +6 -87
  45. data/lib/bel_parser/language/version2_0/functions/abundance.rb +13 -18
  46. data/lib/bel_parser/language/version2_0/functions/biological_process.rb +5 -6
  47. data/lib/bel_parser/language/version2_0/functions/complex_abundance.rb +9 -12
  48. data/lib/bel_parser/language/version2_0/functions/fragment.rb +4 -9
  49. data/lib/bel_parser/language/version2_0/functions/from_location.rb +5 -6
  50. data/lib/bel_parser/language/version2_0/functions/fusion.rb +39 -66
  51. data/lib/bel_parser/language/version2_0/functions/gene_abundance.rb +13 -18
  52. data/lib/bel_parser/language/version2_0/functions/list.rb +5 -6
  53. data/lib/bel_parser/language/version2_0/functions/location.rb +5 -6
  54. data/lib/bel_parser/language/version2_0/functions/micro_rna_abundance.rb +13 -18
  55. data/lib/bel_parser/language/version2_0/functions/molecular_activity.rb +6 -5
  56. data/lib/bel_parser/language/version2_0/functions/pathology.rb +5 -6
  57. data/lib/bel_parser/language/version2_0/functions/protein_abundance.rb +21 -30
  58. data/lib/bel_parser/language/version2_0/functions/protein_modification.rb +11 -17
  59. data/lib/bel_parser/language/version2_0/functions/rna_abundance.rb +13 -18
  60. data/lib/bel_parser/language/version2_0/functions/to_location.rb +5 -6
  61. data/lib/bel_parser/language/version2_0/functions/variant.rb +1 -4
  62. data/lib/bel_parser/language/version2_0/value_encodings/abundance.rb +21 -0
  63. data/lib/bel_parser/language/version2_0/value_encodings/activity.rb +21 -0
  64. data/lib/bel_parser/language/version2_0/value_encodings/any.rb +74 -0
  65. data/lib/bel_parser/language/version2_0/value_encodings/biological_process.rb +21 -0
  66. data/lib/bel_parser/language/version2_0/value_encodings/complex_abundance.rb +21 -0
  67. data/lib/bel_parser/language/version2_0/value_encodings/gene_abundance.rb +21 -0
  68. data/lib/bel_parser/language/version2_0/value_encodings/location.rb +21 -0
  69. data/lib/bel_parser/language/version2_0/value_encodings/micro_rna_abundance.rb +21 -0
  70. data/lib/bel_parser/language/version2_0/value_encodings/pathology.rb +21 -0
  71. data/lib/bel_parser/language/version2_0/value_encodings/protein_abundance.rb +21 -0
  72. data/lib/bel_parser/language/version2_0/value_encodings/protein_modification.rb +21 -0
  73. data/lib/bel_parser/language/version2_0/value_encodings/rna_abundance.rb +21 -0
  74. data/lib/bel_parser/language/version2_0.rb +6 -60
  75. data/lib/bel_parser/language.rb +3 -4
  76. data/lib/bel_parser/parsers/ast/node.rb +14 -2
  77. data/lib/bel_parser/{language/quoting.rb → quoting.rb} +0 -56
  78. data/lib/bel_parser/resource/concept.rb +56 -0
  79. data/lib/bel_parser/resource/concept_scheme.rb +35 -0
  80. data/lib/bel_parser/resource/dataset.rb +34 -0
  81. data/lib/bel_parser/resource/eager_reader.rb +75 -0
  82. data/lib/bel_parser/resource/eager_sparql_reader.rb +51 -0
  83. data/lib/bel_parser/resource/http_cache.rb +71 -0
  84. data/lib/bel_parser/resource/jena_tdb_reader.rb +246 -0
  85. data/lib/bel_parser/resource/lru_cache.rb +111 -0
  86. data/lib/bel_parser/resource/lru_reader.rb +38 -0
  87. data/lib/bel_parser/resource/reader.rb +18 -0
  88. data/lib/bel_parser/resource/resource_file_reader.rb +134 -0
  89. data/lib/bel_parser/resource/sparql_reader.rb +178 -0
  90. data/lib/bel_parser/resource/value.rb +31 -0
  91. metadata +42 -4
  92. data/lib/bel_parser/language/version1_0/syntax/function.rb +0 -28
@@ -0,0 +1,74 @@
1
+ require 'English'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Version1_0
6
+ module ValueEncodings
7
+ # The Any value encoding.
8
+ class Any
9
+ # Return the {Symbol} value.
10
+ #
11
+ # @note This method should be overridden in subclasses.
12
+ def self.to_sym
13
+ raise_not_implemented(__method__) if self != Any
14
+ :*
15
+ end
16
+
17
+ # Returns +true+ if I am a subtype of +other_return_type+; otherwise
18
+ # return +false+.
19
+ #
20
+ # @param [Class] other_return_type to compare to
21
+ # @return [Boolean] +true+ if I am a subtype; +false+ if not
22
+ def self.subtype_of?(other_return_type)
23
+ self <= other_return_type
24
+ end
25
+
26
+ # Retrieve my immediate subtypes.
27
+ #
28
+ # @return [Array<Class>] my immediate subtypes
29
+ def self.subtypes
30
+ (@subtypes ||= []).freeze
31
+ end
32
+
33
+ # Retrieve my transitive subtypes.
34
+ #
35
+ # @return [Array<Class>] my transitive subtypes
36
+ def self.transitive_subtypes
37
+ transitive_subtypes =
38
+ (@subtypes ||= []).flat_map do |subtype|
39
+ [subtype, subtype.subtypes]
40
+ end.flatten
41
+ transitive_subtypes << self
42
+ transitive_subtypes.freeze
43
+ end
44
+
45
+ # Inherited hook overridden to keep track of descendants. This method
46
+ # is inherited by all descendants.
47
+ #
48
+ # @param [Class] cls the subclass that is inheriting me
49
+ # @see .subtypes
50
+ def self.inherited(cls)
51
+ (@subtypes ||= []) << cls
52
+ end
53
+ private_class_method
54
+
55
+ # Raise {NotImplementedError} for +method+. Alters the exception
56
+ # backtrace to exclude this method.
57
+ #
58
+ # @param [#to_s] the method name
59
+ # @raise [NotImplementedError] for +method+
60
+ def self.raise_not_implemented(method)
61
+ msg = "#{name} must implement the #{method} method"
62
+ raise NotImplementedError, msg
63
+ rescue StandardError
64
+ raise(
65
+ $ERROR_INFO.class,
66
+ $ERROR_INFO.message,
67
+ $ERROR_INFO.backtrace[1..-1])
68
+ end
69
+ private_class_method
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version1_0'
2
+ require_relative 'any'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version1_0
7
+ module ValueEncodings
8
+ # BiologicalProcess value encoding.
9
+ class BiologicalProcess < Any
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != BiologicalProcess
15
+ :B
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version1_0'
2
+ require_relative 'abundance'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version1_0
7
+ module ValueEncodings
8
+ # ComplexAbundance value encoding.
9
+ class ComplexAbundance < Abundance
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != ComplexAbundance
15
+ :C
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version1_0'
2
+ require_relative 'abundance'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version1_0
7
+ module ValueEncodings
8
+ # GeneAbundance value encoding.
9
+ class GeneAbundance < Abundance
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != GeneAbundance
15
+ :G
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version1_0'
2
+ require_relative 'rna_abundance'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version1_0
7
+ module ValueEncodings
8
+ # Micro RNA abundance value encoding.
9
+ class MicroRNAAbundance < RNAAbundance
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != MicroRNAAbundance
15
+ :M
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version1_0'
2
+ require_relative 'biological_process'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version1_0
7
+ module ValueEncodings
8
+ # Pathology value encoding.
9
+ class Pathology < BiologicalProcess
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != Pathology
15
+ :O
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version1_0'
2
+ require_relative 'abundance'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version1_0
7
+ module ValueEncodings
8
+ # ProteinAbundance value encoding.
9
+ class ProteinAbundance < Abundance
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != ProteinAbundance
15
+ :P
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version1_0'
2
+ require_relative 'abundance'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version1_0
7
+ module ValueEncodings
8
+ # RNAAbundance value encoding.
9
+ class RNAAbundance < Abundance
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != RNAAbundance
15
+ :R
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,101 +1,20 @@
1
1
  require_relative 'function'
2
2
  require_relative 'specification'
3
+ require_relative 'base_specification'
3
4
 
4
5
  module BELParser
5
6
  module Language
6
7
  module Version1_0
7
- # Specification defines the BEL, version 1.0 specification.
8
- class Specification
9
- include BELParser::Language::Specification
8
+ # Version1_0 specification defines the BEL 1.0 specification.
9
+ class Specification < BaseSpecification
10
+ BaseSpecification.load_version_path('version1_0')
11
+
10
12
  def initialize
11
13
  @version = '1.0'.freeze
12
- load_return_types
13
- load_functions
14
- load_relationships
15
- load_syntax
14
+ load_language_constants(Version1_0)
16
15
  freeze
17
16
  end
18
-
19
- def load_return_types
20
- # Collect return types
21
- ret_classes = Version1_0::ReturnTypes.constants.collect do |symbol|
22
- const = Version1_0::ReturnTypes.const_get(symbol)
23
- const if const.respond_to?(:subtypes)
24
- end
25
- @return_types = ret_classes.compact
26
- @indexed_return_types = index_sym(@return_types)
27
- end
28
-
29
- def load_functions
30
- # Collect functions
31
- function_classes = Version1_0::Functions.constants.collect do |symbol|
32
- const = Version1_0::Functions.const_get(symbol)
33
- const if
34
- const.respond_to?(:short) &&
35
- const.respond_to?(:long)
36
- end
37
- @functions = function_classes.compact
38
- @indexed_functions = index_long_short(@functions)
39
- end
40
-
41
- def load_relationships
42
- # Collect relationships
43
- rel_classes = Version1_0::Relationships.constants.collect do |symbol|
44
- const = Version1_0::Relationships.const_get(symbol)
45
- const if
46
- const.respond_to?(:short) &&
47
- const.respond_to?(:long)
48
- end
49
- @relationships = rel_classes.compact
50
- @indexed_relationships = index_long_short(@relationships)
51
- assign_relationship_categories(@relationships)
52
- end
53
-
54
- def load_syntax
55
- # Collect syntax checkers.
56
- syntax_classes = Version1_0::Syntax.constants.collect do |symbol|
57
- const = Version1_0::Syntax.const_get(symbol)
58
- const if const.respond_to?(:match)
59
- end
60
- @syntax = syntax_classes.compact
61
- end
62
17
  end
63
18
  end
64
19
  end
65
20
  end
66
-
67
- # Require all version 1.0 return types
68
- Dir[
69
- File.join(
70
- File.dirname(File.expand_path(__FILE__)),
71
- 'version1_0', 'return_types', '*.rb')
72
- ].each do |path|
73
- require_relative "version1_0/return_types/#{File.basename(path)}"
74
- end
75
-
76
- # Require all version 1.0 functions.
77
- Dir[
78
- File.join(
79
- File.dirname(File.expand_path(__FILE__)),
80
- 'version1_0', 'functions', '*.rb')
81
- ].each do |path|
82
- require_relative "version1_0/functions/#{File.basename(path)}"
83
- end
84
-
85
- # Require all version 1.0 relationships.
86
- Dir[
87
- File.join(
88
- File.dirname(File.expand_path(__FILE__)),
89
- 'version1_0', 'relationships', '*.rb')
90
- ].each do |path|
91
- require_relative "version1_0/relationships/#{File.basename(path)}"
92
- end
93
-
94
- # Require all version 1.0 syntax checkers.
95
- Dir[
96
- File.join(
97
- File.dirname(File.expand_path(__FILE__)),
98
- 'version1_0', 'syntax', '*.rb')
99
- ].each do |path|
100
- require_relative "version1_0/syntax/#{File.basename(path)}"
101
- end
@@ -14,6 +14,7 @@ module BELParser
14
14
  SHORT = :a
15
15
  LONG = :abundance
16
16
  RETURN_TYPE = BELParser::Language::Version2_0::ReturnTypes::Abundance
17
+ A_ENC = Version2_0::ValueEncodings::Abundance
17
18
  DESCRIPTION = 'Denotes the abundance of an entity.'.freeze
18
19
 
19
20
  def self.short
@@ -51,13 +52,11 @@ module BELParser
51
52
  argument(
52
53
  parameter(
53
54
  prefix(
54
- identifier(
55
- has_namespace,
56
- namespace_of(:*))),
55
+ has_namespace,
56
+ namespace_of(:*)),
57
57
  value(
58
- value_type(
59
- has_encoding,
60
- encoding_of(:Abundance))))))
58
+ has_encoding,
59
+ encoding_of(A_ENC)))))
61
60
  end
62
61
  private_constant :AST
63
62
 
@@ -87,13 +86,11 @@ module BELParser
87
86
  argument(
88
87
  parameter(
89
88
  prefix(
90
- identifier(
91
- has_namespace,
92
- namespace_of(:*))),
89
+ has_namespace,
90
+ namespace_of(:*)),
93
91
  value(
94
- value_type(
95
- has_encoding,
96
- encoding_of(:Abundance))))),
92
+ has_encoding,
93
+ encoding_of(A_ENC)))),
97
94
  argument(
98
95
  term(
99
96
  function(
@@ -128,13 +125,11 @@ module BELParser
128
125
  argument(
129
126
  parameter(
130
127
  prefix(
131
- identifier(
132
- has_namespace,
133
- namespace_of(:*))),
128
+ has_namespace,
129
+ namespace_of(:*)),
134
130
  value(
135
- value_type(
136
- has_encoding,
137
- encoding_of(:Abundance))))),
131
+ has_encoding,
132
+ encoding_of(A_ENC)))),
138
133
  argument(
139
134
  term(
140
135
  function(
@@ -14,6 +14,7 @@ module BELParser
14
14
  SHORT = :bp
15
15
  LONG = :biologicalProcess
16
16
  RETURN_TYPE = BELParser::Language::Version2_0::ReturnTypes::BiologicalProcess
17
+ B_ENC = Version2_0::ValueEncodings::BiologicalProcess
17
18
  DESCRIPTION = 'Denotes a process or population of
18
19
  vents.'.freeze
19
20
 
@@ -52,13 +53,11 @@ module BELParser
52
53
  argument(
53
54
  parameter(
54
55
  prefix(
55
- identifier(
56
- has_namespace,
57
- namespace_of(:*))),
56
+ has_namespace,
57
+ namespace_of(:*)),
58
58
  value(
59
- value_type(
60
- has_encoding,
61
- encoding_of(:BiologicalProcess))))))
59
+ has_encoding,
60
+ encoding_of(B_ENC)))))
62
61
  end
63
62
  private_constant :AST
64
63
 
@@ -14,6 +14,7 @@ module BELParser
14
14
  SHORT = :complex
15
15
  LONG = :complexAbundance
16
16
  RETURN_TYPE = BELParser::Language::Version2_0::ReturnTypes::ComplexAbundance
17
+ C_ENC = Version2_0::ValueEncodings::ComplexAbundance
17
18
  DESCRIPTION = 'Denotes the abundance of a molecular
18
19
  omplex.'.freeze
19
20
 
@@ -52,13 +53,11 @@ module BELParser
52
53
  argument(
53
54
  parameter(
54
55
  prefix(
55
- identifier(
56
- has_namespace,
57
- namespace_of(:*))),
56
+ has_namespace,
57
+ namespace_of(:*)),
58
58
  value(
59
- value_type(
60
- has_encoding,
61
- encoding_of(:Abundance))))))
59
+ has_encoding,
60
+ encoding_of(C_ENC)))))
62
61
  end
63
62
  private_constant :AST
64
63
 
@@ -88,13 +87,11 @@ module BELParser
88
87
  argument(
89
88
  parameter(
90
89
  prefix(
91
- identifier(
92
- has_namespace,
93
- namespace_of(:*))),
90
+ has_namespace,
91
+ namespace_of(:*)),
94
92
  value(
95
- value_type(
96
- has_encoding,
97
- encoding_of(:Abundance))))),
93
+ has_encoding,
94
+ encoding_of(C_ENC)))),
98
95
  argument(
99
96
  term(
100
97
  function(
@@ -54,8 +54,7 @@ module BELParser
54
54
  parameter(
55
55
  prefix(any),
56
56
  value(
57
- value_type(
58
- is_amino_acid_range_pattern)))))
57
+ is_amino_acid_range_pattern))))
59
58
  end
60
59
  private_constant :AST
61
60
 
@@ -86,15 +85,11 @@ module BELParser
86
85
  parameter(
87
86
  prefix(any),
88
87
  value(
89
- value_type(
90
- is_amino_acid_range_pattern)))),
88
+ is_amino_acid_range_pattern))),
91
89
  argument(
92
90
  parameter(
93
- prefix(
94
- any),
95
- value(
96
- value_type(
97
- encoding_of(:*))))))
91
+ prefix(any),
92
+ value(any))))
98
93
  end
99
94
  private_constant :AST
100
95
 
@@ -15,6 +15,7 @@ module BELParser
15
15
  SHORT = :fromLoc
16
16
  LONG = :fromLocation
17
17
  RETURN_TYPE = BELParser::Language::Version2_0::ReturnTypes::FromLocation
18
+ L_ENC = Version2_0::ValueEncodings::Location
18
19
  DESCRIPTION = 'Denotes the from cellular location of the
19
20
  bundance.'.freeze
20
21
 
@@ -53,13 +54,11 @@ module BELParser
53
54
  argument(
54
55
  parameter(
55
56
  prefix(
56
- identifier(
57
- has_namespace,
58
- namespace_of(:*))),
57
+ has_namespace,
58
+ namespace_of(:*)),
59
59
  value(
60
- value_type(
61
- has_encoding,
62
- encoding_of(:Location))))))
60
+ has_encoding,
61
+ encoding_of(L_ENC)))))
63
62
  end
64
63
  private_constant :AST
65
64