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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
24 # Split the values of a key into new key/value pairs.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
30 use Maasha::Biopieces;
33 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
36 my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $beg, $end, $len );
38 $options = Maasha::Biopieces::parse_options(
40 { long => 'beg', short => 'b', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
41 { long => 'end', short => 'e', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
42 { long => 'len', short => 'l', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 },
46 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
47 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
49 if ( not defined $options->{ "beg" } or $options->{ "beg" } < 0 ) {
52 $beg = $options->{ "beg" } - 1; # correcting for start offset
55 if ( defined $options->{ "end" } and $options->{ "end" } - 1 < $beg ) {
57 } elsif ( defined $options->{ "end" } ) {
58 $end = $options->{ "end" } - 1; # correcting for start offset
61 $len = $options->{ "len" };
63 # print "beg->$beg, end->$end, len->$len\n";
65 while ( $record = Maasha::Biopieces::get_record( $in ) )
67 if ( $record->{ "SEQ" } )
69 if ( defined $beg and defined $end )
71 if ( $end - $beg + 1 > length $record->{ "SEQ" } ) {
72 $record->{ "SEQ" } = substr $record->{ "SEQ" }, $beg;
74 $record->{ "SEQ" } = substr $record->{ "SEQ" }, $beg, $end - $beg + 1;
77 elsif ( defined $beg and defined $len )
79 if ( $len > length $record->{ "SEQ" } ) {
80 $record->{ "SEQ" } = substr $record->{ "SEQ" }, $beg;
82 $record->{ "SEQ" } = substr $record->{ "SEQ" }, $beg, $len;
85 elsif ( defined $beg )
87 $record->{ "SEQ" } = substr $record->{ "SEQ" }, $beg;
90 $record->{ "SEQ_LEN" } = length $record->{ "SEQ" };
93 Maasha::Biopieces::put_record( $record, $out );
97 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
102 $run_time_beg = Maasha::Biopieces::run_time();
104 Maasha::Biopieces::log_biopiece();
110 Maasha::Biopieces::close_stream( $in );
111 Maasha::Biopieces::close_stream( $out );
113 $run_time_end = Maasha::Biopieces::run_time();
115 Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options );
119 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<