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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 # Analyze mismatches and indels from ALIGN descriptors in the stream.
28 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
33 use Maasha::Biopieces;
37 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
40 my ( $options, $in, $out, $record, @aligns, $align, $offset, $src, $dst, $data, $s_id, $pos, $count, $new_record );
43 $options = Maasha::Biopieces::parse_options(
45 { long => 'min', short => 'm', type => 'uint', mandatory => 'no', default => 1, allowed => undef, disallowed => '0' },
49 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
50 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
54 while ( $record = Maasha::Biopieces::get_record( $in ) )
56 if ( exists $record->{ 'ALIGN' } )
58 @aligns = split /,/, $record->{ 'ALIGN' };
60 foreach $align ( @aligns )
62 if ( $align =~ /(\d+):([ATCGN-])>([ATCGN-])/ )
68 $data->{ $record->{ 'S_ID' } }->{ $record->{ 'S_BEG' } + $offset }->{ $src }->{ $dst }++;
73 Maasha::Biopieces::put_record( $record, $out );
76 foreach $s_id ( sort keys %{ $data } )
78 foreach $pos ( sort { $a <=> $b } keys %{ $data->{ $s_id } } )
80 foreach $src ( sort keys %{ $data->{ $s_id }->{ $pos } } )
82 foreach $dst ( sort keys %{ $data->{ $s_id }->{ $pos }->{ $src } } )
84 $count = $data->{ $s_id }->{ $pos }->{ $src }->{ $dst };
86 if ( $count >= $options->{ 'min' } )
88 $new_record->{ 'REC_TYPE' } = "SNP";
89 $new_record->{ 'S_ID' } = $s_id;
90 $new_record->{ 'S_POS' } = $pos;
91 $new_record->{ 'SRC' } = $src;
92 $new_record->{ 'DST' } = $dst;
93 $new_record->{ 'SNP_COUNT' } = $count;
96 $new_record->{ 'TYPE' } = "INSERTION";
97 } elsif ( $dst eq '-' ) {
98 $new_record->{ 'TYPE' } = "DELETION";
100 $new_record->{ 'TYPE' } = "MISMATCH";
103 Maasha::Biopieces::put_record( $new_record, $out );
110 Maasha::Biopieces::close_stream( $in );
111 Maasha::Biopieces::close_stream( $out );
114 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
119 Maasha::Biopieces::status_set();
125 Maasha::Biopieces::status_log();
129 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<