Permalink
Browse files

add subjectids for a&a

  • Loading branch information...
1 parent 754fd31 commit 467eca96bd1fdab0613d99048f9436841856aa10 @rautenberg rautenberg committed Feb 21, 2012
Showing with 14 additions and 21 deletions.
  1. +1 −1 lib/algorithm.rb
  2. +1 −1 lib/authorization.rb
  3. +5 −8 lib/compound.rb
  4. +2 −6 lib/model.rb
  5. +5 −5 lib/utils.rb
View
2 lib/algorithm.rb
@@ -527,7 +527,7 @@ def self.match_hits(params)
# @param [Hash] required keys: compound, features, feature_dataset_uri, pc_type
# @return [Hash] Hash with matching Smarts and number of hits
def self.lookup(params)
- params[:compound].lookup(params[:features], params[:feature_dataset_uri],params[:pc_type])
+ params[:compound].lookup(params[:features], params[:feature_dataset_uri],params[:pc_type],params[:subjectid])
end
end
View
2 lib/authorization.rb
@@ -337,7 +337,7 @@ class << self
# @param [String] subjectid
# @return [Boolean] true if access granted, else otherwise
def self.authorized?(uri, request_method, subjectid)
- if CONFIG[:authorization][:free_request].include?(request_method)
+ if CONFIG[:authorization][:free_request].include?(request_method)
#LOGGER.debug "authorized? >>true<< (request is free), method: #{request_method}, URI: #{uri}, subjectid: #{subjectid}"
true
elsif OpenTox::Authorization.free_uri?(uri, request_method)
View
13 lib/compound.rb
@@ -198,9 +198,8 @@ def match_hits(smarts_array)
# @param [Array] Array of feature names
# @param [String] Feature dataset uri
# @return [Hash] Hash with feature name as key and value as value
- def lookup(feature_array,feature_dataset_uri,pc_type)
- ds = OpenTox::Dataset.find(feature_dataset_uri)
-
+ def lookup(feature_array,feature_dataset_uri,pc_type,subjectid=nil)
+ ds = OpenTox::Dataset.find(feature_dataset_uri,subjectid)
#entry = ds.data_entries[self.uri]
entry = nil
ds.data_entries.each { |c_uri, values|
@@ -209,17 +208,15 @@ def lookup(feature_array,feature_dataset_uri,pc_type)
break
end
}
-
LOGGER.debug "#{entry.size} entries in feature ds for query." unless entry.nil?
if entry.nil?
uri, smiles_to_inchi = OpenTox::Algorithm.get_pc_descriptors({:compounds => [self.uri], :pc_type => pc_type})
- uri = OpenTox::Algorithm.load_ds_csv(uri, smiles_to_inchi)
- ds = OpenTox::Dataset.find(uri)
+ uri = OpenTox::Algorithm.load_ds_csv(uri, smiles_to_inchi, subjectid)
+ ds = OpenTox::Dataset.find(uri,subjectid)
entry = ds.data_entries[self.uri]
- ds.delete
+ ds.delete(subjectid)
end
-
features = entry.keys
features.each { |feature|
new_feature = File.join(feature_dataset_uri, "feature", feature.split("/").last)
View
8 lib/model.rb
@@ -237,7 +237,6 @@ def predict(compound_uri,verbose=false,subjectid=nil)
@compound = Compound.new compound_uri
features = {}
-
#LOGGER.debug self.to_yaml
unless @prediction_dataset
@prediction_dataset = Dataset.create(CONFIG[:services]["opentox-dataset"], subjectid)
@@ -248,22 +247,19 @@ def predict(compound_uri,verbose=false,subjectid=nil)
OT.parameters => [{DC.title => "compound_uri", OT.paramValue => compound_uri}]
} )
end
-
if OpenTox::Feature.find(metadata[OT.dependentVariables], subjectid).feature_type == "regression"
all_activities = []
all_activities = @activities.values.flatten.collect! { |i| i.to_f }
end
-
unless database_activity(subjectid) # adds database activity to @prediction_dataset
-
# Calculation of needed values for query compound
@compound_features = eval("#{@feature_calculation_algorithm}({
:compound => @compound,
:features => @features,
:feature_dataset_uri => @metadata[OT.featureDataset],
- :pc_type => self.parameter(\"pc_type\")
+ :pc_type => self.parameter(\"pc_type\"),
+ :subjectid => subjectid
})")
-
# Adding fingerprint of query compound with features and values(p_value*nr_hits)
@compound_fingerprints = {}
@compound_features.each do |feature, value| # value is nil if "Substructure.match"
View
10 lib/utils.rb
@@ -104,13 +104,13 @@ def self.get_pc_descriptors(params)
# Load dataset via CSV
# @param[Array] Ambit result uri, piecewise (1st: base, 2nd: SMILES, 3rd+: features
# @return[String] dataset uri
- def self.load_ds_csv(ambit_result_uri, smiles_to_inchi)
+ def self.load_ds_csv(ambit_result_uri, smiles_to_inchi, subjectid=nil)
master=nil
(1...ambit_result_uri.size).collect { |idx|
curr_uri = ambit_result_uri[0] + ambit_result_uri[idx]
LOGGER.debug "Requesting #{curr_uri}"
- csv_data = CSV.parse( OpenTox::RestClientWrapper.get(curr_uri, {:accept => "text/csv"}) )
+ csv_data = CSV.parse( OpenTox::RestClientWrapper.get(curr_uri, {:accept => "text/csv", :subjectid => subjectid}) )
if csv_data[0] && csv_data[0].size>1
if master.nil? # This is the smiles entry
(1...csv_data.size).each{ |idx| csv_data[idx][1] = smiles_to_inchi[csv_data[idx][1]] }
@@ -145,11 +145,11 @@ def self.load_ds_csv(ambit_result_uri, smiles_to_inchi)
#File.open("/tmp/test.csv", 'w') {|f| f.write( master.collect {|r| r.join(",")}.join("\n") ) }
parser = OpenTox::Parser::Spreadsheets.new
- ds = OpenTox::Dataset.new
- ds.save
+ ds = OpenTox::Dataset.new(nil,subjectid)
+ ds.save(subjectid)
parser.dataset = ds
ds = parser.load_csv(master.collect{|r| r.join(",")}.join("\n"))
- ds.save
+ ds.save(subjectid)
end

0 comments on commit 467eca9

Please sign in to comment.