Class: Plugin
- Inherits:
-
Object
- Object
- Plugin
- Defined in:
- lib/seqtrimnext/plugins/plugin.rb
Direct Known Subclasses
PluginAbAdapters, PluginAdapters, PluginAmplicons, PluginContaminants, PluginExtractInserts, PluginFindPolyAt, PluginIgnoreRepeated, PluginIndeterminations, PluginKey, PluginLinker, PluginLowComplexity, PluginLowHighSize, PluginLowQuality, PluginMids, PluginSangerAdapters, PluginShortInsert, 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_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
-
#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 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 18 def initialize(seq, params) @params = params @stats ={} if can_execute? execute(seq) 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
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 236 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
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 184 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
215 216 217 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 215 def self.check_params(params) return [] end |
.get_graph_filename(plugin_name, stats_name) ⇒ Object
290 291 292 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 290 def self.get_graph_filename(plugin_name,stats_name) return (plugin_name+ '_' +stats_name) end |
.get_graph_title(plugin_name, stats_name) ⇒ Object
286 287 288 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 286 def self.get_graph_title(plugin_name,stats_name) return plugin_name + '/' +stats_name end |
.graph_ignored?(stats_name) ⇒ Boolean
220 221 222 223 224 225 226 227 228 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 220 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
294 295 296 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 294 def self.ignored_graphs return [] end |
.plot_setup(stats_value, stats_name, x, y, init_stats, plot) ⇒ Object
231 232 233 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 231 def self.plot_setup(stats_value,stats_name,x,y,init_stats,plot) return false end |
.valid_graphs ⇒ Object
298 299 300 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 298 def self.valid_graphs return [] end |
Instance Method Details
#add_stats(key, value) ⇒ Object
Initializes the structure stats to the given key and value , only when it is neccesary, and increases its counter
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 62 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
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 75 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
28 29 30 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 28 def can_execute? return true end |
#do_blasts(seqs) ⇒ Object
57 58 59 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 57 def do_blasts(seqs) return [] end |
#execute(seqs) ⇒ Object
Begins the plugin’s execution whit the sequence “seq”
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 33 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 |
#merge_hits(hits, merged_hits, merged_ids = nil, merge_different_ids = true) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 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 135 136 137 138 139 140 141 142 143 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 97 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
87 88 89 90 91 92 93 94 95 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 87 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 |