#!/usr/bin/env perl # Copyright (C) 2007-2009 Martin A. Hansen. # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # http://www.gnu.org/copyleft/gpl.html # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< # Find genes in sequences in stream. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< use warnings; use strict; use Data::Dumper; use Maasha::Common; use Maasha::Biopieces; use Maasha::Filesys; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 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, @commands, $command ); $options = Maasha::Biopieces::parse_options( [ { long => 'full', short => 'f', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, ] ); $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); $tmp_dir = Maasha::Biopieces::get_tmpdir(); $tmp_file = "$tmp_dir/tmp.seq"; $fh_out = Maasha::Filesys::file_write_open( $tmp_file ); while ( $record = Maasha::Biopieces::get_record( $in ) ) { if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) { Maasha::Fasta::put_entry( $entry, $fh_out ); } Maasha::Biopieces::put_record( $record, $out ); } close $fh_out; push @commands, "-c" if $options->{ 'full' }; push @commands, "< $tmp_file > $tmp_file.out"; push @commands, "2> /dev/null" unless $options->{ 'verbose' }; $command = join " ", @commands; Maasha::Common::run( "prodigal", $command ); $fh_in = Maasha::Filesys::file_read_open( "$tmp_file.out" ); $/ = "//\n"; while ( $chunk = <$fh_in> ) { chomp $chunk; @lines = split /\n/, $chunk; $line = shift @lines; if ( $line =~ /^DEFINITION\s+(.+)/ ) { $def = $1; if ( $def =~ /seqhdr="([^"]+)"/ ) { $s_id = $1; } else { Maasha::Common::error( qq(BAD sequence header: $def) ); } $line = shift @lines; if ( $line =~ /^FEATURES/ ) { foreach $line ( @lines ) { next if $line =~ /.+\//; @fields = split " ", $line; $type = $fields[ 0 ]; if ( $fields[ 1 ] =~ /complement/ ) { $strand = "-"; } else { $strand = "+"; } if ( $fields[ 1 ] =~ /(\d+)\.\.>?(\d+)/ ) { $s_beg = $1; $s_end = $2; } else { Maasha::Common::error( qq(BAD locator: $line) ); } $record = { S_ID => $s_id, S_BEG => $s_beg - 1, S_END => $s_end - 1, Q_ID => $type, STRAND => $strand, }; Maasha::Biopieces::put_record( $record, $out ); } } else { Maasha::Common::error( qq(BAD feature: $line) ); } } else { Maasha::Common::error( qq(BAD definition: $line) ); } } close $fh_in; $/ = "\n"; Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< BEGIN { Maasha::Biopieces::status_set(); } END { Maasha::Biopieces::status_log(); } # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< __END__