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, PluginShortInsert, 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.
-
#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) ⇒ 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 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 18 def initialize(seq,params) # $LOG.debug self.class.to_s + " processing sequence: " + seq.seq_name # if (!(self.class.to_s=='PluginLowQuality') ) @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 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
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 207 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
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 155 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
186 187 188 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 186 def self.check_params(params) return [] end |
.get_graph_filename(plugin_name, stats_name) ⇒ Object
261 262 263 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 261 def self.get_graph_filename(plugin_name,stats_name) return (plugin_name+ '_' +stats_name) end |
.get_graph_title(plugin_name, stats_name) ⇒ Object
257 258 259 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 257 def self.get_graph_title(plugin_name,stats_name) return plugin_name + '/' +stats_name end |
.graph_ignored?(stats_name) ⇒ Boolean
191 192 193 194 195 196 197 198 199 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 191 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
265 266 267 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 265 def self.ignored_graphs return [] end |
.plot_setup(stats_value, stats_name, x, y, init_stats, plot) ⇒ Object
202 203 204 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 202 def self.plot_setup(stats_value,stats_name,x,y,init_stats,plot) return false end |
.valid_graphs ⇒ Object
269 270 271 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 269 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
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 37 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
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 50 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 |
#execute(seqs) ⇒ Object
Begins the plugin’s execution whit the sequence “seq”
31 32 33 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 31 def execute(seqs) end |
#merge_hits(hits, merged_hits, merged_ids = nil) ⇒ Object
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 107 108 109 110 111 112 113 114 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 72 def merge_hits(hits,merged_hits,merged_ids=nil) # 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)} # 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
62 63 64 65 66 67 68 69 70 |
# File 'lib/seqtrimnext/plugins/plugin.rb', line 62 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 |