]> git.donarmstrong.com Git - biopieces.git/commitdiff
added cache option to find_adaptor
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 19 Apr 2011 08:31:17 +0000 (08:31 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 19 Apr 2011 08:31:17 +0000 (08:31 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1342 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/find_adaptor

index b37ca8beb5a13a90ff49db75c70721090c290519..908665486c4da40cd90be2d2b786b73bb3464b1e 100755 (executable)
@@ -132,6 +132,7 @@ casts = []
 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
 
@@ -143,11 +144,21 @@ adaptor_disamb = disambiguate(adaptor)
 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