]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixes and test for digest_seq
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 20 Sep 2010 08:40:00 +0000 (08:40 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 20 Sep 2010 08:40:00 +0000 (08:40 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1096 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/digest_seq
bp_test/in/digest_seq.in [new file with mode: 0644]
bp_test/out/digest_seq.out.1 [new file with mode: 0644]
bp_test/out/digest_seq.out.2 [new file with mode: 0644]
bp_test/out/digest_seq.out.3 [new file with mode: 0644]
bp_test/out/digest_seq.out.4 [new file with mode: 0644]
bp_test/test/test_digest_seq [new file with mode: 0755]
code_ruby/Maasha/lib/seq.rb

index 3fab531b4249cd144a5092cb58eb15c4d2b29d87..34aebf089a8a064496b1a73b4456a515f05fb857 100755 (executable)
@@ -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 (file)
index 0000000..6625cac
--- /dev/null
@@ -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 (file)
index 0000000..5b099af
--- /dev/null
@@ -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 (file)
index 0000000..9f706c7
--- /dev/null
@@ -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 (file)
index 0000000..9f706c7
--- /dev/null
@@ -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 (file)
index 0000000..9f706c7
--- /dev/null
@@ -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 (executable)
index 0000000..22082ac
--- /dev/null
@@ -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
index 8b98acee5d13bd1a4e344d37752f8b3569794033..2626ddcb12cf100eee97684cebdb48168a815e58 100644 (file)
@@ -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