Class: Params
- Inherits:
-
Object
- Object
- Params
- Defined in:
- lib/seqtrimnext/classes/params.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#check_db_param(errors, db_param_name) ⇒ Object
def split_databases(db_param_name).
- #check_param(errors, param, param_class, default_value = nil, comment = nil) ⇒ Object
- #check_plugin_list_param(errors, param_name) ⇒ Object
-
#exists?(param_name) ⇒ Boolean
Returns true if exists the parameter and nil if don’t.
-
#get_ab_adapter(adapter) ⇒ Object
Return the ab of param.
- #get_adapter(adapter) ⇒ Object
- #get_comment(plugin, param) ⇒ Object
- #get_fasta(list, name, type) ⇒ Object
-
#get_linker(linker) ⇒ Object
Return the linker of param.
-
#get_mid(mid) ⇒ Object
Return the mid’s size of param.
-
#get_param(param) ⇒ Object
Return the parameter’s list in an array.
- #get_plugin ⇒ Object
-
#initialize(path) ⇒ Params
constructor
Creates the structure and start the reading of parameter’s file.
-
#load_ab_adapters(path_file) ⇒ Object
Load ab_adapters file.
-
#load_adapters(path_file) ⇒ Object
load normal adapters.
-
#load_db_fastas(input_paths) ⇒ Object
end def.
-
#load_linkers(path_file) ⇒ Object
Load mid’s file.
-
#load_mids(path_file) ⇒ Object
Load mid’s file.
- #load_repeated_seqs(file_path) ⇒ Object
-
#print_parameters ⇒ Object
Prints the pair name/numeric-value for every parameter.
-
#read_file(path_file) ⇒ Object
Reads param’s file.
- #repeated_seq?(name) ⇒ Boolean
-
#save_file(path_file) ⇒ Object
Reads param’s file.
- #set_comment(plugin, param, comment) ⇒ Object
- #set_mid(param, value) ⇒ Object
- #set_param(param, value, comment = nil) ⇒ Object
Constructor Details
#initialize(path) ⇒ Params
Creates the structure and start the reading of parameter’s file
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/seqtrimnext/classes/params.rb', line 10 def initialize(path) @params = {} @comments = {} # @param_order={} @mids = {} @ab_adapters={} @adapters={} @linkers = {} @clusters = {} @plugin_comments = {} read_file(path) end |
Class Method Details
.generate_sample_params ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/seqtrimnext/classes/params.rb', line 381 def self.generate_sample_params filename = 'sample_params.txt' x=1 while File.exists?(filename) filename = "sample_params#{x}.txt" x+=1 end f=File.open(filename,'w') f.puts "SAMPLE_PARAMS" f.close puts "Sample params file generated: #{filename}" end |
Instance Method Details
#check_db_param(errors, db_param_name) ⇒ Object
def split_databases(db_param_name)
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/seqtrimnext/classes/params.rb', line 333 def check_db_param(errors,db_param_name) if !get_param(db_param_name).empty? # expand database paths dbs= get_param(db_param_name).gsub('"','').split(/\s+/) # puts "ALGO"*20 # 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_p| db=File.(db_p) if !File.exists?(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" system(cmd) 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 = '"'+procesed_dbs.join(' ')+'"' set_param(db_param_name,db_paths) puts "USED DATABASES\n"+db_paths end end |
#check_param(errors, param, param_class, default_value = nil, comment = nil) ⇒ Object
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/seqtrimnext/classes/params.rb', line 398 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) set_comment(get_plugin,param,comment) # 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) when 'PluginList' r=String(s) r= check_plugin_list_param(errors,param) end rescue Exception => e ="Current value is ##{s}#. " if param_class=='DB' += e. end errors.push "Param #{param} is not a valid #{param_class}. #{}" end # end end |
#check_plugin_list_param(errors, param_name) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/seqtrimnext/classes/params.rb', line 306 def check_plugin_list_param(errors,param_name) # get plugin list pl_list=get_param(param_name) # puts pl_list,param_name list=pl_list.split(',') list.map!{|e| e.strip} # puts "Lista:",list.join(',') # always the pluginExtractInserts at the end list.delete('PluginExtractInserts') list << 'PluginExtractInserts' set_param(param_name,list.join(',')) # if !list.include?('PluginExtractInserts') # raise "PluginExtractInserts do not exists" # # end end |
#exists?(param_name) ⇒ Boolean
Returns true if exists the parameter and nil if don’t
302 303 304 |
# File 'lib/seqtrimnext/classes/params.rb', line 302 def exists?(param_name) return !@params[param_name].nil? end |
#get_ab_adapter(adapter) ⇒ Object
Return the ab of param
214 215 216 217 |
# File 'lib/seqtrimnext/classes/params.rb', line 214 def get_ab_adapter(adapter) # return @ab_adapters[adapter] return get_fasta(@ab_adapters,adapter,"ab_adapter") end |
#get_adapter(adapter) ⇒ Object
219 220 221 222 |
# File 'lib/seqtrimnext/classes/params.rb', line 219 def get_adapter(adapter) # return @adapters[adapter] return get_fasta(@adapters,adapter,"adapter") end |
#get_comment(plugin, param) ⇒ Object
251 252 253 254 255 256 257 |
# File 'lib/seqtrimnext/classes/params.rb', line 251 def get_comment(plugin,param) res = nil if @plugin_comments[plugin] res =@plugin_comments[plugin][param] end return res end |
#get_fasta(list, name, type) ⇒ Object
190 191 192 193 194 195 196 197 198 199 |
# File 'lib/seqtrimnext/classes/params.rb', line 190 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 |
#get_linker(linker) ⇒ Object
Return the linker of param
208 209 210 211 |
# File 'lib/seqtrimnext/classes/params.rb', line 208 def get_linker(linker) # return @linkers[linker] return get_fasta(@linkers,linker,"linker") end |
#get_mid(mid) ⇒ Object
Return the mid’s size of param
202 203 204 205 |
# File 'lib/seqtrimnext/classes/params.rb', line 202 def get_mid(mid) # return @mids[mid] return get_fasta(@mids,mid,"mid") end |
#get_param(param) ⇒ Object
Return the parameter’s list in an array
185 186 187 188 |
# File 'lib/seqtrimnext/classes/params.rb', line 185 def get_param(param) #$LOG.debug "Get Param: #{@params[param]}" return @params[param] end |
#get_plugin ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/seqtrimnext/classes/params.rb', line 225 def get_plugin plugin='General' # puts caller(2)[1] at = caller(2)[1] if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at file = Regexp.last_match[1] line = Regexp.last_match[2].to_i method = Regexp.last_match[3] plugin=File.basename(file,File.extname(file)) end end |
#load_ab_adapters(path_file) ⇒ Object
Load ab_adapters file
99 100 101 102 |
# File 'lib/seqtrimnext/classes/params.rb', line 99 def load_ab_adapters(path_file) @ab_adapters=load_db_fastas(path_file) # puts @ab_adapters end |
#load_adapters(path_file) ⇒ Object
load normal adapters
105 106 107 |
# File 'lib/seqtrimnext/classes/params.rb', line 105 def load_adapters(path_file) @adapters=load_db_fastas(path_file) end |
#load_db_fastas(input_paths) ⇒ Object
end def
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/seqtrimnext/classes/params.rb', line 59 def load_db_fastas(input_paths) res={} 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_linkers(path_file) ⇒ Object
Load mid’s file
111 112 113 114 |
# File 'lib/seqtrimnext/classes/params.rb', line 111 def load_linkers(path_file) @linkers=load_db_fastas(path_file) # puts @linkers end |
#load_mids(path_file) ⇒ Object
Load mid’s file
93 94 95 96 |
# File 'lib/seqtrimnext/classes/params.rb', line 93 def load_mids(path_file) @mids=load_db_fastas(path_file) # puts @mids end |
#load_repeated_seqs(file_path) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/seqtrimnext/classes/params.rb', line 116 def load_repeated_seqs(file_path) @clusters={} if File.exists?(file_path) # File.open(ARGV[0]).each_line do |line| $LOG.debug("Repeated file path:"+file_path) File.open(file_path).each_line do |line| #puts line,line[0] # en ruby19 line[0] da el caracter, no el chr #if (line[0]!=62) && (line[0]!=48) # if (line[0]!='>'[0]) && (line[0]!='0'[0]) # line doesn't finish in * if (line[0]!='>'[0]) && (!(line =~ /\*$/)) #puts line # puts line,line[0] if line =~ />([^\.]+)\.\.\.\s/ #puts 'ok' # puts $1 @clusters[$1]=1 end end end $LOG.info("Repeated sequence count: #{@clusters.count}") else $LOG.error("Clustering file's doesn't exists: #{@clusters.count}") end end |
#print_parameters ⇒ Object
Prints the pair name/numeric-value for every parameter
177 178 179 180 181 182 |
# File 'lib/seqtrimnext/classes/params.rb', line 177 def print_parameters() @params.each do |clave, valor| #$LOG.debug "The Parameter #{clave} have the value " +valor.to_s puts "#{clave} = #{valor} " end end |
#read_file(path_file) ⇒ Object
Reads param’s file
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/seqtrimnext/classes/params.rb', line 26 def read_file(path_file) if path_file && File.exists?(path_file) comments= [] File.open(path_file).each_line do |line| line.chomp! # delete end of line if !line.empty? if !(line =~ /^\s*#/) # if line is not a comment # extract the parameter's name in params[0] and the parameter's value in params[1] params = line.split(/\s*=\s*/) # store in the hash the pair key/value, in our case will be name/numeric-value , # that are save in params[0] and params[1], respectively if (!params[0].nil?) && (!params[1].nil?) set_param(params[0].strip,params[1].strip,comments) comments=[] end #$LOG.debug "read: #{params[1]}" else comments << line.gsub(/^\s*#/,'') end # end if comentario end #end if line end #end each if @params.empty? puts "INVALID PARAMETER FILE: #{path_file}. No parameters defined" exit end end end |
#repeated_seq?(name) ⇒ Boolean
148 149 150 |
# File 'lib/seqtrimnext/classes/params.rb', line 148 def repeated_seq?(name) return !@clusters[name].nil? end |
#save_file(path_file) ⇒ Object
Reads param’s file
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/seqtrimnext/classes/params.rb', line 153 def save_file(path_file) f=File.open(path_file,'w') @plugin_comments.keys.sort.reverse.each do |plugin_name| f.puts "#"*50 f.puts "# " + plugin_name f.puts "#"*50 f.puts '' @plugin_comments[plugin_name].keys.each do |param| comment=get_comment(plugin_name,param) if !comment.nil? && !comment.empty? && comment!='' f.puts comment.map{|c| '# '+c if c!=''} end f.puts '' f.puts "#{param} = #{@params[param]}" f.puts '' end end f.close end |
#set_comment(plugin, param, comment) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/seqtrimnext/classes/params.rb', line 260 def set_comment(plugin,param,comment) if !comment.is_a?(Array) && !comment.nil? comment=comment.split("\n").compact.map{|l| l.strip} end if @plugin_comments[plugin].nil? @plugin_comments[plugin]={} end old_comment='' # remove from other plugins @plugin_comments.each do |plugin_name,comments| if comments.keys.include?(param) && plugin_name!=plugin old_comment=comments[param] comments.delete(param) end end if comment.nil? comment=old_comment end # @comments[param]=(comment || ['']) @plugin_comments[plugin][param]=(comment || ['']) # puts @plugin_comments.keys.to_json # remove empty comments @plugin_comments.reverse_each do |plugin_name,comments| if comments.empty? @plugin_comments.delete(plugin_name) end end end |
#set_mid(param, value) ⇒ Object
297 298 299 |
# File 'lib/seqtrimnext/classes/params.rb', line 297 def set_mid(param,value) @mids[param] = value end |
#set_param(param, value, comment = nil) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/seqtrimnext/classes/params.rb', line 239 def set_param(param,value,comment = nil) plugin=get_plugin @params[param] = value if get_comment(plugin,param).nil? set_comment(plugin,param,comment) end end |