-#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Find the maximum values in the stream for given keys.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
-use warnings;
use strict;
+use Maasha::Biopieces;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $key, $fh, %max_hash, $max_record );
+
+$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 ( exists $record->{ $key } )
+ {
+ if ( exists $max_hash{ $key } ) {
+ $max_hash{ $key } = $record->{ $key } if $record->{ $key } > $max_hash{ $key };
+ } else {
+ $max_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" } } )
+{
+ $max_record->{ $key . "_MAX" } = $max_hash{ $key };
+}
+
+Maasha::Biopieces::put_record( $max_record, $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;
-#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Find the mean values in the stream for given keys.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
-use warnings;
use strict;
+use Maasha::Biopieces;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $key, %sum_hash, %count_hash, $mean, $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 };
+ $count_hash{ $key }++;
+ }
+ }
+
+ Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
+}
+
+$fh = Maasha::Biopieces::write_stream( $options->{ "data_out" } );
+
+foreach $key ( @{ $options->{ "keys" } } )
+{
+ if ( exists $count_hash{ $key } ) {
+ $mean = sprintf( "%.2f", ( $sum_hash{ $key } / $count_hash{ $key } ) );
+ } else {
+ $mean = "N/A";
+ }
+
+ Maasha::Biopieces::put_record( { $key . "_MEAN" => $mean } , $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;
-#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Find the median values in the stream for given keys.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
-use warnings;
use strict;
+use Maasha::Biopieces;
+use Maasha::Calc;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $key, %median_hash, $median, $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" } } ) {
+ push @{ $median_hash{ $key } }, $record->{ $key } if defined $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" } } )
+{
+ if ( $median_hash{ $key } ) {
+ $median = Maasha::Calc::median( $median_hash{ $key } );
+ } else {
+ $median = "N/A";
+ }
+
+ Maasha::Biopieces::put_record( { $key . "_MEDIAN" => $median } , $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;
-#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Find the minimum values in the stream for given keys.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
-use warnings;
use strict;
+use Maasha::Biopieces;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $key, $fh, %min_hash, $min_record );
+
+$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 ( exists $record->{ $key } )
+ {
+ if ( exists $min_hash{ $key } ) {
+ $min_hash{ $key } = $record->{ $key } if $record->{ $key } < $min_hash{ $key };
+ } else {
+ $min_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" } } )
+{
+ $min_record->{ $key . "_MIN" } = $min_hash{ $key };
+}
+
+Maasha::Biopieces::put_record( $min_record, $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;
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 "mean_vals" ) { script_mean_vals( $in, $out, $options ) }
- elsif ( $script eq "median_vals" ) { script_median_vals( $in, $out, $options ) }
- elsif ( $script eq "max_vals" ) { script_max_vals( $in, $out, $options ) }
- elsif ( $script eq "min_vals" ) { script_min_vals( $in, $out, $options ) }
elsif ( $script eq "upload_to_ucsc" ) { script_upload_to_ucsc( $in, $out, $options ) }
close $in if defined $in;
keys|k=s
);
}
- elsif ( $script eq "mean_vals" )
- {
- @options = qw(
- no_stream|x
- data_out|o=s
- keys|k=s
- );
- }
- elsif ( $script eq "median_vals" )
- {
- @options = qw(
- no_stream|x
- data_out|o=s
- keys|k=s
- );
- }
- elsif ( $script eq "max_vals" )
- {
- @options = qw(
- no_stream|x
- data_out|o=s
- keys|k=s
- );
- }
- elsif ( $script eq "min_vals" )
- {
- @options = qw(
- no_stream|x
- data_out|o=s
- keys|k=s
- );
- }
elsif ( $script eq "upload_to_ucsc" )
{
@options = qw(
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|mean_vals|median_vals/ and not $options{ "keys" };
+ Maasha::Common::error( qq(no --keys speficied) ) if $script =~ /sort_records|sum_vals/ and not $options{ "keys" };
if ( $script eq "upload_to_ucsc" )
{
}
-sub script_mean_vals
-{
- # Martin A. Hansen, August 2007.
-
- # Calculate the mean of 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, %count_hash, $mean, $fh );
-
- while ( $record = Maasha::Biopieces::get_record( $in ) )
- {
- foreach $key ( @{ $options->{ "keys" } } )
- {
- if ( $record->{ $key } )
- {
- $sum_hash{ $key } += $record->{ $key };
- $count_hash{ $key }++;
- }
- }
-
- Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
- }
-
- $fh = write_stream( $options->{ "data_out" } );
-
- foreach $key ( @{ $options->{ "keys" } } )
- {
- if ( $count_hash{ $key } ) {
- $mean = sprintf( "%.2f", ( $sum_hash{ $key } / $count_hash{ $key } ) );
- } else {
- $mean = "N/A";
- }
-
- Maasha::Biopieces::put_record( { $key . "_MEAN" => $mean } , $fh );
- }
-
- close $fh;
-}
-
-
-sub script_median_vals
-{
- # Martin A. Hansen, March 2008.
-
- # Calculate the median values of given keys.
-
- my ( $in, # handle to in stream
- $out, # handle to out stream
- $options, # options hash
- ) = @_;
-
- # Returns nothing.
-
- my ( $record, $key, %median_hash, $median, $fh );
-
- while ( $record = Maasha::Biopieces::get_record( $in ) )
- {
- foreach $key ( @{ $options->{ "keys" } } ) {
- push @{ $median_hash{ $key } }, $record->{ $key } if defined $record->{ $key };
- }
-
- Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
- }
-
- $fh = write_stream( $options->{ "data_out" } );
-
- foreach $key ( @{ $options->{ "keys" } } )
- {
- if ( $median_hash{ $key } ) {
- $median = Maasha::Calc::median( $median_hash{ $key } );
- } else {
- $median = "N/A";
- }
-
- Maasha::Biopieces::put_record( { $key . "_MEDIAN" => $median } , $fh );
- }
-
- close $fh;
-}
-
-
-sub script_max_vals
-{
- # Martin A. Hansen, February 2008.
-
- # Determine the maximum values of given keys.
-
- my ( $in, # handle to in stream
- $out, # handle to out stream
- $options, # options hash
- ) = @_;
-
- # Returns nothing.
-
- my ( $record, $key, $fh, %max_hash, $max_record );
-
- while ( $record = Maasha::Biopieces::get_record( $in ) )
- {
- foreach $key ( @{ $options->{ "keys" } } )
- {
- if ( $record->{ $key } )
- {
- $max_hash{ $key } = $record->{ $key } if $record->{ $key } > $max_hash{ $key };
- }
- }
-
- Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
- }
-
- $fh = write_stream( $options->{ "data_out" } );
-
- foreach $key ( @{ $options->{ "keys" } } )
- {
- $max_record->{ $key . "_MAX" } = $max_hash{ $key };
- }
-
- Maasha::Biopieces::put_record( $max_record, $fh );
-
- close $fh;
-}
-
-
-sub script_min_vals
-{
- # Martin A. Hansen, February 2008.
-
- # Determine the minimum values of given keys.
-
- my ( $in, # handle to in stream
- $out, # handle to out stream
- $options, # options hash
- ) = @_;
-
- # Returns nothing.
-
- my ( $record, $key, $fh, %min_hash, $min_record );
-
- while ( $record = Maasha::Biopieces::get_record( $in ) )
- {
- foreach $key ( @{ $options->{ "keys" } } )
- {
- if ( defined $record->{ $key } )
- {
- if ( exists $min_hash{ $key } ) {
- $min_hash{ $key } = $record->{ $key } if $record->{ $key } < $min_hash{ $key };
- } else {
- $min_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" } } )
- {
- $min_record->{ $key . "_MIN" } = $min_hash{ $key };
- }
-
- Maasha::Biopieces::put_record( $min_record, $fh );
-
- close $fh;
-}
-
-
sub script_upload_to_ucsc
{
# Martin A. Hansen, August 2007.