lib/seqtrimnext/plugins/plugin.rb in seqtrimnext-2.0.51 vs lib/seqtrimnext/plugins/plugin.rb in seqtrimnext-2.0.52
- old
+ new
@@ -13,27 +13,52 @@
class Plugin
attr_accessor :stats
#Loads the plugin's execution whit the sequence "seq"
- def initialize(seq,params)
- # $LOG.debug self.class.to_s + " processing sequence: " + seq.seq_name
- # if (!(self.class.to_s=='PluginLowQuality') )
+ def initialize(seq, params)
@params = params
@stats ={}
- execute(seq)
- # puts self.class.to_s + ' PPPPPPPPPP'
- # else
- # $LOG.error " Quality File haven't been provided. It's impossible to execute " +self.class.to_s + seq.seq_qual.nil?.to_s
- # end
+
+ if can_execute?
+ execute(seq)
+ end
+
end
+ def can_execute?
+ return true
+ end
+
#Begins the plugin's execution whit the sequence "seq"
def execute(seqs)
+ blasts=do_blasts(seqs)
+ if !blasts.empty?
+
+ if blasts.is_a?(Array)
+ queries=blasts
+ else
+ queries = blasts.querys
+ end
+
+ seqs.each_with_index do |s,i|
+ exec_seq(s,queries[i])
+ end
+
+ else # there is no blast
+
+ seqs.each do |s|
+ exec_seq(s,nil)
+ end
+
+ end
end
+ def do_blasts(seqs)
+ return []
+ end
#Initializes the structure stats to the given key and value , only when it is neccesary, and increases its counter
def add_stats(key,value)
@stats[key]={} if @stats[key].nil?
@@ -67,18 +92,23 @@
# puts "-------"
#puts "overlap? (#{r1_start}<=#{r2_end}) and (#{r1_end}>=#{r2_start})"
return ((r1_start<=r2_end+1) and (r1_end>=r2_start-1) )
end
- def merge_hits(hits,merged_hits,merged_ids=nil)
+ def merge_hits(hits,merged_hits,merged_ids=nil, merge_different_ids=true)
# puts " merging ============"
# hits.each do |hit|
hits.sort{|h1,h2| (h1.q_end-h1.q_beg+1)<=>(h2.q_end-h2.q_beg+1)}.reverse_each do |hit|
merged_ids.push hit.definition if !merged_ids.nil? && (! merged_ids.include?(hit.definition))
# if new hit's position is already contained in hits, then ignore the new hit
- c=merged_hits.find{|c| overlapX?(hit.q_beg, hit.q_end,c.q_beg,c.q_end)}
+ if merge_different_ids
+ c=merged_hits.find{|c| overlapX?(hit.q_beg, hit.q_end,c.q_beg,c.q_end)}
+ else
+ # overlap with existent hit and same subject id
+ c=merged_hits.find{|c| (overlapX?(hit.q_beg, hit.q_end,c.q_beg,c.q_end) && (hit.subject_id==c.subject_id))}
+ end
# puts " c #{c.inspect}"
if (c.nil?)
# add new contaminant
#puts "NEW HIT #{hit.inspect}"
@@ -87,13 +117,13 @@
#
else
# one is inside each other, just ignore
if ((hit.q_beg>=c.q_beg && hit.q_end <=c.q_end) || (c.q_beg>=hit.q_beg && c.q_end <= hit.q_end))
- # puts "* #{hit.subject_id} inside #{c.subject_id}"
+ # puts "* #{hit.subject_id} inside #{c.subject_id}"
else
# merge with old contaminant
- # puts "#{hit.subject_id} NOT inside #{c.subject_id}"
+ # puts "#{hit.subject_id} NOT inside #{c.subject_id}"
min=[c.q_beg,hit.q_beg].min
max=[c.q_end,hit.q_end].max
c.q_beg=min
c.q_end=max