From 2d901e7bc53f21583f2585a0eec1b3180af97f36 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Mon, 20 Sep 2010 08:40:00 +0000 Subject: [PATCH] fixes and test for digest_seq git-svn-id: http://biopieces.googlecode.com/svn/trunk@1096 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/digest_seq | 4 ++-- bp_test/in/digest_seq.in | 4 ++++ bp_test/out/digest_seq.out.1 | 10 ++++++++++ bp_test/out/digest_seq.out.2 | 5 +++++ bp_test/out/digest_seq.out.3 | 5 +++++ bp_test/out/digest_seq.out.4 | 5 +++++ bp_test/test/test_digest_seq | 19 +++++++++++++++++++ code_ruby/Maasha/lib/seq.rb | 13 ++++++++----- 8 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 bp_test/in/digest_seq.in create mode 100644 bp_test/out/digest_seq.out.1 create mode 100644 bp_test/out/digest_seq.out.2 create mode 100644 bp_test/out/digest_seq.out.3 create mode 100644 bp_test/out/digest_seq.out.4 create mode 100755 bp_test/test/test_digest_seq diff --git a/bp_bin/digest_seq b/bp_bin/digest_seq index 3fab531..34aebf0 100755 --- a/bp_bin/digest_seq +++ b/bp_bin/digest_seq @@ -42,8 +42,6 @@ bp = Biopieces.new options = bp.parse(ARGV, casts) bp.each_record do |record| - bp.puts record - if record.has_key? :SEQ_NAME and record.has_key? :SEQ seq = Seq.new(record[:SEQ_NAME], record[:SEQ]) digest = Digest.new(seq, options[:pattern].to_s, options[:cut_pos]) @@ -53,6 +51,8 @@ bp.each_record do |record| new_record[:REC_TYPE] = "DIGEST" bp.puts new_record end + else + bp.puts record end end diff --git a/bp_test/in/digest_seq.in b/bp_test/in/digest_seq.in new file mode 100644 index 0000000..6625cac --- /dev/null +++ b/bp_test/in/digest_seq.in @@ -0,0 +1,4 @@ +SEQ_NAME: test +SEQ: cgatcgatcGGATCCgagagggtgtgtagtgGAATTCcgctgc +SEQ_LEN: 43 +--- diff --git a/bp_test/out/digest_seq.out.1 b/bp_test/out/digest_seq.out.1 new file mode 100644 index 0000000..5b099af --- /dev/null +++ b/bp_test/out/digest_seq.out.1 @@ -0,0 +1,10 @@ +SEQ_NAME: test[1-10] +SEQ: cgatcgatcG +SEQ_LEN: 10 +REC_TYPE: DIGEST +--- +SEQ_NAME: test[11-43] +SEQ: GATCCgagagggtgtgtagtgGAATTCcgctgc +SEQ_LEN: 33 +REC_TYPE: DIGEST +--- diff --git a/bp_test/out/digest_seq.out.2 b/bp_test/out/digest_seq.out.2 new file mode 100644 index 0000000..9f706c7 --- /dev/null +++ b/bp_test/out/digest_seq.out.2 @@ -0,0 +1,5 @@ +SEQ_NAME: test[1-43] +SEQ: cgatcgatcGGATCCgagagggtgtgtagtgGAATTCcgctgc +SEQ_LEN: 43 +REC_TYPE: DIGEST +--- diff --git a/bp_test/out/digest_seq.out.3 b/bp_test/out/digest_seq.out.3 new file mode 100644 index 0000000..9f706c7 --- /dev/null +++ b/bp_test/out/digest_seq.out.3 @@ -0,0 +1,5 @@ +SEQ_NAME: test[1-43] +SEQ: cgatcgatcGGATCCgagagggtgtgtagtgGAATTCcgctgc +SEQ_LEN: 43 +REC_TYPE: DIGEST +--- diff --git a/bp_test/out/digest_seq.out.4 b/bp_test/out/digest_seq.out.4 new file mode 100644 index 0000000..9f706c7 --- /dev/null +++ b/bp_test/out/digest_seq.out.4 @@ -0,0 +1,5 @@ +SEQ_NAME: test[1-43] +SEQ: cgatcgatcGGATCCgagagggtgtgtagtgGAATTCcgctgc +SEQ_LEN: 43 +REC_TYPE: DIGEST +--- diff --git a/bp_test/test/test_digest_seq b/bp_test/test/test_digest_seq new file mode 100755 index 0000000..22082ac --- /dev/null +++ b/bp_test/test/test_digest_seq @@ -0,0 +1,19 @@ +#!/bin/bash + +source "$BP_DIR/bp_test/lib/test.sh" + +run "$bp -p GGATCC -c 1 -I $in -O $tmp" +assert_no_diff $tmp $out.1 +clean + +run "$bp -p GGACTT -c 1 -I $in -O $tmp" +assert_no_diff $tmp $out.2 +clean + +run "$bp -p GGATCC -c 1000 -I $in -O $tmp" +assert_no_diff $tmp $out.3 +clean + +run "$bp -p GGATCC -c -1000 -I $in -O $tmp" +assert_no_diff $tmp $out.4 +clean diff --git a/code_ruby/Maasha/lib/seq.rb b/code_ruby/Maasha/lib/seq.rb index 8b98ace..2626ddc 100644 --- a/code_ruby/Maasha/lib/seq.rb +++ b/code_ruby/Maasha/lib/seq.rb @@ -168,13 +168,16 @@ class Digest @offset = pos + 1 end - # Handle remaining sequence after last cut. - if @offset > 0 and @offset < @seq.seq.length - seq = Seq.new("#{@seq.seq_name}[#{@offset + 1}-#{@seq.seq.length}]", @seq.seq[@offset .. @seq.seq.length], @seq.type) - - yield seq + if @offset < 0 + @offset = 0 + elsif @offset > @seq.seq.length + @offset = 0 end + seq = Seq.new("#{@seq.seq_name}[#{@offset + 1}-#{@seq.seq.length}]", @seq.seq[@offset .. @seq.seq.length], @seq.type) + + yield seq + self # conventionally end -- 2.39.2