Class: Plugin
- Inherits:
-
Object
- Object
- Plugin
- Defined in:
- lib/seqtrimnext/plugins/plugin.rb
Direct Known Subclasses
PluginAbAdapters, PluginAdapters, PluginAdaptersOld, PluginAmplicons, PluginContaminants, PluginExtractInserts, PluginFindPolyAt, PluginIgnoreRepeated, PluginIndeterminations, PluginKey, PluginLinker, PluginLowComplexity, PluginLowHighSize, PluginLowQuality, PluginMids, PluginRemAditArtifacts, PluginSangerAdapters, PluginShortInsert, PluginSizeTrim, PluginUserContaminants, PluginVectors
Instance Attribute Summary collapse
-
#stats ⇒ Object
Returns the value of attribute stats.
Class Method Summary collapse
-
.auto_setup(stats_value, stats_name, x, y) ⇒ Object
automatically setup data.
-
.check_param(errors, params, param, param_class, default_value = nil, comment = nil) ⇒ Object
def check_length_inserted(p_start,p_end,seq_fasta_length) min_insert_size = @params.get_param(‘min_insert_size ’).to_i v1= p_end.to_i v2= p_start.to_i v3= v1 - v2 $LOG.debug “—— #v3 —-”.
-
.check_params(params) ⇒ Object
Returns an array with the errors due to parameters are missing.
- .get_graph_filename(plugin_name, stats_name) ⇒ Object
- .get_graph_title(plugin_name, stats_name) ⇒ Object
- .graph_ignored?(stats_name) ⇒ Boolean
- .ignored_graphs ⇒ Object
- .plot_setup(stats_value, stats_name, x, y, init_stats, plot) ⇒ Object
- .valid_graphs ⇒ Object
Instance Method Summary collapse
- #add_plugin_stats(cat, item, elapsed_time) ⇒ Object
-
#add_stats(key, value) ⇒ Object
Initializes the structure stats to the given key and value , only when it is neccesary, and increases its counter.
-
#add_text_stats(key, value, text) ⇒ Object
Initializes the structure stats to the given key and value , only when it is neccesary, and increases its counter.
- #can_execute? ⇒ Boolean
- #do_blasts(seqs) ⇒ Object
- #exec_seq(seq, blast_query) ⇒ Object
-
#execute(seqs) ⇒ Object
Begins the plugin’s execution whit the sequence “seq”.
-
#initialize(seq, params) ⇒ Plugin
constructor
Loads the plugin’s execution whit the sequence “seq”.
- #merge_hits(hits, merged_hits, merged_ids = nil, merge_different_ids = true) ⇒ Object
- #overlapX?(r1_start, r1_end, r2_start, r2_end) ⇒ Boolean
Constructor Details
#initialize(seq, params) ⇒ Plugin
Loads the plugin’s execution whit the sequence “seq”
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 18 def initialize(seq, params) @params = params @stats ={} if can_execute? t1=Time.now execute(seq) t2=Time.now add_plugin_stats('execution_time','total_seconds',t2-t1) end end |
Instance Attribute Details
#stats ⇒ Object
Returns the value of attribute stats.
15 16 17 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 15 def stats @stats end |
Class Method Details
.auto_setup(stats_value, stats_name, x, y) ⇒ Object
automatically setup data
256 257 258 259 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 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 256 def self.auto_setup(stats_value,stats_name,x,y) # res =false # # if !self.ignored_graphs.include?(stats_name) && (self.valid_graphs.empty? || self.valid_graphs.include?(stats_name)) # # res = true contains_strings=false stats_value.keys.each do |v| begin r=Integer(v) rescue contains_strings=true break end end # puts "#{stats_name} => #{contains_strings}" if !contains_strings stats_value.keys.each do |v| x.push v.to_i end x.sort! x.each do |v| y.push stats_value[v.to_s].to_i end else # there are strings in X x2=[] stats_value.keys.each do |v| x.push "\"#{v.gsub('\"','').gsub('\'','')}\"" x2.push v end # puts ".#{x}." x2.each do |v| # puts ".#{v}." y.push stats_value[v.to_s] end end # return res end |
.check_param(errors, params, param, param_class, default_value = nil, comment = nil) ⇒ Object
def check_length_inserted(p_start,p_end,seq_fasta_length)
min_insert_size = @params.get_param('min_insert_size ').to_i
v1= p_end.to_i
v2= p_start.to_i
v3= v1 - v2
$LOG.debug "------ #{v3} ----"
res = true
if ((v1 - v2 + 1) > (seq_fasta_length - min_insert_size ))
$LOG.debug "ERROR------ SEQUENCE IS NOT GOOD ----"
res = false
end
return res
end
search a key into the sequence Used: in class PluginLinker and PluginMid
def search_key (seq,key_start,key_end)
p_q_beg=0
p_q_end=0
if (seq.seq_fasta[key_start..key_end]==@params.get_param('key'))
actions=[]
#Add ActionKey and apply it to cut the sequence
type = "ActionKey"
p_q_beg,p_q_end=key_start,key_end
a = seq.new_action(p_q_beg,p_q_end,type) # adds the actionKey/actionMid to the sequence
actions.push a
seq.add_actions(actions) #apply cut to the sequence with the actions
end
return [p_q_beg,p_q_end]
end
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 204 def self.check_param(errors,params,param,param_class,default_value=nil, comment=nil) if !params.exists?(param) if !default_value.nil? params.set_param(param,default_value,comment) else errors.push "The param #{param} is required and thre is no default value available" end else s = params.get_param(param) # 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) end rescue errors.push " The param #{param} is not a valid #{param_class}: ##{s}#" end end end |
.check_params(params) ⇒ Object
Returns an array with the errors due to parameters are missing
235 236 237 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 235 def self.check_params(params) return [] end |
.get_graph_filename(plugin_name, stats_name) ⇒ Object
310 311 312 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 310 def self.get_graph_filename(plugin_name,stats_name) return (plugin_name+ '_' +stats_name) end |
.get_graph_title(plugin_name, stats_name) ⇒ Object
306 307 308 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 306 def self.get_graph_title(plugin_name,stats_name) return plugin_name + '/' +stats_name end |
.graph_ignored?(stats_name) ⇒ Boolean
240 241 242 243 244 245 246 247 248 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 240 def self.graph_ignored?(stats_name) res = true if !self.ignored_graphs.include?(stats_name) && (self.valid_graphs.empty? || self.valid_graphs.include?(stats_name)) res = false end return res end |
.ignored_graphs ⇒ Object
314 315 316 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 314 def self.ignored_graphs return [] end |
.plot_setup(stats_value, stats_name, x, y, init_stats, plot) ⇒ Object
251 252 253 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 251 def self.plot_setup(stats_value,stats_name,x,y,init_stats,plot) return false end |
.valid_graphs ⇒ Object
318 319 320 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 318 def self.valid_graphs return [] end |
Instance Method Details
#add_plugin_stats(cat, item, elapsed_time) ⇒ Object
32 33 34 35 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 32 def add_plugin_stats(cat,item,elapsed_time) @stats[cat]={} if @stats[cat].nil? @stats[cat][item]=elapsed_time end |
#add_stats(key, value) ⇒ Object
Initializes the structure stats to the given key and value , only when it is neccesary, and increases its counter
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 82 def add_stats(key,value) @stats[key]={} if @stats[key].nil? if @stats[key][value].nil? @stats[key][value] = 0 end @stats[key][value] += 1 # puts "@stats #{key} #{value}=#{ @stats[key][value]}" end |
#add_text_stats(key, value, text) ⇒ Object
Initializes the structure stats to the given key and value , only when it is neccesary, and increases its counter
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 95 def add_text_stats(key,value,text) @stats[key]={} if @stats[key].nil? if @stats[key][value].nil? @stats[key][value] = [] end @stats[key][value].push(text) end |
#can_execute? ⇒ Boolean
37 38 39 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 37 def can_execute? return true end |
#do_blasts(seqs) ⇒ Object
77 78 79 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 77 def do_blasts(seqs) return [] end |
#exec_seq(seq, blast_query) ⇒ Object
41 42 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 41 def exec_seq(seq,blast_query) end |
#execute(seqs) ⇒ Object
Begins the plugin’s execution whit the sequence “seq”
45 46 47 48 49 50 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 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 45 def execute(seqs) t1=Time.now blasts=do_blasts(seqs) if !blasts.empty? if blasts.is_a?(Array) queries=blasts else queries = blasts.querys end add_plugin_stats('execution_time','blast_and_parse',Time.now-t1) t1=Time.now seqs.each_with_index do |s,i| exec_seq(s,queries[i]) end else # there is no blast t1=Time.now seqs.each do |s| exec_seq(s,nil) end end add_plugin_stats('execution_time','exec_seq',Time.now-t1) end |
#merge_hits(hits, merged_hits, merged_ids = nil, merge_different_ids = true) ⇒ Object
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 117 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 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}" merged_hits.push(hit.dup) #contaminants.push({:q_begin=>hit.q_beg,:q_end=>hit.q_end,:name=>hit.subject_id}) # 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}" else # merge with old contaminant # 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 # DONE para describir cada Id contaminante encontrado # puts "1 -#{c.subject_id}- -#{hit.subject_id}-" c.subject_id += ' ' + hit.subject_id if (not c.subject_id.include?(hit.subject_id)) # puts "2 -#{c.subject_id}- -#{hit.subject_id}-" # puts "MERGE HIT (#{c.inspect})" end # end end end |
#overlapX?(r1_start, r1_end, r2_start, r2_end) ⇒ Boolean
107 108 109 110 111 112 113 114 115 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 107 def overlapX?(r1_start,r1_end,r2_start,r2_end) # puts r1_start.class # puts r1_end.class # puts r2_start.class # puts r2_end.class # 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 |