3 # Copyright (C) 2007-2010 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
24 # BLAT sequences in the stream against a genome.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
31 use Maasha::Biopieces;
35 use Maasha::UCSC::PSL;
38 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
41 my ( $options, $in, $out, $record, $blat_args, $subject_file, $query_file, $fh_in, $fh_out,
42 $tmp_dir, $type, $result_file, $entry );
44 $options = Maasha::Biopieces::parse_options(
46 { long => 'database', short => 'd', type => 'file', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
47 { long => 'genome', short => 'g', type => 'genome', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
48 { long => 'fast_map', short => 'f', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
49 { long => 'occ', short => 'c', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
50 { long => 'intron_max', short => 'i', type => 'uint', mandatory => 'no', default => 750000, allowed => undef, disallowed => undef },
51 { long => 'tile_size', short => 't', type => 'uint', mandatory => 'no', default => 11, allowed => undef, disallowed => 0 },
52 { long => 'step_size', short => 's', type => 'uint', mandatory => 'no', default => 11, allowed => undef, disallowed => 0 },
53 { long => 'min_identity', short => 'm', type => 'uint', mandatory => 'no', default => 90, allowed => undef, disallowed => 0 },
54 { long => 'min_score', short => 'M', type => 'uint', mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
55 { long => 'one_off', short => 'o', type => 'uint', mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
56 { long => 'allow_N_blocks', short => 'N', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
60 Maasha::Common::error( qq(both --database and --genome specified) ) if $options->{ "genome" } and $options->{ "database" };
61 Maasha::Common::error( qq(no --database or --genome specified) ) if not $options->{ "genome" } and not $options->{ "database" };
63 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
64 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
66 if ( $options->{ 'database' } ) {
67 $subject_file = $options->{ 'database' };
69 $subject_file = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/fasta/$options->{ 'genome' }.fna";
72 $blat_args .= " -tileSize=$options->{ 'tile_size' }";
73 $blat_args .= " -oneOff=$options->{ 'one_off' }";
74 $blat_args .= " -minIdentity=$options->{ 'min_identity' }";
75 $blat_args .= " -minScore=$options->{ 'min_score' }";
76 $blat_args .= " -stepSize=$options->{ 'step_size' }";
77 $blat_args .= " -maxIntron=$options->{ 'intron_max' }";
78 $blat_args .= " -fastMap" if $options->{ 'fast_map' };
79 $blat_args .= " -extendThroughN" if $options->{ 'allow_N_blocks' };
80 # $blat_args .= " -ooc=" . Maasha::Config::genome_blat_ooc( $options->{ "genome" }, 11 ) if $options->{ 'ooc' };
82 $tmp_dir = Maasha::Biopieces::get_tmpdir();
83 $query_file = "$tmp_dir/blat.seq";
85 $fh_out = Maasha::Filesys::file_write_open( $query_file );
87 while ( $record = Maasha::Biopieces::get_record( $in ) )
89 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
91 $type = Maasha::Seq::seq_guess_type( $record->{ 'SEQ' } ) if not $type;
92 Maasha::Fasta::put_entry( $entry, $fh_out, 80 );
95 Maasha::Biopieces::put_record( $record, $out );
100 $blat_args .= " -t=dnax" if $type eq "PROTEIN";
101 $blat_args .= " -q=$type";
103 $result_file = "$tmp_dir/blat.psl";
105 if ( $options->{ 'verbose' } ) {
106 Maasha::Common::run( "blat", "$subject_file $query_file $blat_args $result_file" );
108 Maasha::Common::run( "blat", "$subject_file $query_file $blat_args $result_file > /dev/null 2>&1" );
113 $fh_in = Maasha::Filesys::file_read_open( $result_file );
115 while ( $entry = Maasha::UCSC::PSL::psl_entry_get( $fh_in ) )
117 if ( $record = Maasha::UCSC::PSL::psl2biopiece( $entry ) ) {
118 Maasha::Biopieces::put_record( $record, $out );
125 Maasha::Biopieces::close_stream( $in );
126 Maasha::Biopieces::close_stream( $out );
129 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
134 Maasha::Biopieces::status_set();
140 Maasha::Biopieces::status_log();
144 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<