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 require 'maasha/genbank'
27 # Class for running the Prodigal gene finder.
28 # http://prodigal.ornl.gov/
32 # Method to initialize a Prodigal object
33 # given a temporary infile, outfile and options hash.
34 def initialize(infile, outfile, options)
40 # Method to run Prodigal.
43 commands << "prodigal"
44 commands << "-c" if @options[:full]
45 commands << "-p #{@options[:procedure]}"
46 commands << "-i #{@infile}"
47 commands << "-o #{@outfile}"
49 execute(commands, @options[:verbose])
52 # Method for iterating over the Prodigal results,
53 # which are in GenBank format.
55 Genbank.open(@outfile, mode='r') do |gb|
62 # Method that returns the sum of the predicted gene lengths.
67 coverage += gb[:S_END] - gb[:S_BEG]
75 # Method to execute commands on the command line.
76 # TODO this wants to be in a module on its own.
77 def execute(commands, verbose = false)
78 commands.unshift "nice -n 19"
79 commands.push "> /dev/null 2>&1" unless verbose
81 command = commands.join(" ")
85 raise "Command failed: #{command}" unless $?.success?
87 $stderr.puts "Command failed: #{command}"