-#!/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__
-#!/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__
use strict;
-use Maasha::Common;
-use Maasha::Fasta;
use Maasha::Biopieces;
+use Maasha::Filesys;
+use Maasha::Fasta;
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
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;
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;
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 ) }
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 ) }
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(
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(
}
-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.
}
-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.
}
-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.
}
+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.