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 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
31 use Maasha::Biopieces;
37 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
40 my ( $options, $in, $out, $tmp_dir, $tmp_in, $tmp_out, $fh_out, $record, $entry, $count, $args, $line, @fields );
42 $options = Maasha::Biopieces::parse_options(
44 { long => 'in_file', short => 'i', type => 'file', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
45 { long => 'genome', short => 'g', type => 'genome', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
46 { long => 'seed_size', short => 's', type => 'uint', mandatory => 'no', default => 10, allowed => undef, disallowed => undef },
47 { long => 'mismatches', short => 'm', type => 'uint', mandatory => 'no', default => 2, allowed => undef, disallowed => undef },
48 { long => 'gap_size', short => 'G', type => 'uint', mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
49 { long => 'cpus', short => 'c', type => 'uint', mandatory => 'no', default => 1, allowed => undef, disallowed => 0 },
53 Maasha::Common::error( qq(both --in_file and --genome specified) ) if $options->{ "genome" } and $options->{ "in_file" };
54 Maasha::Common::error( qq(no --in_file or --genome specified) ) if not $options->{ "genome" } and not $options->{ "in_file" };
56 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
57 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
59 $options->{ "in_file" } = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/fasta/$options->{ 'genome' }.fna" if $options->{ 'genome' };
61 $tmp_dir = Maasha::Biopieces::get_tmpdir();
62 $tmp_in = "$tmp_dir/soap_query.seq";
63 $tmp_out = "$tmp_dir/soap.result";
65 $fh_out = Maasha::Common::write_open( $tmp_in );
69 while ( $record = Maasha::Biopieces::get_record( $in ) )
71 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
73 Maasha::Fasta::put_entry( $entry, $fh_out );
78 Maasha::Biopieces::put_record( $record, $out );
86 "-s $options->{ 'seed_size' }",
89 "-v $options->{ 'mismatches' }",
90 "-g $options->{ 'gap_size' }",
91 "-p $options->{ 'cpus' }",
92 "-d $options->{ 'in_file' }",
96 $args .= " > /dev/null 2>&1" if not $options->{ 'verbose' };
98 Maasha::Common::run( "soap", $args, 1 );
102 $fh_out = Maasha::Filesys::file_read_open( $tmp_out );
106 while ( $line = <$fh_out> )
110 @fields = split /\t/, $line;
112 $record->{ "REC_TYPE" } = "SOAP";
113 $record->{ "Q_ID" } = $fields[ 0 ];
114 $record->{ "SCORE" } = $fields[ 3 ];
115 $record->{ "STRAND" } = $fields[ 6 ];
116 $record->{ "S_ID" } = $fields[ 7 ];
117 $record->{ "S_BEG" } = $fields[ 8 ] - 1; # soap is 1-based
118 $record->{ "S_END" } = $fields[ 8 ] + $fields[ 5 ] - 2;
120 Maasha::Biopieces::put_record( $record, $out );
128 Maasha::Biopieces::close_stream( $in );
129 Maasha::Biopieces::close_stream( $out );
132 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
137 Maasha::Biopieces::status_set();
143 Maasha::Biopieces::status_log();
147 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<