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

bp_bin/plot_lendist
code_perl/Maasha/BioRun.pm

index fdf5bd287f78613d2aea83bb9b15f855cad57e77..0197aca2758f78d8e9c5c6788172449c83c1cc2b 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 length distribution histogram.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
 
-use warnings;
 use strict;
+use Maasha::Biopieces;
+use Maasha::Plot;
+use Maasha::Calc;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $default, $terminals, $record, %data_hash, $max, @data_list, $i, $result, $fh );
+
+$default   = "Length Distribution";
+$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 },
+    ]   
+);
+
+$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" };
+}
+
+$max = Maasha::Calc::list_max( [ keys %data_hash ] );
+
+for ( $i = 0; $i < $max; $i++ ) {
+    push @data_list, [ $i, $data_hash{ $i } || 0 ];
+}
+
+$result = Maasha::Plot::histogram_lendist( \@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 c063bc290ddd282192d2ca7fee0dd1fa91e6f30a..d5f4e1fc2431c04ecd55f7b63d57d3225bc2266c 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_lendist" )             { script_plot_lendist(              $in, $out, $options ) }
     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 ) }
@@ -419,18 +418,6 @@ sub get_options
             no_stream|x
         );
     }
-    elsif ( $script eq "plot_lendist" )
-    {
-        @options = qw(
-            no_stream|x
-            data_out|o=s
-            terminal|t=s
-            title|T=s
-            xlabel|X=s
-            ylabel|Y=s
-            key|k=s
-        );
-    }
     elsif ( $script eq "plot_matches" )
     {
         @options = qw(
@@ -563,7 +550,6 @@ 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/ and not $options{ "genome" };
-    Maasha::Common::error( qq(no --key specified) )                     if $script =~ /plot_lendist/ and not $options{ "key" };
 
     if ( $script eq "upload_to_ucsc" )
     {
@@ -2077,46 +2063,6 @@ sub script_remove_ucsc_tracks
 }
 
 
-sub script_plot_lendist
-{
-    # Martin A. Hansen, August 2007.
-
-    # Plot length distribution 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" } ||= "Length Distribution";
-
-    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" };
-    }
-
-    $max = Maasha::Calc::list_max( [ keys %data_hash ] );
-
-    for ( $i = 0; $i < $max; $i++ ) {
-        push @data_list, [ $i, $data_hash{ $i } || 0 ];
-    }
-
-    $result = Maasha::Plot::histogram_lendist( \@data_list, $options );
-
-    $fh = Maasha::Biopieces::write_stream( $options->{ "data_out" } );
-
-    print $fh "$_\n" foreach @{ $result };
-
-    close $fh;
-}
-
-
 sub script_plot_matches
 {
     # Martin A. Hansen, August 2007.