From 8ebb06ddc85b38cd6ec71d81f55b800fd5825c15 Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 10 Nov 2016 19:53:34 +0000 Subject: version bump;units;general class update;sort by --- VERSION | 2 +- application.rb | 79 ++++++++++++++++++++++++++------------------------- bin/nano-lazar-start | 0 bin/nano-lazar-stop | 0 config.ru | 4 +-- npo.rb | 11 +++++++ views/predict.haml | 42 ++++++++++++++++----------- views/prediction.haml | 18 ++++++------ 8 files changed, 88 insertions(+), 68 deletions(-) mode change 100644 => 100755 bin/nano-lazar-start mode change 100644 => 100755 bin/nano-lazar-stop create mode 100644 npo.rb diff --git a/VERSION b/VERSION index bcab45a..81340c7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.3 +0.0.4 diff --git a/application.rb b/application.rb index 8a218f4..baba620 100644 --- a/application.rb +++ b/application.rb @@ -1,8 +1,9 @@ require 'qsar-report' require 'rdiscount' +require File.join './npo.rb' $ambit_search = "http://data.enanomapper.net/substance?type=name&search=" -$npo_search = "http://bioportal.bioontology.org/search?q=%s&ontologies=NPO&include_properties=false&include_views=false&includeObsolete=false&require_definition=false&exact_match=false&categories=" +include OpenTox configure :development do #$logger = Logger.new(STDOUT) @@ -17,11 +18,11 @@ get '/?' do end #=begin get '/qmrf-report/:id' do - prediction_model = OpenTox::Model::NanoPrediction.find(params[:id]) + prediction_model = Model::NanoPrediction.find(params[:id]) if prediction_model model = prediction_model.model model_type = "regression" - report = OpenTox::QMRFReport.new + report = QMRFReport.new if File.directory?("#{File.dirname(__FILE__)}/../../lazar") lazar_commit = `cd #{File.dirname(__FILE__)}/../../lazar; git rev-parse HEAD`.strip lazar_commit = "https://github.com/opentox/lazar/tree/#{lazar_commit}" @@ -34,38 +35,38 @@ get '/qmrf-report/:id' do report.value "qmrf_date", "#{Time.now.strftime('%d %B %Y')}" report.change_catalog :authors_catalog, :firstauthor, {:name => "Christoph Helma", :affiliation => "in silico toxicology gmbh", :contact => "Rastatterstrasse 41, CH-4057 Basel, Switzerland", :email => "helma@in-silico.ch", :number => "1", :url => "http://in-silico.ch"} report.ref_catalog :qmrf_authors, :authors_catalog, :firstauthor - report.change_catalog :authors_catalog, :modelauthor, {:name => "Christoph Helma", :affiliation => "in silico toxicology gmbh", :contact => "Contact Address", :email => "Contact Email", :number => "1", :url => "Web Page"} + report.change_catalog :authors_catalog, :modelauthor, {:name => "Christoph Helma", :affiliation => "in silico toxicology gmbh", :contact => "Rastatterstrasse 41, CH-4057 Basel, Switzerland", :email => "helma@in-silico.ch", :number => "1", :url => "http://in-silico.ch"} report.ref_catalog :model_authors, :authors_catalog, :modelauthor report.value "model_date", "#{Time.parse(model.created_at.to_s).strftime('%Y')}" - report.change_catalog :publications_catalog, :publications_catalog_1, {:title => "Rautenberg, Gebele and Helma (2013), Validation of read across predictions for nanoparticle toxicities ", :url => "in preparation"} + report.change_catalog :publications_catalog, :publications_catalog_1, {:title => "Helma, Rautenberg and Gebele (2013), Validation of read across predictions for nanoparticle toxicities ", :url => "in preparation"} report.ref_catalog :references, :publications_catalog, :publications_catalog_1 report.value "model_species", prediction_model.species report.change_catalog :endpoints_catalog, :endpoints_catalog_1, {:name => prediction_model.endpoint, :group => ""} report.ref_catalog :model_endpoint, :endpoints_catalog, :endpoints_catalog_1 report.value "endpoint_units", "#{prediction_model.unit}" - report.value "algorithm_type", "#{model.class.to_s.gsub('OpenTox::Model::Lazar','')}" - #TODO add more - report.change_catalog :algorithms_catalog, :algorithms_catalog_1, {:definition => "see Helma 2016 and lazar.in-silico.ch, submitted version: #{lazar_commit}", :description => "Neighbor algorithm: #{model.neighbor_algorithm.gsub('_',' ').titleize}#{(model.neighbor_algorithm_parameters[:min_sim] ? ' with similarity > ' + model.neighbor_algorithm_parameters[:min_sim].to_s : '')}"} - report.ref_catalog :algorithm_explicit, :algorithms_catalog, :algorithms_catalog_1 - report.change_catalog :algorithms_catalog, :algorithms_catalog_3, {:definition => "see Helma 2016 and lazar.in-silico.ch, submitted version: #{lazar_commit}", :description => "modified k-nearest neighbor #{model_type}"} - report.ref_catalog :algorithm_explicit, :algorithms_catalog, :algorithms_catalog_3 - if model.prediction_algorithm_parameters - pred_algorithm_params = (model.prediction_algorithm_parameters[:method] == "rf" ? "random forest" : model.prediction_algorithm_parameters[:method]) - end - report.change_catalog :algorithms_catalog, :algorithms_catalog_2, {:definition => "see Helma 2016 and lazar.in-silico.ch, submitted version: #{lazar_commit}", :description => "Prediction algorithm: #{model.prediction_algorithm.gsub('OpenTox::Algorithm::','').gsub('_',' ').gsub('.', ' with ')} #{(pred_algorithm_params ? pred_algorithm_params : '')}"} - report.ref_catalog :algorithm_explicit, :algorithms_catalog, :algorithms_catalog_2 + report.value "algorithm_type", "#{model.class.to_s.gsub('Model::Lazar','')}" + #TODO add updated algorithms + #report.change_catalog :algorithms_catalog, :algorithms_catalog_1, {:definition => "see Helma 2016 and lazar.in-silico.ch, submitted version: #{lazar_commit}", :description => "Neighbor algorithm: #{model.neighbor_algorithm.gsub('_',' ').titleize}#{(model.neighbor_algorithm_parameters[:min_sim] ? ' with similarity > ' + model.neighbor_algorithm_parameters[:min_sim].to_s : '')}"} + #report.ref_catalog :algorithm_explicit, :algorithms_catalog, :algorithms_catalog_1 + #report.change_catalog :algorithms_catalog, :algorithms_catalog_3, {:definition => "see Helma 2016 and lazar.in-silico.ch, submitted version: #{lazar_commit}", :description => "modified k-nearest neighbor #{model_type}"} + #report.ref_catalog :algorithm_explicit, :algorithms_catalog, :algorithms_catalog_3 + #if model.prediction_algorithm_parameters + # pred_algorithm_params = (model.prediction_algorithm_parameters[:method] == "rf" ? "random forest" : model.prediction_algorithm_parameters[:method]) + #end + #report.change_catalog :algorithms_catalog, :algorithms_catalog_2, {:definition => "see Helma 2016 and lazar.in-silico.ch, submitted version: #{lazar_commit}", :description => "Prediction algorithm: #{model.prediction_algorithm.gsub('Algorithm::','').gsub('_',' ').gsub('.', ' with ')} #{(pred_algorithm_params ? pred_algorithm_params : '')}"} + #report.ref_catalog :algorithm_explicit, :algorithms_catalog, :algorithms_catalog_2 # Descriptors in the model 4.3 - if model.neighbor_algorithm_parameters[:type] - report.change_catalog :descriptors_catalog, :descriptors_catalog_1, {:description => "", :name => "#{model.neighbor_algorithm_parameters[:type]}", :publication_ref => "", :units => ""} - report.ref_catalog :algorithms_descriptors, :descriptors_catalog, :descriptors_catalog_1 - end + #if model.neighbor_algorithm_parameters[:type] + # report.change_catalog :descriptors_catalog, :descriptors_catalog_1, {:description => "", :name => "#{model.neighbor_algorithm_parameters[:type]}", :publication_ref => "", :units => ""} + # report.ref_catalog :algorithms_descriptors, :descriptors_catalog, :descriptors_catalog_1 + #end # Descriptor selection 4.4 - report.value "descriptors_selection", "#{model.feature_selection_algorithm.gsub('_',' ')} #{model.feature_selection_algorithm_parameters.collect{|k,v| k.to_s + ': ' + v.to_s}.join(', ')}" if model.feature_selection_algorithm - response['Content-Type'] = "application/xml" + #report.value "descriptors_selection", "#{model.feature_selection_algorithm.gsub('_',' ')} #{model.feature_selection_algorithm_parameters.collect{|k,v| k.to_s + ': ' + v.to_s}.join(', ')}" if model.feature_selection_algorithm - return report.to_xml + response['Content-Type'] = "application/xml" + return report.to_xml else bad_request_error "model with id: #{params[:id]} does not exist." end @@ -73,23 +74,23 @@ end #=end get '/predict/?' do @prediction_models = [] - prediction_models = OpenTox::Model::NanoPrediction.all - prediction_models.each{|m| m.model[:feature_selection_algorithm_parameters]["category"] == "P-CHEM" ? @prediction_models[0] = m : @prediction_models[1] = m} + prediction_models = Model::NanoPrediction.all + prediction_models.each{|m| m.model[:algorithms]["descriptors"]["categories"] == ["P-CHEM"] ? @prediction_models[0] = m : @prediction_models[1] = m} # define type (pc or pcp) @prediction_models.each_with_index{|m,idx| idx == 0 ? m[:pc_model] = true : m[:pcp_model] = true} # collect nanoparticles by training dataset (Ag + Au) - dataset = OpenTox::Dataset.find_by(:name=> "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles") + dataset = Dataset.find_by(:name=> "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles") nanoparticles = dataset.nanoparticles - # select physchem_parameters by relevant_features for of each model - @pc_relevant_features = @prediction_models[0].model.relevant_features.collect{|id, v| OpenTox::Feature.find(id)} - @pcp_relevant_features = @prediction_models[1].model.relevant_features.collect{|id, v| OpenTox::Feature.find(id)} + # select physchem_parameters by relevant features for each model + @pc_relevant_features = @prediction_models[0].model.descriptor_ids.collect{|id, v| Feature.find(id)} + @pcp_relevant_features = @prediction_models[1].model.descriptor_ids.collect{|id, v| Feature.find(id)} pcp = nanoparticles.sample - pcp.physchem_descriptors.delete_if{|id,v| !@pcp_relevant_features.include?(OpenTox::Feature.find(id))} + pcp.properties.delete_if{|id,v| !@pcp_relevant_features.include?(Feature.find(id))} @example_pcp = pcp pc = nanoparticles.sample - pc.physchem_descriptors.delete_if{|id,v| !@pc_relevant_features.include?(OpenTox::Feature.find(id))} + pc.properties.delete_if{|id,v| !@pc_relevant_features.include?(Feature.find(id))} @example_pc = pc haml :predict @@ -102,7 +103,7 @@ end post '/predict/?' do # choose the right prediction model - prediction_model = OpenTox::Model::NanoPrediction.find(params[:prediction_model]) + prediction_model = Model::NanoPrediction.find(params[:prediction_model]) size = params[:size].to_i @type = params[:type] @@ -123,28 +124,28 @@ post '/predict/?' do # define relevant_features by input - @type = "pc" ? (@pc_relevant_features = input_pc.collect{|id,v| OpenTox::Feature.find(id)}) : (@pc_relevant_features = []) - @type = "pcp" ? (@pcp_relevant_features = input_pc.collect{|id,v| OpenTox::Feature.find(id)}) : (@pcp_relevant_features = []) + @type = "pc" ? (@pc_relevant_features = input_pc.collect{|id,v| Feature.find(id)}) : (@pc_relevant_features = []) + @type = "pcp" ? (@pcp_relevant_features = input_pc.collect{|id,v| Feature.find(id)}) : (@pcp_relevant_features = []) if input_pc == example_pc && input_core == example_core && input_coating == example_coating # unchanged input = database hit - nanoparticle = OpenTox::Nanoparticle.find_by(:id => params[:example_id]) - nanoparticle.physchem_descriptors = input_pc + nanoparticle = Nanoparticle.find_by(:id => params[:example_id]) + nanoparticle.properties = input_pc @match = true @nanoparticle = nanoparticle @name = nanoparticle.name else # changed input = create nanoparticle to predict - nanoparticle = OpenTox::Nanoparticle.new + nanoparticle = Nanoparticle.new nanoparticle.core = input_core nanoparticle.coating = input_coating - nanoparticle.physchem_descriptors = input_pc + nanoparticle.properties = input_pc @match = false @nanoparticle = nanoparticle end # prediction output @input = input_pc - @prediction = prediction_model.model.predict_substance nanoparticle + @prediction = prediction_model.model.predict nanoparticle haml :prediction end diff --git a/bin/nano-lazar-start b/bin/nano-lazar-start old mode 100644 new mode 100755 diff --git a/bin/nano-lazar-stop b/bin/nano-lazar-stop old mode 100644 new mode 100755 diff --git a/config.ru b/config.ru index 36438a3..0662ccd 100644 --- a/config.ru +++ b/config.ru @@ -7,7 +7,7 @@ require "sinatra/reloader" if development? FileUtils.mkdir_p 'log' unless File.exists?('log') log = File.new("log/nano-lazar.log", "a") -$stdout.reopen(log) -$stderr.reopen(log) +#$stdout.reopen(log) +#$stderr.reopen(log) run Sinatra::Application diff --git a/npo.rb b/npo.rb new file mode 100644 index 0000000..8d7075a --- /dev/null +++ b/npo.rb @@ -0,0 +1,11 @@ +$npo = { + "Localized Surface Plasmon Resonance (LSPR) index" => "http://bioportal.bioontology.org/ontologies/OBI?p=classes&conceptid=http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FOBI_0001136", + "ZETA POTENTIAL" => "http://bioportal.bioontology.org/ontologies/ENM?p=classes&conceptid=http%3A%2F%2Fpurl.bioontology.org%2Fontology%2Fnpo%23NPO_1302", + "Total protein (BCA assay)" => "http://bioportal.bioontology.org/ontologies/ENM?p=classes&conceptid=http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FOAE_0001659", + "Core size" => "http://bioportal.bioontology.org/ontologies/ENM?p=classes&conceptid=http%3A%2F%2Fpurl.enanomapper.org%2Fonto%2FENM_8000039", + "Z-Average Hydrodynamic Diameter" => "http://bioportal.bioontology.org/ontologies/ENM?p=classes&conceptid=http%3A%2F%2Fpurl.bioontology.org%2Fontology%2Fnpo%23NPO_1915", + "Volume Mean Hydrodynamic Diameter" => "http://bioportal.bioontology.org/ontologies/ENM?p=classes&conceptid=http%3A%2F%2Fpurl.bioontology.org%2Fontology%2Fnpo%23NPO_1915", + "Intensity Mean Hydrodynamic Diameter" => "http://bioportal.bioontology.org/ontologies/ENM?p=classes&conceptid=http%3A%2F%2Fpurl.bioontology.org%2Fontology%2Fnpo%23NPO_1915", + "Autot (ICP-AES)" => "http://bioportal.bioontology.org/ontologies/ERO?p=classes&conceptid=http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FERO_0001675", + "Polydispersity index" => "http://bioportal.bioontology.org/ontologies/ENM?p=classes&conceptid=http%3A%2F%2Fpurl.bioontology.org%2Fontology%2Fnpo%23NPO_1155" +} diff --git a/views/predict.haml b/views/predict.haml index 5d5d6f0..7819698 100644 --- a/views/predict.haml +++ b/views/predict.haml @@ -11,7 +11,7 @@ - @prediction_models.each_with_index do |m, idx| %li{:class => ("active" if idx == 0)} %a{:href => "#model_#{idx}", :id => "linkTab#{idx}", data: {toggle:"tab"}} - = "#{idx+1}. #{m.model.feature_selection_algorithm_parameters[:category].nil? ? "Physchem & Proteomics" : "Physchem" }" + = "#{idx+1}. #{m[:pcp_model] ? "Physchem & Proteomics" : "Physchem" }" %div.tab-content - @prediction_models.each_with_index do |m, idx| - m[:pc_model] ? (example = @example_pc; type = "pc"; relevant_features = @pc_relevant_features) : (example = @example_pcp; type = "pcp"; relevant_features = @pcp_relevant_features) @@ -39,17 +39,23 @@ Unit: = m.unit %br - Prediction algorithm: - = m.model.prediction_algorithm.split(".").last.gsub("_"," ") + %b Algorithms: %br - Prediction algorithm parameter: - = "random forest" if m.model.prediction_algorithm_parameters["method"] == "rf" + Similarity: + %a{:href=> "http://www.rubydoc.info/gems/lazar/OpenTox%2F#{m.model.algorithms["similarity"]["method"].sub("::", "%2F")}", :rel=>"external"} + = m.model.algorithms["similarity"]["method"] + = ", min: #{m.model.algorithms["similarity"]["min"]}" %br - Neighbor algorithm: - = m.model.neighbor_algorithm.gsub("_", " ") + Prediction: + %a{:href=>"http://www.rubydoc.info/gems/lazar/OpenTox%2F#{m.model.algorithms["prediction"]["method"].sub("::","%2f")}", :rel=>"external"} + = m.model.algorithms["prediction"]["method"] %br - Neighbor algorithm parameter: - = "min sim = #{m.model.neighbor_algorithm_parameters["min_sim"]}" + Feature selection: + = m.model.algorithms["feature_selection"]["method"].split(".").last + %br + Descriptors: + = m.model.algorithms["descriptors"]["method"]+"," + = m.model.algorithms["descriptors"]["categories"] %p %b Independent crossvalidations (log2 transformed): - crossvalidations =[] @@ -89,7 +95,7 @@ // example data to compare %input{:id=>"example_core",:type=>"hidden",:name=>"example_core",:value=>"#{example.core}"} %input{:id=>"example_coating",:type=>"hidden",:name=>"example_coating",:value=>"#{example.coating}"} - %input{:id=>"example_pc",:type=>"hidden",:name=>"example_pc",:value=>"#{example.physchem_descriptors}"} + %input{:id=>"example_pc",:type=>"hidden",:name=>"example_pc",:value=>"#{example.properties}"} - size = relevant_features.size %input{:id=>"size",:type=>"hidden",:name=>"size",:value=>size} %input{:id=>"id",:type=>"hidden",:name=>"example_id",:value=>example.id} @@ -107,9 +113,13 @@ %input{:id=>"input_coating",:type=>"hidden",:name=>"in_coating",:value=>example.coating} // prediction model id %input{:id=>"prediction_model",:type=>"hidden",:name=>"prediction_model",:value=>m.id} - - relevant_features.sort_by{|d| d.category}.each_with_index do |relf,id| + //sort the relevant features + - pc = relevant_features.collect{|f| f if f.category == "P-CHEM"}.compact + - pcp = relevant_features.collect{|f| f if f.category == "Proteomics"}.compact + - relevant_features = pc.sort_by{|f| f.name} + pcp.sort_by{|f| f.name} + - relevant_features.each_with_index do |relf,id| - feature = relf - - v = example.physchem_descriptors.find{|id,v| id == feature.id.to_s } + - v = example.properties.find{|id,v| id == feature.id.to_s } - name = feature.name - if feature[:conditions] && !feature[:conditions]["MEDIUM"].blank? - name = feature.name + " / " + feature[:conditions]["MEDIUM"] @@ -119,12 +129,10 @@ - id = id + 1 - if feature.category == "Proteomics" %h5 - %a{:href=>"http://www.uniprot.org/uniprot/#{name}", :rel=>"external"}= name - - else - / prepare name string for npo_search - - string = name.split("/").first.downcase.gsub(/%s/, "%20") + %a{:href=>"http://www.uniprot.org/uniprot/#{name}", :rel=>"external"}= name + (feature.unit.blank? ? "" : " (#{feature.unit})") + - if feature.category == "P-CHEM" %h5 - %a{:href=>$npo_search % string, :rel=>"external"}= name + %a.descriptor{:href=>$npo[feature.name], :rel=>"external"}= name + (feature.unit.blank? ? "" : " (#{feature.unit})") // input physchem parameters %input.input-sm.form-control{:id=>id,:type=>"text",:name=>"input_value_#{id}",:value=>"#{val[0] if val[0]}", :disabled=>("disabled" if val[0] == "-")} - if val[0] == "-" diff --git a/views/prediction.haml b/views/prediction.haml index 53a9cfd..e451c5f 100644 --- a/views/prediction.haml +++ b/views/prediction.haml @@ -12,7 +12,7 @@ $(".tablesorter").tablesorter({ debug: false, theme: "bootstrap", - headerTemplate: '{content} {icon}', + //headerTemplate: '{content} {icon}', widgets: ['uitheme', 'staticRow', 'stickyHeaders'], widgetOptions: { stickyHeaders_attachTo: 'neighbors', @@ -43,15 +43,15 @@ Net cell association %br [mL/ug(Mg)] - - @input.each{|d| OpenTox::Feature.find(d[0]).category}.each do |key| - - feature = OpenTox::Feature.find_by(:id=>key[0]) + - @input.each{|d| Feature.find(d[0]).category}.each do |key| + - feature = Feature.find_by(:id=>key[0]) - name = feature.name - if (feature[:conditions] && !feature[:conditions]["MEDIUM"].blank?) - name = feature.name + " / " + feature[:conditions]["MEDIUM"] - else - name = feature.name - %th.physchem - = name + %th.physchem.sorter-false + %a.descriptor{:href=>$npo[feature.name], :rel=>"external"}= name + (feature.unit.blank? ? "" : " (#{feature.unit})") %tbody / query and match combined %tr.static @@ -118,7 +118,7 @@ / neighbors - if @prediction[:neighbors] - @prediction[:neighbors].each_with_index do |neighbor,idx| - - nano = OpenTox::Nanoparticle.find(neighbor["_id"]) + - nano = Nanoparticle.find(neighbor[:id]) %tr / ID %td @@ -126,7 +126,7 @@ %h5.th5= nano.name / Similarity %td - %h5.th5= neighbor["similarity"].round(3) + %h5.th5= neighbor[:similarity].round(3) / Composition %td %h5.th5 Core: @@ -137,8 +137,8 @@ / Tox %td.tox %h5.th5 Measurement: - = neighbor["measurements"][0] + = neighbor[:measurement] / Physchem - - nano.physchem_descriptors.delete_if{|id,v| @type == "pc" ? !@pc_relevant_features.include?(OpenTox::Feature.find(id)) : !@pcp_relevant_features.include?(OpenTox::Feature.find(id))}.sort_by{|id,v| @pc_relevant_features.index OpenTox::Feature.find(id)}.each do |k,v| + - nano.properties.delete_if{|id,v| @type == "pc" ? !@pc_relevant_features.include?(Feature.find(id)) : !@pcp_relevant_features.include?(Feature.find(id))}.sort_by{|id,v| @pc_relevant_features.index Feature.find(id)}.each do |k,v| %td.physchem = v[0].round(3) unless v.nil? -- cgit v1.2.3