require "plugin" ######################################################## # Author: Almudena Bocinos Rioboo # # Defines the main methods that are necessary to execute PluginShortInserted # Inherit: Plugin ######################################################## class PluginShortInsert < Plugin def cut_by(items,sub_inserts) delete=false # puts " eee1 #{sub_inserts.inspect} item #{items.inspect}" # puts " eee1 #{sub_inserts.join('-')}" items.each do |item| sub_inserts.each do |sub_i| if ((item.start_pos<=sub_i[0]) && (item.end_pos>=sub_i[1])) # if not exists any subinsert delete=true elsif ((item.end_pos>=sub_i[0]) && (item.end_pos+1<=sub_i[1])) # if exists an subinsert between the item one and the end of subinsert sub_inserts.push [item.end_pos+1,sub_i[1]] # mark subinsert after the item delete=true # puts " !!!! 1 #{sub_inserts.inspect}" if ((item.start_pos-1>=sub_i[0])) # if exists an subinsert between the start of the subinsert and the item sub_inserts.push [sub_i[0],item.start_pos-1] # mark subinsert before the item delete=true # puts " !!!! 2-1 #{sub_inserts.inspect}" end elsif ((item.start_pos-1>=sub_i[0]) && (item.start_pos<=sub_i[1])) # if exists an subinsert between the start of the subinsert and the item sub_inserts.push [sub_i[0],item.start_pos-1,] # mark subinsert before the item delete=true # puts " !!!! 2-2 #{sub_inserts.inspect}" end # sub_inserts.delete [sub_i[0],sub_i[1]] and delete=false and puts " DELETEEE ___________ #{delete}" if delete if delete sub_inserts.delete [sub_i[0],sub_i[1]] delete=false # puts " DELETEEE ___________ #{delete} #{[sub_i[0] , sub_i[1]] }" end # puts " eee2 #{sub_inserts.join(',')}" end #each sub_insert end #each low_qual end #select the best subinsert, when there is not a linker def select_the_best(sub_inserts) insert_size = 0 insert = nil sub_inserts.each do |sub_i| if (insert_size<(sub_i[1]-sub_i[0]+1)) insert_size = (sub_i[1]-sub_i[0]+1) insert=sub_i end end sub_inserts=[] sub_inserts.push insert if !insert.nil? # puts " subinsert #{sub_inserts.join(' ')}" return sub_inserts end #Begins the plugin1's execution to warn if the inserted is so short def execute(seqs) seqs.each do |s| exec_seq(s) end end def exec_seq(seq) $LOG.debug "[#{self.class.to_s}, seq: #{seq.seq_name}]: checking if insert of sequence has enought size" # puts "inserto #{seq.insert_start}, #{seq.insert_end} size #{seq.seq_fasta.size}" if (seq.seq_fasta.size > 0) # para acciones que no tienen activado el cortar, se las corta aquí sub_inserts=[] sub_inserts.push [ seq.insert_start, seq.insert_end] low_quals=seq.get_actions(ActionLowQuality) # puts "low qual size #{low_quals.size}" cut_by(low_quals,sub_inserts) # puts '?' + sub_inserts.join('?') if sub_inserts.empty? p_beg,p_end = 0,-1 # position from an empty insert else sub_inserts=select_the_best(sub_inserts) #vemos el tamaño del inserto actual # puts " antes current_insert #{seq.seq_fasta.length}" # p_beg,p_end = seq.current_insert # p_beg,p_end = seq.insert_bounds p_beg,p_end = sub_inserts[0][0],sub_inserts[0][1] # insert positions # puts " p_beg p_end #{p_beg} #{p_end}" # puts " despues current_insert #{p_beg} #{p_end}" size_min_insert = @params.get_param('min_insert_size_trimmed').to_i end else p_beg,p_end = 0,-1 # position from an empty insert # puts " p_beg p_end #{p_beg} #{p_end} size= #{p_end-p_beg+1}" end # puts "INSERTO:"+seq.seq_fasta actions=[] # puts " in PLUGIN SHORT INSERT previous to add action #{p_beg} #{p_end}" if p_end-p_beg+1 <= 0 type = "ActionEmptyInsert" # puts " in PLUGIN EMPTY previous to add action #{p_beg} #{p_end}" # a = seq.add_action(p_beg,p_end,type) a=seq.new_action(0,0,type) actions.push a add_stats('short_inserts',0) # puts "1 p_beg p_end #{p_beg} #{p_end}" seq.seq_rejected=true seq.seq_rejected_by_message='empty insert' elsif ((p_end-p_beg+1)