]> git.donarmstrong.com Git - biopieces.git/commitdiff
added substitute_vals biopiece
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sun, 20 Jan 2013 19:03:41 +0000 (19:03 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sun, 20 Jan 2013 19:03:41 +0000 (19:03 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@2079 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/substitute_vals [new file with mode: 0755]
bp_test/in/substitute_vals.in [new file with mode: 0644]
bp_test/out/substitute_vals.out.1 [new file with mode: 0644]
bp_test/out/substitute_vals.out.2 [new file with mode: 0644]
bp_test/out/substitute_vals.out.3 [new file with mode: 0644]
bp_test/out/substitute_vals.out.4 [new file with mode: 0644]
bp_test/out/substitute_vals.out.5 [new file with mode: 0644]
bp_test/test/test_substitute_vals [new file with mode: 0755]

diff --git a/bp_bin/substitute_vals b/bp_bin/substitute_vals
new file mode 100755 (executable)
index 0000000..9217bc8
--- /dev/null
@@ -0,0 +1,97 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2007-2013 Martin A. Hansen.
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# http://www.gnu.org/copyleft/gpl.html
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Substitute values to keys in the stream.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+use warnings;
+use strict;
+use Maasha::Biopieces;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $options, $in, $out, $record, $search, $replace, $keys, $key );
+
+$options = Maasha::Biopieces::parse_options(
+    [
+        { long => 'search',      short => 's', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
+        { long => 'replace',     short => 'r', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
+        { long => 'global',      short => 'g', type => 'flag',   mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
+        { long => 'ignore_case', short => 'i', type => 'flag',   mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
+        { long => 'keys',        short => 'k', type => 'list',   mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
+    ]   
+);
+
+$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
+$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+
+$search  = $options->{ "search" };
+$replace = $options->{ "replace" };
+
+while ( $record = Maasha::Biopieces::get_record( $in ) ) 
+{
+    $keys = $options->{ "keys" } || [ keys %{ $record } ];
+
+    foreach $key (@{ $keys })
+    {
+        if ( $options->{ 'global' } and $options->{ 'ignore_case' } ) {
+            $record->{ $key } =~ s/$search/$replace/gi;
+        } elsif ( $options->{ 'global' } ) {
+            $record->{ $key } =~ s/$search/$replace/g;
+        } elsif ( $options->{ 'ignore_case' } ) {
+            $record->{ $key } =~ s/$search/$replace/i;
+        } else {
+            $record->{ $key } =~ s/$search/$replace/;
+        }
+    }
+
+    Maasha::Biopieces::put_record( $record, $out );
+}
+
+Maasha::Biopieces::close_stream( $in );
+Maasha::Biopieces::close_stream( $out );
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+BEGIN
+{
+    Maasha::Biopieces::status_set();
+}
+
+
+END
+{
+    Maasha::Biopieces::status_log();
+}
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+__END__
diff --git a/bp_test/in/substitute_vals.in b/bp_test/in/substitute_vals.in
new file mode 100644 (file)
index 0000000..5c23689
--- /dev/null
@@ -0,0 +1,12 @@
+SEQ_NAME: test1
+SEQ: AGNCTTTTCATTCTGACTGCAACGGGCAATACCTGCCGTGAGTAAATNNN
+SEQ_LEN: 50
+---
+SEQ_NAME: test2
+SEQ: TGGGCGTTNNNNNGCAGGTAAATAGGCTTCTGTNNGACGTACTATAACGT
+SEQ_LEN: 50
+---
+SEQ_NAME: test3
+SEQ: NNNNATAGTACTACAGTAACGAAAGTCNNGGATTTTTCTGAAGAGCTTTA
+SEQ_LEN: 50
+---
diff --git a/bp_test/out/substitute_vals.out.1 b/bp_test/out/substitute_vals.out.1
new file mode 100644 (file)
index 0000000..fc9d59b
--- /dev/null
@@ -0,0 +1,12 @@
+SEQ: AGNCTTTTCATTCTGACTGCAACGGGCAATACCTGCCGTGAGTAAATNNN
+SEQ_LEN: 0
+SEQ_NAME: test
+---
+SEQ: TGGGCGTTNNNNNGCAGGTAAATAGGCTTCTGTNNGACGTACTATAACGT
+SEQ_LEN: 0
+SEQ_NAME: test
+---
+SEQ: NNNNATAGTACTACAGTAACGAAAGTCNNGGATTTTTCTGAAGAGCTTTA
+SEQ_LEN: 0
+SEQ_NAME: test
+---
diff --git a/bp_test/out/substitute_vals.out.2 b/bp_test/out/substitute_vals.out.2
new file mode 100644 (file)
index 0000000..ef70029
--- /dev/null
@@ -0,0 +1,12 @@
+SEQ: AGNCTTTTCATTCTGACTGCAACGGGCAATACCTGCCGTGAGTAAATNNN
+SEQ_LEN: 50
+SEQ_NAME: test1
+---
+SEQ: TGGGCGTTNNNNNGCAGGTAAATAGGCTTCTGTNNGACGTACTATAACGT
+SEQ_LEN: 50
+SEQ_NAME: test2
+---
+SEQ: NNNNATAGTACTACAGTAACGAAAGTCNNGGATTTTTCTGAAGAGCTTTA
+SEQ_LEN: 50
+SEQ_NAME: test3
+---
diff --git a/bp_test/out/substitute_vals.out.3 b/bp_test/out/substitute_vals.out.3
new file mode 100644 (file)
index 0000000..dca7924
--- /dev/null
@@ -0,0 +1,12 @@
+SEQ: AGCTTTTCATTCTGACTGCAACGGGCAATACCTGCCGTGAGTAAATNNN
+SEQ_LEN: 50
+SEQ_NAME: test1
+---
+SEQ: TGGGCGTTNNNNGCAGGTAAATAGGCTTCTGTNNGACGTACTATAACGT
+SEQ_LEN: 50
+SEQ_NAME: test2
+---
+SEQ: NNNATAGTACTACAGTAACGAAAGTCNNGGATTTTTCTGAAGAGCTTTA
+SEQ_LEN: 50
+SEQ_NAME: test3
+---
diff --git a/bp_test/out/substitute_vals.out.4 b/bp_test/out/substitute_vals.out.4
new file mode 100644 (file)
index 0000000..2c96acc
--- /dev/null
@@ -0,0 +1,12 @@
+SEQ: AGCTTTTCATTCTGACTGCAACGGGCAATACCTGCCGTGAGTAAAT
+SEQ_LEN: 50
+SEQ_NAME: test1
+---
+SEQ: TGGGCGTTGCAGGTAAATAGGCTTCTGTGACGTACTATAACGT
+SEQ_LEN: 50
+SEQ_NAME: test2
+---
+SEQ: ATAGTACTACAGTAACGAAAGTCGGATTTTTCTGAAGAGCTTTA
+SEQ_LEN: 50
+SEQ_NAME: test3
+---
diff --git a/bp_test/out/substitute_vals.out.5 b/bp_test/out/substitute_vals.out.5
new file mode 100644 (file)
index 0000000..96de1af
--- /dev/null
@@ -0,0 +1,12 @@
+SEQ: AGNCTTTTCATTCTGACTGCAACGGGCAATACCTGCCGTGAGTAAAT
+SEQ_LEN: 50
+SEQ_NAME: test1
+---
+SEQ: TGGGCGTTGCAGGTAAATAGGCTTCTGTNNGACGTACTATAACGT
+SEQ_LEN: 50
+SEQ_NAME: test2
+---
+SEQ: ATAGTACTACAGTAACGAAAGTCNNGGATTTTTCTGAAGAGCTTTA
+SEQ_LEN: 50
+SEQ_NAME: test3
+---
diff --git a/bp_test/test/test_substitute_vals b/bp_test/test/test_substitute_vals
new file mode 100755 (executable)
index 0000000..043d5b9
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+source "$BP_DIR/bp_test/lib/test.sh"
+
+run "$bp -I $in -s '\d' -r '' -O $tmp"
+assert_no_diff $tmp $out.1
+clean
+
+run "$bp -I $in -k SEQ -s 'n' -r '' -O $tmp"
+assert_no_diff $tmp $out.2
+clean
+
+run "$bp -I $in -k SEQ -s 'n' -r '' -i -O $tmp"
+assert_no_diff $tmp $out.3
+clean
+
+run "$bp -I $in -k SEQ -s 'n' -r '' -i -g -O $tmp"
+assert_no_diff $tmp $out.4
+clean
+
+run "$bp -I $in -k SEQ -s 'n{3,}' -r '' -i -g -O $tmp"
+assert_no_diff $tmp $out.5
+clean