From 4edbb58ed5bb576baf5803866a7d9c02f79e27d7 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Fri, 15 Oct 2010 10:04:59 +0000 Subject: [PATCH] added tests for mean_vals git-svn-id: http://biopieces.googlecode.com/svn/trunk@1138 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/mean_vals | 2 +- bp_bin/median_vals | 17 ++++++++++++----- bp_test/in/mean_vals.in | 15 +++++++++++++++ bp_test/out/mean_vals.out.1 | 4 ++++ bp_test/out/mean_vals.out.2 | 18 ++++++++++++++++++ bp_test/test/test_mean_vals | 11 +++++++++++ 6 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 bp_test/in/mean_vals.in create mode 100644 bp_test/out/mean_vals.out.1 create mode 100644 bp_test/out/mean_vals.out.2 create mode 100755 bp_test/test/test_mean_vals diff --git a/bp_bin/mean_vals b/bp_bin/mean_vals index 007b287..974c9b4 100755 --- a/bp_bin/mean_vals +++ b/bp_bin/mean_vals @@ -86,7 +86,7 @@ foreach $key ( @{ $options->{ "keys" } } ) $new_record->{ $key . "_MEAN" } = $mean } -if ( $options->{ "keys" } ) +if ( $options->{ "keys" } and $new_record ) { $new_record->{ 'REC_TYPE' } = "MEAN"; diff --git a/bp_bin/median_vals b/bp_bin/median_vals index 36bfff5..b999665 100755 --- a/bp_bin/median_vals +++ b/bp_bin/median_vals @@ -35,7 +35,7 @@ use Maasha::Calc; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $options, $in, $out, $record, $key, %median_hash, $median, $fh ); +my ( $options, $in, $out, $record, $new_record, $key, %median_hash, $median, $fh ); $options = Maasha::Biopieces::parse_options( [ @@ -65,6 +65,9 @@ while ( $record = Maasha::Biopieces::get_record( $in ) ) Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" }; } +Maasha::Biopieces::close_stream( $in ); +Maasha::Biopieces::close_stream( $out ); + $fh = Maasha::Biopieces::write_stream( $options->{ "data_out" } ); foreach $key ( @{ $options->{ "keys" } } ) @@ -75,13 +78,17 @@ foreach $key ( @{ $options->{ "keys" } } ) $median = "N/A"; } - Maasha::Biopieces::put_record( { $key . "_MEDIAN" => $median } , $fh ); + $new_record->{ $key . "_MEDIAN" } = $mean } -close $fh; +if ( $options->{ "keys" } ) +{ + $new_record->{ 'REC_TYPE' } = "MEDIAN"; -Maasha::Biopieces::close_stream( $in ); -Maasha::Biopieces::close_stream( $out ); + Maasha::Biopieces::put_record( $new_record, $fh ); +} + +close $fh; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< diff --git a/bp_test/in/mean_vals.in b/bp_test/in/mean_vals.in new file mode 100644 index 0000000..401f694 --- /dev/null +++ b/bp_test/in/mean_vals.in @@ -0,0 +1,15 @@ +V3: 0;1;2;3;4;5 +V0: Human +V2: 78 +V1: 123 +--- +V3: 6;7;8 +V0: Dog +V2: 81 +V1: 45 +--- +V3: 9 +V0: Mouse +V2: 5 +V1: 6 +--- diff --git a/bp_test/out/mean_vals.out.1 b/bp_test/out/mean_vals.out.1 new file mode 100644 index 0000000..a10166e --- /dev/null +++ b/bp_test/out/mean_vals.out.1 @@ -0,0 +1,4 @@ +V1_MEAN: 58.00 +REC_TYPE: MEAN +V2_MEAN: 54.67 +--- diff --git a/bp_test/out/mean_vals.out.2 b/bp_test/out/mean_vals.out.2 new file mode 100644 index 0000000..001cc5c --- /dev/null +++ b/bp_test/out/mean_vals.out.2 @@ -0,0 +1,18 @@ +V3_MEAN: 2.50 +V3: 0;1;2;3;4;5 +V0: Human +V2: 78 +V1: 123 +--- +V3_MEAN: 7.00 +V3: 6;7;8 +V0: Dog +V2: 81 +V1: 45 +--- +V3_MEAN: 9.00 +V3: 9 +V0: Mouse +V2: 5 +V1: 6 +--- diff --git a/bp_test/test/test_mean_vals b/bp_test/test/test_mean_vals new file mode 100755 index 0000000..5fabaa4 --- /dev/null +++ b/bp_test/test/test_mean_vals @@ -0,0 +1,11 @@ +#!/bin/bash + +source "$BP_DIR/bp_test/lib/test.sh" + +run "$bp -I $in -k V1,V2 -o $tmp -x" +assert_no_diff $tmp $out.1 +clean + +run "$bp -I $in -l V3 -O $tmp" +assert_no_diff $tmp $out.2 +clean -- 2.39.5