3 # Copyright (C) 2007-2009 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 # Use soap to match short nucleotide sequences in the stream against a specified genome.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
30 use Maasha::Biopieces;
36 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
39 my ( $options, $in, $out, $tmp_dir, $tmp_in, $tmp_out, $fh_out, $record, $entry, $count, $args, $line, @fields );
41 $options = Maasha::Biopieces::parse_options(
43 { long => 'in_file', short => 'i', type => 'file', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
44 { long => 'genome', short => 'g', type => 'genome', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
45 { long => 'seed_size', short => 's', type => 'uint', mandatory => 'no', default => 10, allowed => undef, disallowed => undef },
46 { long => 'mismatches', short => 'm', type => 'uint', mandatory => 'no', default => 2, allowed => undef, disallowed => undef },
47 { long => 'gap_size', short => 'G', type => 'uint', mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
48 { long => 'cpus', short => 'c', type => 'uint', mandatory => 'no', default => 1, allowed => undef, disallowed => 0 },
52 Maasha::Common::error( qq(both --in_file and --genome specified) ) if $options->{ "genome" } and $options->{ "in_file" };
53 Maasha::Common::error( qq(no --in_file or --genome specified) ) if not $options->{ "genome" } and not $options->{ "in_file" };
55 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
56 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
58 $options->{ "in_file" } = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/fasta/$options->{ 'genome' }.fna" if $options->{ 'genome' };
60 $tmp_dir = Maasha::Biopieces::get_tmpdir();
61 $tmp_in = "$tmp_dir/soap_query.seq";
62 $tmp_out = "$tmp_dir/soap.result";
64 $fh_out = Maasha::Common::write_open( $tmp_in );
68 while ( $record = Maasha::Biopieces::get_record( $in ) )
70 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
72 Maasha::Fasta::put_entry( $entry, $fh_out );
77 Maasha::Biopieces::put_record( $record, $out );
85 "-s $options->{ 'seed_size' }",
88 "-v $options->{ 'mismatches' }",
89 "-g $options->{ 'gap_size' }",
90 "-p $options->{ 'cpus' }",
91 "-d $options->{ 'in_file' }",
95 $args .= " > /dev/null 2>&1" if not $options->{ 'verbose' };
97 Maasha::Common::run( "soap", $args, 1 );
101 $fh_out = Maasha::Filesys::file_read_open( $tmp_out );
105 while ( $line = <$fh_out> )
109 @fields = split /\t/, $line;
111 $record->{ "REC_TYPE" } = "SOAP";
112 $record->{ "Q_ID" } = $fields[ 0 ];
113 $record->{ "SCORE" } = $fields[ 3 ];
114 $record->{ "STRAND" } = $fields[ 6 ];
115 $record->{ "S_ID" } = $fields[ 7 ];
116 $record->{ "S_BEG" } = $fields[ 8 ] - 1; # soap is 1-based
117 $record->{ "S_END" } = $fields[ 8 ] + $fields[ 5 ] - 2;
119 Maasha::Biopieces::put_record( $record, $out );
127 Maasha::Biopieces::close_stream( $in );
128 Maasha::Biopieces::close_stream( $out );
131 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
136 Maasha::Biopieces::status_set();
142 Maasha::Biopieces::status_log();
146 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<