Class: BELParser::Language::Version1_0::Upgrades::FusionTransformation

Inherits:
Object
  • Object
show all
Includes:
AST::Processor::Mixin, TermTransformation, Parsers::AST::Sexp
Defined in:
lib/bel_parser/language/version1_0/upgrades/fusion_transformation.rb

Constant Summary

Constants included from TermTransformation

TermTransformation::ACTIVITIES, TermTransformation::PMODTYPES

Instance Method Summary collapse

Methods included from TermTransformation

#collapse, #on_argument, #on_function, #on_nested_statement, #on_object, #on_observed_term, #on_simple_statement, #on_statement, #on_subject

Methods included from Parsers::AST::Sexp

#annotation_definition, #argument, #blank_line, build, #comment, #comment_line, #document_property, #domain, #function, #identifier, #keyword, #list, #list_item, #multi_identifier, #name, #namespace_definition, #nested_statement, #object, #observed_term, #parameter, #pattern, #prefix, #relationship, #set, #simple_statement, #statement, #string, #subject, #term, #unset, #uri, #url, #value

Methods included from AST::Processor::Mixin

#handler_missing, #process, #process_all

Instance Method Details

#fusion_node?(term_node) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bel_parser/language/version1_0/upgrades/fusion_transformation.rb', line 14

def fusion_node?(term_node)
  fusion_func = false

  fusionable_func =
    [
      'p', 'proteinAbundance',
      'r', 'rnaAbundance',
      'g', 'geneAbundance'
    ].include?(term_node.function.identifier.string_literal)
  return false unless fusionable_func

  if term_node.arguments[1] && term_node.arguments[1].child.respond_to?('function')
      ['fus', 'fusion'].include?(term_node.arguments[1].child.function.identifier.string_literal)
  else
    false
  end
end

#on_term(term_node) ⇒ Object



32
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
# File 'lib/bel_parser/language/version1_0/upgrades/fusion_transformation.rb', line 32

def on_term(term_node)
  if fusion_node?(term_node)
    fusionable_func = term_node.function.identifier.string_literal
    parameter = term_node.arguments[0].child

    first_prefix = parameter.prefix.identifier.string_literal
    first_value = parameter.value.children[0].string_literal
    parameter = term_node.arguments[1].child.arguments[0].child
    second_prefix = parameter.prefix.identifier.string_literal
    second_value = parameter.value.children[0].string_literal

    term(
      function(
        identifier(fusionable_func)),
        term(
          function(
            identifier('fus')),
          argument(
            parameter(
              prefix(
                identifier(first_prefix)),
              value(
                identifier(first_value)))),
          argument(
            parameter(
              prefix(
                identifier(second_prefix)),
              value(
                  identifier(second_value))))))
  else
    term_node.updated([process(term_node.function), term_node.arguments.map! {|arg| process(arg)}].flatten())
  end
end