1 # Copyright (C) 2011 Martin A. Hansen.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # http://www.gnu.org/copyleft/gpl.html
19 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
21 # This software is part of the Biopieces framework (www.biopieces.org).
23 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 # Class for running the Prodigal gene finder.
26 # http://prodigal.ornl.gov/
30 # Method to initialize a Prodigal object
31 # given a temporary infile, outfile and options hash.
32 def initialize(infile, outfile, options)
33 @infile = infile # FASTA
34 @outfile = outfile # GFF
35 @options = options # Options hash
38 # Method to run Prodigal.
41 commands << "prodigal"
42 commands << "-c" if @options[:full]
43 commands << "-p #{@options[:procedure]}"
45 commands << "-i #{@infile}"
46 commands << "-a #{@outfile}"
48 commands << "-q" unless @options[:verbose]
50 execute(commands, @options[:verbose])
53 # Method for iterating over the Prodigal results,
54 # which are in GFF format.
56 Fasta.open(@outfile, 'r') do |ios|
60 fields = entry.seq_name.split(" # ")
62 record[:REC_TYPE] = "GENE"
63 record[:S_ID] = fields[0]
64 record[:S_BEG] = fields[1].to_i - 1
65 record[:S_END] = fields[2].to_i - 1
66 record[:S_LEN] = record[:S_END] - record[:S_BEG] + 1
67 record[:STRAND] = fields[3] == '1' ? '+' : '-'
68 record[:SEQ] = entry.seq
69 record[:SEQ_LEN] = entry.length
76 # Method that returns the sum of the predicted gene lengths.
81 coverage += gb[:S_END] - gb[:S_BEG]
89 # Method to execute commands on the command line.
90 # TODO this wants to be in a module on its own.
91 def execute(commands, verbose = false)
92 commands.unshift "nice -n 19"
93 commands << " > /dev/null"
95 command = commands.join(" ")
98 raise "Command failed: #{command}" unless $?.success?