]> git.donarmstrong.com Git - biopieces.git/commitdiff
migrated and fixed calc_fixedstep
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 26 May 2009 09:14:05 +0000 (09:14 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 26 May 2009 09:14:05 +0000 (09:14 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@410 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/calc_fixedstep
code_perl/Maasha/BioRun.pm
code_perl/Maasha/UCSC/Wiggle.pm

index fdf5bd287f78613d2aea83bb9b15f855cad57e77..9c14f2ca49ed2ca2ae0bed582948926fee64b46e 100755 (executable)
@@ -1,6 +1,123 @@
-#!/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 fixedstep entries from records in the stream.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
 
-use warnings;
 use strict;
+use Maasha::Biopieces;
+use Maasha::Filesys;
+use Maasha::UCSC::BED;
+use Maasha::UCSC::Wiggle;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $tmp_dir, $bed_file, $fh_in, $fh_out,
+     $file_hash, $chr, $bed_entry, $fixedstep_file, $fixedstep_entry );
+
+$options = Maasha::Biopieces::parse_options(
+    [
+        { long => 'check', short => 'C', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
+    ]   
+);
+
+$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
+$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+
+$tmp_dir = Maasha::Biopieces::get_tmpdir();
+
+$bed_file = "$tmp_dir/calc_fixedstep.bed";
+$fh_out   = Maasha::Filesys::file_write_open( $bed_file );
+
+while ( $record = Maasha::Biopieces::get_record( $in ) ) 
+{
+    if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record ) ) {
+        Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, undef, $options->{ 'check' } );
+    }
+
+    Maasha::Biopieces::put_record( $record, $out );
+}
+
+close $fh_out;
+
+$file_hash = Maasha::UCSC::BED::bed_file_split_on_chr( $bed_file, $tmp_dir );
+
+unlink $bed_file;
+
+foreach $chr ( sort keys %{ $file_hash } )
+{
+    $bed_file       = $file_hash->{ $chr };
+
+    $fixedstep_file = Maasha::UCSC::Wiggle::fixedstep_calc( $bed_file, $chr, $options->{ 'use_score' }, $options->{ 'use_log10' } );        
+
+    #$fixedstep_file = "$bed_file.fixedstep";
+    
+    # Maasha::Common::run( "bed2fixedstep", "< $bed_file > $fixedstep_file" );
+
+    $fh_in = Maasha::Filesys::file_read_open( $fixedstep_file );
+
+    while ( $fixedstep_entry = Maasha::UCSC::Wiggle::fixedstep_entry_get( $fh_in ) )
+    {
+        if ( $record = Maasha::UCSC::Wiggle::fixedstep2biopiece( $fixedstep_entry ) ) {
+            Maasha::Biopieces::put_record( $record, $out );
+        }
+    }
+
+    close $fh_in;
+
+    unlink $bed_file;
+    unlink $fixedstep_file;
+}
+
+Maasha::Filesys::dir_remove( $tmp_dir );
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+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 );
+}
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
 
-use Maasha::BioRun;
+__END__
index edb52b027f7640ee632fb6ffce8a4f33e7c766e4..bb5437f6274d9659ca14041fc05bb7e1f5793120 100644 (file)
@@ -135,7 +135,6 @@ sub run_script
     elsif ( $script eq "complexity_seq" )           { script_complexity_seq(            $in, $out, $options ) }
     elsif ( $script eq "oligo_freq" )               { script_oligo_freq(                $in, $out, $options ) }
     elsif ( $script eq "create_weight_matrix" )     { script_create_weight_matrix(      $in, $out, $options ) }
-    elsif ( $script eq "calc_fixedstep" )           { script_calc_fixedstep(            $in, $out, $options ) }
     elsif ( $script eq "remove_indels" )            { script_remove_indels(             $in, $out, $options ) }
     elsif ( $script eq "transliterate_seq" )        { script_transliterate_seq(         $in, $out, $options ) }
     elsif ( $script eq "transliterate_vals" )       { script_transliterate_vals(        $in, $out, $options ) }
@@ -326,12 +325,6 @@ sub get_options
             num|n=s
         );
     }
-    elsif ( $script eq "calc_fixedstep" )
-    {
-        @options = qw(
-            check|C
-        );
-    }
     elsif ( $script eq "length_seq" )
     {
         @options = qw(
@@ -1833,64 +1826,6 @@ sub script_create_weight_matrix
 }
 
 
-sub script_calc_fixedstep
-{
-    # Martin A. Hansen, September 2008.
-
-    # Calculates fixedstep entries from data in the stream.
-
-    my ( $in,        # handle to in stream
-         $out,       # handle to out stream
-         $options,   # options hash
-       ) = @_;
-
-    # Returns nothing.
-
-    my ( $bed_file, $fh_in, $fh_out, $record, $file_hash, $chr, $bed_entry, $fixedstep_file, $fixedstep_entry );
-
-    $bed_file = "$BP_TMP/calc_fixedstep.bed";
-    $fh_out   = Maasha::Filesys::file_write_open( $bed_file );
-
-    while ( $record = Maasha::Biopieces::get_record( $in ) ) 
-    {
-        if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record ) ) {
-            Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, undef, $options->{ 'check' } );
-        }
-    }
-
-    close $fh_out;
-
-    $file_hash = Maasha::UCSC::BED::bed_file_split_on_chr( $bed_file, $BP_TMP );
-
-    unlink $bed_file;
-
-    foreach $chr ( sort keys %{ $file_hash } )
-    {
-        $bed_file       = $file_hash->{ $chr };
-
-        $fixedstep_file = Maasha::UCSC::Wiggle::fixedstep_calc( $bed_file, $chr, $options->{ 'use_score' }, $options->{ 'use_log10' } );        
-
-        #$fixedstep_file = "$bed_file.fixedstep";
-        
-        # Maasha::Common::run( "bed2fixedstep", "< $bed_file > $fixedstep_file" );
-
-        $fh_in = Maasha::Filesys::file_read_open( $fixedstep_file );
-
-        while ( $fixedstep_entry = Maasha::UCSC::Wiggle::fixedstep_entry_get( $fh_in ) )
-        {
-            if ( $record = Maasha::UCSC::Wiggle::fixedstep2biopiece( $fixedstep_entry ) ) {
-                Maasha::Biopieces::put_record( $record, $out );
-            }
-        }
-
-        close $fh_in;
-
-        unlink $bed_file;
-        unlink $fixedstep_file;
-    }
-}
-
-
 sub script_remove_indels
 {
     # Martin A. Hansen, August 2007.
index 6103a49902c814c7cbf8704c682ef228d468d43b..0e512e1beae9d29b47bf048522c040a90e15e61c 100644 (file)
@@ -87,6 +87,8 @@ sub fixedstep_entry_get
 
     $entry = <$fh>;
 
+    return if not $entry;
+
     chomp $entry;
 
     @lines = split "\n", $entry;
@@ -219,7 +221,7 @@ sub fixedstep_calc
     {
         @block = "fixedStep chrom=$chr start=" . ( $beg + 1 ) . " step=1";
 
-        for ( $i = $beg; $i <= $end; $i++ )
+        for ( $i = $beg; $i < $end; $i++ )
         {
             if ( $use_log10 ) {
                 push @block, sprintf "%.4f", Maasha::Calc::log10( $array->[ $i ] );
@@ -263,7 +265,7 @@ sub fixedstep_calc_array
     {
         if ( $use_score ) {
             $clones = $bed->[ score ];
-        } elsif ( $bed->[ name ] =~ /_(\d+)$/ ) {
+        } elsif ( defined $bed->[ name ] and $bed->[ name ] =~ /_(\d+)$/ ) {
             $clones = $1;
         } else {
             $clones = 1;