From: martinahansen Date: Thu, 28 May 2009 09:51:57 +0000 (+0000) Subject: migrated sum_vals X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b7e4315becedf4cf650f131aa711abfa21a07525;p=biopieces.git migrated sum_vals git-svn-id: http://biopieces.googlecode.com/svn/trunk@436 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/sum_vals b/bp_bin/sum_vals index fdf5bd2..2a69acd 100755 --- a/bp_bin/sum_vals +++ b/bp_bin/sum_vals @@ -1,6 +1,96 @@ -#!/usr/bin/env perl +#!/usr/bin/env perl -w + +# Copyright (C) 2007-2009 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Calculate the total sums for the values of given keys. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $key, %sum_hash, $fh ); + +$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 => 'yes', default => undef, allowed => undef, disallowed => undef }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + foreach $key ( @{ $options->{ "keys" } } ) + { + if ( $record->{ $key } ) { + $sum_hash{ $key } += $record->{ $key }; + } + } + + Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" }; +} + +$fh = Maasha::Biopieces::write_stream( $options->{ "data_out" } ); + +foreach $key ( @{ $options->{ "keys" } } ) { + Maasha::Biopieces::put_record( { $key . "_SUM" => $sum_hash{ $key } || 0 } , $fh ); +} + +close $fh; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +BEGIN +{ + $run_time_beg = Maasha::Biopieces::run_time(); + + Maasha::Biopieces::log_biopiece(); +} + + +END +{ + Maasha::Biopieces::close_stream( $in ); + Maasha::Biopieces::close_stream( $out ); + + $run_time_end = Maasha::Biopieces::run_time(); + + Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options ); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +__END__ -use Maasha::BioRun; diff --git a/code_perl/Maasha/BioRun.pm b/code_perl/Maasha/BioRun.pm index 33884c4..8ad9239 100644 --- a/code_perl/Maasha/BioRun.pm +++ b/code_perl/Maasha/BioRun.pm @@ -157,7 +157,6 @@ sub run_script elsif ( $script eq "plot_matches" ) { script_plot_matches( $in, $out, $options ) } elsif ( $script eq "plot_seqlogo" ) { script_plot_seqlogo( $in, $out, $options ) } elsif ( $script eq "plot_phastcons_profiles" ) { script_plot_phastcons_profiles( $in, $out, $options ) } - elsif ( $script eq "sum_vals" ) { script_sum_vals( $in, $out, $options ) } elsif ( $script eq "upload_to_ucsc" ) { script_upload_to_ucsc( $in, $out, $options ) } close $in if defined $in; @@ -530,14 +529,6 @@ sub get_options direction|d=s ); } - elsif ( $script eq "sum_vals" ) - { - @options = qw( - no_stream|x - data_out|o=s - keys|k=s - ); - } elsif ( $script eq "upload_to_ucsc" ) { @options = qw( @@ -663,7 +654,7 @@ sub get_options Maasha::Common::error( qq(both --in_file and --genome specified) ) if $script eq "soap_seq" and $options{ "genome" } and $options{ "in_file" }; Maasha::Common::error( qq(no --genome specified) ) if $script =~ /get_genome_align|get_genome_phastcons|plot_phastcons_profiles|plot_karyogram/ and not $options{ "genome" }; Maasha::Common::error( qq(no --key specified) ) if $script =~ /plot_lendist|plot_histogram/ and not $options{ "key" }; - Maasha::Common::error( qq(no --keys speficied) ) if $script =~ /sort_records|sum_vals/ and not $options{ "keys" }; + Maasha::Common::error( qq(no --keys speficied) ) if $script =~ /sort_records/ and not $options{ "keys" }; if ( $script eq "upload_to_ucsc" ) { @@ -2683,43 +2674,6 @@ sub script_plot_matches } -sub script_sum_vals -{ - # Martin A. Hansen, August 2007. - - # Calculates the sums for values of given keys. - - my ( $in, # handle to in stream - $out, # handle to out stream - $options, # options hash - ) = @_; - - # Returns nothing. - - my ( $record, $key, %sum_hash, $fh ); - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - foreach $key ( @{ $options->{ "keys" } } ) - { - if ( $record->{ $key } ) { - $sum_hash{ $key } += $record->{ $key }; - } - } - - Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" }; - } - - $fh = write_stream( $options->{ "data_out" } ); - - foreach $key ( @{ $options->{ "keys" } } ) { - Maasha::Biopieces::put_record( { $key . "_SUM" => $sum_hash{ $key } || 0 } , $fh ); - } - - close $fh; -} - - sub script_upload_to_ucsc { # Martin A. Hansen, August 2007.