3 # Copyright (C) 2007-2009 Martin A. Hansen.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
32 use Maasha::Biopieces;
35 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
38 my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $data_in, $num, $skip, $line, @fields, @fields2, $i );
40 $options = Maasha::Biopieces::parse_options(
42 { long => 'data_in', short => 'i', type => 'files!', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
43 { long => 'delimit', short => 'd', type => 'string', mandatory => 'no', default => '\s+', allowed => undef, disallowed => undef },
44 { long => 'cols', short => 'c', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
45 { long => 'keys', short => 'k', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
46 { long => 'skip', short => 's', type => 'uint', mandatory => 'no', default => '0', allowed => undef, disallowed => undef },
47 { long => 'num', short => 'n', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => '0' },
51 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
52 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
54 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
55 Maasha::Biopieces::put_record( $record, $out );
58 if ( $options->{ 'data_in' } )
60 $data_in = Maasha::Common::read_open_multi( $options->{ 'data_in' } );
63 $skip = $options->{ 'skip' };
65 while ( $line = <$data_in> )
73 next if $line =~ /^#|^$/;
80 @fields = split /$options->{'delimit'}/, $line;
82 if ( $options->{ "cols" } ) {
83 map { push @fields2, $fields[ $_ ] } @{ $options->{ "cols" } };
88 for ( $i = 0; $i < @fields2; $i++ )
90 if ( $options->{ "keys" }->[ $i ] ) {
91 $record->{ $options->{ "keys" }->[ $i ] } = $fields2[ $i ];
93 $record->{ "V" . $i } = $fields2[ $i ];
97 Maasha::Biopieces::put_record( $record, $out );
99 last if $options->{ "num" } and $num == $options->{ "num" };
108 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
113 $run_time_beg = Maasha::Biopieces::run_time();
115 Maasha::Biopieces::log_biopiece();
120 Maasha::Biopieces::close_stream( $in );
121 Maasha::Biopieces::close_stream( $out );
123 $run_time_end = Maasha::Biopieces::run_time();
125 Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options );
129 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<