in progress
[jalview.git] / forester / ruby / evoruby / lib / evo / soft / raxml.rb
1 #
2 # = lib/soft/raxml - Raxml class
3 #
4 # Copyright::  Copyright (C) 2009 Christian M. Zmasek
5 # License::    GNU Lesser General Public License (LGPL)
6 #
7 # $Id: raxml.rb,v 1.1 2009/10/07 00:08:35 cmzmasek Exp $
8 #
9 # last modified: 2009/10/06
10
11 require 'lib/evo/soft/resource_locations'
12 require 'lib/evo/util/util'
13
14 module Evoruby
15     
16     class Raxml 
17         
18         VERBOSE = true
19         
20         def initialize
21             @fast_me_home = Util.get_env_variable_value( ResourceLocations::FASTME_HOME_ENV_VARIABLE )
22             Util.check_file_for_readability( @fast_me_home )
23         end
24         
25         def run( pwd_file, bootstrap_number, initial_tree ) 
26             Util.check_file_for_readability( pwd_file )
27             if bootstrap_number == nil || bootstrap_number < 0
28                 error_msg = "illegal bootstrap number: " + bootstrap_number
29                 raise ArgumentError, error_msg
30             end
31             if initial_tree == nil || (!initial_tree.eql?( "BME" ) && !initial_tree.eql?( "GME" ) && !initial_tree.eql?( "NJ" ) )
32                 error_msg = "illegal initial tree: " + initial_tree
33                 raise ArgumentError, error_msg
34             end
35             input = String.new()
36             if bootstrap_number > 1 
37                 input = '-b #{initial_tree} -i #{pwd_file} -n #{bootstrap_number} -s b'
38             else 
39                 input = '-b #{initial_tree} -i #{pwd_file} -s b'
40             end
41             if VERBOSE
42                 puts @fast_me_home + " " + input
43             end
44             IO.popen( @fast_me_home, 'r+' ) do |io|
45                 io.puts input
46                 io.close_write
47                 return io.read
48             end
49         end
50     end # class Raxml 
51     
52 end # module Evoruby