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 # Determines the distance between mapped mate pair sequence matches.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
32 use Maasha::Biopieces;
35 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
38 my ( $options, $in, $out, $record, %data, $q_id, $mate, $contig, $strand, @mates1, @mates2, $mate1, $mate2, $new_record );
40 $options = Maasha::Biopieces::parse_options();
42 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
43 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
45 while ( $record = Maasha::Biopieces::get_record( $in ) )
47 if ( exists $record->{ 'S_ID' } and
48 exists $record->{ 'Q_ID' } and
49 exists $record->{ 'STRAND' } and
50 exists $record->{ 'S_BEG' }
53 ( $q_id, $mate ) = split "/", $record->{ 'Q_ID' }, 2;
59 if ( $record->{ 'STRAND' } eq '+' ) {
60 $record->{ 'STRAND' } = '-';
62 $record->{ 'STRAND' } = '+';
66 push @{ $data{ $record->{ 'S_ID' } }{ $record->{ 'STRAND' } }{ $q_id }{ $mate } }, $record;
70 Maasha::Biopieces::put_record( $record, $out );
73 # print Dumper( \%data ); # DEBUG
75 foreach $contig ( keys %data )
77 foreach $strand ( keys %{ $data{ $contig } } )
79 foreach $q_id ( keys %{ $data{ $contig }{ $strand } } )
81 next if not exists $data{ $contig }{ $strand }{ $q_id }{ 1 };
82 next if not exists $data{ $contig }{ $strand }{ $q_id }{ 2 };
84 @mates1 = @{ $data{ $contig }{ $strand }{ $q_id }{ 1 } };
85 @mates2 = @{ $data{ $contig }{ $strand }{ $q_id }{ 2 } };
87 @mates1 = sort { $a->{ 'S_BEG' } <=> $b->{ 'S_BEG' } } @mates1;
88 @mates2 = sort { $a->{ 'S_BEG' } <=> $b->{ 'S_BEG' } } @mates2;
90 foreach $mate1 ( @mates1 )
92 foreach $mate2 ( @mates2 )
96 Q_ID1 => $mate1->{ 'Q_ID' },
97 Q_ID2 => $mate2->{ 'Q_ID' },
98 S_BEG1 => $mate1->{ 'S_BEG' },
99 S_BEG2 => $mate2->{ 'S_BEG' },
100 S_END1 => $mate1->{ 'S_END' },
101 S_END2 => $mate2->{ 'S_END' },
102 SEQ_LEN1 => $mate1->{ 'SEQ_LEN' },
103 SEQ_LEN2 => $mate2->{ 'SEQ_LEN' },
104 STRAND => $mate1->{ 'STRAND' },
105 DIST => abs( $mate2->{ 'S_BEG' } - $mate1->{ 'S_BEG' } ),
108 Maasha::Biopieces::put_record( $new_record, $out );
115 Maasha::Biopieces::close_stream( $in );
116 Maasha::Biopieces::close_stream( $out );
119 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
124 Maasha::Biopieces::status_set();
130 Maasha::Biopieces::status_log();
134 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<