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 # Locates and removes a specified adaptor sequence from sequences in stream.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
30 use Maasha::Biopieces;
34 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
37 my ( $options, $in, $out, $record, $adaptor, $seq, $adaptor_len,
38 $seq_len, $offset, $max_match, $max_mismatch, $pos );
40 $options = Maasha::Biopieces::parse_options(
42 { long => 'adaptor', short => 'a', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
43 { long => 'mismatches', short => 'm', type => 'uint', mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
44 { long => 'offset', short => 'o', type => 'uint', mandatory => 'no', default => 1, allowed => undef, disallowed => 0 },
45 { long => 'remove', short => 'r', type => 'string', mandatory => 'no', default => 'after', allowed => 'before,after,skip', disallowed => undef },
49 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
50 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
52 $max_mismatch = $options->{ "mismatches" };
53 $offset = $options->{ "offset" };
55 if ( not defined $offset ) {
61 $adaptor = uc $options->{ "adaptor" };
62 $adaptor_len = length $adaptor;
64 while ( $record = Maasha::Biopieces::get_record( $in ) )
66 if ( $record->{ "SEQ" } )
68 $seq = uc $record->{ "SEQ" };
69 $seq_len = length $seq;
71 $pos = Maasha::Common::index_m( $seq, $adaptor, $seq_len, $adaptor_len, $offset, $max_mismatch );
73 $record->{ "ADAPTOR_POS" } = $pos;
75 if ( $pos >= 0 and $options->{ "remove" } ne "skip" )
77 if ( $options->{ "remove" } eq "after" )
79 $record->{ "SEQ" } = substr $record->{ "SEQ" }, 0, $pos;
80 $record->{ "SEQ_LEN" } = $pos;
84 $record->{ "SEQ" } = substr $record->{ "SEQ" }, $pos + $adaptor_len;
85 $record->{ "SEQ_LEN" } = length $record->{ "SEQ" };
89 Maasha::Biopieces::put_record( $record, $out );
93 Maasha::Biopieces::put_record( $record, $out );
98 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
103 $run_time_beg = Maasha::Biopieces::run_time();
105 Maasha::Biopieces::log_biopiece();
111 Maasha::Biopieces::close_stream( $in );
112 Maasha::Biopieces::close_stream( $out );
114 $run_time_end = Maasha::Biopieces::run_time();
116 Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options );
120 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<