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