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 );
42 $options = Maasha::Biopieces::parse_options();
44 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
45 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
47 $tmp_dir = Maasha::Biopieces::get_tmpdir();
48 $tmp_file = "$tmp_dir/tmp.seq";
49 $fh_out = Maasha::Filesys::file_write_open( $tmp_file );
51 while ( $record = Maasha::Biopieces::get_record( $in ) )
53 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) {
54 Maasha::Fasta::put_entry( $entry, $fh_out );
57 Maasha::Biopieces::put_record( $record, $out );
60 if ( $options->{ 'verbise' } ) {
61 Maasha::Common::run( "prodigal", "< $tmp_file > $tmp_file.out" );
63 Maasha::Common::run( "prodigal", "< $tmp_file > $tmp_file.out 2> /dev/null" );
66 $fh_in = Maasha::Filesys::file_read_open( "$tmp_file.out" );
70 while ( $chunk = <$fh_in> )
74 @lines = split /\n/, $chunk;
78 if ( $line =~ /^DEFINITION\s+(.+)/ )
82 if ( $def =~ /seqhdr="([^"]+)"/ ) {
85 Maasha::Common::error( qq(BAD sequence header: $def) );
90 if ( $line =~ /^FEATURES/ )
92 foreach $line ( @lines )
94 next if $line =~ /.+\//;
96 @fields = split " ", $line;
100 if ( $fields[ 1 ] =~ /complement/ ) {
106 if ( $fields[ 1 ] =~ /(\d+)\.\.>?(\d+)/ )
113 Maasha::Common::error( qq(BAD locator: $line) );
124 Maasha::Biopieces::put_record( $record, $out );
129 Maasha::Common::error( qq(BAD feature: $line) );
134 Maasha::Common::error( qq(BAD definition: $line) );
142 Maasha::Biopieces::close_stream( $in );
143 Maasha::Biopieces::close_stream( $out );
146 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
151 Maasha::Biopieces::status_set();
157 Maasha::Biopieces::status_log();
161 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<