Class: OpenBEL::Routes::Expressions::ParameterOrthologTransform

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

Constant Summary collapse

NAMESPACE_PREFERENCE =
[
  "hgnc",
  "mgi",
  "rgd",
  "gocc",
  "scomp",
  "meshcs",
  "sfam",
  "gobp",
  "meshpp",
  "chebi",
  "schem",
  "do",
  "meshd",
  "sdis",
  "sp",
  "affx",
  "egid",
]

Instance Method Summary collapse

Constructor Details

#initialize(namespaces, annotations, species_tax_id) ⇒ ParameterOrthologTransform

Returns a new instance of ParameterOrthologTransform.



367
368
369
370
371
372
373
374
# File 'app/openbel/api/routes/expressions.rb', line 367

def initialize(namespaces, annotations, species_tax_id)
  @namespaces = namespaces
  @orthology = OrthologAdapter.new(
    namespaces, species_tax_id
  )
  @species_tax_id = species_tax_id
  @parameter_errors = []
end

Instance Method Details

#call(ast_node) ⇒ Object



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'app/openbel/api/routes/expressions.rb', line 380

def call(ast_node)
  if ast_node.is_a?(BelAstNodeToken) &&
      ast_node.token_type == :BEL_TOKEN_NV

    ns_value = [
      ast_node.left.to_typed_node.value,
      ast_node.right.to_typed_node.value
    ]
    orthologs = @orthology[ns_value]
    if !orthologs.empty?
      orthologs.sort_by! { |ortholog| namespace_preference(ortholog) }
      ortholog = orthologs.first
      BEL::LibBEL::bel_free_ast_node(ast_node.left.pointer)
      ast_node.left  = BelAstNode.new(
        bel_new_ast_node_value(:BEL_VALUE_PFX, ortholog[0].upcase)
      )

      BEL::LibBEL::bel_free_ast_node(ast_node.right.pointer)
      ast_node.right = BelAstNode.new(
        bel_new_ast_node_value(:BEL_VALUE_VAL, ortholog[1])
      )
    else
      # flag as ortholog error if this parameter has a namespace and
      # the namespace value is either not known or its species differs
      # from our target
      if ns_value[0] != nil
        namespace, value = ns_value
        namespace        = @namespaces.find(namespace).first
        if namespace
          value = namespace.find(value).first
          if !value || value.fromSpecies != @species_tax_id
            @parameter_errors << value
          end
        end
      end
    end
  end
end

#parameter_errorsObject



376
377
378
# File 'app/openbel/api/routes/expressions.rb', line 376

def parameter_errors
  @parameter_errors.uniq
end