]> git.donarmstrong.com Git - biopieces.git/commitdiff
added analyze_snp
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 9 Nov 2009 14:15:46 +0000 (14:15 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 9 Nov 2009 14:15:46 +0000 (14:15 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@758 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/analyze_snp [new file with mode: 0755]
bp_bin/bwa_seq

diff --git a/bp_bin/analyze_snp b/bp_bin/analyze_snp
new file mode 100755 (executable)
index 0000000..90b81b6
--- /dev/null
@@ -0,0 +1,132 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2007-2009 Martin A. Hansen.
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# http://www.gnu.org/copyleft/gpl.html
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+# Analyze mismatches and indels from ALIGN descriptors in the stream.
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+use warnings;
+use strict;
+use Maasha::Biopieces;
+use Data::Dumper;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $options, $in, $out, $record, @aligns, $align, $offset, $src, $dst, $data, $s_id, $pos, $count, $new_record );
+
+
+$options = Maasha::Biopieces::parse_options(
+    [
+        { long => 'min', short => 'm', type => 'uint', mandatory => 'no', default => 1, allowed => undef, disallowed => '0' },
+    ]
+);
+
+$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
+$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+
+$data = {};
+
+while ( $record = Maasha::Biopieces::get_record( $in ) ) 
+{
+    if ( exists $record->{ 'ALIGN' } )
+    {
+        @aligns = split /,/, $record->{ 'ALIGN' };
+
+        foreach $align ( @aligns )
+        {
+            if ( $align =~ /(\d+):([ATCGN-])>([ATCGN-])/ )
+            {
+                $offset = $1;
+                $src    = $2;
+                $dst    = $3;
+
+                $data->{ $record->{ 'S_ID' } }->{ $record->{ 'S_BEG' } + $offset }->{ $src }->{ $dst }++;
+            }
+        }
+    }
+
+    Maasha::Biopieces::put_record( $record, $out );
+}
+
+foreach $s_id ( sort keys %{ $data } )
+{
+    foreach $pos ( sort { $a <=> $b } keys %{ $data->{ $s_id } } )
+    {
+        foreach $src ( sort keys %{ $data->{ $s_id }->{ $pos } } )
+        {
+            foreach $dst ( sort keys %{ $data->{ $s_id }->{ $pos }->{ $src } } )
+            {
+                $count = $data->{ $s_id }->{ $pos }->{ $src }->{ $dst };
+
+                if ( $count >= $options->{ 'min' } )
+                {
+                    $new_record->{ 'REC_TYPE' }  = "SNP";
+                    $new_record->{ 'S_ID' }      = $s_id;
+                    $new_record->{ 'S_POS' }     = $pos;
+                    $new_record->{ 'SRC' }       = $src;
+                    $new_record->{ 'DST' }       = $dst;
+                    $new_record->{ 'SNP_COUNT' } = $count;
+
+                    if ( $src eq '-' ) {
+                        $new_record->{ 'TYPE' } = "INSERTION";
+                    } elsif ( $dst eq '-' ) {
+                        $new_record->{ 'TYPE' } = "DELETION";
+                    } else {
+                        $new_record->{ 'TYPE' } = "MISMATCH";
+                    }
+
+                    Maasha::Biopieces::put_record( $new_record, $out );
+                }
+            }
+        }
+    }
+}
+
+Maasha::Biopieces::close_stream( $in );
+Maasha::Biopieces::close_stream( $out );
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+BEGIN
+{
+    Maasha::Biopieces::status_set();
+}
+
+
+END
+{
+    Maasha::Biopieces::status_log();
+}
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+__END__
index c712b8f86a17c2de2bebdc515e13245e5d9b8056..ff1818516c69cf58f7833a4bfb41b6555d7ad8aa 100755 (executable)
@@ -100,7 +100,7 @@ else
 
 $fh_in = Maasha::Filesys::file_read_open( $tmp_sam );
 
-while ( $entry = Maasha::SAM::get_entry( $fh_in ) )
+while ( $entry = Maasha::SAM::sam_entry_get( $fh_in ) )
 {
     if ( $record = Maasha::SAM::sam2biopiece( $entry ) ) {
         Maasha::Biopieces::put_record( $record, $out );