casts << {:long=>'adaptor', :short=>'r', :type=>'string', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
casts << {:long=>'edit_distance', :short=>'e', :type=>'uint', :mandatory=>false, :default=>20, :allowed=>nil, :disallowed=>nil}
casts << {:long=>'pos', :short=>'p', :type=>'int', :mandatory=>false, :default=>1, :allowed=>nil, :disallowed=>"0"}
+casts << {:long=>'cache', :short=>'c', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
bp = Biopieces.new
pos = options[:pos]
pos -= 1 if pos > 0 # pos was 1-based
+cache = {}
+
bp.each_record do |record|
if record.has_key? :SEQ
entry = Seq.new(record[:SEQ_NAME], record[:SEQ], "dna", record[:SCORES])
- if match = entry.adaptor_find(adaptor, adaptor_disamb, pos, options[:edit_distance])
+ if cache[entry.seq.upcase] and options[:cache]
+ match = cache[entry.seq.upcase]
+ else
+ match = entry.adaptor_find(adaptor, adaptor_disamb, pos, options[:edit_distance])
+
+ cache[entry.seq.upcase] = match if match and options[:cache]
+ end
+
+ if match
record[:ADAPTOR_POS] = match.pos
record[:ADAPTOR_LEN] = match.length
record[:ADAPTOR_MATCH] = match.match