bel_parser 1.0.0.alpha.9 → 1.0.0.alpha.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ec7298783e8859243fb8ba8ca8f5a317ce76066
4
- data.tar.gz: ae09c0ccf3a4ad7edad1288aa2b557dfc8496f60
3
+ metadata.gz: 56e97fd6f3c7806fa34aea964a08dbceb7c03d91
4
+ data.tar.gz: 79712252a5ee0abbb4c92ccbfe1291b3e5dd657a
5
5
  SHA512:
6
- metadata.gz: 6fce1307bbce3fe4bcf5047a045f2a1b1a98fb92c8b0f1ece305189736f26847f18e238059ae07ccb690bcc703cd45d0e0f4b6b717072d9020c46b788ce9e623
7
- data.tar.gz: 98f2a8f16b931302f508a5259a56345cc22e81fd017ffb1233e61aacbe4c4a180204a6e6e1b9e9db30a978e20e9d274782093e111577f6e4b0222509dfbe534e
6
+ metadata.gz: 90cd6d95eb8a80079dda7d53f99e0a883390ab1a7a40125de67a397c91bf453778a5f31ac7c9b018fd299c798eb3d82e7c24299fba6f233a75048a3a86f9b86b
7
+ data.tar.gz: 7cdb7c9cc960b319e960bebeea568c74742434b6831d73b27f9a648e6684476611521863018693c17f7bce8ddc55ba86a75c4e2eaae26ad3303ccb04c9fcdd21
data/.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  'Anthony Bargnesi',
12
12
  'Nick Bargnesi',
13
13
  ]
14
- spec.date = %q{2016-04-13}
14
+ spec.date = %q{2016-04-14}
15
15
  spec.email = %q{abargnesi@selventa.com}
16
16
  spec.files = [
17
17
  Dir.glob('lib/**/*.{rb,rl}'),
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.9
1
+ 1.0.0.alpha.10
@@ -0,0 +1,68 @@
1
+ module BELParser
2
+ module Language
3
+ # AminoAcid defines a controlled vocabulary of twenty Amino Acids that are
4
+ # encoded by the universal genetic code. It does not contain the additional
5
+ # Amino Acids incorporated into proteins by synthetic means.
6
+ #
7
+ # see https://en.wikipedia.org/wiki/Amino_acid
8
+ module AminoAcid
9
+ Alanine = [:Alanine, :A, :Ala].freeze
10
+ Arginine = [:Arginine, :R, :Arg].freeze
11
+ Asparagine = [:Asparagine, :N, :Asn].freeze
12
+ AsparticAcid = [:'Aspartic Acid', :D, :Asp].freeze
13
+ Cysteine = [:Cysteine, :C, :Cys].freeze
14
+ GlutamicAcid = [:'Glutamic Acid', :E, :Glu].freeze
15
+ Glutamine = [:Glutamine, :Q, :Gln].freeze
16
+ Glycine = [:Glycine, :G, :Gly].freeze
17
+ Histidine = [:Histidine, :H, :His].freeze
18
+ Isoleucine = [:Isoleucine, :I, :Ile].freeze
19
+ Leucine = [:Leucine, :L, :Leu].freeze
20
+ Lysine = [:Lysine, :K, :Lys].freeze
21
+ Methionine = [:Methionine, :M, :Met].freeze
22
+ Phenylalanine = [:Phenylalanine, :F, :Phe].freeze
23
+ Proline = [:Proline, :P, :Pro].freeze
24
+ Serine = [:Serine, :S, :Ser].freeze
25
+ Threonine = [:Threonine, :T, :Thr].freeze
26
+ Tryptophan = [:Tryptophan, :W, :Trp].freeze
27
+ Tyrosine = [:Tyrosine, :Y, :Tyr].freeze
28
+ Valine = [:Valine, :V, :Val].freeze
29
+
30
+ # Determines if +sym+ represents an amino acid code.
31
+ #
32
+ # @param [#to_sym] sym amino acid code
33
+ # @return [Boolean] +true+ if +sym+ amino acid code is included in
34
+ # supported amino acids; +false+ if not supported
35
+ def self.includes?(sym)
36
+ @hash.key?(sym.to_sym)
37
+ end
38
+
39
+ # Gets all supported amino acid names.
40
+ def self.names
41
+ @names
42
+ end
43
+
44
+ # Gets all supported amino acid codes (i.e. name, 1-Letter, 3-Letter).
45
+ def self.values
46
+ @values
47
+ end
48
+
49
+ unless defined? @hash
50
+ @hash = {}
51
+ constants.map(&method(:const_get)).each do |values|
52
+ @hash.update(
53
+ Hash[values.map { |v| [v, values.first] }]
54
+ )
55
+ end
56
+ @hash.freeze
57
+ end
58
+
59
+ unless defined? @names
60
+ @names = constants.map(&method(:const_get)).map(&:first).sort.freeze
61
+ end
62
+
63
+ unless defined? @values
64
+ @values = constants.map(&method(:const_get)).map(&:to_a).flatten.freeze
65
+ end
66
+ end
67
+ end
68
+ end
@@ -3,6 +3,10 @@ require 'bel_parser/parsers/ast/node'
3
3
  module BELParser
4
4
  module Language
5
5
  module Semantics
6
+ # FunctionDeprecation implements a {SemanticsFunction} that maps a
7
+ # {BELParser::Parsers::AST::Function} to a {SemanticsWarning} if the
8
+ # referenced function is deprecated for the
9
+ # {BELParser::Language::Specification}.
6
10
  class FunctionDeprecation
7
11
  include SemanticsFunction
8
12
 
@@ -19,6 +23,9 @@ module BELParser
19
23
  end
20
24
  end
21
25
 
26
+ # Represents a {SemanticsWarning} when a
27
+ # {BELParser::Parsers::AST::Function} references a deprecated function
28
+ # for the {BELParser::Language::Specification}.
22
29
  class FunctionDeprecationWarning < SemanticsWarning
23
30
  attr_reader :deprecated_function
24
31
 
@@ -28,7 +35,7 @@ module BELParser
28
35
  end
29
36
 
30
37
  def to_s
31
- %Q{Function "#{deprecated_function}" is deprecated.}
38
+ %(Function "#{deprecated_function}" is deprecated.)
32
39
  end
33
40
  end
34
41
  end
@@ -0,0 +1,55 @@
1
+ require 'bel_parser/parsers/ast/node'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Semantics
6
+ # MultipleSubjectObject implements a {SemanticsFunction} that maps a
7
+ # {BELParser::Parsers::AST::Statement} to a {SemanticsWarning} if the
8
+ # subject term is referenced as an argument of the object list term.
9
+ class MultipleSubjectObject
10
+ include SemanticsFunction
11
+
12
+ private_class_method :new
13
+
14
+ def self.map(stmt_node, spec, _namespaces)
15
+ return nil unless stmt_node.is_a?(BELParser::Parsers::AST::Statement)
16
+ return nil unless stmt_node.relationship?
17
+ rel = spec.relationship(stmt_node.relationship.string_literal.to_sym)
18
+ return nil unless rel.listable?
19
+
20
+ list_func = spec.function(:list)
21
+ return nil unless list_func
22
+ return nil unless stmt_node.object.term?
23
+
24
+ map_subject_object(stmt_node, rel, spec)
25
+ end
26
+
27
+ def self.map_subject_object(stmt_node, rel, spec)
28
+ sub_term = stmt_node.subject.term
29
+ list_term = stmt_node.object.child
30
+
31
+ if list_term.arguments.any? { |arg| sub_term == arg.child }
32
+ MultipleSubjectObjectWarning.new(stmt_node, spec, rel)
33
+ end
34
+ end
35
+ end
36
+
37
+ # Represents a {SemanticsWarning} when a
38
+ # {BELParser::Parsers::AST::Statement} includes the subject term as an
39
+ # argument of an object list term.
40
+ class MultipleSubjectObjectWarning < SemanticsWarning
41
+ def initialize(stmt_node, spec, rel)
42
+ super(stmt_node, spec)
43
+ @rel = rel
44
+ end
45
+
46
+ def to_s
47
+ <<-MSG.gsub(/ {12}/, '').gsub(/\n/, '')
48
+ A "#{@rel.long}" statement cannot use the subject term as an
49
+ object list() argument.
50
+ MSG
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -44,11 +44,6 @@ module BELParser
44
44
  Causal Relationships: #{causal_relationships}
45
45
  MSG
46
46
  end
47
-
48
- private
49
-
50
- def causal_relationships
51
- end
52
47
  end
53
48
  end
54
49
  end
@@ -0,0 +1,56 @@
1
+ require 'bel_parser/parsers/ast/node'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Semantics
6
+ # NonObjectList implements a {SemanticsFunction} that maps a
7
+ # {BELParser::Parsers::AST::Object} to a {SemanticsWarning} if the
8
+ # object of a multiple relationship *is not* a list term.
9
+ class NonObjectList
10
+ include SemanticsFunction
11
+
12
+ private_class_method :new
13
+
14
+ def self.map(stmt_node, spec, _namespaces)
15
+ return nil unless stmt_node.is_a?(BELParser::Parsers::AST::Statement)
16
+ return nil unless stmt_node.relationship?
17
+
18
+ list_func = spec.function(:list)
19
+ return nil unless list_func
20
+
21
+ rel = spec.relationship(stmt_node.relationship.string_literal.to_sym)
22
+ return nil unless rel.listable?
23
+
24
+ map_object(stmt_node.object, rel, list_func, spec)
25
+ end
26
+
27
+ def self.map_object(obj_node, rel, list_func, spec)
28
+ return NonObjectListWarning.new(
29
+ obj_node,
30
+ spec,
31
+ rel) unless obj_node.term?
32
+
33
+ obj_func = obj_node.child.function.identifier.string_literal
34
+ NonObjectListWarning.new(
35
+ obj_node,
36
+ spec,
37
+ rel) unless spec.function(obj_func.to_sym) == list_func
38
+ end
39
+ end
40
+
41
+ # Represents a {SemanticsWarning} when a
42
+ # multiple relationship {BELParser::Parsers::AST::Statement} does not
43
+ # reference an object list term.
44
+ class NonObjectListWarning < SemanticsWarning
45
+ def initialize(statement_node, spec, rel)
46
+ super(statement_node, spec)
47
+ @rel = rel
48
+ end
49
+
50
+ def to_s
51
+ %(The "#{@rel.long}" relationship must take a list() object term.)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -3,6 +3,10 @@ require 'bel_parser/parsers/ast/node'
3
3
  module BELParser
4
4
  module Language
5
5
  module Semantics
6
+ # RelationshipDeprecation implements a {SemanticsFunction} that maps a
7
+ # {BELParser::Parsers::AST::Relationship} to a {SemanticsWarning} if the
8
+ # referenced relationship is deprecated for the
9
+ # {BELParser::Language::Specification}.
6
10
  class RelationshipDeprecation
7
11
  include SemanticsFunction
8
12
 
@@ -19,6 +23,9 @@ module BELParser
19
23
  end
20
24
  end
21
25
 
26
+ # Represents a {SemanticsWarning} when a
27
+ # {BELParser::Parsers::AST::Relationship} references a deprecated
28
+ # relationship for the {BELParser::Language::Specification}.
22
29
  class RelationshipDeprecationWarning < SemanticsWarning
23
30
  attr_reader :deprecated_relationship
24
31
 
@@ -28,7 +35,7 @@ module BELParser
28
35
  end
29
36
 
30
37
  def to_s
31
- %Q{Relationship "#{deprecated_relationship}" is deprecated.}
38
+ %(Relationship "#{deprecated_relationship}" is deprecated.)
32
39
  end
33
40
  end
34
41
  end
@@ -0,0 +1,60 @@
1
+ require 'bel_parser/parsers/ast/node'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Semantics
6
+ # RelationshipNotListable implements a {SemanticsFunction} that maps a
7
+ # {BELParser::Parsers::AST::Statement} to a {SemanticsWarning} if the
8
+ # relationship cannot be used for multiple terms in a list.
9
+ class RelationshipNotListable
10
+ include SemanticsFunction
11
+
12
+ private_class_method :new
13
+
14
+ def self.map(node, spec, _namespaces)
15
+ return nil unless node.is_a?(BELParser::Parsers::AST::Statement)
16
+ return nil unless node.relationship?
17
+ return nil unless node.object.term?
18
+
19
+ map_statement(node, spec)
20
+ end
21
+
22
+ def self.map_statement(stmt_node, spec)
23
+ list_func = spec.function(:list)
24
+ return nil unless list_func
25
+
26
+ obj_func = stmt_node.object.child.function.identifier.string_literal
27
+ return nil unless spec.function(obj_func.to_sym) == list_func
28
+
29
+ rel = spec.relationship(stmt_node.relationship.string_literal.to_sym)
30
+ return nil unless rel
31
+
32
+ RelationshipNotMultipleWarning.new(stmt_node, spec, rel) unless
33
+ rel.listable?
34
+ end
35
+ end
36
+
37
+ # Represents a {SemanticsWarning} when a statement has a relationship
38
+ # that cannot reference multiple objects.
39
+ class RelationshipNotMultipleWarning < SemanticsWarning
40
+ def initialize(statement_node, spec, rel)
41
+ super(statement_node, spec)
42
+ @rel = rel
43
+ end
44
+
45
+ def to_s
46
+ multiple_relationships =
47
+ @specification
48
+ .listable_relationships
49
+ .map(&:long)
50
+ .join(', ')
51
+ <<-MSG.gsub(/ {12}/, '').strip
52
+ Statement must use a multiple relationship with a list object.
53
+ The "#{@rel.long}" relationship cannot reference multiple objects.
54
+ Multiple Relationships: #{multiple_relationships}
55
+ MSG
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -210,8 +210,33 @@ module BELParser
210
210
  super(:term, children, properties)
211
211
  end
212
212
 
213
+ def function
214
+ children[0]
215
+ end
216
+
217
+ def variadic_arguments?
218
+ children[1].type == :variadic_arguments
219
+ end
220
+
221
+ def arguments
222
+ children[1..-1]
223
+ end
224
+
213
225
  def match(parse_node, _)
214
- type == parse_node.type ? success(parse_node) : failure(parse_node)
226
+ return failure(nil) if parse_node.nil?
227
+ return failure(parse_node) unless parse_node.type == type
228
+
229
+ # Return success if semantic AST does not supply argument patterns.
230
+ if arguments.empty? || variadic_arguments?
231
+ success(parse_node)
232
+ else
233
+ # Otherwise, check argument length.
234
+ if arguments.length == parse_node.arguments.length
235
+ success(parse_node)
236
+ else
237
+ failure(parse_node)
238
+ end
239
+ end
215
240
  end
216
241
  end
217
242
 
@@ -1,6 +1,7 @@
1
1
  require_relative '../../version1_0'
2
2
  require_relative '../../function'
3
3
  require_relative '../../signature'
4
+ require_relative '../../amino_acid'
4
5
  require_relative '../../semantics'
5
6
 
6
7
  module BELParser
@@ -63,7 +64,7 @@ module BELParser
63
64
  any),
64
65
  value(
65
66
  value_type(
66
- encoding_of(:*))))),
67
+ amino_acid_of(*AminoAcid.values))))),
67
68
  argument(
68
69
  parameter(
69
70
  prefix(
@@ -74,7 +75,9 @@ module BELParser
74
75
  end
75
76
  private_constant :AST
76
77
 
77
- STRING_FORM = 'proteinModification(E:*,E:*,E:*)proteinModification'.freeze
78
+ STRING_FORM =
79
+ 'proteinModification(E:*,T:AminoAcid,E:*)proteinModification'
80
+ .freeze
78
81
  private_constant :STRING_FORM
79
82
 
80
83
  def self.semantic_ast
@@ -110,11 +113,13 @@ module BELParser
110
113
  any),
111
114
  value(
112
115
  value_type(
113
- encoding_of(:*))))))
116
+ amino_acid_of(*AminoAcid.values))))))
114
117
  end
115
118
  private_constant :AST
116
119
 
117
- STRING_FORM = 'proteinModification(E:*,E:*)proteinModification'.freeze
120
+ STRING_FORM =
121
+ 'proteinModification(E:*,T:AminoAcid)proteinModification'
122
+ .freeze
118
123
  private_constant :STRING_FORM
119
124
 
120
125
  def self.semantic_ast
@@ -56,7 +56,7 @@ module BELParser
56
56
  any),
57
57
  value(
58
58
  value_type(
59
- encoding_of(:*))))),
59
+ amino_acid_of(*AminoAcid.values))))),
60
60
  argument(
61
61
  parameter(
62
62
  prefix(
@@ -70,11 +70,12 @@ module BELParser
70
70
  any),
71
71
  value(
72
72
  value_type(
73
- encoding_of(:*))))))
73
+ amino_acid_of(*AminoAcid.values))))))
74
74
  end
75
75
  private_constant :AST
76
76
 
77
- STRING_FORM = 'substitution(E:*,E:*,E:*)substitution'.freeze
77
+ STRING_FORM =
78
+ 'substitution(T:AminoAcid,E:*,T:AminoAcid)substitution'.freeze
78
79
  private_constant :STRING_FORM
79
80
 
80
81
  def self.semantic_ast
@@ -1,6 +1,7 @@
1
1
  require_relative '../../version2_0'
2
2
  require_relative '../../function'
3
3
  require_relative '../../signature'
4
+ require_relative '../../amino_acid'
4
5
  require_relative '../../semantics'
5
6
 
6
7
  module BELParser
@@ -14,7 +15,8 @@ module BELParser
14
15
 
15
16
  SHORT = :pmod
16
17
  LONG = :proteinModification
17
- RETURN_TYPE = BELParser::Language::Version2_0::ReturnTypes::ProteinModification
18
+ RETURN_TYPE =
19
+ BELParser::Language::Version2_0::ReturnTypes::ProteinModification
18
20
  DESCRIPTION = 'Denotes a covalently modified protein
19
21
  bundance'.freeze
20
22
 
@@ -61,7 +63,9 @@ module BELParser
61
63
  end
62
64
  private_constant :AST
63
65
 
64
- STRING_FORM = 'proteinModification(E:modificationType)proteinModification'.freeze
66
+ STRING_FORM =
67
+ 'proteinModification(E:modificationType)proteinModification'
68
+ .freeze
65
69
  private_constant :STRING_FORM
66
70
 
67
71
  def self.semantic_ast
@@ -97,11 +101,13 @@ module BELParser
97
101
  prefix(any),
98
102
  value(
99
103
  value_type(
100
- encoding_of(:*))))))
104
+ amino_acid_of(*AminoAcid.values))))))
101
105
  end
102
106
  private_constant :AST
103
107
 
104
- STRING_FORM = 'proteinModification(E:modificationType,E:*)proteinModification'.freeze
108
+ STRING_FORM =
109
+ 'proteinModification(E:modificationType,T:AminoAcid)proteinModification'
110
+ .freeze
105
111
  private_constant :STRING_FORM
106
112
 
107
113
  def self.semantic_ast
@@ -137,7 +143,7 @@ module BELParser
137
143
  prefix(any),
138
144
  value(
139
145
  value_type(
140
- encoding_of(:*))))),
146
+ amino_acid_of(*AminoAcid.values))))),
141
147
  argument(
142
148
  parameter(
143
149
  prefix(any),
@@ -147,7 +153,9 @@ module BELParser
147
153
  end
148
154
  private_constant :AST
149
155
 
150
- STRING_FORM = 'proteinModification(E:modificationType,E:*,E:*)proteinModification'.freeze
156
+ STRING_FORM =
157
+ 'proteinModification(E:modificationType,T:AminoAcid,E:*)proteinModification'
158
+ .freeze
151
159
  private_constant :STRING_FORM
152
160
 
153
161
  def self.semantic_ast
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bel_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.9
4
+ version: 1.0.0.alpha.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Bargnesi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-13 00:00:00.000000000 Z
12
+ date: 2016-04-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Implements language versions 1.0 and 2.0.
15
15
  email: abargnesi@selventa.com
@@ -30,6 +30,7 @@ files:
30
30
  - lib/bel_parser/expression/parser.rb
31
31
  - lib/bel_parser/expression/validator.rb
32
32
  - lib/bel_parser/language.rb
33
+ - lib/bel_parser/language/amino_acid.rb
33
34
  - lib/bel_parser/language/expression_validator.rb
34
35
  - lib/bel_parser/language/function.rb
35
36
  - lib/bel_parser/language/quoting.rb
@@ -38,8 +39,11 @@ files:
38
39
  - lib/bel_parser/language/semantics/deeply_nested_statement.rb
39
40
  - lib/bel_parser/language/semantics/function_deprecation.rb
40
41
  - lib/bel_parser/language/semantics/list_function_subject.rb
42
+ - lib/bel_parser/language/semantics/multiple_subject_object.rb
41
43
  - lib/bel_parser/language/semantics/non_causal_nested_statement.rb
44
+ - lib/bel_parser/language/semantics/non_object_list.rb
42
45
  - lib/bel_parser/language/semantics/relationship_deprecation.rb
46
+ - lib/bel_parser/language/semantics/relationship_not_listable.rb
43
47
  - lib/bel_parser/language/semantics/signature_mapping.rb
44
48
  - lib/bel_parser/language/semantics_ast.rb
45
49
  - lib/bel_parser/language/semantics_function.rb