From b866eeddf9e363ece75c6865de862dc98f30935d Mon Sep 17 00:00:00 2001 From: martinahansen Date: Tue, 19 Apr 2011 08:31:17 +0000 Subject: [PATCH] added cache option to find_adaptor git-svn-id: http://biopieces.googlecode.com/svn/trunk@1342 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/find_adaptor | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bp_bin/find_adaptor b/bp_bin/find_adaptor index b37ca8b..9086654 100755 --- a/bp_bin/find_adaptor +++ b/bp_bin/find_adaptor @@ -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 -- 2.39.5