]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/blat_seq
changed shebang
[biopieces.git] / bp_bin / blat_seq
1 #!/usr/bin/env perl
2
3 # Copyright (C) 2007-2009 Martin A. Hansen.
4
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.
9
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.
14
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.
18
19 # http://www.gnu.org/copyleft/gpl.html
20
21
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
23
24 # BLAT sequences in the stream against a genome.
25
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
27
28
29 use strict;
30 use Maasha::Biopieces;
31 use Maasha::Filesys;
32 use Maasha::Fasta;
33 use Maasha::Seq;
34 use Maasha::UCSC::PSL;
35
36
37 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
38
39
40 my ( $options, $in, $out, $record, $blat_args, $genome_file, $query_file, $fh_in, $fh_out,
41      $tmp_dir, $type, $result_file, $entry );
42
43 $options = Maasha::Biopieces::parse_options(
44     [
45         { long => 'genome',       short => 'g', type => 'genome', mandatory => 'yes', default => undef,  allowed => undef, disallowed => undef },
46         { long => 'fast_map',     short => 'f', type => 'flag',   mandatory => 'no',  default => undef,  allowed => undef, disallowed => undef },
47         { long => 'occ',          short => 'c', type => 'flag',   mandatory => 'no',  default => undef,  allowed => undef, disallowed => undef },
48         { long => 'intron_max',   short => 'i', type => 'uint',   mandatory => 'no',  default => 750000, allowed => undef, disallowed => undef },
49         { long => 'tile_size',    short => 't', type => 'uint',   mandatory => 'no',  default => 11,     allowed => undef, disallowed => 0 },
50         { long => 'step_size',    short => 's', type => 'uint',   mandatory => 'no',  default => 11,     allowed => undef, disallowed => 0 },
51         { long => 'min_identity', short => 'm', type => 'uint',   mandatory => 'no',  default => 90,     allowed => undef, disallowed => 0 },
52         { long => 'min_score',    short => 'M', type => 'uint',   mandatory => 'no',  default => 0,      allowed => undef, disallowed => undef },
53         { long => 'one_off',      short => 'o', type => 'uint',   mandatory => 'no',  default => 0,      allowed => undef, disallowed => undef },
54     ]   
55 );
56
57 $in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
58 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
59
60 $genome_file = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/fasta/$options->{ 'genome' }.fna";
61
62 $blat_args .= " -tileSize=$options->{ 'tile_size' }";
63 $blat_args .= " -oneOff=$options->{ 'one_off' }";
64 $blat_args .= " -minIdentity=$options->{ 'min_identity' }";
65 $blat_args .= " -minScore=$options->{ 'min_score' }";
66 $blat_args .= " -stepSize=$options->{ 'step_size' }";
67 $blat_args .= " -maxIntron=$options->{ 'intron_max' }";
68 $blat_args .= " -fastMap" if $options->{ 'fast_map' };
69 # $blat_args .= " -ooc=" . Maasha::Config::genome_blat_ooc( $options->{ "genome" }, 11 ) if $options->{ 'ooc' };
70
71 $tmp_dir = Maasha::Biopieces::get_tmpdir();
72 $query_file = "$tmp_dir/blat.seq";
73
74 $fh_out = Maasha::Filesys::file_write_open( $query_file );
75
76 while ( $record = Maasha::Biopieces::get_record( $in ) ) 
77 {
78     if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
79     {
80         $type = Maasha::Seq::seq_guess_type( $record->{ 'SEQ' } ) if not $type;
81         Maasha::Fasta::put_entry( $entry, $fh_out, 80 );
82     }
83
84     Maasha::Biopieces::put_record( $record, $out );
85 }
86
87 close $fh_out;
88
89 $blat_args .= " -t=dnax" if $type eq "protein";
90 $blat_args .= " -q=$type";
91
92 $result_file = "$tmp_dir/blat.psl";
93
94 if ( $options->{ 'verbose' } ) {
95     Maasha::Common::run( "blat", "$genome_file $query_file $blat_args $result_file" );
96 } else {
97     Maasha::Common::run( "blat", "$genome_file $query_file $blat_args $result_file > /dev/null 2>&1" );
98 }
99
100 unlink $query_file;
101
102 $fh_in = Maasha::Filesys::file_read_open( $result_file );
103
104 while ( $entry = Maasha::UCSC::PSL::psl_entry_get( $fh_in ) )
105 {
106     if ( $record = Maasha::UCSC::PSL::psl2biopiece( $entry ) ) {
107         Maasha::Biopieces::put_record( $record, $out );
108     }
109 }
110
111 close  $fh_in;
112 unlink $result_file;
113
114 Maasha::Biopieces::close_stream( $in );
115 Maasha::Biopieces::close_stream( $out );
116
117
118 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
119
120
121 BEGIN
122 {
123     Maasha::Biopieces::status_set();
124 }
125
126
127 END
128 {
129     Maasha::Biopieces::status_log();
130 }
131
132
133 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
134
135
136 __END__