}
private static String getPathToCmd() {
- //TODO this needs to come from env variable, etc.
+ //TODO this needs to come from config file!!
//FIXME ..
//should not be in this class!
String path = "";
path = "C:\\Program Files\\mafft-win\\mafft.bat";
}
else {
- path = "/home/czmasek/SOFTWARE/MSA/MAFFT/mafft-6.864-without-extensions/scripts/mafft";
+ path = "/home/czmasek/bin/mafft";
}
return path;
}
my_opts.add( path_to_input_seqs.getAbsolutePath() );
final SystemCommandExecutor command_executor = new SystemCommandExecutor( my_opts );
final int _exit_code = command_executor.executeCommand();
+ final StringBuilder stderr = command_executor.getStandardErrorFromCommand();
+ _error = stderr.toString();
if ( _exit_code != 0 ) {
- throw new IOException( "MAFFT program failed, exit code: " + _exit_code + ", command: " + my_opts );
+ throw new IOException( "MAFFT program failed, exit code: " + _exit_code + "\nCommand:\n" + my_opts
+ + "\nError:\n" + stderr );
}
final StringBuilder stdout = command_executor.getStandardOutputFromCommand();
- final StringBuilder stderr = command_executor.getStandardErrorFromCommand();
if ( ( stdout == null ) || ( stdout.length() < 2 ) ) {
- throw new IOException( "MAFFT program did not produce any output, command: " + my_opts );
+ throw new IOException( "MAFFT program did not produce any output\nCommand:\n" + my_opts + "\nError:\n"
+ + stderr );
}
- _error = stderr.toString();
final Msa msa = FastaParser.parseMsa( stdout.toString() );
return msa;
}
try {
final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
- final String msa_str_1 = "seq_1 abc\nseq2 ghi\nseq_1 def\nseq2 jkm\n";
+ final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
+ if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
+ return false;
+ }
+ if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
+ return false;
+ }
+ if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
+ return false;
+ }
+ if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
+ return false;
+ }
+ if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
+ return false;
+ }
+ if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
+ return false;
+ }
+ if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
+ return false;
+ }
+ if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
+ return false;
+ }
+ if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
+ return false;
+ }
+ if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
+ return false;
+ }
+ if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
+ return false;
+ }
+ if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
+ return false;
+ }
final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
return false;
Msa msa = null;
final MsaInferrer mafft = Mafft.createInstance();
msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
- if ( ( msa == null ) || ( msa.getLength() < 10 ) || ( msa.getNumberOfSequences() != 19 ) ) {
+ if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
+ return false;
+ }
+ if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
return false;
}
}
public class SystemCommandExecutor {
private final List<String> _command_information;
- private final String _admin_password;
private ThreadedStreamHandler _input_stream_handler;
private ThreadedStreamHandler _error_stream_handler;
private final static boolean DEBUG = false;
*/
public SystemCommandExecutor( final List<String> command_information ) {
if ( ( command_information == null ) || command_information.isEmpty() ) {
- throw new IllegalArgumentException( "The commandInformation is required." );
+ throw new IllegalArgumentException( "command information is required" );
}
checkCmdFile( new File( command_information.get( 0 ) ) );
_command_information = command_information;
- _admin_password = null;
}
public static boolean isExecuteableFile( final File path_to_cmd_f ) {
// these need to run as java threads to get the standard output and error from the command.
// the inputstream handler gets a reference to our stdOutput in case we need to write
// something to it, such as with the sudo command
- _input_stream_handler = new ThreadedStreamHandler( inputStream, stdOutput, _admin_password );
+ _input_stream_handler = new ThreadedStreamHandler( inputStream, stdOutput );
_error_stream_handler = new ThreadedStreamHandler( errorStream );
- // TODO the inputStreamHandler has a nasty side-effect of hanging if the given password is wrong; fix it
_input_stream_handler.start();
_error_stream_handler.start();
// TODO a better way to do this?
// generated by process.waitFor() call
throw e;
}
- // finally {
+ // finally {
return exit_value;
- // }
+ // }
}
/**
sudoIsRequested = true;
}
+ ThreadedStreamHandler( final InputStream inputStream, final OutputStream outputStream ) {
+ this.inputStream = inputStream;
+ this.outputStream = outputStream;
+ printWriter = new PrintWriter( outputStream );
+ sudoIsRequested = false;
+ }
+
private void doSleep( final long millis ) {
try {
Thread.sleep( millis );