30db1768a243ae93dfe152bcb505a354b077b670
[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\\", "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(),
18                                      c.getPathToLocalFastme(),
19                                      c.getPathToLocalRaxml(),
20                                      c.getPathToLocalClustalOmega() );
21     }
22
23     public boolean canDoMsa() {
24         return ( getPathToLocalMafft() != null );
25     }
26
27     public File getPathToLocalMafft() {
28         return _path_to_local_mafft;
29     }
30
31     public File getPathToLocalFastme() {
32         return _path_to_local_fastme;
33     }
34
35     public File getPathToLocalRaxml() {
36         return _path_to_local_raxml;
37     }
38
39     private final static File createLocalPath( final File path, final String name ) {
40         if ( ( path != null ) && path.canExecute() && !path.isDirectory() ) {
41             return path;
42         }
43         final File p1 = new File( name );
44         if ( p1.canExecute() && !p1.isDirectory() ) {
45             return p1;
46         }
47         for( final String path_str : DEFAULT_PATHS ) {
48             try {
49                 final File p2 = new File( path_str + name );
50                 if ( p2.canExecute() && !p2.isDirectory() ) {
51                     return p2;
52                 }
53                 final File p3 = new File( path_str + name + ".exe" );
54                 if ( p3.canExecute() && !p3.isDirectory() ) {
55                     return p3;
56                 }
57                 final File p4 = new File( path_str + name + ".bat" );
58                 if ( p4.canExecute() && !p4.isDirectory() ) {
59                     return p4;
60                 }
61             }
62             catch ( final Exception e ) {
63             }
64         }
65         return null;
66     }
67
68     private InferenceManager( final File path_to_local_mafft,
69                               final File path_to_local_fastme,
70                               final File path_to_local_raxml,
71                               final File path_to_local_clustalo ) {
72         _path_to_local_mafft = createLocalPath( path_to_local_mafft, "mafft" );
73         _path_to_local_fastme = createLocalPath( path_to_local_fastme, "fastme" );
74         _path_to_local_raxml = createLocalPath( path_to_local_raxml, "raxml" );
75     }
76 }