Fixed issue with reading from TreeBase
[jalview.git] / forester / java / src / org / forester / archaeopteryx / tools / InferenceManager.java
1
2 package org.forester.archaeopteryx.tools;
3
4 import java.io.File;
5
6 import org.forester.archaeopteryx.Configuration;
7
8 public final class InferenceManager {
9
10     private final static String DEFAULT_PATHS[] = {"C:\\Program Files\\mafft-win\\", "C:\\Program Files\\", "C:\\Program Files (x86)\\", "/bin/",
11         "/usr/local/bin/", "/usr/bin/"     };
12     private final File          _path_to_local_mafft;
13     private final File          _path_to_local_fastme;
14     private final File          _path_to_local_raxml;
15
16     public static InferenceManager createInstance( final Configuration c ) {
17         return new InferenceManager( c.getPathToLocalMafft(), c.getPathToLocalFastme(), c.getPathToLocalRaxml() );
18     }
19
20     public boolean canDoMsa() {
21         return ( getPathToLocalMafft() != null );
22     }
23
24     public File getPathToLocalMafft() {
25         return _path_to_local_mafft;
26     }
27
28     public File getPathToLocalFastme() {
29         return _path_to_local_fastme;
30     }
31
32     public File getPathToLocalRaxml() {
33         return _path_to_local_raxml;
34     }
35
36     private final static File createLocalPath( final File path, final String name ) {
37         if ( ( path != null ) && path.canExecute() && !path.isDirectory() ) {
38             return path;
39         }
40         final File p1 = new File( name );
41         if ( p1.canExecute() && !p1.isDirectory() ) {
42             return p1;
43         }
44         for( final String path_str : DEFAULT_PATHS ) {
45             try {
46                 final File p2 = new File( path_str + name );
47                 if ( p2.canExecute() && !p2.isDirectory() ) {
48                     return p2;
49                 }
50                 final File p3 = new File( path_str + name + ".exe" );
51                 if ( p3.canExecute() && !p3.isDirectory() ) {
52                     return p3;
53                 }
54                 final File p4 = new File( path_str + name + ".bat" );
55                 if ( p4.canExecute() && !p4.isDirectory() ) {
56                     return p4;
57                 }
58             }
59             catch ( final Exception e ) {
60             }
61         }
62         return null;
63     }
64
65     private InferenceManager( final File path_to_local_mafft,
66                               final File path_to_local_fastme,
67                               final File path_to_local_raxml ) {
68         _path_to_local_mafft = createLocalPath( path_to_local_mafft, "mafft" );
69         _path_to_local_fastme = createLocalPath( path_to_local_fastme, "fastme" );
70         _path_to_local_raxml = createLocalPath( path_to_local_raxml, "raxml" );
71     }
72 }