in progress
[jalview.git] / forester / java / src / org / forester / msa / MafftOLD.java
1
2 package org.forester.msa;
3
4 import java.io.BufferedReader;
5 import java.io.File;
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.io.InputStreamReader;
9 import java.util.List;
10
11 import org.forester.io.parsers.FastaParser;
12 import org.forester.util.ExternalProgram;
13 import org.forester.util.ForesterUtil;
14
15 public final class MafftOLD implements MsaInferrer {
16
17     private String       _error;
18     private int          _exit_code;
19     private final String _path_to_prg;
20
21     public static MsaInferrer createInstance( final String path_to_prg ) {
22         return new MafftOLD( path_to_prg );
23     }
24
25     private MafftOLD( final String path_to_prg ) {
26         _path_to_prg = new String( path_to_prg );
27         init();
28     }
29
30     @Override
31     public Object clone() {
32         throw new NoSuchMethodError();
33     }
34
35     @Override
36     public String getErrorDescription() {
37         return _error;
38     }
39
40     @Override
41     public int getExitCode() {
42         return _exit_code;
43     }
44
45     @Override
46     public Msa infer( final File path_to_input_seqs, final List<String> opts ) throws IOException, InterruptedException {
47         init();
48         final String[] my_opts = new String[ opts.size() + 1 ];
49         for( int i = 0; i < opts.size(); i++ ) {
50             my_opts[ i ] = opts.get( i );
51         }
52         my_opts[ opts.size() ] = path_to_input_seqs.getAbsolutePath();
53         final ExternalProgram mafft_prg = new ExternalProgram( _path_to_prg );
54         mafft_prg.launch( my_opts );
55         // _exit_code = mafft_prg.waitFor();
56         // if ( _exit_code != 0 ) {
57         //    throw new IOException( "MAFFT failed, exit code: " + _exit_code );
58         // }
59         final BufferedReader r = new BufferedReader( new InputStreamReader( mafft_prg.getErrorStream() ) );
60         final StringBuffer error_sb = new StringBuffer();
61         String line = null;
62         while ( ( line = r.readLine() ) != null ) {
63             error_sb.append( line );
64             error_sb.append( ForesterUtil.LINE_SEPARATOR );
65         }
66         r.close();
67         if ( error_sb.length() > 0 ) {
68             _error = error_sb.toString();
69             throw new IOException( "MAFFT failed" );
70         }
71         final InputStream is = mafft_prg.getInputStream();
72         final Msa msa = FastaParser.parseMsa( is );
73         is.close();
74         return msa;
75     }
76
77     private void init() {
78         _error = null;
79         _exit_code = -100;
80     }
81 }