From 44d9ceb30f6f8649f2d6fc179a925302f14d8a05 Mon Sep 17 00:00:00 2001 From: gebele Date: Mon, 16 Jul 2018 14:20:03 +0000 Subject: add mazzatorta --- Gemfile | 1 + application.rb | 84 ++++++++++++++++++++++++++++++++++++++++++++++++--- lazar-gui.gemspec | 10 +++--- views/batch.haml | 10 ++++-- views/predict.haml | 12 ++++++-- views/prediction.haml | 22 +++++++++++++- 6 files changed, 122 insertions(+), 17 deletions(-) diff --git a/Gemfile b/Gemfile index 7b443e3..9945517 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ gemspec gem "lazar", :path => "../lazar" gem "toxtree", :path => "../toxtree" gem "kazius-alerts", :path => "../kazius-alerts" +gem "loael-mazzatorta", :path => "../loael-mazzatorta" gem "gem-path" gem "sinatra" gem "sinatra-reloader" diff --git a/application.rb b/application.rb index ee7837f..fdb7086 100644 --- a/application.rb +++ b/application.rb @@ -38,8 +38,11 @@ get '/predict/?' do @existing_datasets = dataset_storage @models = Model::Validation.all @models = @models.delete_if{|m| m.model.name =~ /\b(Net cell association)\b/} - @endpoints = @models.collect{|m| m.endpoint}.sort.uniq - @endpoints << "Oral toxicity (Cramer rules)" + #endpoints = @models.collect{|m| m.endpoint =~ /LOAEL/ ? m.endpoint+" (lazar)" : m.endpoint} + endpoints = @models.collect{|m| m.endpoint} + endpoints << "Oral toxicity (Cramer rules)" + endpoints << "Lowest observed adverse effect level (LOAEL) (Mazzatorta)" + @endpoints = endpoints.sort.uniq @models.count <= 0 ? (haml :info) : (haml :predict) end @@ -63,6 +66,22 @@ get '/task/?' do string += "Cramer rules, with extensions:#{prediction["Cramer rules, with extensions"][pageNumber.to_i]}" string += "" html += "#{string}" + elsif params[:model] == "Mazzatorta" + prediction = task.predictions[params[:model]] + compound = Compound.find prediction["compounds"][pageNumber] + image = compound.svg + smiles = compound.smiles + html = "" + html += "" + string = "" + html += "#{string}
#{image}
#{smiles}
" + if prediction["mazzatorta"][pageNumber.to_i][:prediction] + string += "" + string += "" + else + string += "" + end + string += "
Prediction:#{prediction["mazzatorta"][pageNumber.to_i][:mmol_prediction]} (mmol/kg_bw/day)
#{prediction["mazzatorta"][pageNumber.to_i][:prediction]} (mg/kg_bw/day)
Warnings:#{prediction["mazzatorta"][pageNumber.to_i][:warnings]}
" else predictions = task.predictions[params[:model]].collect{|hash| hash.values[0]} prediction_object = Prediction.find predictions[pageNumber] @@ -188,9 +207,13 @@ get '/predict/csv/:task/:model/:filename/?' do end end end - endpoint = (params[:model] == "Cramer") ? "Oral_toxicity_(Cramer_rules)" : (m.endpoint =~ /Mutagenicity/i ? "Consensus_mutagenicity" : "#{m.endpoint}_(#{m.species})") + if params[:model] == "Mazzatorta" + endpoint = "Lowest observed adverse effect level (LOAEL) (Rats) (Mazzatorta)" + else + endpoint = (params[:model] == "Cramer") ? "Oral_toxicity_(Cramer_rules)" : (m.endpoint =~ /Mutagenicity/i ? "Consensus_mutagenicity" : "#{m.endpoint}_(#{m.species})") + end tempfile = Tempfile.new - if params[:model] == "Cramer" + if params[:model] == "Cramer" || params[:model] == "Mazzatorta" # add duplicate warning at the end of a line if ID matches if @dups lines = task.csv.split("\n") @@ -309,7 +332,7 @@ post '/predict/?' do task = Task.run do @models.each_with_index do |model,idx| t = @tasks[idx] - unless model == "Cramer" + if model !~ /Cramer|Mazzatorta/ m = Model::Validation.find model type = (m.regression? ? "Regression" : "Classification") # add header for regression @@ -420,6 +443,47 @@ post '/predict/?' do t[:csv] = header # write predictions @predictions["#{model}"] = predictions + elsif model == "Mazzatorta" + compounds = @compounds.collect{|cid| c = Compound.find cid; c.smiles} + prediction = LoaelMazzatorta.predict(compounds) + output = {} + output["model_name"] = "Lowest observed adverse effect level (LOAEL) (Rats) (Mazzatorta)" + output["mazzatorta"] = [] + #output["mazzatorta"] = prediction + # header + if @ids.blank? + csv = "ID,Input,Endpoint,Unique SMILES,Prediction (mmol/kg_bw/day),Prediction (mg/kg_bw/day),Notes\n" + else + csv = "ID,Original ID,Input,Endpoint,Unique SMILES,Prediction (mmol/kg_bw/day),Prediction (mg/kg_bw/day),Notes\n" + end + # content + compounds.each_with_index do |smiles, idx| + compound = Compound.find @compounds[idx] + if prediction[idx]["value"] + output["mazzatorta"][idx] = {:mmol_prediction => compound.mg_to_mmol(prediction[idx]["value"].delog10p).signif(3),:prediction => prediction[idx]["value"].delog10p.signif(3)} + else + output["mazzatorta"][idx] = {:warnings => prediction[idx]["warnings"][0].split("\t").first} + end + if @ids.blank? + csv << "#{idx+1},#{@identifiers[idx]},#{output["model_name"]},#{smiles},"\ + "#{output["mazzatorta"][idx][:mmol_prediction] if output["mazzatorta"][idx][:mmol_prediction]},"\ + "#{output["mazzatorta"][idx][:prediction] if output["mazzatorta"][idx][:prediction]},"\ + "#{output["mazzatorta"][idx][:warnings] if output["mazzatorta"][idx][:warnings]}\n" + else + csv << "#{idx+1},#{@ids[idx]},#{@identifiers[idx]},#{output["model_name"]},#{smiles},"\ + "#{output["mazzatorta"][idx][:mmol_prediction] if output["mazzatorta"][idx][:mmol_prediction]},"\ + "#{output["mazzatorta"][idx][:prediction] if output["mazzatorta"][idx][:prediction]},"\ + "#{output["mazzatorta"][idx][:warnings] if output["mazzatorta"][idx][:warnings]}\n" + end + end + predictions = {} + predictions["mazzatorta"] = output["mazzatorta"] + #predictions["compounds"] = @compounds + # write csv + t[:csv] = csv + # write predictions + @predictions["#{model}"] = predictions + t.update_percent(100) else # Cramer model compounds = @compounds.collect{|cid| c = Compound.find cid; c.smiles} prediction = [Toxtree.predict(compounds, "Cramer rules"), Toxtree.predict(compounds, "Cramer rules with extensions")] @@ -486,6 +550,16 @@ post '/predict/?' do if model_id == "Cramer" @toxtree = true @predictions << [Toxtree.predict(@compound.smiles, "Cramer rules"), Toxtree.predict(@compound.smiles, "Cramer rules with extensions")] + elsif model_id == "Mazzatorta" + prediction = LoaelMazzatorta.predict(@compound.smiles) + output = {} + $logger.debug prediction + if prediction["value"] + output["mazzatorta"] = {:mmol_prediction => @compound.mg_to_mmol(prediction["value"].delog10p).signif(3),:prediction => prediction["value"].delog10p.signif(3)} + else + output["mazzatorta"] << {:warnings => prediction["warnings"][0].split("\t").first} + end + @predictions << output else model = Model::Validation.find model_id @models << model diff --git a/lazar-gui.gemspec b/lazar-gui.gemspec index 592d929..34f1aef 100644 --- a/lazar-gui.gemspec +++ b/lazar-gui.gemspec @@ -16,11 +16,11 @@ Gem::Specification.new do |s| s.add_runtime_dependency "lazar" s.add_runtime_dependency "toxtree" s.add_runtime_dependency "kazius-alerts" - s.add_runtime_dependency "gem-path", "~> 0.6.1", '>= 0.6.1' - s.add_runtime_dependency "sinatra", "~> 1.4.0", '>= 1.4.0' - s.add_runtime_dependency "rdiscount", "~> 2.1.0", '>= 2.1.0' - s.add_runtime_dependency "haml", "~> 4.0.0", '>= 4.0.0' - s.add_runtime_dependency "sass", "~> 3.4.0", '>= 3.4.0' + s.add_runtime_dependency "gem-path" + s.add_runtime_dependency "sinatra" + s.add_runtime_dependency "rdiscount" + s.add_runtime_dependency "haml" + s.add_runtime_dependency "sass" s.add_runtime_dependency "unicorn" s.post_install_message = %q{ diff --git a/views/batch.haml b/views/batch.haml index 1aa6779..165b64b 100644 --- a/views/batch.haml +++ b/views/batch.haml @@ -76,7 +76,7 @@ callback: function(data, pagination) { var html = simpleTemplating(data); $('#data-container_'+id).html(html); - $('#data-container_'+id).css("min-height", $(window).height() + "px" ); + //$('#data-container_'+id).css("min-height", $(window).height() + "px" ); } }); } else if (span.className = "glyphicon glyphicon-menu-down"){ @@ -105,8 +105,12 @@ #result.panel{:id=>idx} %div.row %div.col-md-6 - %h5= (model == "Cramer") ? "Oral toxicity (Cramer rules)" : (m.endpoint =~ /Mutagenicity/i ? "Consensus mutagenicity" : "#{m.endpoint} (#{m.species})") - #pager{:id=>idx} + - if model =~ /Mazzatorta/ + %h5= "Lowest observed adverse effect level (LOAEL) (Mazzatorta) Rats" + #pager{:id=>idx} + - else + %h5= (model == "Cramer") ? "Oral toxicity (Cramer rules)" : (m.endpoint =~ /Mutagenicity/i ? "Consensus mutagenicity" : "#{m.endpoint} (#{m.species})") + #pager{:id=>idx} %div.col-md-6.h5 %a.btn.btn-default.btn-xs.disabled{:id => "detailsbutton_#{idx}", :data=>{:toggle=>"collapse"}, :href=>"javascript:void(0)", :onclick=>"pagePredictions('#{task}','#{model}','#{idx}')", :style=>"font-size:small;"} %span.glyphicon.glyphicon-menu-right diff --git a/views/predict.haml b/views/predict.haml index d638451..0afcc99 100644 --- a/views/predict.haml +++ b/views/predict.haml @@ -186,8 +186,8 @@ - @endpoints.each do |endpoint| %div{:id=>endpoint.gsub(/\s+/, "_")} %h4.head-back=endpoint - - unless endpoint =~ /^Oral/ - - @models.select{|m| m.endpoint == endpoint}.each do |model| + - if endpoint !~ /^Oral|Mazzatorta/ + - @models.select{|m| endpoint = endpoint.gsub("(lazar)","").strip if endpoint =~ /lazar/; m.endpoint == endpoint}.each do |model| %div.row{:id => model.id,:style=>"margin-bottom:1em;"} %span.col-lg-4.col-md-4.col-sm-4.col-xs-4 %input.check{:type => "checkbox", :name => "selection[#{model.id}]", :id => "selection[#{model.species.gsub(/\s+/, "_")}]", :value => true, :disabled => false} @@ -223,12 +223,18 @@ }); } } - - else + - elsif endpoint =~ /^Oral/ %div.row{:id => "Cramer",:style=>"margin-bottom:1em;"} %span.col-lg-4.col-md-4.col-sm-4.col-xs-4 %input.check{:type => "checkbox", :name => "selection[Cramer]", :id => "selection[Cramer]", :value => true, :disabled => false} %label{:for => "selection[Cramer]"} Cramer rules + - elsif endpoint =~ /Mazzatorta/ + %div.row{:id => "Mazzatorta",:style=>"margin-bottom:1em;"} + %span.col-lg-4.col-md-4.col-sm-4.col-xs-4 + %input.check{:type => "checkbox", :name => "selection[Mazzatorta]", :id => "selection[Mazzatorta]", :value => true, :disabled => false} + %label{:for => "selection[Mazzatorta]"} + Rats %fieldset#bottom.well %div.row %div.col-md-2 diff --git a/views/prediction.haml b/views/prediction.haml index b4b51ca..152efc9 100644 --- a/views/prediction.haml +++ b/views/prediction.haml @@ -23,6 +23,8 @@ - @model_types = {} - @dbhit = {} - toxtree = @predictions.pop if @toxtree == true + - mazzatorta = @predictions.find{|p| p["mazzatorta"]} + - @predictions.delete(mazzatorta) if mazzatorta - unless @predictions.blank? - @predictions.each_with_index do |prediction,i| - if prediction["Consensus prediction"] @@ -138,7 +140,7 @@ %br =prediction[:warnings].join("
") - / show Cramer rules if checked + / Cramer - if @toxtree == true %td{:style=>"vertical-align:top;white-space:nowrap;"} %b.title Oral toxicity (Cramer rules) @@ -151,6 +153,24 @@ %br =toxtree.last["Cramer rules, with extensions"] + / Mazzatorta + - if mazzatorta + %td{:style=>"vertical-align:top;white-space:nowrap;"} + %b.title Lowest observed adverse effect level (LOAEL) (Rats) (Mazzatorta) + %p + - hash = mazzatorta["mazzatorta"] + - unless hash.keys.include?("warnings") + %b Prediction: + %br + = "#{hash[:mmol_prediction]} (mmol/kg_bw/day)" + %br + = "#{hash[:prediction]} (mg/kg_bw/day)" + - else + %b Warnings: + %br + = "#{hash[:warnings]}" + + / always show the neighbors table, message is given there. Except only Cramer is selected. - unless @predictions.blank? = haml :neighbors, :layout => false -- cgit v1.2.3