]> git.donarmstrong.com Git - biopieces.git/commitdiff
migrated plot_histogram
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 29 May 2009 09:40:25 +0000 (09:40 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 29 May 2009 09:40:25 +0000 (09:40 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@449 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/plot_histogram
code_perl/Maasha/BioRun.pm

index fdf5bd287f78613d2aea83bb9b15f855cad57e77..989222e299c5dad742fe79e75ab5eb5791e37d7c 100755 (executable)
@@ -1,6 +1,106 @@
-#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Plot a simple histogram.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
 
-use warnings;
 use strict;
+use Maasha::Biopieces;
+use Maasha::Plot;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $default, $terminals, $record, %data_hash, $max, @data_list, $i, $result, $fh );
+
+$default   = "Histogram";
+$terminals = "dumb,x11,aqua,post,svg";
+
+$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 => 'key',       short => 'k', type => 'string', mandatory => 'yes', default => undef,    allowed => undef,      disallowed => undef },
+        { long => 'terminal',  short => 't', type => 'string', mandatory => 'no',  default => 'dumb',   allowed => $terminals, disallowed => undef },
+        { long => 'title',     short => 'T', type => 'string', mandatory => 'no',  default => $default, allowed => undef,      disallowed => undef },
+        { long => 'xlabel',    short => 'X', type => 'string', mandatory => 'no',  default => undef,    allowed => undef,      disallowed => undef },
+        { long => 'ylabel',    short => 'Y', type => 'string', mandatory => 'no',  default => undef,    allowed => undef,      disallowed => undef },
+        { long => 'sort',      short => 's', type => 'string', mandatory => 'no',  default => 'num',    allowed => 'num,alph', 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 ) ) 
+{
+    $data_hash{ $record->{ $options->{ "key" } } }++ if defined $record->{ $options->{ "key" } };
+
+    Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
+}
+
+if ( $options->{ "sort" } eq "num" ) {
+    map { push @data_list, [ $_, $data_hash{ $_ } ] } sort { $a <=> $b } keys %data_hash;
+} else {
+    map { push @data_list, [ $_, $data_hash{ $_ } ] } sort keys %data_hash;
+}
+
+$result = Maasha::Plot::histogram_simple( \@data_list, $options );
+
+$fh = Maasha::Biopieces::write_stream( $options->{ "data_out" } );
+
+print $fh "$_\n" foreach @{ $result };
+
+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;
index f926070f5bd1adca9a335c667da482eeb4a99445..be5975b745822db9f03e639c9643a5ef0de7482b 100644 (file)
@@ -143,7 +143,6 @@ sub run_script
     elsif ( $script eq "write_ucsc_config" )        { script_write_ucsc_config(         $in, $out, $options ) }
     elsif ( $script eq "remove_mysql_tables" )      { script_remove_mysql_tables(       $in, $out, $options ) }
     elsif ( $script eq "remove_ucsc_tracks" )       { script_remove_ucsc_tracks(        $in, $out, $options ) }
-    elsif ( $script eq "plot_histogram" )           { script_plot_histogram(            $in, $out, $options ) }
     elsif ( $script eq "plot_lendist" )             { script_plot_lendist(              $in, $out, $options ) }
     elsif ( $script eq "plot_karyogram" )           { script_plot_karyogram(            $in, $out, $options ) }
     elsif ( $script eq "plot_matches" )             { script_plot_matches(              $in, $out, $options ) }
@@ -421,19 +420,6 @@ sub get_options
             no_stream|x
         );
     }
-    elsif ( $script eq "plot_histogram" )
-    {
-        @options = qw(
-            no_stream|x
-            data_out|o=s
-            terminal|t=s
-            title|T=s
-            xlabel|X=s
-            ylabel|Y=s
-            key|k=s
-            sort|s=s
-        );
-    }
     elsif ( $script eq "plot_lendist" )
     {
         @options = qw(
@@ -587,7 +573,7 @@ sub get_options
     Maasha::Common::error( qq(no --in_file or --genome specified) )     if $script eq "soap_seq" and not $options{ "genome" } and not $options{ "in_file" };
     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 --key specified) )                     if $script =~ /plot_lendist/ and not $options{ "key" };
 
     if ( $script eq "upload_to_ucsc" )
     {
@@ -2101,47 +2087,6 @@ sub script_remove_ucsc_tracks
 }
 
 
-sub script_plot_histogram
-{
-    # Martin A. Hansen, September 2007.
-
-    # Plot a simple histogram for a given key using GNU plot.
-
-    my ( $in,        # handle to in stream
-         $out,       # handle to out stream
-         $options,   # options hash
-       ) = @_;
-
-    # Returns nothing.
-
-    my ( $record, %data_hash, $max, @data_list, $i, $result, $fh );
-
-    $options->{ "title" } ||= "Histogram";
-    $options->{ "sort" }  ||= "num";
-
-    while ( $record = Maasha::Biopieces::get_record( $in ) ) 
-    {
-        $data_hash{ $record->{ $options->{ "key" } } }++ if defined $record->{ $options->{ "key" } };
-
-        Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
-    }
-
-    if ( $options->{ "sort" } eq "num" ) {
-        map { push @data_list, [ $_, $data_hash{ $_ } ] } sort { $a <=> $b } keys %data_hash;
-    } else {
-        map { push @data_list, [ $_, $data_hash{ $_ } ] } sort keys %data_hash;
-    }
-
-    $result = Maasha::Plot::histogram_simple( \@data_list, $options );
-
-    $fh = Maasha::Biopieces::write_stream( $options->{ "data_out" } );
-
-    print $fh "$_\n" foreach @{ $result };
-
-    close $fh;
-}
-
-
 sub script_plot_lendist
 {
     # Martin A. Hansen, August 2007.