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 # Intersect records in the stream based on overlapping intervals contained in values to specific keys.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
31 use Maasha::Biopieces;
35 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
38 my ( $options, $in, $out, $record, $opt_key, $opt_strand, $found, $pos, $lookup_hash );
40 $options = Maasha::Biopieces::parse_options(
42 { long => 'key', short => 'k', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
43 { long => 'strand', short => 's', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
44 { long => 'inverse', short => 'i', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
48 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
49 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
51 $opt_key = $options->{ 'key' };
52 $opt_strand = $options->{ 'strand' };
54 while ( $record = Maasha::Biopieces::get_record( $in ) )
56 if ( exists $record->{ 'S_ID' } and exists $record->{ 'S_BEG' } and exists $record->{ 'S_END' } )
58 $record->{ 'STRAND' } ||= '.';
60 if ( exists $record->{ $opt_key } )
62 map { $lookup_hash->{ $record->{ 'S_ID' } }->{ $record->{ 'STRAND' } }->{ $_ } = 1 } ( $record->{ 'S_BEG' } .. $record->{ 'S_END' } );
68 foreach $pos ( $record->{ 'S_BEG' } .. $record->{ 'S_END' } )
72 if ( exists $lookup_hash->{ $record->{ 'S_ID' } }->{ $record->{ 'STRAND' } }->{ $pos } )
81 if ( exists $lookup_hash->{ $record->{ 'S_ID' } }->{ '+' }->{ $pos } or
82 exists $lookup_hash->{ $record->{ 'S_ID' } }->{ '-' }->{ $pos }
92 if ( ( $found and not $options->{ 'inverse' } ) or
93 ( not $found and $options->{ 'inverse' } )
96 Maasha::Biopieces::put_record( $record, $out );
102 # print Dumper( $lookup_hash );
104 Maasha::Biopieces::close_stream( $in );
105 Maasha::Biopieces::close_stream( $out );
108 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
113 Maasha::Biopieces::status_set();
119 Maasha::Biopieces::status_log();
123 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<