diff options
author | gebele <gebele@in-silico.ch> | 2018-09-24 14:33:43 +0000 |
---|---|---|
committer | gebele <gebele@in-silico.ch> | 2018-09-24 14:33:43 +0000 |
commit | 9b28faf75acb5a74ac0fac37433fbed4d1d39c7c (patch) | |
tree | ba0c5faf576933cb92455ec060430b3f56816f97 /batch.rb | |
parent | 427d0fc4e4190f201ff6a3a1ee29c6f6bf56bc56 (diff) |
allow tab separated smi files
Diffstat (limited to 'batch.rb')
-rw-r--r-- | batch.rb | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -1,6 +1,10 @@ require 'csv' require 'tempfile' +def has_tab?(line) + !!(line =~ /\t/) +end + module OpenTox class Batch @@ -24,7 +28,13 @@ module OpenTox $logger.debug "Skipping import of #{file}, it is already in the database (id: #{batch.id})." else $logger.debug "Parsing #{file}." - table = CSV.read file, :skip_blanks => true, :encoding => 'windows-1251:utf-8' + # check delimiter + line = File.readlines(file).first + if has_tab?(line) + table = CSV.read file, :col_sep => "\t", :skip_blanks => true, :encoding => 'windows-1251:utf-8' + else + table = CSV.read file, :skip_blanks => true, :encoding => 'windows-1251:utf-8' + end batch = self.new(:source => source, :name => name, :identifiers => [], :ids => [], :compounds => []) # original IDs @@ -37,7 +47,11 @@ module OpenTox feature_names = table.shift.collect{|f| f.strip} warnings << "Duplicated features in table header." unless feature_names.size == feature_names.uniq.size compound_format = feature_names.shift.strip - bad_request_error "#{compound_format} is not a supported compound format. Accepted formats: SMILES, InChI." unless compound_format =~ /SMILES|InChI/i + unless compound_format =~ /SMILES|InChI/i + File.delete file + bad_request_error "'#{compound_format}' is not a supported compound format in the header. " \ + "Accepted formats: SMILES, InChI. Please take a look on the help page." + end numeric = [] features = [] # guess feature types |