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