Class: BELParser::Language::Version1_0::Upgrades::VariationTransformation

Inherits:
Object
  • Object
show all
Includes:
AST::Processor::Mixin, TermTransformation, Parsers::AST::Sexp
Defined in:
lib/bel_parser/language/version1_0/upgrades/variation_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

#dna_sub_conversion(parent_func, param_prefix, param_value, ref, loc, alt) ⇒ Object

and RNA



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/bel_parser/language/version1_0/upgrades/variation_transformation.rb', line 83

def dna_sub_conversion(parent_func, param_prefix, param_value, ref, loc, alt)  # and RNA
  converted_parent_func =
    case parent_func
    when 'p', 'proteinAbundance'
      'p'
    when 'g', 'geneAbundance'
      'c'
    when 'r', 'rnaAbundance'
      'r'
    end

  term(
    function(
      identifier(parent_func)),
    argument(
      parameter(
        prefix(
          identifier(param_prefix)),
        value(
          identifier(param_value)))),
    argument(
      term(
        function(
          identifier('var')),
        argument(
          parameter(
            value(
              identifier(%("#{converted_parent_func}.#{loc}#{ref}>#{alt}"))))))))
end

#dna_trunc_conversion(parent_func, param_prefix, param_value, loc) ⇒ Object

and RNA



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/bel_parser/language/version1_0/upgrades/variation_transformation.rb', line 133

def dna_trunc_conversion(parent_func, param_prefix, param_value, loc)  # and RNA
  converted_parent_func =
    case parent_func
    when 'p', 'proteinAbundance'
      'p'
    when 'g', 'geneAbundance'
      'c'
    when 'r', 'rnaAbundance'
      'r'
    end

  term(
    function(
      identifier(parent_func)),
    argument(
      parameter(
        prefix(
          identifier(param_prefix)),
        value(
          identifier(param_value)))),
    argument(
      term(
        function(
          identifier('var')),
        argument(
          parameter(
            value(
              identifier(%("#{converted_parent_func}.#{loc}*"))))))))
end

#on_term(term_node) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
# File 'lib/bel_parser/language/version1_0/upgrades/variation_transformation.rb', line 14

def on_term(term_node)
  is_parent_func = ['p', 'proteinAbundance', 'r', 'rnaAbundance', 'g', 'geneAbundance'].include?(term_node.function.identifier.string_literal)
  parent_func    = term_node.function.identifier.string_literal

  unless is_parent_func
    return term_node.updated([process(term_node.function), term_node.arguments.map! {|arg| process(arg)}].flatten())
  end

  if term_node.arguments[0].parameter?
    param_prefix = term_node.arguments[0].child.prefix.identifier.string_literal
    param_value  = term_node.arguments[0].child.value.children[0].string_literal
  end

  if term_node.arguments[1].respond_to?('child') && term_node.arguments[1].child.respond_to?('function') && term_node.arguments[1].child.function
    is_sub_func = ['sub', 'substitution'].include?(term_node.arguments[1].child.function.identifier.string_literal)
    is_trunc_func = ['trunc', 'truncation'].include?(term_node.arguments[1].child.function.identifier.string_literal)
  end

  if is_sub_func || is_trunc_func
    if is_parent_func && is_sub_func
      variant_node = term_node.arguments[1].child
      ref = variant_node.arguments[0].child.value.children[0].string_literal
      loc = variant_node.arguments[1].child.value.children[0].string_literal
      alt = variant_node.arguments[2].child.value.children[0].string_literal

      if ['p'].include?(parent_func)
        return protein_sub_conversion(parent_func, param_prefix, param_value, ref, loc, alt)
      else
        return dna_sub_conversion(parent_func, param_prefix, param_value, ref, loc, alt)
      end
    end

    if is_parent_func && is_trunc_func

      variant_node = term_node.arguments[1].child
      loc = variant_node.arguments[0].child.value.children[0].string_literal

      if ['p'].include?(parent_func)
        return protein_trunc_conversion(parent_func, param_prefix, param_value, loc)
      else
        return dna_trunc_conversion(parent_func, param_prefix, param_value, loc)
      end

    end
  else
    term_node.updated([process(term_node.function), term_node.arguments.map! {|arg| process(arg)}].flatten())
  end
end

#protein_sub_conversion(parent_func, param_prefix, param_value, ref, loc, alt) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bel_parser/language/version1_0/upgrades/variation_transformation.rb', line 63

def protein_sub_conversion(parent_func, param_prefix, param_value, ref, loc, alt)
  term(
    function(
      identifier(parent_func)),
    argument(
      parameter(
        prefix(
          identifier(param_prefix)),
        value(
          identifier(param_value)))),
    argument(
      term(
        function(
          identifier('var')),
        argument(
          parameter(
            value(
              identifier(%("#{parent_func}.#{ref}#{loc}#{alt}"))))))))
end

#protein_trunc_conversion(parent_func, param_prefix, param_value, loc) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/bel_parser/language/version1_0/upgrades/variation_transformation.rb', line 113

def protein_trunc_conversion(parent_func, param_prefix, param_value, loc)
  term(
    function(
      identifier(parent_func)),
    argument(
      parameter(
        prefix(
          identifier(param_prefix)),
        value(
          identifier(param_value)))),
    argument(
      term(
        function(
          identifier('var')),
        argument(
          parameter(
            value(
              identifier(%("#{parent_func}.#{loc}*"))))))))
end