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 # Find genes in sequences in stream.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
33 use Maasha::Biopieces;
37 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
40 my ( $options, $in, $out, $record, $tmp_dir, $tmp_file, $fh_out, $fh_in, $entry, $chunk, @lines, $line, $s_id, $type, $s_beg, $s_end, $strand, @fields, $def,
41 @commands, $command );
43 $options = Maasha::Biopieces::parse_options(
45 { long => 'full', short => 'f', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
49 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
50 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
52 $tmp_dir = Maasha::Biopieces::get_tmpdir();
53 $tmp_file = "$tmp_dir/tmp.seq";
54 $fh_out = Maasha::Filesys::file_write_open( $tmp_file );
56 while ( $record = Maasha::Biopieces::get_record( $in ) )
58 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) {
59 Maasha::Fasta::put_entry( $entry, $fh_out );
62 Maasha::Biopieces::put_record( $record, $out );
67 push @commands, "-c" if $options->{ 'full' };
68 push @commands, "< $tmp_file > $tmp_file.out";
69 push @commands, "2> /dev/null" unless $options->{ 'verbose' };
71 $command = join " ", @commands;
73 Maasha::Common::run( "prodigal", $command );
75 $fh_in = Maasha::Filesys::file_read_open( "$tmp_file.out" );
79 while ( $chunk = <$fh_in> )
83 @lines = split /\n/, $chunk;
87 if ( $line =~ /^DEFINITION\s+(.+)/ )
91 if ( $def =~ /seqhdr="([^"]+)"/ ) {
94 Maasha::Common::error( qq(BAD sequence header: $def) );
99 if ( $line =~ /^FEATURES/ )
101 foreach $line ( @lines )
103 next if $line =~ /.+\//;
105 @fields = split " ", $line;
107 $type = $fields[ 0 ];
109 if ( $fields[ 1 ] =~ /complement/ ) {
115 if ( $fields[ 1 ] =~ /(\d+)\.\.>?(\d+)/ )
122 Maasha::Common::error( qq(BAD locator: $line) );
133 Maasha::Biopieces::put_record( $record, $out );
138 Maasha::Common::error( qq(BAD feature: $line) );
143 Maasha::Common::error( qq(BAD definition: $line) );
151 Maasha::Biopieces::close_stream( $in );
152 Maasha::Biopieces::close_stream( $out );
155 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
160 Maasha::Biopieces::status_set();
166 Maasha::Biopieces::status_log();
170 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<