From 8083fd8b07e404f62bf4a553216c8761daab9a93 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Fri, 15 Oct 2010 14:14:08 +0000 Subject: [PATCH] polishing min max sum etc git-svn-id: http://biopieces.googlecode.com/svn/trunk@1142 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/max_vals | 20 ++++++++++++-------- bp_bin/median_vals | 4 ++-- bp_bin/min_vals | 20 ++++++++++++-------- bp_test/in/max_vals.in | 15 +++++++++++++++ bp_test/in/median_vals.in | 15 +++++++++++++++ bp_test/in/min_vals.in | 15 +++++++++++++++ bp_test/out/max_vals.out.1 | 4 ++++ bp_test/out/max_vals.out.2 | 18 ++++++++++++++++++ bp_test/out/median_vals.out.1 | 4 ++++ bp_test/out/median_vals.out.2 | 18 ++++++++++++++++++ bp_test/out/min_vals.out.1 | 4 ++++ bp_test/out/min_vals.out.2 | 18 ++++++++++++++++++ bp_test/test/test_max_vals | 11 +++++++++++ bp_test/test/test_median_vals | 11 +++++++++++ bp_test/test/test_min_vals | 11 +++++++++++ 15 files changed, 170 insertions(+), 18 deletions(-) create mode 100644 bp_test/in/max_vals.in create mode 100644 bp_test/in/median_vals.in create mode 100644 bp_test/in/min_vals.in create mode 100644 bp_test/out/max_vals.out.1 create mode 100644 bp_test/out/max_vals.out.2 create mode 100644 bp_test/out/median_vals.out.1 create mode 100644 bp_test/out/median_vals.out.2 create mode 100644 bp_test/out/min_vals.out.1 create mode 100644 bp_test/out/min_vals.out.2 create mode 100755 bp_test/test/test_max_vals create mode 100755 bp_test/test/test_median_vals create mode 100755 bp_test/test/test_min_vals diff --git a/bp_bin/max_vals b/bp_bin/max_vals index d25bee4..52ede7c 100755 --- a/bp_bin/max_vals +++ b/bp_bin/max_vals @@ -35,7 +35,7 @@ use Maasha::Calc; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $options, $in, $out, $record, $key, $fh, %max_hash, $max_record ); +my ( $options, $in, $out, $record, $key, $fh, %max_hash, $new_record ); $options = Maasha::Biopieces::parse_options( [ @@ -74,20 +74,24 @@ 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" } } ) -{ - $max_record->{ $key . "_MAX" } = $max_hash{ $key }; +foreach $key ( @{ $options->{ "keys" } } ) { + $new_record->{ $key . "_MAX" } = $max_hash{ $key }; } -Maasha::Biopieces::put_record( $max_record, $fh ); +if ( $options->{ "keys" } and $new_record ) +{ + $new_record->{ 'REC_TYPE' } = "MIN"; + + Maasha::Biopieces::put_record( $new_record, $fh ); +} close $fh; -Maasha::Biopieces::close_stream( $in ); -Maasha::Biopieces::close_stream( $out ); - # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< diff --git a/bp_bin/median_vals b/bp_bin/median_vals index b999665..e32415c 100755 --- a/bp_bin/median_vals +++ b/bp_bin/median_vals @@ -78,10 +78,10 @@ foreach $key ( @{ $options->{ "keys" } } ) $median = "N/A"; } - $new_record->{ $key . "_MEDIAN" } = $mean + $new_record->{ $key . "_MEDIAN" } = $median; } -if ( $options->{ "keys" } ) +if ( $options->{ "keys" } and $new_record ) { $new_record->{ 'REC_TYPE' } = "MEDIAN"; diff --git a/bp_bin/min_vals b/bp_bin/min_vals index 1f73ed0..11410e3 100755 --- a/bp_bin/min_vals +++ b/bp_bin/min_vals @@ -35,7 +35,7 @@ use Maasha::Calc; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $options, $in, $out, $record, $key, $fh, %min_hash, $min_record ); +my ( $options, $in, $out, $record, $new_record, $key, $fh, %min_hash ); $options = Maasha::Biopieces::parse_options( [ @@ -73,20 +73,24 @@ 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" } } ) -{ - $min_record->{ $key . "_MIN" } = $min_hash{ $key }; +foreach $key ( @{ $options->{ "keys" } } ) { + $new_record->{ $key . "_MIN" } = $min_hash{ $key }; } -Maasha::Biopieces::put_record( $min_record, $fh ); +if ( $options->{ "keys" } and $new_record ) +{ + $new_record->{ 'REC_TYPE' } = "MIN"; + + Maasha::Biopieces::put_record( $new_record, $fh ); +} close $fh; -Maasha::Biopieces::close_stream( $in ); -Maasha::Biopieces::close_stream( $out ); - # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< diff --git a/bp_test/in/max_vals.in b/bp_test/in/max_vals.in new file mode 100644 index 0000000..401f694 --- /dev/null +++ b/bp_test/in/max_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/in/median_vals.in b/bp_test/in/median_vals.in new file mode 100644 index 0000000..401f694 --- /dev/null +++ b/bp_test/in/median_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/in/min_vals.in b/bp_test/in/min_vals.in new file mode 100644 index 0000000..401f694 --- /dev/null +++ b/bp_test/in/min_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/max_vals.out.1 b/bp_test/out/max_vals.out.1 new file mode 100644 index 0000000..299dbbf --- /dev/null +++ b/bp_test/out/max_vals.out.1 @@ -0,0 +1,4 @@ +V2_MAX: 81 +V1_MAX: 123 +REC_TYPE: MIN +--- diff --git a/bp_test/out/max_vals.out.2 b/bp_test/out/max_vals.out.2 new file mode 100644 index 0000000..e096065 --- /dev/null +++ b/bp_test/out/max_vals.out.2 @@ -0,0 +1,18 @@ +V3_MAX: 5.00 +V3: 0;1;2;3;4;5 +V0: Human +V2: 78 +V1: 123 +--- +V3_MAX: 8.00 +V3: 6;7;8 +V0: Dog +V2: 81 +V1: 45 +--- +V3_MAX: 9.00 +V3: 9 +V0: Mouse +V2: 5 +V1: 6 +--- diff --git a/bp_test/out/median_vals.out.1 b/bp_test/out/median_vals.out.1 new file mode 100644 index 0000000..a08fdbf --- /dev/null +++ b/bp_test/out/median_vals.out.1 @@ -0,0 +1,4 @@ +V1_MEDIAN: 45 +REC_TYPE: MEDIAN +V2_MEDIAN: 78 +--- diff --git a/bp_test/out/median_vals.out.2 b/bp_test/out/median_vals.out.2 new file mode 100644 index 0000000..0b4b6be --- /dev/null +++ b/bp_test/out/median_vals.out.2 @@ -0,0 +1,18 @@ +V3_MEDIAN: 3.50 +V3: 0;1;2;3;4;5 +V0: Human +V2: 78 +V1: 123 +--- +V3_MEDIAN: 7.00 +V3: 6;7;8 +V0: Dog +V2: 81 +V1: 45 +--- +V3_MEDIAN: 9.00 +V3: 9 +V0: Mouse +V2: 5 +V1: 6 +--- diff --git a/bp_test/out/min_vals.out.1 b/bp_test/out/min_vals.out.1 new file mode 100644 index 0000000..0564b7e --- /dev/null +++ b/bp_test/out/min_vals.out.1 @@ -0,0 +1,4 @@ +REC_TYPE: MIN +V1_MIN: 6 +V2_MIN: 5 +--- diff --git a/bp_test/out/min_vals.out.2 b/bp_test/out/min_vals.out.2 new file mode 100644 index 0000000..52953e9 --- /dev/null +++ b/bp_test/out/min_vals.out.2 @@ -0,0 +1,18 @@ +V3: 0;1;2;3;4;5 +V0: Human +V2: 78 +V1: 123 +V3_MIN: 0.00 +--- +V3: 6;7;8 +V0: Dog +V2: 81 +V1: 45 +V3_MIN: 6.00 +--- +V3: 9 +V0: Mouse +V2: 5 +V1: 6 +V3_MIN: 9.00 +--- diff --git a/bp_test/test/test_max_vals b/bp_test/test/test_max_vals new file mode 100755 index 0000000..5fabaa4 --- /dev/null +++ b/bp_test/test/test_max_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 diff --git a/bp_test/test/test_median_vals b/bp_test/test/test_median_vals new file mode 100755 index 0000000..5fabaa4 --- /dev/null +++ b/bp_test/test/test_median_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 diff --git a/bp_test/test/test_min_vals b/bp_test/test/test_min_vals new file mode 100755 index 0000000..5fabaa4 --- /dev/null +++ b/bp_test/test/test_min_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