]> git.donarmstrong.com Git - biopieces.git/commitdiff
migrating read_ tools
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 2 Jun 2009 12:17:53 +0000 (12:17 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 2 Jun 2009 12:17:53 +0000 (12:17 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@460 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/read_2bit
bp_bin/read_bed
bp_bin/read_fasta
code_perl/Maasha/BioRun.pm
code_perl/Maasha/Common.pm
code_perl/Maasha/Filesys.pm

index fdf5bd287f78613d2aea83bb9b15f855cad57e77..25f0193ba82bdc4869bc4e66be9c0a119703fecb 100755 (executable)
@@ -1,6 +1,110 @@
-#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Read nucleotide sequences in 2bit format from one or more files.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
 
-use warnings;
 use strict;
+use Maasha::Biopieces;
+use Maasha::Filesys;
+use Maasha::TwoBit;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $file, $data_in, $mask, $toc, $line, $num );
+
+$options = Maasha::Biopieces::parse_options(
+    [
+        { long => 'data_in', short => 'i', type => 'files!', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
+        { long => 'num',     short => 'n', type => 'uint',   mandatory => 'no', default => undef, allowed => undef, disallowed => '0'   },
+        { long => 'no_mask', short => 'N', 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" } );
+
+while ( $record = Maasha::Biopieces::get_record( $in ) ) {
+    Maasha::Biopieces::put_record( $record, $out );
+}
+
+$mask = 1 if not $options->{ "no_mask" };
+
+$num = 1;
+
+foreach $file ( @{ $options->{ "data_in" } } )
+{
+    $data_in = Maasha::Filesys::file_read_open( $file );
+
+    $toc = Maasha::TwoBit::twobit_get_TOC( $data_in );
+
+    foreach $line ( @{ $toc } )
+    {
+        $record->{ "SEQ_NAME" } = $line->[ 0 ];
+        $record->{ "SEQ" }      = Maasha::TwoBit::twobit_get_seq( $data_in, $line->[ 1 ], undef, undef, $mask );
+        $record->{ "SEQ_LEN" }  = length $record->{ "SEQ" };
+
+        Maasha::Biopieces::put_record( $record, $out );
+
+        goto NUM if $options->{ "num" } and $num == $options->{ "num" };
+
+        $num++;
+    }
+
+    close $data_in;
+}
+
+NUM:
+
+close $data_in if $data_in;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+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 fdf5bd287f78613d2aea83bb9b15f855cad57e77..18c5c226fe1b5f892e7d07dfb3b36b0317a3df65 100755 (executable)
@@ -1,6 +1,101 @@
-#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Read BED data (Browser Extensible Data) from one or more files.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
 
-use warnings;
 use strict;
+use Maasha::Biopieces;
+use Maasha::Filesys;
+use Maasha::UCSC::BED;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $file, $record, $bed_entry, $data_in, $num );
+
+$options = Maasha::Biopieces::parse_options(
+    [
+        { long => 'data_in', short => 'i', type => 'files!', mandatory => 'no', default => undef, allowed => undef, disallowed => undef   },
+        { long => 'cols',    short => 'c', type => 'uint',   mandatory => 'no', default => undef, allowed => undef, disallowed => '0,1,2' },
+        { long => 'num',     short => 'n', type => 'uint',   mandatory => 'no', default => undef, allowed => undef, disallowed => '0'     },
+        { 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" } );
+
+while ( $record = Maasha::Biopieces::get_record( $in ) ) {
+    Maasha::Biopieces::put_record( $record, $out );
+}
+
+if ( $options->{ 'data_in' } )
+{
+    $num = 1;
+
+    $data_in = Maasha::Filesys::files_read_open( $options->{ 'data_in' } );
+
+    while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $data_in, $options->{ 'cols' }, $options->{ 'check' } ) )
+    {
+        $record = Maasha::UCSC::BED::bed2biopiece( $bed_entry );
+
+        Maasha::Biopieces::put_record( $record, $out );
+
+        last if $options->{ "num" } and $num == $options->{ "num" };
+
+        $num++;
+    }
+
+    close $data_in;
+}
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+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 092e0c5e681be38a6375fc460d01f0ba04e4b50f..9449a0d68cfbc2e00147ad381e656bde142fed88 100755 (executable)
@@ -27,9 +27,9 @@
 
 
 use strict;
-use Maasha::Common;
-use Maasha::Fasta;
 use Maasha::Biopieces;
+use Maasha::Filesys;
+use Maasha::Fasta;
 
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@@ -53,7 +53,7 @@ while ( $record = Maasha::Biopieces::get_record( $in ) ) {
 
 if ( $options->{ 'data_in' } )
 {
-    $data_in = Maasha::Common::read_open_multi( $options->{ 'data_in' } );
+    $data_in = Maasha::Filesys::files_read_open( $options->{ 'data_in' } );
 
     $num = 1;
 
index aebeb94520574f93205466e4ee94383ac68346a7..7b5a9da0fa38ffcf0277a15fa2d685fed7ce1b96 100644 (file)
@@ -39,14 +39,9 @@ use Maasha::Config;
 use Maasha::Common;
 use Maasha::Filesys;
 use Maasha::Fasta;
-use Maasha::Align;
-use Maasha::Matrix;
-use Maasha::Match;
 use Maasha::EMBL;
 use Maasha::Stockholm;
 use Maasha::Seq;
-use Maasha::Patscan;
-use Maasha::Plot;
 use Maasha::Calc;
 use Maasha::UCSC;
 use Maasha::UCSC::BED;
@@ -117,7 +112,6 @@ sub run_script
 
     if    ( $script eq "print_usage" )              { script_print_usage(               $in, $out, $options ) }
     elsif ( $script eq "read_psl" )                 { script_read_psl(                  $in, $out, $options ) }
-    elsif ( $script eq "read_bed" )                 { script_read_bed(                  $in, $out, $options ) }
     elsif ( $script eq "read_fixedstep" )           { script_read_fixedstep(            $in, $out, $options ) }
     elsif ( $script eq "read_blast_tab" )           { script_read_blast_tab(            $in, $out, $options ) }
     elsif ( $script eq "read_embl" )                { script_read_embl(                 $in, $out, $options ) }
@@ -125,7 +119,6 @@ sub run_script
     elsif ( $script eq "read_phastcons" )           { script_read_phastcons(            $in, $out, $options ) }
     elsif ( $script eq "read_soft" )                { script_read_soft(                 $in, $out, $options ) }
     elsif ( $script eq "read_gff" )                 { script_read_gff(                  $in, $out, $options ) }
-    elsif ( $script eq "read_2bit" )                { script_read_2bit(                 $in, $out, $options ) }
     elsif ( $script eq "read_solexa" )              { script_read_solexa(               $in, $out, $options ) }
     elsif ( $script eq "read_solid" )               { script_read_solid(                $in, $out, $options ) }
     elsif ( $script eq "read_mysql" )               { script_read_mysql(                $in, $out, $options ) }
@@ -174,15 +167,6 @@ sub get_options
             num|n=s
         );
     }
-    elsif ( $script eq "read_bed" )
-    {
-        @options = qw(
-            data_in|i=s
-            cols|c=s
-            num|n=s
-            check|C
-        );
-    }
     elsif ( $script eq "read_fixedstep" )
     {
         @options = qw(
@@ -240,14 +224,6 @@ sub get_options
             num|n=s
         );
     }
-    elsif ( $script eq "read_2bit" )
-    {
-        @options = qw(
-            data_in|i=s
-            num|n=s
-            no_mask|N
-        );
-    }
     elsif ( $script eq "read_solexa" )
     {
         @options = qw(
@@ -548,53 +524,6 @@ sub script_read_psl
 }
 
 
-sub script_read_bed
-{
-    # Martin A. Hansen, August 2007.
-
-    # Read bed table from stream or file.
-
-    my ( $in,        # handle to in stream
-         $out,       # handle to out stream
-         $options,   # options hash
-       ) = @_;
-
-    # Returns nothing.
-
-    my ( $cols, $file, $record, $bed_entry, $data_in, $num );
-
-    $cols = $options->{ 'cols' }->[ 0 ];
-
-    while ( $record = Maasha::Biopieces::get_record( $in ) ) {
-        Maasha::Biopieces::put_record( $record, $out );
-    }
-
-    $num = 1;
-
-    foreach $file ( @{ $options->{ "files" } } )
-    {
-        $data_in = Maasha::Common::read_open( $file );
-
-        while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $data_in, $cols, $options->{ 'check' } ) )
-        {
-            $record = Maasha::UCSC::BED::bed2biopiece( $bed_entry );
-
-            Maasha::Biopieces::put_record( $record, $out );
-
-            goto NUM if $options->{ "num" } and $num == $options->{ "num" };
-
-            $num++;
-        }
-
-        close $data_in;
-    }
-
-    NUM:
-
-    close $data_in if $data_in;
-}
-
-
 sub script_read_fixedstep
 {
     # Martin A. Hansen, Juli 2008.
@@ -1027,57 +956,6 @@ sub script_read_gff
 }
 
 
-sub script_read_2bit
-{
-    # Martin A. Hansen, March 2008.
-
-    # Read sequences from 2bit file.
-
-    my ( $in,        # handle to in stream
-         $out,       # handle to out stream
-         $options,   # options hash
-       ) = @_;
-
-    # Returns nothing.
-
-    my ( $record, $file, $data_in, $mask, $toc, $line, $num );
-
-    $mask = 1 if not $options->{ "no_mask" };
-
-    while ( $record = Maasha::Biopieces::get_record( $in ) ) {
-        Maasha::Biopieces::put_record( $record, $out );
-    }
-
-    $num = 1;
-
-    foreach $file ( @{ $options->{ "files" } } )
-    {
-        $data_in = Maasha::Common::read_open( $file );
-
-        $toc = Maasha::TwoBit::twobit_get_TOC( $data_in );
-
-        foreach $line ( @{ $toc } )
-        {
-            $record->{ "SEQ_NAME" } = $line->[ 0 ];
-            $record->{ "SEQ" }      = Maasha::TwoBit::twobit_get_seq( $data_in, $line->[ 1 ], undef, undef, $mask );
-            $record->{ "SEQ_LEN" }  = length $record->{ "SEQ" };
-
-            Maasha::Biopieces::put_record( $record, $out );
-
-            goto NUM if $options->{ "num" } and $num == $options->{ "num" };
-
-            $num++;
-        }
-
-        close $data_in;
-    }
-
-    NUM:
-
-    close $data_in if $data_in;
-}
-
-
 sub script_read_solexa
 {
     # Martin A. Hansen, March 2008.
index 75f89cd0b209e078da2880c7ec8e3d4486879ab6..d998d80299f011bc7843a2ee69ed82246c1a1f47 100644 (file)
@@ -237,46 +237,6 @@ sub read_open
 }
 
 
-sub read_open_multi
-{
-    # Martin A. Hansen, May 2009.
-
-    # Cats a number of files and returns a filehandle.
-
-    my ( $files,   # full path to file
-       ) = @_;
-
-    # returns filehandle
-
-    my ( $file, $fh, $type, %type_hash, $file_string );
-
-    foreach $file ( @{ $files } )
-    {
-        Maasha::Common::error( qq(No such file: $file) ) if not -f $file;
-    
-        $type = `file $file`;
-
-        if ( $type =~ /gzip compressed/ ) {
-            $type_hash{ 'gzip' } = 1;
-        } else {
-            $type_hash{ 'ascii' } = 1;
-        }
-    }
-
-    Maasha::Common::error( qq(Mixture of zipped and unzipped files) ) if scalar keys %type_hash > 1;
-
-    $file_string = join " ", @{ $files };
-
-    if ( $type =~ /gzip compressed/ ) {
-        $fh = new IO::File "zcat $file_string|" or Maasha::Common::error( qq(Could not open pipe: $!) );
-    } else {
-        $fh = new IO::File "cat $file_string|" or Maasha::Common::error( qq(Could not open pipe: $!) );
-    }
-
-    return $fh;
-}
-
-
 sub write_open
 {
     # Martin A. Hansen, January 2004.
index cb27c95ff62d4544f6c0c607d085e76ce5aca875..b189a4124e8dc53c380891fa6effed427ad05759 100644 (file)
@@ -66,6 +66,46 @@ sub file_read_open
 }
 
 
+sub files_read_open
+{
+    # Martin A. Hansen, May 2009.
+
+    # Cats a number of files and returns a filehandle.
+
+    my ( $files,   # full path to file
+       ) = @_;
+
+    # returns filehandle
+
+    my ( $file, $fh, $type, %type_hash, $file_string );
+
+    foreach $file ( @{ $files } )
+    {
+        Maasha::Common::error( qq(No such file: $file) ) if not -f $file;
+    
+        $type = `file $file`;
+
+        if ( $type =~ /gzip compressed/ ) {
+            $type_hash{ 'gzip' } = 1;
+        } else {
+            $type_hash{ 'ascii' } = 1;
+        }
+    }
+
+    Maasha::Common::error( qq(Mixture of zipped and unzipped files) ) if scalar keys %type_hash > 1;
+
+    $file_string = join " ", @{ $files };
+
+    if ( $type =~ /gzip compressed/ ) {
+        $fh = new IO::File "zcat $file_string|" or Maasha::Common::error( qq(Could not open pipe: $!) );
+    } else {
+        $fh = new IO::File "cat $file_string|" or Maasha::Common::error( qq(Could not open pipe: $!) );
+    }
+
+    return $fh;
+}
+
+
 sub file_write_open
 {
     # Martin A. Hansen, January 2004.