in progress
[jalview.git] / forester / ruby / evoruby / lib / evo / soft / fastme.rb
1 #
2 # = lib/soft/fastme - FastMe class
3 #
4 # Copyright::  Copyright (C) 2009 Christian M. Zmasek
5 # License::    GNU Lesser General Public License (LGPL)
6 #
7 # $Id: fastme.rb,v 1.3 2009/10/08 22:44:54 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 FastMe
17
18         VERBOSE = false
19        
20         OUTTREE      = 'output.tre'
21         OUTPUT_D     = 'output.d'
22         VERSION      = '2.0'
23         
24         def initialize
25             @fast_me_home = Util.get_env_variable_value( ResourceLocations::FASTME_HOME_ENV_VARIABLE )
26             Util.check_file_for_readability( @fast_me_home )
27         end
28
29         def run( pwd_file, bootstrap_number, initial_tree )
30             Util.check_file_for_readability( pwd_file )
31             if bootstrap_number == nil || bootstrap_number < 0
32                 error_msg = "illegal bootstrap number: " + bootstrap_number
33                 raise ArgumentError, error_msg
34             end
35             init_tree_option = determine_initial_tree( initial_tree )
36             input = String.new()
37             if bootstrap_number > 1
38                 input = "-b #{init_tree_option} -i #{pwd_file} -n #{bootstrap_number} -s b"
39             else
40                 input = "-b #{init_tree_option} -i #{pwd_file} -s b"
41             end
42             if VERBOSE
43                 puts @fast_me_home + " " + input
44             end
45             IO.popen( @fast_me_home + " " + input, 'r+' ) do |io|
46                 io.close_write
47                 return io.read
48             end
49         end
50
51         private
52
53         def determine_initial_tree( initial_tree )
54             opt = nil
55             if ( initial_tree == :BME )
56                 opt = "BME"
57             elsif ( initial_tree == :GME )
58                 opt = "GME"
59             elsif ( initial_tree == :NJ )
60                 opt = "NJ"
61             else
62                 error_msg = "unknown initial tree"
63                 raise ArgumentError, error_msg
64             end
65             return opt
66         end
67
68     end # class FastMe
69
70 end # module Evoruby