Class: SysMODB::SearchBiomodel

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/search_biomodel.rb

Instance Method Summary collapse

Constructor Details

#initializeSearchBiomodel

Returns a new instance of SearchBiomodel.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/search_biomodel.rb', line 12

def initialize
  @connection = Savon.configure do |config|
    config.log = false
    HTTPI.log = false
    config.raise_errors = false
    Savon::Client.new do
      wsdl.document = "http://www.ebi.ac.uk/biomodels-main/services/BioModelsWebServices?wsdl"
      wsdl.namespace = "http://biomodels.ebi.ac.uk"
    end
  end

end

Instance Method Details

#get_all_modelsObject



152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/search_biomodel.rb', line 152

def get_all_models
  client = connection
  response = client.request(:biom, "get_all_models") do
    soap.body = {:modelName => "?", :attributes! => {:modelName => {"xsi:type" => "xsd:string"}}}
  end
  search_results = response.to_hash[:multi_ref][:item] unless response.nil?
  if search_results.nil?
    []
  else
    search_results
  end
end

#get_model_name_by_id(search_string) ⇒ Object

more used for testing



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/search_biomodel.rb', line 139

def get_model_name_by_id (search_string)
  client = connection
  response = client.request(:biom, "get_model_name_by_id") do
    soap.body = {:id => search_string, :attributes! => {:id => {"xsi:type" => "xsd:string"}}}
  end
  search_results = response.to_hash[:get_model_name_by_id_response][:get_model_name_by_id_return]
  if search_results.nil? || search_results.include?('is an invalid Model ID.')
    []
  else
    search_results
  end
end

#getModel(model_id) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/search_biomodel.rb', line 55

def getModel(model_id)
  client = connection
  response = client.request(:biom, "get_model_by_id") do
    soap.body = {:id => model_id, :attributes! => {:id => {"xsi:type" => "xsd:string"}}}
  end

  search_results = response.to_hash[:get_model_by_id_response][:get_model_by_id_return] unless response.nil?
  if search_results.nil?
    []
  else
    search_results
  end
end

#getSimpleModel(model_id) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/search_biomodel.rb', line 71

def getSimpleModel(model_id)
  client = connection
  response = client.request(:biom, "get_simple_model_by_id") do
    soap.body = {:id => model_id, :attributes! => {:id => {"xsi:type" => "xsd:string"}}}
  end

  if !response.nil?
   begin 
     search_results = response.to_hash[:get_simple_model_by_id_response][:get_simple_model_by_id_return]
   rescue
     return []
   end
  end
  if search_results.nil?
    return []
  else
    return search_results
  end
end

#models(search_string) ⇒ Object



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
# File 'lib/search_biomodel.rb', line 26

def models(search_string)
  #collect results from sub-methods
  results = Array.new
  results << @connection.search_by_name(search_string)
  results << @connection.search_by_chebiid(search_string)
  results << @connection.search_by_person(search_string)

  #turn into one big array, remove duplicates and select first X
  results = results.flatten
  results = results.uniq
  results = results.first(10)

  sbml_results = Array.new

  results.each_with_index do |a, i| 
     if !a.nil?
      sbml_results[i] = Hash.new 
      begin
        sbml_results[i] = Nori.parse(@connection.getSimpleModel(a))[:simple_models][:simple_model] 
      rescue
        sbml_results[i] = nil
      end
     end
  end
  sbml_results
end

#search_by_chebiid(search_string) ⇒ Object

search_by_chebiid search_by_name search_by_person



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/search_biomodel.rb', line 95

def search_by_chebiid(search_string)
  client = connection
  response = client.request(:biom, "get_models_id_by_ch_ebi_id") do
    soap.body = {:ChEBBId => search_string, :attributes! => {:ChEBBId => {"xsi:type" => "xsd:string"}}}
  end

  search_results = response.to_hash[:get_models_id_by_ch_ebi_id_response][:get_models_id_by_ch_ebi_id_return][:get_models_id_by_ch_ebi_id_return] unless response.nil?
  if search_results.nil?
    []
  else
    search_results
  end
end

#search_by_name(search_string) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/search_biomodel.rb', line 110

def search_by_name (search_string)
  client = connection
  response = client.request(:biom, "get_models_id_by_name") do
    soap.body = {:modelName => search_string, :attributes! => {:modelName => {"xsi:type" => "xsd:string"}}}
  end
  search_results = response.to_hash[:get_models_id_by_name_response][:get_models_id_by_name_return][:get_models_id_by_name_return]
  if search_results.nil?
    []
  else
    search_results
  end
end

#search_by_person(search_string) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/search_biomodel.rb', line 123

def search_by_person (search_string)
  client = connection
  response = client.request(:biom, "get_models_id_by_person") do
    soap.body = {:personName => search_string, :attributes! => {:personName => {"xsi:type" => "xsd:string"}}}
  end
  search_results = response.to_hash[:get_models_id_by_person_response][:get_models_id_by_person_return][:get_models_id_by_person_return]
  if search_results.nil?
    []
  else
    search_results
  end
end