migrated blat_seq
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 25 May 2009 07:40:26 +0000 (07:40 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 25 May 2009 07:40:26 +0000 (07:40 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@406 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/blat_seq
code_perl/Maasha/BioRun.pm
code_perl/Maasha/UCSC/PSL.pm

index fdf5bd287f78613d2aea83bb9b15f855cad57e77..bc5af18b8e51eaffb7b98d352499bdac07abef8a 100755 (executable)
@@ -1,6 +1,135 @@
-#!/usr/bin/env perl
+#!/usr/bin/env perl -w
+
+# 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# BLAT sequences in the stream against a genome.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
 
-use warnings;
 use strict;
+use Maasha::Biopieces;
+use Maasha::Filesys;
+use Maasha::Fasta;
+use Maasha::Seq;
+use Maasha::UCSC::PSL;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $blat_args, $genome_file, $query_file, $fh_in, $fh_out,
+     $tmp_dir, $type, $result_file, $entry );
+
+$options = Maasha::Biopieces::parse_options(
+    [
+        { long => 'genome',       short => 'g', type => 'genome', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
+        { long => 'occ',          short => 'c', type => 'flag',   mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
+        { long => 'tile_size',    short => 't', type => 'uint',   mandatory => 'no',  default => 11,    allowed => undef, disallowed => 0 },
+        { long => 'step_size',    short => 's', type => 'uint',   mandatory => 'no',  default => 11,    allowed => undef, disallowed => 0 },
+        { long => 'min_identity', short => 'm', type => 'uint',   mandatory => 'no',  default => 90,    allowed => undef, disallowed => 0 },
+        { long => 'min_score',    short => 'M', type => 'uint',   mandatory => 'no',  default => 0,     allowed => undef, disallowed => undef },
+        { long => 'one_off',      short => 'o', type => 'uint',   mandatory => 'no',  default => 0,     allowed => undef, disallowed => undef },
+    ]   
+);
+
+$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
+$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+
+$genome_file = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/fasta/$options->{ 'genome' }.fna";
+
+$blat_args .= " -tileSize=$options->{ 'tile_size' }";
+$blat_args .= " -oneOff=$options->{ 'one_off' }";
+$blat_args .= " -minIdentity=$options->{ 'min_identity' }";
+$blat_args .= " -minScore=$options->{ 'min_score' }";
+$blat_args .= " -stepSize=$options->{ 'step_size' }";
+# $blat_args .= " -ooc=" . Maasha::Config::genome_blat_ooc( $options->{ "genome" }, 11 ) if $options->{ 'ooc' };
+
+$tmp_dir = Maasha::Biopieces::get_tmpdir();
+$query_file = "$tmp_dir/blat.seq";
+
+$fh_out = Maasha::Filesys::file_write_open( $query_file );
+
+while ( $record = Maasha::Biopieces::get_record( $in ) ) 
+{
+    if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
+    {
+        $type = Maasha::Seq::seq_guess_type( $record->{ 'SEQ' } ) if not $type;
+        Maasha::Fasta::put_entry( $entry, $fh_out, 80 );
+    }
+
+    Maasha::Biopieces::put_record( $record, $out );
+}
+
+close $fh_out;
+
+$blat_args .= " -t=dnax" if $type eq "protein";
+$blat_args .= " -q=$type";
+
+$result_file = "$tmp_dir/blat.psl";
+
+Maasha::Common::run( "blat", "$genome_file $query_file $blat_args $result_file > /dev/null 2>&1" );
+
+unlink $query_file;
+
+$fh_in = Maasha::Filesys::file_read_opem( $result_file );
+
+while ( $entry = Maasha::UCSC::PSL::psl_entry_get( $fh_in ) )
+{
+    if ( $record = Maasha::UCSC::PSL::psl2biopiece( $entry ) ) {
+        Maasha::Biopieces::put_record( $record, $out );
+    }
+}
+
+close  $fh_in;
+unlink $result_file;
+
+Maasha::Filesys::dir_remove( $tmp_dir );
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+BEGIN
+{
+    $run_time_beg = Maasha::Biopieces::run_time();
+
+    Maasha::Biopieces::log_biopiece();
+}
+
+
+END
+{
+    Maasha::Biopieces::close_stream( $in );
+    Maasha::Biopieces::close_stream( $out );
+
+    $run_time_end = Maasha::Biopieces::run_time();
+
+    Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options );
+}
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+__END__
 
-use Maasha::BioRun;
index d9973a89ee870b07723c054e92491e94716b0b98..ef4891143ec31f9e428b05c965a8fd8b7371f61d 100644 (file)
@@ -147,7 +147,6 @@ sub run_script
     elsif ( $script eq "tile_seq" )                 { script_tile_seq(                  $in, $out, $options ) }
     elsif ( $script eq "invert_align" )             { script_invert_align(              $in, $out, $options ) }
     elsif ( $script eq "patscan_seq" )              { script_patscan_seq(               $in, $out, $options ) }
-    elsif ( $script eq "blat_seq" )                 { script_blat_seq(                  $in, $out, $options ) }
     elsif ( $script eq "soap_seq" )                 { script_soap_seq(                  $in, $out, $options ) }
     elsif ( $script eq "match_seq" )                { script_match_seq(                 $in, $out, $options ) }
     elsif ( $script eq "create_vmatch_index" )      { script_create_vmatch_index(       $in, $out, $options ) }
@@ -423,18 +422,6 @@ sub get_options
             genome|g=s
         );
     }
-    elsif ( $script eq "blat_seq" )
-    {
-        @options = qw(
-            genome|g=s
-            tile_size|t=s
-            step_size|s=s
-            min_identity|m=s
-            min_score|M=s
-            one_off|o=s
-            ooc|c
-        );
-    }
     elsif ( $script eq "soap_seq" )
     {
         @options = qw(
@@ -858,7 +845,7 @@ sub get_options
     Maasha::Common::error( qq(no --index_name specified) )              if $script =~ /create_vmatch_index/ and not $options{ "index_name" };
     Maasha::Common::error( qq(no --in_file or --genome specified) )     if $script eq "soap_seq" and not $options{ "genome" } and not $options{ "in_file" };
     Maasha::Common::error( qq(both --in_file and --genome specified) )  if $script eq "soap_seq" and $options{ "genome" } and $options{ "in_file" };
-    Maasha::Common::error( qq(no --genome specified) )                  if $script =~ /get_genome_align|get_genome_phastcons|blat_seq|plot_phastcons_profiles|plot_karyogram/ and not $options{ "genome" };
+    Maasha::Common::error( qq(no --genome specified) )                  if $script =~ /get_genome_align|get_genome_phastcons|plot_phastcons_profiles|plot_karyogram/ and not $options{ "genome" };
     Maasha::Common::error( qq(no --key specified) )                     if $script =~ /plot_lendist|plot_histogram/ and not $options{ "key" };
     Maasha::Common::error( qq(no --keys speficied) )                    if $script =~ /sort_records|count_vals|sum_vals|mean_vals|median_vals|length_vals/ and not $options{ "keys" };
 
@@ -2475,70 +2462,6 @@ sub script_patscan_seq
 }
 
 
-sub script_blat_seq
-{
-    # Martin A. Hansen, August 2007.
-
-    # BLATs sequences in stream against a given genome.
-
-    my ( $in,        # handle to in stream
-         $out,       # handle to out stream
-         $options,   # options hash
-       ) = @_;
-
-    # Returns nothing.
-
-    my ( $blat_args, $genome_file, $query_file, $fh_in, $fh_out, $type, $record, $result_file, $entries, $entry );
-
-    $genome_file = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/fasta/$options->{ 'genome' }.fna";
-
-    $options->{ 'tile_size' }    ||= 11;
-    $options->{ 'one_off' }      ||= 0;
-    $options->{ 'min_identity' } ||= 90;
-    $options->{ 'min_score' }    ||= 0;
-    $options->{ 'step_size' }    ||= $options->{ 'tile_size' };
-
-    $blat_args .= " -tileSize=$options->{ 'tile_size' }";
-    $blat_args .= " -oneOff=$options->{ 'one_off' }";
-    $blat_args .= " -minIdentity=$options->{ 'min_identity' }";
-    $blat_args .= " -minScore=$options->{ 'min_score' }";
-    $blat_args .= " -stepSize=$options->{ 'step_size' }";
-#    $blat_args .= " -ooc=" . Maasha::Config::genome_blat_ooc( $options->{ "genome" }, 11 ) if $options->{ 'ooc' };
-
-    $query_file = "$BP_TMP/blat.seq";
-
-    $fh_out = Maasha::Common::write_open( $query_file );
-
-    while ( $record = Maasha::Biopieces::get_record( $in ) ) 
-    {
-        if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
-        {
-            $type = Maasha::Seq::seq_guess_type( $entry->[ SEQ ] ) if not $type;
-            Maasha::Fasta::put_entry( $entry, $fh_out, 80 );
-        }
-
-        Maasha::Biopieces::put_record( $record, $out );
-    }
-
-    close $fh_out;
-
-    $blat_args .= " -t=dnax" if $type eq "protein";
-    $blat_args .= " -q=$type";
-
-    $result_file = "$BP_TMP/blat.psl";
-
-    Maasha::Common::run( "blat", "$genome_file $query_file $blat_args $result_file > /dev/null 2>&1" );
-
-    unlink $query_file;
-
-    $entries = Maasha::UCSC::psl_get_entries( $result_file );
-
-    map { Maasha::Biopieces::put_record( $_, $out ) } @{ $entries };
-
-    unlink $result_file;
-}
-
-
 sub script_soap_seq
 {
     # Martin A. Hansen, July 2008.
index a45006ec0bfbb85967cf31d33bb38b1ac71c16df..4dfaf841f8dc7155d0b439ffc1ec3bf33c5b15dd 100644 (file)
@@ -120,7 +120,7 @@ sub psl_entry_get
 }
 
 
-sub psl2record
+sub psl2biopiece
 {
     # Martin A. Hansen, November 2008
 
@@ -179,11 +179,11 @@ sub psl_calc_score
 
     my ( $score );
 
-    $score = $psl_entry[ MATCHES ] +
-             int( $psl_entry[ REPMATCHES ] / 2 ) - 
-             $psl_entry[ MISMATCHES ] - 
-             $psl_entry[ QNUMINSERT ] - 
-             $psl_entry[ SNUMINSERT ];
+    $score = $psl_entry->[ MATCHES ] +
+             int( $psl_entry->[ REPMATCHES ] / 2 ) - 
+             $psl_entry->[ MISMATCHES ] - 
+             $psl_entry->[ QNUMINSERT ] - 
+             $psl_entry->[ SNUMINSERT ];
 
     return $score;
 }