Class: NDFRT

Inherits:
Object
  • Object
show all
Defined in:
lib/ndfrt.rb,
lib/ndfrt/concept.rb,
lib/ndfrt/version.rb,
lib/ndfrt/interaction.rb

Defined Under Namespace

Classes: Concept, Interaction

Constant Summary collapse

VERSION =
'0.0.2'

Instance Method Summary collapse

Constructor Details

#initializeNDFRT

Returns a new instance of NDFRT.



10
11
12
# File 'lib/ndfrt.rb', line 10

def initialize
  @nori = Nori.new(convert_tags_to: -> tag { tag.snakecase.to_sym })
end

Instance Method Details

#all_records_by_kind(kind) ⇒ Object Also known as: all_concepts_by_kind



84
85
86
87
88
# File 'lib/ndfrt.rb', line 84

def all_records_by_kind kind
  kind = kind.upcase + "_KIND"
  query = "/allconcepts?kind=#{kind}"
  data = get_response_hash query
end

#api_versionObject



14
15
16
# File 'lib/ndfrt.rb', line 14

def api_version
  get_response_hash("/version")[:version][:version_name].to_s
end

#find_by(hash) ⇒ Object



43
44
45
46
# File 'lib/ndfrt.rb', line 43

def find_by hash
  return find_by_id(hash[:type], hash[:id]) if hash.has_key? :id
  return find_by_name(hash[:name], hash[:kind]) if hash.has_key? :name
end

#find_by_id(type, id) ⇒ Object



48
49
50
51
52
# File 'lib/ndfrt.rb', line 48

def find_by_id type, id
  type = type.upcase
  query = "/idType=#{type}&idString=#{id}"
  return get_concepts query
end

#find_by_name(name, kind = nil) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/ndfrt.rb', line 54

def find_by_name name, kind = nil
  query = "/search?conceptName=#{name}"
  unless kind.nil?
    kind = kind.upcase + '_KIND'
    query += "&kindName=#{kind}"
  end
  return get_concepts query
end

#find_interacting_drugs(nui, scope = 3) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/ndfrt.rb', line 63

def find_interacting_drugs nui, scope = 3
  query = "/interaction/nui=#{nui}&scope=#{scope}"
  response = get_response_hash query
  data = response[:group_interactions][:interactions][:group_interacting_drugs][:interacting_drug]
  data = [data] unless data.is_a? Array
  return data.map { |i| NDFRT::Concept.new i[:concept] }
end

#find_interactions_between(nuis, scope = 3) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/ndfrt.rb', line 71

def find_interactions_between nuis, scope = 3
  query = "/interaction?nuis=#{nuis.join('+')}&scope=#{scope}"
  data = get_response_hash query
  return data[:full_interaction_group][:full_interaction].map do |fi|
    NDFRT::Interaction.new fi[:interaction_triple_group][:interaction_triple]
  end
end

#get_info(nui) ⇒ Object



79
80
81
82
# File 'lib/ndfrt.rb', line 79

def get_info nui
  query = "/allInfo/#{nui}"
  return OpenStruct.new get_response_hash(query)[:full_concept]
end

#possible_associationsObject



23
24
25
# File 'lib/ndfrt.rb', line 23

def possible_associations
  get_options "association"
end

#possible_kindsObject



31
32
33
# File 'lib/ndfrt.rb', line 31

def possible_kinds
  get_options("kind").map { |k| k.split('_')[0...-1].join('_').downcase }
end

#possible_options_for(type) ⇒ Object Also known as: available_options_for



18
19
20
# File 'lib/ndfrt.rb', line 18

def possible_options_for type
  get_options type.to_s.downcase
end

#possible_propertiesObject



35
36
37
# File 'lib/ndfrt.rb', line 35

def possible_properties
  get_options "property"
end

#possible_rolesObject



39
40
41
# File 'lib/ndfrt.rb', line 39

def possible_roles
  get_options "role"
end

#possible_typesObject



27
28
29
# File 'lib/ndfrt.rb', line 27

def possible_types
  get_options "type"
end