Class: OpenBEL::Routes::Expressions::OrthologAdapter

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

Overview

Hash-like

Constant Summary collapse

EMPTY =
[].freeze

Instance Method Summary collapse

Constructor Details

#initialize(namespaces, species_tax_id) ⇒ OrthologAdapter

Returns a new instance of OrthologAdapter.



526
527
528
529
# File 'app/openbel/api/routes/expressions.rb', line 526

def initialize(namespaces, species_tax_id)
  @namespaces = namespaces
  @species_tax_id = species_tax_id
end

Instance Method Details

#[](key) ⇒ Object



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'app/openbel/api/routes/expressions.rb', line 531

def [](key)
  namespace, value = key

  if value.start_with?('"') && value.end_with?('"')
    value = value[1...-1]
  end

  namespace = @namespaces.find(namespace).first
  return EMPTY unless namespace
  value     = namespace.find(value).first
  return EMPTY unless value
  orthologs = value.orthologs.select { |orth|
    orth.fromSpecies == @species_tax_id
  }.to_a
  return EMPTY if orthologs.empty?

  orthologs.map! { |ortholog_value|
    [
      ortholog_value.namespace.prefix,
      ortholog_value.prefLabel
    ]
  }
  orthologs
end