From: martinahansen Date: Fri, 6 Aug 2010 08:59:16 +0000 (+0000) Subject: added -o option and tests to analyze_vals X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=cba09ac68ac99668cfe9c802b91712b7c1a20fc2;p=biopieces.git added -o option and tests to analyze_vals git-svn-id: http://biopieces.googlecode.com/svn/trunk@1037 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/analyze_vals b/bp_bin/analyze_vals index d1d9ede..726c91c 100755 --- a/bp_bin/analyze_vals +++ b/bp_bin/analyze_vals @@ -36,12 +36,13 @@ use Data::Dumper; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $options, $in, $out, $record, $analysis, $key, $len, %skip_hash, +my ( $options, $in, $out, $record, $analysis, $key, $len, %skip_hash, $data_out, %key_hash, $skip, $keys, $types, $counts, $mins, $maxs, $sums, $means ); $options = Maasha::Biopieces::parse_options( [ { long => 'no_stream', short => 'x', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'data_out', short => 'o', type => 'file', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, { long => 'keys', short => 'k', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, { long => 'no_keys', short => 'K', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, ] @@ -50,6 +51,9 @@ $options = Maasha::Biopieces::parse_options( $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); +$data_out = Maasha::Biopieces::write_stream( $options->{ "data_out" }, $options->{ "compress" } ); +$data_out ||= \*STDOUT; + map { $skip_hash{ $_ } = 1 } @{ $options->{ "no_keys" } }; map { $key_hash{ $_ } = 1; $skip = 1 } @{ $options->{ "keys" } }; @@ -122,13 +126,15 @@ foreach $key ( sort keys %{ $analysis } ) $means .= sprintf "% 15s", $analysis->{ $key }->{ "MEAN" }; } -print "$keys\n"; -print "$types\n"; -print "$counts\n"; -print "$mins\n"; -print "$maxs\n"; -print "$sums\n"; -print "$means\n"; +print $data_out "$keys\n"; +print $data_out "$types\n"; +print $data_out "$counts\n"; +print $data_out "$mins\n"; +print $data_out "$maxs\n"; +print $data_out "$sums\n"; +print $data_out "$means\n"; + +close $data_out; Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_test/in/analyze_vals.in b/bp_test/in/analyze_vals.in new file mode 100644 index 0000000..0df90f2 --- /dev/null +++ b/bp_test/in/analyze_vals.in @@ -0,0 +1,9 @@ +V0: Human +V1: 123 +--- +V0: Dog +V1: 45 +--- +V0: Mouse +V1: 6 +--- diff --git a/bp_test/out/analyze_vals.out.1 b/bp_test/out/analyze_vals.out.1 new file mode 100644 index 0000000..ea45064 --- /dev/null +++ b/bp_test/out/analyze_vals.out.1 @@ -0,0 +1,7 @@ +KEY V0 V1 +TYPE alph num +COUNT 3 3 +MIN 3 6 +MAX 5 123 +SUM 13.00 174.00 +MEAN 4.33 58.00 diff --git a/bp_test/out/analyze_vals.out.2 b/bp_test/out/analyze_vals.out.2 new file mode 100644 index 0000000..7065732 --- /dev/null +++ b/bp_test/out/analyze_vals.out.2 @@ -0,0 +1,7 @@ +KEY V0 +TYPE alph +COUNT 3 +MIN 3 +MAX 5 +SUM 13.00 +MEAN 4.33 diff --git a/bp_test/out/analyze_vals.out.3 b/bp_test/out/analyze_vals.out.3 new file mode 100644 index 0000000..6726a07 --- /dev/null +++ b/bp_test/out/analyze_vals.out.3 @@ -0,0 +1,7 @@ +KEY V1 +TYPE num +COUNT 3 +MIN 6 +MAX 123 +SUM 174.00 +MEAN 58.00 diff --git a/bp_test/test/test_analyze_vals b/bp_test/test/test_analyze_vals new file mode 100755 index 0000000..4fa0b2e --- /dev/null +++ b/bp_test/test/test_analyze_vals @@ -0,0 +1,15 @@ +#!/bin/bash + +source "$BP_DIR/bp_test/lib/test.sh" + +run "$bp -I $in -o $tmp -x" +assert_no_diff $tmp $out.1 +rm $tmp + +run "$bp -I $in -k V0 -o $tmp -x" +assert_no_diff $tmp $out.2 +rm $tmp + +run "$bp -I $in -K V0 -o $tmp -x" +assert_no_diff $tmp $out.3 +rm $tmp