summaryrefslogtreecommitdiff
path: root/test/toxbank-investigation-sparql.rb
blob: c335083318344bff5fab8efa0f33550c0d5f955a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
require_relative "toxbank-setup.rb"

# Test API extension SPARQL templates 
class TBSPARQLTest < MiniTest::Test

  def self.test_order
    :sorted
  end

  # login as pi and create a test investigation
  def test_00_create_investigation
    OpenTox::RestClientWrapper.subjectid = $pi[:subjectid] # set pi as the logged in user
    @@uri = ""
    file = File.join File.dirname(__FILE__), "data/toxbank-investigation/valid", "BII-I-1-tb2_ftp.zip"
    response = OpenTox::RestClientWrapper.post $investigation[:uri], {:file => File.open(file)}, { :subjectid => $pi[:subjectid] }
    task_uri = response.chomp
    task = OpenTox::Task.new task_uri
    task.wait
    uri = task.resultURI
    assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
    @@uri = URI(uri)
    OpenTox::RestClientWrapper.put @@uri.to_s, { :published => "true", :summarySearchable => "true"}, { :subjectid => $pi[:subjectid] }
  end  

  # initial tests to be changed
  def test_01_nonexisting_template
    assert_raises OpenTox::ResourceNotFoundError do
      response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/not_existing_template", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    end
  end

  def test_02_existing_template
    response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/investigation_details", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    assert_equal 200, response.code
  end

  def test_03_camelcase_template
    response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/InvestigationDetails", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    assert_equal 200, response.code
  end

  # Retrieves all factors (name, value, ontology URI of the value) given an investigation URI
  def test_04_factors_by_investigation
    response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/factors_by_investigation", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    headvars = result["head"]["vars"]
    assert headvars.include?("factorname")
    assert headvars.include?("value")
    assert headvars.include?("ontouri")
    assert headvars.include?("unitOnto")
    assert headvars.include?("unit")
    assert headvars.include?("unitID")
    factorvalues = result["results"]["bindings"].map {|n|  "#{n["factorname"]["value"]}:::#{n["value"]["value"]}"}
    assert factorvalues.include?("limiting nutrient:::phosphorus")
    assert factorvalues.include?("limiting nutrient:::glucose")
    assert factorvalues.include?("limiting nutrient:::carbon")
    assert factorvalues.include?("limiting nutrient:::sulfur")
    assert factorvalues.include?("limiting nutrient:::nitrogen")
    assert factorvalues.include?("limiting nutrient:::ethanol")
    assert factorvalues.include?("rate:::0.1")
    assert factorvalues.include?("rate:::0.2")
    assert factorvalues.include?("rate:::0.07")
  end

  def test_05_characteristics_by_investigation
    response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/characteristics_by_investigation", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    propnamevalues = result["results"]["bindings"].map {|n|  "#{n["propname"]["value"]}:::#{n["value"]["value"]}:::#{n["ontouri"]["value"]}"}
    assert propnamevalues.include?("organism:::Saccharomyces cerevisiae (Baker's yeast):::http://purl.obolibrary.org/obo/NEWT_4932")
    assert propnamevalues.include?("Label:::biotin:::http://purl.obolibrary.org/chebi/15956")
    assert propnamevalues.include?("organism:::Saccharomyces cerevisiae (Baker's yeast):::http://purl.obolibrary.org/obo/NEWT_4932")
  end


  def test_06_investigation_endpoint_technology
    response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/investigation_endpoint_technology", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    #puts result
    endpointtechnologies = result["results"]["bindings"].map {|n|  "#{n["endpoint"]["value"]}:::#{n["technology"]["value"]}"}
    assert endpointtechnologies.include?("http://purl.org/obo/owl/OBI#424:::http://purl.org/obo/owl/OBI#400148")
    assert endpointtechnologies.include?("http://purl.org/obo/owl/OBI#OBI_0000615:::http://purl.org/obo/owl/OBI#OBI_0000470")
    assert endpointtechnologies.include?("http://purl.org/obo/owl/OBI#366:::http://purl.org/obo/owl/OBI#OBI_0000470")
    assert endpointtechnologies.include?("http://purl.org/obo/owl/OBI#424:::http://purl.org/obo/owl/OBI#400148")
    assert_equal endpointtechnologies.size, 4 
  end

  def test_07_investigation_and_characteristics
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_and_characteristics", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    inv_chars = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}:::#{n["propname"]["value"]}:::#{n["propValue"]["value"]}:::#{n["ontouri"]["value"]}"}
    assert inv_chars.include?("#{@@uri}:::Label:::#{@@uri}/CV2:::http://purl.obolibrary.org/chebi/15956")
    assert inv_chars.include?("#{@@uri}:::organism:::#{@@uri}/CV4:::http://purl.obolibrary.org/obo/NEWT_4932")
    assert_equal 200, response.code
  end

  def test_08_investigations_and_protocols
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigations_and_protocols", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    inv_protocols = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}:::#{n["protocol"]["value"]}:::#{n["label"]["value"]}"}
    #puts result
    assert inv_protocols.include?("#{@@uri}:::#{@@uri}/P11:::biotin labeling")
    assert inv_protocols.include?("#{@@uri}:::#{@@uri}/P4:::EukGE-WS4")
    assert inv_protocols.include?("#{@@uri}:::#{@@uri}/P1:::metabolite extraction")
    assert inv_protocols.include?("#{@@uri}:::#{@@uri}/P10:::mRNA extraction")
    assert inv_protocols.include?("#{@@uri}:::#{@@uri}/P5:::protein extraction")
    assert inv_protocols.include?("#{@@uri}:::#{@@uri}/P3:::growth protocol")
    assert inv_protocols.include?("#{@@uri}:::#{@@uri}/P9:::ITRAQ labeling")
    assert_equal 200, response.code
  end

  def test_09_factorvalues_by_investigation
    response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/factorvalues_by_investigation", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    #puts result
    ["biosample","sample", "factorname", "value", "ontouri", "unitOnto", "unit"].each do |v|
      assert result["head"]["vars"].include?(v.to_s)
    end
    
    biosample = result["results"]["bindings"].map{|n| "#{n["biosample"]["value"]}"}
    assert biosample.include?("#{@@uri}/source2659")

    sample = result["results"]["bindings"].map{|n| "#{n["sample"]}"}
    type = result["results"]["bindings"].map{|n| "#{n["sample"]["type"]}"}
    assert type.include?("uri")
    value = result["results"]["bindings"].map{|n| "#{n["sample"]["value"]}"}
    assert value.include?("#{@@uri}/sample2409")
    
    factorname = result["results"]["bindings"].map{|n| "#{n["factorname"]}"}
    type = result["results"]["bindings"].map{|n| "#{n["factorname"]["type"]}"}
    assert type.include?("literal")
    value = result["results"]["bindings"].map{|n| "#{n["factorname"]["value"]}"}
    assert value.include?("limiting nutrient")
  end

  def test_10_characteristics_by_sample
    response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/characteristics_by_sample/source2659", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    #puts result
    ["propname", "value", "ontouri"].each do |v|
      assert result["head"]["vars"].include?(v.to_s)
    end

    propname = result["results"]["bindings"].map{|n| "#{n["propname"]["value"]}"}
    assert propname.include?("organism")

    value = result["results"]["bindings"].map{|n| "#{n["value"]["value"]}"}
    assert value.include?("Saccharomyces cerevisiae (Baker's yeast)")

    ontouri = result["results"]["bindings"].map{|n| "#{n["ontouri"]["value"]}"}
    assert ontouri.include?("http://purl.obolibrary.org/obo/NEWT_4932")
  end

  def test_13_investigation_by_characteristic_value
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_characteristic_value", {:value => "Saccharomyces cerevisiae (Baker's yeast)"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    char_value = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}"}
    assert char_value.include?("#{@@uri}")
    assert_equal 200, response.code
  end

  def test_14_investigation_by_characteristic_name
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_characteristic_name", {:value => "organism"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    char_name = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}"}
    assert char_name.include?("#{@@uri}")
    assert_equal 200, response.code
  end

  def test_15_investigation_by_characteristic
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_characteristic", {:value => "http://purl.obolibrary.org/obo/NEWT_4932"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    inv_char = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}"}
    assert inv_char.include?("#{@@uri}")
    assert_equal 200, response.code
  end
  
  # Retrieves investigation URI and factors (name, value, ontology URI of the value)
  def test_16_investigations_and_factors
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigations_and_factors", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    #puts result
    ["investigation", "factorname", "value", "ontouri"].each do |v|
      assert result["head"]["vars"].include?(v.to_s)
    end

    investigation = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}"}
    assert investigation.include?("#{@@uri}")

    factorname = result["results"]["bindings"].map{|n| "#{n["factorname"]["value"]}"}
    assert factorname.include?("limiting nutrient")

    value = result["results"]["bindings"].map{|n| "#{n["value"]["value"]}"}
    assert value.include?("phosphorus")

    ontouri = result["results"]["bindings"].map{|n| "#{n["ontouri"]["value"]}"}
    #assert value.include?("http://purl.obolibrary.org/chebi/CHEBI:28748")
  end
  
  def test_17_genelist
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/genelist", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    assert result["head"]["vars"].include?("genes")
  end

  def test_30_empty_factorValues_search
    assert_raises OpenTox::BadRequestError do
      response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_factors", {:factorValues => ""}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    end
  end

  def test_31_empty_value_search
    assert_raises OpenTox::BadRequestError do
      response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_characteristic", {:value => ""}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    end
  end

  # delete investigation/{id}
  # @note expect code 200
  def test_90_delete_investigation
    result = OpenTox::RestClientWrapper.delete @@uri.to_s, {}, {:subjectid => $pi[:subjectid]}
    assert_equal 200, result.code
  end

end

class TBSPARQLTestExtended < MiniTest::Test

  def self.test_order
    :sorted
  end

  # login as pi and create a test investigation
  def test_00_create_investigation
    OpenTox::RestClientWrapper.subjectid = $pi[:subjectid] # set pi as the logged in user
    @@uri = ""
    file = File.join File.dirname(__FILE__), "data/toxbank-investigation/valid", "GC-ToxBank-15_tb2.zip"
    response = OpenTox::RestClientWrapper.post $investigation[:uri], {:file => File.open(file)}, { :subjectid => $pi[:subjectid] }
    task_uri = response.chomp
    task = OpenTox::Task.new task_uri
    task.wait
    uri = task.resultURI
    assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
    @@uri = URI(uri)
    OpenTox::RestClientWrapper.put @@uri.to_s, { :published => "true", :summarySearchable => "true"}, { :subjectid => $pi[:subjectid] }
    subtask = OpenTox::RestClientWrapper.get "#{@@uri}/subtaskuri", {}, {:accept => "text/uri-list", :subjectid => $pi[:subjectid]}
    puts "SubTaskURI is: #{subtask}"
    if subtask != ""
      task = OpenTox::Task.new subtask.chomp
      task.wait
      puts task.hasStatus
    end
    puts "sleep 120s"
    sleep 120
  end  
  
  # Retrieves all factors (name, value, ontology URI of the value) given an investigation URI
  def test_04_factors_by_investigation
    response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/factors_by_investigation", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    ["factorname", "value", "ontouri", "unitOnto", "unit"].each do |v|
      assert result["head"]["vars"].include?(v.to_s)
    end
    
    factors = result["results"]["bindings"].map{|n| "#{n["factorname"]["value"]}:::#{n["value"]["value"]}:::#{n["ontouri"]["value"]}:::#{n["unitOnto"]["value"]}:::#{n["unit"]["value"]}:::#{n["unitID"]["value"]}"}
    #puts factors
    assert factors.include?("sample TimePoint:::8::::::::::::")
    assert factors.include?("dose:::0::::::http://purl.obolibrary.org/obo/UO_0000064:::micromolar:::UO:0000064")
    assert factors.include?("compound:::DOXORUBICIN:::http://purl.obolibrary.org/chebi/CHEBI:28748:::::::::")
  end

  def test_05_files_by_investigation
    response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/files_by_investigation", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    #puts result
    ["assay", "assayFile", "endpoint", "endpointLabel", "platform", "technology", "techLabel", "file", "term", "downloaduri"].each do |v|
      assert result["head"]["vars"].include?(v.to_s)
    end
  end
  
  def test_06_files_and_assays_by_investigation
    response = OpenTox::RestClientWrapper.get "#{@@uri}/sparql/files_and_assays_by_investigation", {}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    #puts result
    ["study", "assay", "assayFile", "endpoint", "endpointLabel", "technology", "techLabel", "platform", "file", "term"].each do |v|
      assert result["head"]["vars"].include?(v.to_s)
    end
  end
  

  # Retrieves protocol URI containing any of the factor value URI (e.g. two compound URIs)
  def test_10_protocols_by_factors
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/protocols_by_factors", {:factorValues => "['http://purl.obolibrary.org/chebi/CHEBI:28748']"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    protocol_factors = result["results"]["bindings"].map{|n| "#{n["protocol"]["value"]}:::#{n["label"]["value"]}:::#{n["factorname"]["value"]}:::#{n["value"]["value"]}"}
    #puts protocol_factors
    assert_equal 200, response.code
    #assert protocol_factors.include?("#{@@uri}/P4:::labeling:::compound:::DOXORUBICIN")
    #assert protocol_factors.include?("#{@@uri}/P3:::RNA extraction:::compound:::DOXORUBICIN")
    #assert protocol_factors.include?("#{@@uri}/P2:::normalization data transformation:::compound:::DOXORUBICIN")
    #assert protocol_factors.include?("#{@@uri}/P1:::data transformation:::compound:::DOXORUBICIN")
    #assert protocol_factors.include?("#{@@uri}/P5:::data collection:::compound:::DOXORUBICIN")
    #assert protocol_factors.include?("#{@@uri}/P6:::nucleic acid hybridization:::compound:::DOXORUBICIN")
  end

  # Retrieves investigation URI containing any of the factor value URI (e.g. two compound URIs)
  def test_11_investigation_by_factors
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_factors", {:factorValues => "['http://purl.obolibrary.org/chebi/CHEBI:28748']"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    #puts response
    result = JSON.parse(response)
    inv_factors = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}"}
    assert_equal 200, response.code
    assert inv_factors.include?("#{@@uri}")
  end

  # Retrieves investigation URI given a factor value URI (e.g. compound URI)
  def test_12_investigation_by_factor
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_factor", {:value => "http://purl.obolibrary.org/chebi/CHEBI:28748"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    #puts response
    result = JSON.parse(response)
    inv_factor = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}"}
    assert_equal 200, response.code
    assert inv_factor.include?("#{@@uri}")
  end

  def test_16_investigation_by_pvalue
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_pvalue", {:value => "0.65614"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    #puts response
    inv_pvalue = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}"}
    assert_equal 200, response.code
    assert inv_pvalue.include?("#{@@uri}")
  end
  
  def test_17_investigation_by_qvalue
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_qvalue", {:value => "0.805517"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    #puts response
    result = JSON.parse(response)
    inv_qvalue = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}"}
    assert_equal 200, response.code
    assert inv_qvalue.include?("#{@@uri}")
  end
  
  def test_18_investigation_by_foldchange
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_foldchange", {:value => "0.035"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    #puts response
    inv_foldchange = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}"}
    assert_equal 200, response.code
    assert inv_foldchange.include?("#{@@uri}")
  end
  
  def test_19_investigation_by_genes
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_genes", {:geneIdentifiers => "['entrez:3075']"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    #puts response
    inv_genes = result["results"]["bindings"].map{|n| "#{n["investigation"]["value"]}"}
    assert_equal 200, response.code
    assert inv_genes.include?("#{@@uri}")
  end

  def test_19_b_investigation_by_genes
    assert_raises OpenTox::BadRequestError do
      response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_genes", {:geneIdentifiers => "['entrez3075', 'uniprot:P10809']"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    end
  end
  
  def test_20_investigation_by_gene_and_value
    # check for FC, pValue, qValue
    # with relOperator = below
    ["FC", "pvalue", "qvalue"].each do |value_type|
      response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_gene_and_value", {:geneIdentifiers => "['entrez:3075', 'uniprot:P10809']", :value => "#{value_type}:0.5", :relOperator => "below"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
      result = JSON.parse(response)
      #puts response
      ["investigation"].each do |v|
        assert result["head"]["vars"].include?(v.to_s)
      end
      assert_equal 200, response.code
    end
  end
  
  def test_20_investigation_by_gene_and_value_a
    # check for FC, pValue, qValue
    # with relOperator = above
    ["FC", "pvalue", "qvalue"].each do |value_type|
      response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_gene_and_value", {:geneIdentifiers => "['entrez:3075', 'uniprot:P10809']", :value => "#{value_type}:0.5", :relOperator => "above"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
      result = JSON.parse(response)
      #puts response
      ["investigation"].each do |v|
        assert result["head"]["vars"].include?(v.to_s)
      end
      assert_equal 200, response.code
    end
  end
  
  def test_20_investigation_by_gene_and_value_b
    # check for FC, pValue, qValue
    ["FC", "pvalue", "qvalue"].each do |value_type|
      assert_raises OpenTox::BadRequestError do
        response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_gene_and_value", {:geneIdentifiers => "['entrez:3075', 'uniprot:P10809']", :value => "#{value_type}:0.5"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
      end
    end
  end
  
  def test_21_investigation_by_gene_and_value
    # check for valid request
    assert_raises OpenTox::BadRequestError do
      response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_gene_and_value", {:geneIdentifiers => "['entrez:3075', 'uniprot:P10809']", :value => "FC0.7"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    end
    assert_raises OpenTox::BadRequestError do
      response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_gene_and_value", {:geneIdentifiers => "['entrez:3075', 'uniprot:P10809']", :value => "DC=0.7"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    end
    assert_raises OpenTox::BadRequestError do
      response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/investigation_by_gene_and_value", {:geneIdentifiers => "['entrez3075']", :value => "DC:0.7"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    end
  end

  def test_22_biosearch_json
    # check the json output for a bio search gene
    response = OpenTox::RestClientWrapper.get "#{$investigation[:uri]}/sparql/biosearch", {:geneIdentifiers => "['entrez:3075']"}, {:accept => "application/json", :subjectid => $pi[:subjectid]}
    result = JSON.parse(response)
    #puts response
    gene = result["results"]["bindings"].map{|n| "#{n["gene"]}"}
    assert_equal 200, response.code
    assert gene.include?("Entrez:3075")
    title = result["results"]["bindings"].map{|n| "#{n["title"]["value"]}"}
    assert title.include?("p-value'High.24hr-Control.24hr'")
  end

  # delete investigation/{id}
  # @note expect code 200
  def test_90_delete_investigation
    result = OpenTox::RestClientWrapper.delete @@uri.to_s, {}, {:subjectid => $pi[:subjectid]}
    assert_equal 200, result.code
  end
end