From d4af4e66f7aee7d99deecc7b3a3125eb3748884e Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Sat, 19 May 2012 01:46:36 +0000 Subject: [PATCH] in progress --- forester/java/src/org/forester/msa/Mafft.java | 14 ++++--- forester/java/src/org/forester/test/Test.java | 43 +++++++++++++++++++- .../org/forester/util/SystemCommandExecutor.java | 11 ++--- .../org/forester/util/ThreadedStreamHandler.java | 7 ++++ 4 files changed, 60 insertions(+), 15 deletions(-) diff --git a/forester/java/src/org/forester/msa/Mafft.java b/forester/java/src/org/forester/msa/Mafft.java index 0cdaac2..b56ca1e 100644 --- a/forester/java/src/org/forester/msa/Mafft.java +++ b/forester/java/src/org/forester/msa/Mafft.java @@ -50,7 +50,7 @@ public final class Mafft implements MsaInferrer { } 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 = ""; @@ -62,7 +62,7 @@ public final class Mafft implements MsaInferrer { 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; } @@ -109,15 +109,17 @@ public final class Mafft implements MsaInferrer { 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; } diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index fae52db..adcbac9 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -8211,12 +8211,48 @@ public final class Test { 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; @@ -8265,7 +8301,10 @@ public final class Test { 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; } } diff --git a/forester/java/src/org/forester/util/SystemCommandExecutor.java b/forester/java/src/org/forester/util/SystemCommandExecutor.java index bb87989..6160382 100644 --- a/forester/java/src/org/forester/util/SystemCommandExecutor.java +++ b/forester/java/src/org/forester/util/SystemCommandExecutor.java @@ -38,7 +38,6 @@ import java.util.List; public class SystemCommandExecutor { private final List _command_information; - private final String _admin_password; private ThreadedStreamHandler _input_stream_handler; private ThreadedStreamHandler _error_stream_handler; private final static boolean DEBUG = false; @@ -63,11 +62,10 @@ public class SystemCommandExecutor { */ public SystemCommandExecutor( final List 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 ) { @@ -114,9 +112,8 @@ public class SystemCommandExecutor { // 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? @@ -134,9 +131,9 @@ public class SystemCommandExecutor { // generated by process.waitFor() call throw e; } - // finally { + // finally { return exit_value; - // } + // } } /** diff --git a/forester/java/src/org/forester/util/ThreadedStreamHandler.java b/forester/java/src/org/forester/util/ThreadedStreamHandler.java index ed70e75..a8a91e8 100644 --- a/forester/java/src/org/forester/util/ThreadedStreamHandler.java +++ b/forester/java/src/org/forester/util/ThreadedStreamHandler.java @@ -81,6 +81,13 @@ class ThreadedStreamHandler extends Thread { 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 ); -- 1.7.10.2