]> git.donarmstrong.com Git - biopieces.git/commitdiff
added bwa_seq
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 28 Sep 2009 16:29:54 +0000 (16:29 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 28 Sep 2009 16:29:54 +0000 (16:29 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@685 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/bowtie_seq
bp_bin/bwa_seq [new file with mode: 0755]
code_perl/Maasha/Matrix.pm
code_perl/Maasha/Plot.pm

index 2b9254d882c8ac728f6c59b2ec2c2dc9c9bc49c5..dc8b09e11fa71f11b7935ccc91f07ccc47d60453 100755 (executable)
@@ -21,7 +21,7 @@
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
-# Use bowtie to map sequences in the stream against a specified genome.
+# Use bowtie to map sequences in the stream against a specified genome or index.
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
@@ -51,7 +51,7 @@ $options = Maasha::Biopieces::parse_options(
     ]   
 );
 
-Maasha::Common::error( qq(both --index_hame and --genome specified) ) if     $options->{ "genome" } and     $options->{ "index_name" };
+Maasha::Common::error( qq(both --index_name and --genome specified) ) if     $options->{ "genome" } and     $options->{ "index_name" };
 Maasha::Common::error( qq(no --index_name or --genome specified) )    if not $options->{ "genome" } and not $options->{ "index_name" };
 
 $in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
diff --git a/bp_bin/bwa_seq b/bp_bin/bwa_seq
new file mode 100755 (executable)
index 0000000..c712b8f
--- /dev/null
@@ -0,0 +1,138 @@
+#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Use BWA to map sequences in the stream against a specified genome or index.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+use warnings;
+use strict;
+use Data::Dumper;
+use Maasha::Biopieces;
+use Maasha::Common;
+use Maasha::Fastq;
+use Maasha::SAM;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $options, $in, $out, $index, $tmp_dir, $tmp_fq, $tmp_sai, $tmp_sam, $fh_in, $fh_out, $record, $entry, $line, @fields, $type, @args, $arg );
+
+$options = Maasha::Biopieces::parse_options(
+    [
+        { long => 'genome',      short => 'g', type => 'genome', mandatory => 'no', default => undef, allowed => undef,     disallowed => undef },
+        { long => 'index_name',  short => 'i', type => 'string', mandatory => 'no', default => undef, allowed => undef,     disallowed => undef },
+        { long => 'mismatches',  short => 'm', type => 'uint',   mandatory => 'no', default => 0,     allowed => "0,1,2,3", disallowed => undef },
+        { long => 'max_hits',    short => 'h', type => 'uint',   mandatory => 'no', default => undef, allowed => undef,     disallowed => 0     },
+        { long => 'cpus',        short => 'c', type => 'uint',   mandatory => 'no', default => 1,     allowed => undef,     disallowed => 0     },
+    ]   
+);
+
+Maasha::Common::error( qq(both --index_name and --genome specified) ) if     $options->{ "genome" } and     $options->{ "index_name" };
+Maasha::Common::error( qq(no --index_name or --genome specified) )    if not $options->{ "genome" } and not $options->{ "index_name" };
+
+$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
+$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+
+if ( defined $options->{ 'genome' } ) {
+    $index = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/bowtie/$options->{ 'genome' }";
+} elsif (defined $options->{ 'index_name' } ) {
+    $index = $options->{ 'index_name' };
+}
+
+$tmp_dir = Maasha::Biopieces::get_tmpdir();
+$tmp_fq  = "$tmp_dir/bwa.fq";
+$tmp_sai = "$tmp_dir/bwa.fq.sai";
+$tmp_sam = "$tmp_dir/bwa.fq.sam";
+
+$fh_out = Maasha::Filesys::file_write_open( $tmp_fq );
+
+while ( $record = Maasha::Biopieces::get_record( $in ) ) 
+{
+    if ( $entry = Maasha::Fastq::biopiece2fastq( $record ) ) {
+        Maasha::Fastq::put_entry( $entry, $fh_out );
+    }
+
+    Maasha::Biopieces::put_record( $record, $out );
+}
+
+close $fh_out;
+
+push @args, "-t $options->{ 'cpus' }";
+push @args, "-R $options->{ 'max_hits' }" if $options->{ 'max_hits' };
+
+$arg = join " ", @args;
+
+if ( $options->{ 'verbose' } )
+{
+    print STDERR qq(Running: bwa aln $arg $index $tmp_fq > $tmp_sai\n);
+    Maasha::Common::run( "bwa", "aln $arg $index $tmp_fq > $tmp_sai" );
+    print STDERR qq(Running: bwa samse $index $tmp_sai $tmp_fq > $tmp_sam\n);
+    Maasha::Common::run( "bwa", "samse $index $tmp_sai $tmp_fq > $tmp_sam" )
+}
+else
+{
+    Maasha::Common::run( "bwa", "aln $arg $index $tmp_fq       > $tmp_sai 2> /dev/null" );
+    Maasha::Common::run( "bwa", "samse $index $tmp_sai $tmp_fq > $tmp_sam 2> /dev/null" );
+}
+
+$fh_in = Maasha::Filesys::file_read_open( $tmp_sam );
+
+while ( $entry = Maasha::SAM::get_entry( $fh_in ) )
+{
+    if ( $record = Maasha::SAM::sam2biopiece( $entry ) ) {
+        Maasha::Biopieces::put_record( $record, $out );
+    }
+}
+
+close $fh_in;
+
+unlink $tmp_fq;
+unlink $tmp_sai;
+unlink $tmp_sam;
+
+Maasha::Biopieces::close_stream( $in );
+Maasha::Biopieces::close_stream( $out );
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+BEGIN
+{
+    Maasha::Biopieces::status_set();
+}
+
+
+END
+{
+    Maasha::Biopieces::status_log();
+}
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+__END__
index ed90a25ab943d7171e00aef0bbd1c3337be1ac17..5d340f3a668c9553b0ec652da4429c98afa5202e 100644 (file)
@@ -181,12 +181,60 @@ sub matrix_flip
         }
     }
 
-    $matrix = $AoA;
+    @{ $matrix } = @{ $AoA };
 
     return wantarray ? @{ $matrix } : $matrix;
 }
 
 
+sub matrix_deflate_rows
+{
+    # Martin A. Hansen, September 2009.
+
+    # Reduces the number of elements in all rows,
+    # by collectiong elements in buckets that are
+    # averaged.
+
+    my ( $matrix,   # AoA data structure
+         $new_size
+       ) = @_;
+
+    # Returns nothing.
+
+    my ( $row );
+
+    foreach $row ( @{ $matrix } ) {
+        list_deflate( $row, $new_size );
+    }
+}
+
+
+sub matrix_deflate_cols
+{
+    # Martin A. Hansen, September 2009.
+
+    # Reduces the number of elements in all columns,
+    # by collectiong elements in buckets that are
+    # averaged.
+
+    my ( $matrix,   # AoA data structure
+         $new_size
+       ) = @_;
+
+    # Returns nothing.
+
+    my ( $col );
+
+    matrix_flip( $matrix );
+
+    foreach $col ( @{ $matrix } ) {
+        list_deflate( $col, $new_size );
+    }
+
+    matrix_flip( $matrix );
+}
+
+
 sub matrix_rotate_right
 {
     # Martin A. Hansen, April 2007
@@ -443,7 +491,7 @@ sub col_get
 
 sub cols_get
 {
-    # Martin A. Hansen, April 2007
+    # Martin A. Hansen, April 2007.
 
     # returns a range of requested columns from a given matrix
 
@@ -913,8 +961,8 @@ sub list_deflate
     # Defaltes a list of values to a specified size 
     # and at the same time average the values.
 
-    my ( $list,
-         $new_size,
+    my ( $list,       # list to deflate
+         $new_size,   # new number of elements in list
        ) = @_;
 
     # Returns nothing.
@@ -928,8 +976,6 @@ sub list_deflate
     $bucket_size  = int( $old_size / $new_size );
     $bucket_rest  = $old_size - ( $new_size * $bucket_size );
 
-    print STDERR "old_size: $old_size    new_size: $new_size   bucket_size: $bucket_size   bucket_rest: $bucket_rest\n";
-
     $i = 0;
 
     while ( $i < $new_size )
index a662fbcd99683e6cb0ba2edff8e7ed5f28adeb04..682c46fb383b932505e1d3652b5ebe50de841cd7 100644 (file)
@@ -97,11 +97,8 @@ sub lineplot_simple
 
     for ( $i = 1; $i < scalar @{ $data->[ 0 ] } + 1; $i++ )
     {
-        if ( ( $i % 5 ) == 0 )
-        {
-            $title = $options->{ 'keys' }->[ $i - 1 ] || $options->{ 'list' };
-            push @plot_cmd, qq("$tmp_file" using $i with lines title "$title"); 
-        }
+        $title = $options->{ 'keys' }->[ $i - 1 ] || $options->{ 'list' } || "";
+        push @plot_cmd, qq("$tmp_file" using $i with lines title "$title"); 
     }
 
     print $fh_in "plot " . join( ", ", @plot_cmd ) . "\n";