Class: OpenTox::Application

Inherits:
Service
  • Object
show all
Defined in:
helper.rb,
application.rb,
helper_isatab.rb,
helper_unformatted.rb

Overview

full API description for ToxBank investigation service see:

Defined Under Namespace

Modules: Helpers

URI Routes collapse

Instance Method Details

#delete("/investigation/:id") ⇒ String

Delete an investigation

Parameters:

  • header (Hash)
    • subjectid [String] authorization token

Returns:

  • (String)

    status message and HTTP code

See Also:


512
513
514
515
516
517
518
519
520
521
# File 'application.rb', line 512

delete '/investigation/:id' do
  kill_isa2rdf
  set_index false
  FileUtils.remove_entry dir
  `cd #{File.dirname(__FILE__)}/investigation; git commit -am "#{dir} deleted by #{OpenTox::Authorization.get_user}"`
  FourStore.delete investigation_uri
  delete_investigation_policy
  response['Content-Type'] = 'text/plain'
  "Investigation #{params[:id]} deleted"
end

#get("/investigation/?") ⇒ String

List URIs of all investigations or investigations of a user.

Parameters:

  • header (hash)
    • Accept [String] <text/uri-list, application/rdf+xml, application/json>

    • subjectid [String] authorization token

Returns:

  • (String)

    text/uri-list, application/rdf+xml, application/json List of investigations.

Raises:

  • (BadRequestError)

    if wrong mime-type

See Also:


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'application.rb', line 59

get '/investigation/?' do
  mime_types = ['text/uri-list', 'application/rdf+xml', 'application/json']
  bad_request_error "Mime type #{@accept} not supported here. Please request data as text/uri-list, application/json or application/rdf+xml." unless mime_types.include? @accept
  if (@accept == "text/uri-list" && !request.env['HTTP_USER'])
    qlist @accept
  elsif (@accept == "application/rdf+xml" && !request.env['HTTP_USER'])
    FourStore.query "CONSTRUCT {?s <#{RDF.type}> <#{RDF::ISA}Investigation> } WHERE { ?s <#{RDF.type}> <#{RDF::ISA}Investigation>.}", @accept
  elsif (@accept == "application/rdf+xml" && request.env['HTTP_USER'])
    FourStore.query "CONSTRUCT {?investigation <#{RDF.type}> <#{RDF::ISA}Investigation> }
    WHERE {?investigation <#{RDF.type}> <#{RDF::ISA}Investigation>. ?investigation <#{RDF::TB}hasOwner> <#{request.env['HTTP_USER']}>}", @accept
  elsif (@accept == "application/json" && request.env['HTTP_USER'])
    response = FourStore.query "SELECT ?uri ?updated WHERE {?uri <#{RDF::TB}hasOwner> <#{request.env["HTTP_USER"]}>; <#{RDF::DC.modified}> ?updated  FILTER regex(?updated, \"[A-Z]{3}$\")}", @accept
    # get timestring and parse to timestamp {3,4} for different zones
    response.gsub(/(\d{2}\s[a-zA-Z]{3}\s\d{4}\s\d{2}\:\d{2}\:\d{2}\s[A-Z]{3,4})/){|t| get_timestamp t}
  elsif (@accept == "text/uri-list" && request.env['HTTP_USER'])
    result = FourStore.query "SELECT ?uri WHERE {?uri <#{RDF::TB}hasOwner> <#{request.env["HTTP_USER"]}>; <#{RDF::DC.modified}> ?updated}", @accept
    result.split("\n").collect{|u| u.sub(/(\/)+$/,'')}.join("\n")
  else
    bad_request_error "Mime type: '#{@accept}' not supported with user: '#{request.env['HTTP_USER']}'."
  end
end

#get("/investigation/:id/dashboard") ⇒ Array

Get investigation dashboard values.

Parameters:

  • header (Hash)
    • Accept [String] <application/json>

    • subjectid [String] authorization token

Returns:

  • (Array)

    application/json.

See Also:


299
300
301
302
303
304
# File 'application.rb', line 299

get '/investigation/:id/dashboard' do
  bad_request_error "Mime type #{@accept} not supported here. Please request data as application/json." unless (@accept.to_s == "application/json")
  bad_request_error "No dashboard content available." unless is_isatab?
  response['Content-Type'] = 'application/json'
  get_cache
end

#get("/investigation/:id/:filename") ⇒ String

Get a study, assay, data representation

Parameters:

  • header (Hash)
    • Accept [String] <text/tab-separated-values, application/sparql-results+json>

    • subjectid [String] authorization token

Returns:

  • (String)

    of mime-type [text/tab-separated-values] - Study, assay, data representation in ISA-TAB or RDF format.

See Also:


374
375
376
377
378
379
380
381
382
# File 'application.rb', line 374

['/investigation/:id/isatab/:filename','/investigation/:id/files/:filename'].each do |path|
  get path do
    resource_not_found_error "File #{File.join investigation_uri,"isatab",params[:filename]} does not exist."  unless File.exist? file
    filetype = (File.symlink?(file) ? File.new(File.readlink(file)).mime_type : File.new(file).mime_type)
    #TODO set mime-type for isatab ?
    # send_file file, :type => (request.path =~ /isatab/) ? 'text/tab-separated-values' : filetype
    send_file file, :type => filetype
  end
end

#get("/investigation/ftpfiles/?") ⇒ String

List all uploaded FTP-files of a user.

Parameters:

  • header (hash)
    • Accept [String] <text/uri-list, application/json>

    • subjectid [String] authorization token

Returns:

  • (String)

    text/uri-list, application/json List of files.

Raises:

  • (BadRequestError)

    if wrong mime-type

See Also:


90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'application.rb', line 90

get '/investigation/ftpfiles/?' do
   bad_request_error "Mime type #{@accept} not supported here. Please request data as text/uri-list or application/json." unless (@accept.to_s == "text/uri-list") || (@accept.to_s == "application/json")
   filehash = get_ftpfiles
   user = Authorization.get_user
   case @accept.to_s
    when "application/json"
      return JSON.pretty_generate( {"head"=>{"vars" => ["filename","basename"]},"results"=> {"bindings"=>filehash.collect{|fullname, basename| {"filename"=>{"type"=>"string", "value"=> fullname.gsub("/home/ftpusers/#{user}/","")}, "basename"=>{"type"=>"string", "value"=> basename}}}}} )
    when "text/uri-list"
      return filehash.collect{|fullname,basename| "#{fullname.gsub("/home/ftpusers/#{user}/","")}\n"}
    else
      return filehash
    end
end

#get("/investigation/:id") ⇒ String

Get an investigation representation.

Parameters:

  • header (Hash)
    • Accept [String] <text/tab-separated-values, text/uri-list, application/zip, application/rdf+xml>

    • subjectid [String] authorization token

Returns:

  • (String)

    text/tab-separated-values, text/uri-list, application/zip, application/rdf+xml - Investigation in the requested format.

Raises:

  • (ResourceNotFoundError)

    if directory didn't exists

See Also:


271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'application.rb', line 271

get '/investigation/:id' do
  resource_not_found_error "Investigation #{investigation_uri} does not exist."  unless File.exist? dir # not called in before filter???
  mime_types = ['text/tab-separated-values', 'text/uri-list', 'application/zip', 'application/rdf+xml']
  bad_request_error "Mime type #{@accept} not supported here. Please request data as text/tab-separated-values, text/uri-list, application/zip or application/rdf+xml." unless mime_types.include? @accept
  case @accept
  when "text/tab-separated-values"
    invfile = Dir["#{dir}/i_*.txt"][0]
    resource_not_found_error "Investigation is not in ISA-TAB format. Please request metadata for details." if invfile.blank?
    send_file Dir["./investigation/#{params[:id]}/i_*txt"].first, :type => @accept
  when "text/uri-list"
    uri_list
  when "application/zip"
    resource_not_found_error "Investigation zip does not exist. Please request application/rdf+xml."  unless File.exist? File.join(dir, "investigation_#{params[:id]}.zip")
    send_file File.join dir, "investigation_#{params[:id]}.zip"
  else
    # application/rdf+xml
    FourStore.query "CONSTRUCT { ?s ?p ?o } FROM <#{investigation_uri}> WHERE {?s ?p ?o}", @accept
  end
end

#get("/investigation/:id/sparql/:templatename") ⇒ String

Get data by predefined SPARQL templates for an investigation resource

Parameters:

  • header (Hash)
    • Accept [String] <application/sparql-results+xml, application/json, text/uri-list, text/html>

    • subjectid [String] authorization token

Returns:

  • (String)

    sparql-results+xml, json, uri-list, html


407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'application.rb', line 407

['/investigation/:id/sparql/:templatename', '/investigation/:id/sparql/:templatename/:biosample'].each do |path|
  get path do
    templates = get_templates "investigation"
    templatename = params[:templatename].underscore
    $logger.debug "templatename:\t#{templatename}"
    resource_not_found_error "Template: #{params[:templatename]} does not exist."  unless templates.has_key? templatename
    unless templatename == "characteristics_by_sample"
      sparqlstring = File.read(templates[templatename]) % { :investigation_uri => investigation_uri }
    else
      sparqlstring = File.read(templates[templatename]) % { :sample_uri => investigation_uri + "/" + params[:biosample] }
    end
    FourStore.query sparqlstring, @accept
  end
end

#get("/investigation/:id/metadata") ⇒ String

Get investigation metadata.

Parameters:

  • header (Hash)
    • Accept [String] <text/plain, text/turtle, application/rdf+xml>

    • subjectid [String] authorization token

Returns:

  • (String)

    text/plain, text/turtle, application/rdf+xml.

See Also:


314
315
316
317
318
319
320
321
322
323
324
# File 'application.rb', line 314

get '/investigation/:id/metadata' do
  resource_not_found_error "Investigation #{investigation_uri} does not exist."  unless File.exist? dir # not called in before filter???
  mime_types = ['text/plain', 'text/turtle', 'application/rdf+xml']
  bad_request_error "Mime type #{@accept} not supported here. Please request data as text/plain, text/turtle or application/rdf+xml." unless mime_types.include? @accept
  FourStore.query "CONSTRUCT {?s ?p ?o.} 
                   FROM <#{investigation_uri}>
                   WHERE {?s <#{RDF.type}> <#{RDF::ISA}Investigation>.
                   OPTIONAL {?s <http://purl.org/dc/terms/license> ?o.}
                          ?s ?p ?o . 
                   } ", @accept
end

#get("/investigation/:id/protocol") ⇒ String

Get investigation protocol uri

Returns:

  • (String)

    text/plain, text/turtle, application/rdf+xml

Raises:

  • (ResourceNotFoundError)

    if file do not exist

See Also:


332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'application.rb', line 332

get '/investigation/:id/protocol' do
  resource_not_found_error "Investigation #{investigation_uri} does not exist."  unless File.exist? dir # not called in before filter???
  mime_types = ['text/plain', 'text/turtle', 'application/rdf+xml']
  bad_request_error "Mime type #{@accept} not supported here. Please request data as text/plain, text/turtle or application/rdf+xml." unless mime_types.include? @accept
  FourStore.query "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                   PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
                   CONSTRUCT {?study <#{RDF::ISA}hasProtocol> ?protocol.
                              ?protocol a ?type.
                              ?protocol rdfs:label ?label.
                   }
                   FROM <#{investigation_uri}>
                   WHERE {<#{investigation_uri}> <#{RDF::ISA}hasStudy> ?study.
                   ?study <#{RDF::ISA}hasProtocol> ?protocol.
                   ?protocol a ?type.
                   OPTIONAL { ?protocol rdfs:label ?label.}
                   }", @accept
end

#get("/investigation/:id/:recource") ⇒ String

Note:

Result includes your own and published investigations.

Get n-triples, turtle or RDF for an investigation resource

Parameters:

  • header (Hash)
    • Accept [String] <text/plain, text/turtle, application/rdf+xml>

    • subjectid [String] authorization token

Returns:

  • (String)

    text/plain, text/turtle, application/rdf+xml


392
393
394
395
396
397
398
# File 'application.rb', line 392

get '/investigation/:id/:resource' do
  resource_not_found_error "Investigation #{investigation_uri} does not exist."  unless File.exist? dir
  mime_types = ['text/plain', 'text/turtle', 'application/rdf+xml']
  bad_request_error "Mime type #{@accept} not supported here. Please request data as text/plain, text/turtle or application/rdf+xml." unless mime_types.include? @accept
  result = FourStore.query " CONSTRUCT {  <#{File.join(investigation_uri,params[:resource])}> ?p ?o.  } FROM <#{investigation_uri}> WHERE { <#{File.join(investigation_uri,params[:resource])}> ?p ?o .  } ", @accept
  result.blank? ? "Resource '#{params[:resource]}' not found.\n" : result
end

#get("/investigation/sparql/:templatename") ⇒ String

Get data by predefined SPARQL templates for investigations

Parameters:

  • header (Hash)
    • Accept [String] <application/sparql-results+xml, application/json, text/uri-list, text/html>

    • subjectid [String] authorization token

Returns:

  • (String)

    sparql-results+xml, json, uri-list, html


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
# File 'application.rb', line 194

get '/investigation/sparql/:templatename' do
  bad_request_error "Mime type #{@accept} not supported here. Please request data as 'application/json'." unless (@accept.to_s == "application/json")
  templates = get_templates ""
  templatename = params[:templatename].underscore
  resource_not_found_error "Template: #{params[:templatename]} does not exist."  unless templates.has_key? templatename
  bad_request_error "relational operator not expected." if params[:relOperator] and templatename !~ /_by_gene_and_value$/
  case templatename
  when /_by_gene_and_value$/
    bad_request_error "missing parameter geneIdentifiers. '#{params[:geneIdentifiers]} is not a valid gene identifier." if params[:geneIdentifiers].blank? || params[:geneIdentifiers] !~ /.*\:.*/
    bad_request_error "missing relational operator 'above' or 'below' ." if params[:relOperator].blank? || params[:relOperator] !~ /^above$|^below$/
    bad_request_error "missing parameter value. Request needs a value." if params[:value].blank?
    bad_request_error "missing parameter value_type. Request needs a value_type like 'FC:0.7'." if params[:value].to_s !~ /.*\:.*/
    bad_request_error "wrong parameter value_type. Request needs a value_type like 'FC,pvalue,qvalue'." if params[:value].split(":").first !~ /^FC$|^pvalue$|^qvalue$/

    #if params[:relOperator].blank?
    #  relOperator = "<="
    #else
    #  relOperator = params[:relOperator] =~ /above/ ? ">=" : "<="
    #end
    relOperator = params[:relOperator] =~ /above/ ? ">=" : "<="
    genes = params[:geneIdentifiers].gsub(/[\[\]\"]/ , "").split(",")
    # split params[:value] in "value_type" and "value"
    value_type = "http://onto.toxbank.net/isa/" + params[:value].split(":").first
    value = params[:value].split(":").last
    if genes.class == Array
      VArr = []
      genes.each do |gene|
        VArr << "{ ?dataentry skos:closeMatch #{gene.gsub("'","").strip}. }" unless gene.empty?
      end
      sparqlstring = File.read(templates[templatename]) % { :Values => VArr.join(" UNION "), :value_type => value_type, :value => value, :relOperator => relOperator }
    else
      sparqlstring = File.read(templates[templatename]) % { :Values => "{ ?dataentry skos:closeMatch #{values.gsub("'","").strip}. }", :value_type => value_type, :value => value, :relOperator => relOperator }
    end
    $logger.debug sparqlstring
    result = FourStore.query sparqlstring, "application/json"
    check_get_access result
  when /_and_/
    result = FourStore.query File.read(templates[templatename]) , "application/json"
    check_get_access result
  when /_by_[a-z]+s$/
    genesparql = templatename.match(/_by_genes$/)
    params[:geneIdentifiers].split(",").each{|gene| bad_request_error "'#{gene}' is not a valid gene identifier." if gene !~ /.*\:.*/} if params[:geneIdentifiers]
    values = genesparql ? params[:geneIdentifiers] : params[:factorValues]
    bad_request_error "missing parameter #{genesparql ? "geneIdentifiers": "factorValues"}. Request needs one or multiple(separated by comma)." if values.blank?
    values = values.gsub(/[\[\]\"]/ , "").split(",") if values.class == String
    VArr = []
    if templatename.match(/_by_factors$/)
      values.each do |value|
        VArr << "{ ?factorValue isa:hasOntologyTerm <#{value.gsub("'","").strip}>. }"
      end
    else
      values.each do |value|
        VArr << (genesparql ? "{ ?dataentry skos:closeMatch #{value.gsub("'","").strip}. }" :  "{ ?value isa:hasOntologyTerm <#{value.gsub("'","").strip}>. }")
      end
    end
    sparqlstring = File.read(templates[templatename]) % { :Values => VArr.join(" UNION ") }
    result = FourStore.query sparqlstring, "application/json"
    check_get_access result
  when /_by_[a-z_]+(?<!s)$/
    bad_request_error "missing parameter value. Request needs a value." if params[:value].blank?
    sparqlstring = File.read(templates[templatename]) % { :value => params[:value] }
    result = FourStore.query sparqlstring, "application/json"
    check_get_access result
  else
    not_implemented_error "Template: #{params[:templatename]} is not implemented yet."
  end
end

#get("/investigation/:id/subtaskuri") ⇒ String

Get SubTaskURI of an investigation. Returns the URI of an data subtask or an empty string if requested with 'text/uri-list'

Parameters:

  • header (Hash)
    • Accept [String] <text/uri-list, application/json>

    • subjectid [String] authorization token

Returns:

  • (String)

    text/uri-list or application/json.

Raises:

  • (ResourceNotFoundError)

    if investigation URI do not exist.


359
360
361
362
363
364
# File 'application.rb', line 359

get '/investigation/:id/subtaskuri' do
  resource_not_found_error "Investigation #{investigation_uri} does not exist."  unless File.exist? dir
  mime_types = ['text/uri-list', 'application/json']
  bad_request_error "Mime type #{@accept} not supported here. Please request data as text/uri-list or application/json." unless mime_types.include? @accept
  FourStore.query "SELECT ?subtaskuri WHERE { <#{investigation_uri}> <#{RDF::TB.hasSubTaskURI}> ?subtaskuri. }", @accept
end

#head("/investigation/?") ⇒ String

Head request.

Returns:

  • (String)

    only HTTP headers.


46
47
# File 'application.rb', line 46

head '/investigation/?' do
end

#post("/investigation/?") ⇒ String

Create a new investigation from ISA-TAB files.

Parameters:

  • header (Hash)
    • Accept [String] <'multipart/form-data'>

    • subjectid [String] authorization token

  • Zipped (File)

    investigation files in ISA-TAB format.

Returns:

  • (String)

    text/uri-list Task URI.

Raises:

  • (BadRequestError)

    without file upload and wrong mime-type.

See Also:


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
# File 'application.rb', line 114

post '/investigation/?' do
  # CH: Task.create is now Task.run(description,creator_uri,subjectid) to avoid method clashes
  params[:id] = SecureRandom.uuid
  task = OpenTox::Task.run("#{params[:file] ? params[:file][:filename] : "no file attached"}: Uploading, validating and converting to RDF",to("/investigation")) do
    #params[:id] = SecureRandom.uuid
    mime_types = ['application/zip','text/tab-separated-values']
    inv_types = ['noData', 'unformattedData', 'ftpData']
    # no data or ftp data
    if params[:type] && !params[:file]
      bad_request_error "Investigation type '#{params[:type]}' not supported." unless inv_types.include? params[:type]
      case params[:type]
      when "noData"
        bad_request_error "Parameter 'ftpData' not expected for type '#{params[:type]}'." if params[:ftpFile]
        clean_params "noftp"
        OpenTox::Authorization.create_pi_policy(investigation_uri)
        prepare_upload
        params2rdf
      when "ftpData"
        clean_params "ftp"
        OpenTox::Authorization.create_pi_policy(investigation_uri)
        prepare_upload
        link_ftpfiles_by_params
        params2rdf
      end
    # unformated data
    elsif params[:type] && params[:file]
      bad_request_error "Mime type #{params[:file][:type]} not supported. Please submit data as zip archive (application/zip)." unless mime_types[0] == params[:file][:type]
      bad_request_error "Investigation type '#{params[:type]}' not supported." unless inv_types.include? params[:type]
      bad_request_error "No file expected for type '#{params[:type]}'." unless params[:type] == "unformattedData"
      bad_request_error "File '#{params[:file][:filename]}' is to large. Please choose FTP investigation type and upload to your FTP directory first." unless (params[:file][:tempfile].size.to_i < 10485760)
      clean_params "noftp"
      OpenTox::Authorization.create_pi_policy(investigation_uri)
      prepare_upload
      params2rdf
    # isa-tab data
    elsif params[:file] && !params[:type]
      bad_request_error "Mime type #{params[:file][:type]} not supported. Please submit data as zip archive (application/zip) or as tab separated text (text/tab-separated-values)" unless mime_types.include? params[:file][:type]
      OpenTox::Authorization.create_pi_policy(investigation_uri)
      case params[:file][:type]
      when 'application/zip'
        prepare_upload
        extract_zip
        isa2rdf
      end
    # no params or data
    else
      bad_request_error "No file uploaded or parameters given."
    end
    # set flags and modified date
    set_flag(RDF::TB.isPublished, false, "boolean")
    set_flag(RDF::TB.isSummarySearchable, (params[:summarySearchable].to_s == "true" ? true : false), "boolean")
    set_modified
    # set access rules
    create_policy "user", params[:allowReadByUser] if params[:allowReadByUser]
    create_policy "group", params[:allowReadByGroup] if params[:allowReadByGroup]
    investigation_uri
  end
  # remove unformatted investigation if import error
  begin
    t = OpenTox::Task.new task.uri
    t.wait
    if t.hasStatus == "Error"
      $logger.debug "Error in POST: #{investigation_uri} remove dir."
      FileUtils.remove_entry dir if Dir.exist?(dir)
      `cd #{File.dirname(__FILE__)}/investigation; git commit -am "#{dir} deleted by #{OpenTox::Authorization.get_user}"` if `cd #{File.dirname(__FILE__)}/investigation; git diff` != ""
      FourStore.delete investigation_uri
      delete_investigation_policy
    end
  end
  response['Content-Type'] = 'text/uri-list'
  halt 202,task.uri+"\n"
end

#put("/investigation/:id") ⇒ String

Add studies, assays or data to an investigation. Send as Content-type multipart/form-data

Parameters:

  • header (Hash)
    • subjectid [String] authorization token

  • params (Hash)
    • allowReadByUser [String] one or multiple userservice-URIs (User)

    • allowReadByGroup [String] one or multiple userservice-URIs (Organisations, Projects)

    • summarySearchable [String] true/false (default is false)

    • published true/false [String] (default is false)

  • Zipped (File)

    investigation files in ISA-TAB format.

Returns:

  • (String)

    text/uri-list Task URI

See Also:


435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'application.rb', line 435

put '/investigation/:id' do
  task = OpenTox::Task.run("#{investigation_uri}: Add studies, assays or data.",@uri) do
    mime_types = ['application/zip','text/tab-separated-values']
    inv_types = ['noData', 'unformattedData', 'ftpData']
    param_types = ['title', 'abstract', 'owningOrg', 'owningPro', 'authors', 'keywords', 'ftpFile']
    bad_request_error "Mime type #{params[:file][:type]} not supported. Please submit data as zip archive (application/zip) or as tab separated text (text/tab-separated-values)" unless mime_types.include?(params[:file][:type]) if params[:file]
    inv_type = investigation_type
    
    # no data or ftp data
    if params[:type] && !params[:file]
      bad_request_error "Parameter '#{params[:type]}' not supported." unless inv_types.include? params[:type]
      case params[:type]
      when "noData"
        bad_request_error "Expected type is '#{inv_type}'." unless params[:type] == inv_type
        bad_request_error "Parameter 'ftpFile' not expected for type '#{params[:type]}'." if params[:ftpFile]
        clean_params "noftp"
        prepare_upload
        params2rdf
      when "ftpData"
        bad_request_error "Expected type is '#{inv_type}'." unless params[:type] == inv_type
        clean_params "ftp"
        prepare_upload
        params2rdf
      end
    # unformated data
    elsif params[:type] && params[:file]
      bad_request_error "Parameter '#{params[:type]}' not supported." unless inv_types.include? params[:type]
      bad_request_error "Mime type #{params[:file][:type]} not supported. Please submit data as zip archive (application/zip)." unless mime_types[0] == params[:file][:type]
      bad_request_error "No file expected for type '#{params[:type]}'." unless params[:type] == "unformattedData"
      bad_request_error "File '#{params[:file][:filename]}' is to large. Please choose FTP investigation type and upload to your FTP directory first." unless (params[:file][:tempfile].size.to_i < 10485760)
      bad_request_error "Expected type is '#{inv_type}'." unless params[:type] == inv_type
      clean_params "noftp"
      prepare_upload
      params2rdf
    # isatab data
    elsif params[:file] && !params[:type]
      bad_request_error "Mime type #{params[:file][:type]} not supported. Please submit data as zip archive (application/zip) or as tab separated text (text/tab-separated-values)" unless mime_types.include? params[:file][:type]
      bad_request_error "Unable to edit unformatted investigation with ISA-TAB data." unless is_isatab? 
      prepare_upload
      extract_zip if params[:file][:type] == 'application/zip'
      kill_isa2rdf
      isa2rdf
    # set flags and policies
    elsif !params[:type] && !inv_type.blank? && (params[:summarySearchable]||params[:published]||params[:allowReadByGroup]||params[:allowReadByUser])
      # pass to set flags or policies
    # require type for non-isatab
    elsif !params[:type] && !inv_type.blank?
      bad_request_error "Expected type is '#{inv_type}'."
    # incomplete request
    elsif !params[:file] && !params[:type] && !params[:summarySearchable] && !params[:published] && !params[:allowReadByGroup] && !params[:allowReadByUser]
      bad_request_error "No file uploaded or any valid parameter given."
    end
    
    set_flag(RDF::TB.isPublished, (params[:published].to_s == "true" ? true : false), "boolean") if params[:file] || (!params[:file] && params[:published])
    set_flag(RDF::TB.isSummarySearchable, (params[:summarySearchable].to_s == "true" ? true : false), "boolean") if params[:file] || (!params[:file] && params[:summarySearchable])
    set_modified
    create_policy "user", params[:allowReadByUser] if params[:allowReadByUser]
    create_policy "group", params[:allowReadByGroup] if params[:allowReadByGroup]
    curi = clean_uri(uri)
    if qfilter("isPublished", curi) =~ /#{curi}/ && qfilter("isSummarySearchable", curi) =~ /#{curi}/
      $logger.debug "index investigation"
      set_index true
    else
      set_index false
    end
    investigation_uri
  end
  response['Content-Type'] = 'text/uri-list'
  halt 202,task.uri+"\n"
end