-#!/usr/bin/env perl
+#!/usr/bin/env ruby
-# Copyright (C) 2007-2009 Martin A. Hansen.
+# Copyright (C) 2007-2011 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
# http://www.gnu.org/copyleft/gpl.html
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-# Find genes in sequences in stream.
-
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+# This program is part of the Biopieces framework (www.biopieces.org).
-use warnings;
-use strict;
-use Data::Dumper;
-use Maasha::Common;
-use Maasha::Biopieces;
-use Maasha::Filesys;
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+# Find genes in prokaryotic genomic sequences in the stream.
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-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 );
-
-$options = Maasha::Biopieces::parse_options();
-
-$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 );
-}
-
-if ( $options->{ 'verbise' } ) {
- Maasha::Common::run( "prodigal", "< $tmp_file > $tmp_file.out" );
-} else {
- Maasha::Common::run( "prodigal", "< $tmp_file > $tmp_file.out 2> /dev/null" );
-}
-
-$fh_in = Maasha::Filesys::file_read_open( "$tmp_file.out" );
-
-$/ = "//\n";
-
-while ( $chunk = <$fh_in> )
-{
- chomp $chunk;
-
- @lines = split /\n/, $chunk;
+require 'maasha/biopieces'
+require 'maasha/fasta'
+require 'maasha/prodigal'
- $line = shift @lines;
+casts = []
+casts << {:long=>'full', :short=>'f', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
+casts << {:long=>'procedure', :short=>'p', :type=>'string', :mandatory=>true, :default=>'single', :allowed=>'single,meta', :disallowed=>nil}
- if ( $line =~ /^DEFINITION\s+(.+)/ )
- {
- $def = $1;
+options = Biopieces.options_parse(ARGV, casts)
- 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 );
-
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+tmpdir = Biopieces.mktmpdir
+infile = File.join(tmpdir, "in.fna")
+outfile = File.join(tmpdir, "out.prodigal")
+Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
+ Fasta.open(infile, mode="w") do |fasta_io|
+ input.each_record do |record|
+ output.puts record
-BEGIN
-{
- Maasha::Biopieces::status_set();
-}
+ if record[:SEQ_NAME] and record[:SEQ]
+ seq = Seq.new_bp(record)
+ fasta_io.puts seq.to_fasta
+ end
+ end
+ end
+ prodigal = Prodigal.new(infile, outfile, options)
+ prodigal.run
-END
-{
- Maasha::Biopieces::status_log();
-}
+ prodigal.each do |record|
+ output.puts record
+ end
+end
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<