Class: PluginLowQuality
- Defined in:
- lib/seqtrimnext/plugins/plugin_low_quality.rb
Overview
Inherit: Plugin
Instance Attribute Summary
Attributes inherited from Plugin
Class Method Summary collapse
-
.check_params(params) ⇒ Object
Returns an array with the errors due to parameters are missing.
Instance Method Summary collapse
- #add_action_after_high_qual(p_begin, p_end, actions, seq) ⇒ Object
- #add_action_before_high_qual(p_begin, p_end, actions, seq, start) ⇒ Object
- #create_sum_window(qual, ini, index_window_end) ⇒ Object
-
#cut_fine_bounds(qual, new_start, new_end) ⇒ Object
cuts fine the high quality bounds.
- #cut_fine_bounds_short(qual, new_start, new_end) ⇒ Object
- #exec_seq(seq) ⇒ Object
-
#execute(seqs) ⇒ Object
Begins the plugin1’s execution whit the sequence “seq” Creates an action by each subsequence with low quality to eliminate it A subsequence has low quality if (the add of all its qualitis < subsequence_size*20) Creates the qualities windows from the sequence, looks for the subsequence with high quality and mark, with an action, the before part to the High Quality Subsequence like a low quality part Finally mark, with an action, the after part to the High Quality Subsequence like a low quality part —————————————————————–.
- #find_bounds_high_quality(sum, ini, index_window_end) ⇒ Object
Methods inherited from Plugin
#add_stats, #add_text_stats, auto_setup, check_param, get_graph_filename, get_graph_title, graph_ignored?, ignored_graphs, #initialize, #merge_hits, #overlapX?, plot_setup, valid_graphs
Constructor Details
This class inherits a constructor from Plugin
Class Method Details
.check_params(params) ⇒ Object
Returns an array with the errors due to parameters are missing
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/seqtrimnext/plugins/plugin_low_quality.rb', line 374 def self.check_params(params) errors=[] comment='Minimum quality value for every nucleotide' default_value = 20 params.check_param(errors,'min_quality','Integer',default_value,comment) comment='Quality window for scanning low quality segments' default_value = 15 params.check_param(errors,'window_width','Integer',default_value,comment) return errors end |
Instance Method Details
#add_action_after_high_qual(p_begin, p_end, actions, seq) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/seqtrimnext/plugins/plugin_low_quality.rb', line 237 def add_action_after_high_qual(p_begin,p_end,actions,seq) action_size = seq.insert_end-p_end if action_size>=(@window/2) # puts "action_SIZE2 #{action_size} > #{@window/2}" if ((p_end<seq.seq_fasta.size-1) && (action_size>0) ) #if there is action before the high qual part # it's created an action before of the high quality part a = seq.new_action(p_end-seq.insert_start+1,seq.seq_fasta.size-1,"ActionLowQuality") # adds the ActionInsert to the sequence before adding the actionMid actions.push a end end end |
#add_action_before_high_qual(p_begin, p_end, actions, seq, start) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/seqtrimnext/plugins/plugin_low_quality.rb', line 220 def add_action_before_high_qual(p_begin,p_end,actions,seq,start) action_size = p_begin-1 if action_size>=(@window/2) # puts "action_SIZE1 #{action_size} > #{@window/2}" if ( (p_begin>0) && (action_size>0) ) #if there is action before the high qual part # it's created an action before of the high quality part a = seq.new_action(start ,p_begin-1,"ActionLowQuality") # adds the ActionInsert to the sequence before adding the actionMid # puts " new low qual start: #{start} = #{a.start_pos} end: #{p_begin} -1 = #{a.end_pos}" actions.push a end end end |
#create_sum_window(qual, ini, index_window_end) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/seqtrimnext/plugins/plugin_low_quality.rb', line 16 def create_sum_window(qual,ini,index_window_end) # puts "--------index w #{index_window_end}" sum=[] i=ini # puts "#{i} #{index_window_end}" while (i<=index_window_end) # initialize sum sum[i]=0 i += 1 end # puts " contenido de sum" + sum.join.to_s + " i index_window_end window #{i} #{index_window_end} #{@window}" i=ini while (i<ini+@window) sum[ini] += qual[i] i+=1 end i=ini+1 while (i<=index_window_end) sum[i]=sum[i-1]-qual[i-1]+qual[i+@window-1] i+=1 end # puts '2____' + sum.join(',') + 'pos sum' + ini.to_s return sum end |
#cut_fine_bounds(qual, new_start, new_end) ⇒ Object
cuts fine the high quality bounds
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/seqtrimnext/plugins/plugin_low_quality.rb', line 138 def cut_fine_bounds(qual,new_start,new_end) # puts " ççççççççççççççç #{new_start+@window} >= #{new_end} " # puts " #{new_start} #{new_end} .o.o.o.o.o.o.o.o1" # cut it fine one_ok = 0 i=@window-1 # puts " qual[new_start+i] new_start #{new_start} i #{i} = #{new_start+i} qual.size #{qual.size}" while (i>=0) if (qual[new_start+i] < @low) break if one_ok else one_ok = 1 end i-=1 end new_start += i+1 oneOk = 0 i=0 while (i<@window) if (qual[new_end+i] < @low) break if oneOk else oneOk = 1 end i+=1 end new_end += i-1 # puts "6b new_start #{new_start} new-end #{new_end}" # puts " #{new_start} #{new_end} .o.o.o.o.o.o.o.o2" return new_start, new_end end |
#cut_fine_bounds_short(qual, new_start, new_end) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/seqtrimnext/plugins/plugin_low_quality.rb', line 108 def cut_fine_bounds_short(qual,new_start,new_end) i=0 # puts " qual[new_start+i] new_start #{new_start} i #{i} = #{new_start+i} qual.size #{qual.size}" while (i<@window) if (qual[new_start+i]>=@low) break end i+=1 end new_start +=i # puts "#{new_start} ***********" i=@window -1 while (i>=0) if (qual[new_end+i]>=@low) break end i-=1 end new_end += i # puts "6a new_start #{new_start} new-end #{new_end}" # puts " #{new_start} #{new_end} .o.o.o.o.o.o.o.o2 short" return new_start, new_end end |
#exec_seq(seq) ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 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 331 332 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 |
# File 'lib/seqtrimnext/plugins/plugin_low_quality.rb', line 276 def exec_seq(seq) if ((self.class.to_s=='PluginLowQuality') && seq.seq_qual.nil? ) $LOG.error " Quality File haven't been provided. It's impossible to execute " + self.class.to_s elsif (seq.seq_qual.size>0) $LOG.info "[#{self.class.to_s}, seq: #{seq.seq_name}]: checking low quality of the sequence" @low=@params.get_param('min_quality').to_i if @params.get_param('window_width').to_i>seq.seq_fasta.length @window=seq.seq_fasta.length else @window=@params.get_param('window_width').to_i end @cut_off=@window*@low type='ActionLowQuality' low_qual=0 actions=[] p_begin,p_end =0,-1 # positions from high quality bounds # @stats[:low_qual]={} # @stats['low_qual']={} while ((p_begin>=0) && (p_end + 1 < seq.seq_qual.size) ) p_begin_old,p_end_old= p_begin, p_end p_begin,p_end = find_high_quality(seq.seq_qual,p_end+1) # entra=(p_begin>0) or (p_end_old<0) # # puts "high ini fin #{p_begin} #{p_end} ini-old fin-old #{p_begin_old} #{p_end_old} __ ___ ___ ___1" if ((p_begin>0) && (p_begin-p_end_old-1>=@window/2)) #if we have found the high quality part, and the low quality part has enough size # it's created an action before of the high quality part add_action_before_high_qual(p_begin,p_end,actions,seq,p_end_old+1) # puts "low1 ini fin #{p_end_old+1} #{p_begin-1} = #{p_begin-1-p_end_old-1+1}" low_qual = p_begin-1-p_end_old-1 + 1 add_stats('low_qual',low_qual) # @stats[:low_qual]={low_qual => 1} end # puts "-----ññññ----- high quality #{p_begin} #{p_end}+#{seq.insert_start} seq size #{seq.seq_fasta.size}" end # puts "high [#{p_begin}, #{p_end}] old [#{p_begin_old}, #{p_end_old}] size #{seq.seq_qual.size}" if ((p_begin>=0) && (p_end+1<seq.seq_qual.size)) #if we have found the high quality part # it's created an action after of the high quality part add_action_after_high_qual(p_begin,p_end,actions,seq) # puts "low2 ini fin #{p_end+1} #{seq.seq_fasta.size-1} = #{seq.seq_fasta.size-1-p_end-1+1}" low_qual = seq.seq_fasta.size-1 - p_end-seq.insert_start-1 + 1 # if @stats[:low_qual][low_qual].nil? # @stats[:low_qual][low_qual] = 0 # end # @stats[:low_qual][low_qual] += 1 add_stats('low_qual',low_qual) # @stats[:low_qual]={low_qual => 1} end # puts "-----ññññ----- high quality #{p_begin} #{p_end}" if p_end<0 and p_end_old #add action low qual to all the part a = seq.new_action(p_end_old+1 ,seq.seq_fasta.size-1,"ActionLowQuality") # adds the ActionInsert to the sequence before adding the actionMid # puts "new low qual start: #{p_end_old+1} end: #{seq.seq_fasta.size-1} = #{seq.seq_fasta.size-1 - p_end_old-1 + 1}" low_qual = seq.seq_fasta.size-1 - p_end_old-1 + 1 # if @stats[:low_qual][low_qual].nil? # @stats[:low_qual][low_qual] = 0 # end # @stats[:low_qual][low_qual] += 1 add_stats('low_qual',low_qual) # @stats[:low_qual]={'low_qual' => 1} actions.push a end # puts "------- ADDING ACTIONs LOW QUAL #{actions.size}" seq.add_actions(actions) end end |
#execute(seqs) ⇒ Object
Begins the plugin1’s execution whit the sequence “seq” Creates an action by each subsequence with low quality to eliminate it A subsequence has low quality if (the add of all its qualitis < subsequence_size*20)
Creates the qualities windows from the sequence, looks for the subsequence with high quality and mark, with an action, the before part to the High Quality Subsequence like a low quality part Finally mark, with an action, the after part to the High Quality Subsequence like a low quality part
269 270 271 272 273 |
# File 'lib/seqtrimnext/plugins/plugin_low_quality.rb', line 269 def execute(seqs) seqs.each do |s| exec_seq(s) end end |
#find_bounds_high_quality(sum, ini, index_window_end) ⇒ Object
51 52 53 54 55 56 57 58 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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/seqtrimnext/plugins/plugin_low_quality.rb', line 51 def find_bounds_high_quality(sum,ini,index_window_end) new_start = -1 new_end = -1 # puts " ini #{ini} iwe #{index_window_end}" # puts "ini #{ini} index_window_end #{index_window_end} sum[ini] #{sum[ini]} cut_off #{@cut_off} suma #{sum.size} " if (ini>index_window_end) temp_start= ini # new_start, new_end = temp_start, index_window_end new_end = index_window_end # para que no crea que no hay alta calidad, sino que hemos sobrepasado el indice final de la ventana # new_start, new_end = index_window_end, index_window_end end # puts " temp_start #{temp_start}" if (ini>index_window_end) temp_start=((ini<=index_window_end) && (sum[ini]>=@cut_off))? ini : -1 i=ini+1 while (i<=index_window_end) if (sum[i]>=@cut_off) if (temp_start<0) temp_start=i #just in! # puts "just in ---- #{sum[i]}>= cut off #{@cut_off} pos #{temp_start}" end else # puts "sum #{sum[i]} < cut off " if(temp_start>=0) #just out! # puts "update #{sum[i]}< cut off #{@cut_off} pos #{i}.if #{i-1} - #{temp_start} > #{new_end} - #{new_start}" if (((i-1-temp_start)>=(new_end-new_start))) new_start,new_end=temp_start,i-1 # puts "just out ---- new start,new_end = #{temp_start}, #{i-1} index_window_end = #{index_window_end}" end temp_start= -1 end end i+=1 end # puts "4 temp_start #{temp_start} new_start #{new_start} new-end #{new_end}" if (temp_start != -1) # finished while ok # puts "4 #{index_window_end} - #{temp_start} > #{new_end} - #{new_start}" if ((index_window_end- temp_start) >= (new_end-new_start)) #put the end of the window at the end of sequence new_start, new_end = temp_start, index_window_end #-1 end end # puts "5 temp_start #{temp_start} new_start #{new_start} new-end #{new_end}" # puts " newstart #{new_start} newend #{new_end}" return new_start,new_end end |