Class: OpenBEL::Routes::Expressions::SequenceVariationFunctionHasLocationPredicate

Inherits:
Object
  • Object
show all
Includes:
BEL::LibBEL
Defined in:
app/openbel/api/routes/expressions.rb

Constant Summary collapse

SEQUENCE_VARIATION_FX =
[
  'fus', 'fusion',
  'pmod', 'proteinModification',
  'sub', 'substitution',
  'trunc', 'truncation'
]

Instance Method Summary collapse

Instance Method Details

#call(ast_node) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'app/openbel/api/routes/expressions.rb', line 300

def call(ast_node)
  # check if AST node is a TERM
  if !ast_node.is_a?(BelAstNodeToken) || ast_node.token_type != :BEL_TOKEN_TERM
    return false
  end

  # check if AST node is a pmod TERM
  if !SEQUENCE_VARIATION_FX.include?(ast_node.left.to_typed_node.value)
    return false
  end

  # walk arg AST nodes until terminal
  arg_node = ast_node.right.to_typed_node
  while !(arg_node.left.pointer.null? && arg_node.right.pointer.null?)
    # check if NV token child
    arg_token = arg_node.left.to_typed_node

    if arg_token.token_type == :BEL_TOKEN_NV
      # true if namespace value is an integer
      node_value = arg_token.right.to_typed_node.value
      if integer?(node_value)
        return true
      end
    end

    # advance to the next ARG
    arg_node = arg_node.right.to_typed_node
  end

  return false
end