diff options
author | mr <mr@mrautenberg.de> | 2011-05-25 13:36:36 +0200 |
---|---|---|
committer | mr <mr@mrautenberg.de> | 2011-05-25 13:36:36 +0200 |
commit | 796ef9b86fcdcf5f9520b958c09cb37ae1374bf4 (patch) | |
tree | 9171e9be466efe88136adf6b0341e715f9f0d599 /lib | |
parent | a222e4b7235633c61e2c185d5b3e3d5467453d57 (diff) | |
parent | 153c740268c1bf6255f14f80550f690179a72fd9 (diff) |
Merge branch 'hotfix/uri_available' into development
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dataset.rb | 10 | ||||
-rw-r--r-- | lib/helper.rb | 3 | ||||
-rw-r--r-- | lib/parser.rb | 66 |
3 files changed, 60 insertions, 19 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb index 2b5759e..4005c1c 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -74,7 +74,7 @@ module OpenTox # @param [optional,String] uri URI of the dataset service, defaults to service specified in configuration # @return [Array] Array of dataset object without data (use one of the load_* methods to pull data from the server) def self.all(uri=CONFIG[:services]["opentox-dataset"], subjectid=nil) - RestClientWrapper.get(uri,{:accept => "text/uri-list",:subjectid => subjectid}).to_s.each_line.collect{|u| Dataset.new(u, subjectid)} + RestClientWrapper.get(uri,{:accept => "text/uri-list",:subjectid => subjectid}).to_s.each_line.collect{|u| Dataset.new(u.chomp, subjectid)} end # Load YAML representation into the dataset @@ -158,8 +158,12 @@ module OpenTox # Load and return only features from the dataset service # @return [Hash] Features of the dataset def load_features(subjectid=nil) - parser = Parser::Owl::Dataset.new(@uri, subjectid) - @features = parser.load_features(subjectid) + if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) + @features = YAML.load(RestClientWrapper.get(File.join(@uri,"features"), {:accept => "application/x-yaml", :subjectid => subjectid})) + else + parser = Parser::Owl::Dataset.new(@uri, subjectid) + @features = parser.load_features(subjectid) + end @features end diff --git a/lib/helper.rb b/lib/helper.rb index 3a6126a..995f3e9 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -44,8 +44,9 @@ helpers do def uri_available?(urlStr) url = URI.parse(urlStr) + subjectidstr = @subjectid ? "?subjectid=#{CGI.escape @subjectid}" : "" Net::HTTP.start(url.host, url.port) do |http| - return http.head("#{url.request_uri}?subjectid=#{CGI.escape @subjectid}").code == "200" + return http.head("#{url.request_uri}#{subjectidstr}").code == "200" end end diff --git a/lib/parser.rb b/lib/parser.rb index 7bdee95..5f847c3 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -277,7 +277,16 @@ module OpenTox def load_spreadsheet(book) book.default_sheet = 0 add_features book.row(1) - 2.upto(book.last_row) { |i| add_values book.row(i) } + + # AM: fix mixed read in + regression_features=false + 2.upto(book.last_row) { |i| + row = book.row(i) + regression_features = detect_regression_features row + break if regression_features==true + } + + 2.upto(book.last_row) { |i| add_values book.row(i),regression_features } warnings @dataset end @@ -289,11 +298,21 @@ module OpenTox row = 0 input = csv.split("\n") add_features split_row(input.shift) - input.each { |row| add_values split_row(row) } + + + # AM: fix mixed read in + regression_features=false + input.each { |row| + row = split_row(row) + regression_features = detect_regression_features row + break if regression_features==true + } + input.each { |row| add_values split_row(row),regression_features } warnings @dataset end + private def warnings @@ -335,7 +354,20 @@ module OpenTox end end - def add_values(row) + def detect_regression_features row + row.shift + regression_features=false + row.each_index do |i| + value = row[i] + type = feature_type(value) + if type == OT.NumericFeature + regression_features=true + end + end + regression_features + end + + def add_values(row, regression_features=false) smiles = row.shift compound = Compound.from_smiles(smiles) @@ -353,19 +385,23 @@ module OpenTox @feature_types[feature] << type - case type - when OT.NominalFeature - case value.to_s - when TRUE_REGEXP - val = true - when FALSE_REGEXP - val = false - end - when OT.NumericFeature + if (regression_features) val = value.to_f - when OT.StringFeature - val = value.to_s - @activity_errors << smiles+", "+row.join(", ") + else + case type + when OT.NominalFeature + case value.to_s + when TRUE_REGEXP + val = true + when FALSE_REGEXP + val = false + end + when OT.NumericFeature + val = value.to_f + when OT.StringFeature + val = value.to_s + @activity_errors << smiles+", "+row.join(", ") + end end if val!=nil @dataset.add(compound.uri, feature, val) |