lib/seqtrimnext/classes/params.rb in seqtrimnext-2.0.39 vs lib/seqtrimnext/classes/params.rb in seqtrimnext-2.0.41

- old
+ new

@@ -11,10 +11,11 @@ @params = {} @comments = {} # @param_order={} @mids = {} @ab_adapters={} + @adapters={} @linkers = {} @clusters = {} @plugin_comments = {} @@ -53,21 +54,40 @@ end end end# end def - def load_db_fastas(path_file) + def load_db_fastas(input_paths) + res={} - if File.exists?(path_file) - ff = FastaFile.new(path_file) - ff.each {|n,f| - # @mid_sizes[n]=f.size - res[n]=f - } - ff.close + if (!input_paths.nil?) & (input_paths!='') + # remove quotes + paths=input_paths.gsub(/\A['"]+|['"]+\Z/, "") + + # split paths by spaces + # puts "PATHS:" + # puts paths.split(' ') + paths.split(' ').each do |path_file| + + if File.exists?(path_file) + ff = FastaFile.new(path_file) + ff.each {|n,f| + res[n]=f + } + + ff.close + end + end + end + + # puts "LOADED_DB #{paths}:" + # res.each do |k,v| + # puts k + # end + return res end # Load mid's file def load_mids(path_file) @@ -76,17 +96,23 @@ end # Load ab_adapters file def load_ab_adapters(path_file) @ab_adapters=load_db_fastas(path_file) - # puts @ab_adapters + # puts @ab_adapters end + # load normal adapters + def load_adapters(path_file) + @adapters=load_db_fastas(path_file) + end + + # Load mid's file def load_linkers(path_file) @linkers=load_db_fastas(path_file) - # puts @linkers + # puts @linkers end def load_repeated_seqs(file_path) @clusters={} @@ -154,26 +180,45 @@ def get_param(param) #$LOG.debug "Get Param: #{@params[param]}" return @params[param] end + def get_fasta(list,name,type) + res = list[name] + + if res.nil? + $LOG.error("Error. The #{type}: #{name} was not correctly loaded") + raise "Error. The #{type}: #{name} was not found in loaded #{name}s: #{list.map{|k,v| k}}." + end + + return res + end + # Return the mid's size of param - def get_mid(param) - return @mids[param] + def get_mid(mid) + # return @mids[mid] + return get_fasta(@mids,mid,"mid") end # Return the linker of param def get_linker(linker) - return @linkers[linker] + # return @linkers[linker] + return get_fasta(@linkers,linker,"linker") end # Return the ab of param def get_ab_adapter(adapter) - return @ab_adapters[adapter] + # return @ab_adapters[adapter] + return get_fasta(@ab_adapters,adapter,"ab_adapter") end + def get_adapter(adapter) + # return @adapters[adapter] + return get_fasta(@adapters,adapter,"adapter") + end + def get_plugin plugin='General' # puts caller(2)[1] at = caller(2)[1] if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at @@ -298,20 +343,25 @@ # def split_databases(db_param_name) def check_db_param(errors,db_param_name) # expand database paths dbs= get_param(db_param_name).gsub('"','').split(/\s+/) # puts "ALGO"*20 - puts dbs.join(',') + # puts "INPUT DATABASES:\n"+dbs.join(',') + + procesed_dbs=[] # # TODO - chequear aqui que la db no esta vacia y que esta formateada. - dbs.reverse_each {|db| + dbs.reverse_each {|db_p| + db=File.expand_path(db_p) + if !File.exists?(db) - path=File.join($FORMATTED_DB_PATH,db) + path=File.join($FORMATTED_DB_PATH,db_p) else path=db end + if Dir.glob(path+'*.n*').entries.empty? puts "DB file #{path} not formatted" if File.writable_real?(path) cmd = "makeblastdb -in #{path} -parse_seqids -dbtype nucl" @@ -319,19 +369,23 @@ else raise "Can't format database. We don't have write permissions in: #{path}" end end + procesed_dbs << path + if !File.exists?(path) raise "DB File #{path} does not exists" # exit end } - db_paths = '"'+dbs.join(' ')+'"' + db_paths = '"'+procesed_dbs.join(' ')+'"' + set_param(db_param_name,db_paths) - # puts "DATABASES"+db_paths + + puts "USED DATABASES\n"+db_paths end def self.generate_sample_params @@ -349,53 +403,53 @@ puts "Sample params file generated: #{filename}" end def check_param(errors,param,param_class,default_value=nil, comment=nil) - + if !exists?(param) if default_value.nil? #|| (default_value.is_a?(String) && default_value.empty?) errors.push "The param #{param} is required and no default value is available" else set_param(param,default_value,comment) end end - s = get_param(param) + s = get_param(param) - set_comment(get_plugin,param,comment) + set_comment(get_plugin,param,comment) - # check_class=Object.const_get(param_class) - begin + # check_class=Object.const_get(param_class) + begin - case param_class - when 'Integer' - r = Integer(s) - when 'Float' - r = Float(s) - when 'String' - r = String(s) - when 'DB' - # it is a string - r = String(s) - # and must be a valid db - - r = check_db_param(errors,param) + case param_class + when 'Integer' + r = Integer(s) + when 'Float' + r = Float(s) + when 'String' + r = String(s) + when 'DB' + # it is a string + r = String(s) + # and must be a valid db - when 'PluginList' - r=String(s) - r= check_plugin_list_param(errors,param) - end + r = check_db_param(errors,param) - rescue Exception => e - message="Current value is ##{s}#. " - if param_class=='DB' - message += e.message - end + when 'PluginList' + r=String(s) + r= check_plugin_list_param(errors,param) + end - errors.push "Param #{param} is not a valid #{param_class}. #{message}" + rescue Exception => e + message="Current value is ##{s}#. " + if param_class=='DB' + message += e.message end + + errors.push "Param #{param} is not a valid #{param_class}. #{message}" + end # end end end