}
}
args.add("-o");
- args.add(resultFile.getAbsolutePath());
- args.add(modelFile.getAbsolutePath());
- args.add(alignmentFile.getAbsolutePath());
+ args.add(getFilePath(resultFile));
+ args.add(getFilePath(modelFile));
+ args.add(getFilePath(alignmentFile));
return runCommand(args);
}
private SequenceI[] importData(File resultFile,
List<AlignmentOrder> allOrders) throws IOException
{
- StockholmFile file = new StockholmFile(resultFile.getAbsolutePath(),
+ StockholmFile file = new StockholmFile(getFilePath(resultFile),
DataSourceType.FILE);
SequenceI[] result = file.getSeqsAsArray();
AlignmentOrder msaorder = new AlignmentOrder(result);
List<String> args = new ArrayList<>();
args.add(command);
args.add("-o");
- args.add(searchOutputFile.getAbsolutePath());
+ args.add(getFilePath(searchOutputFile));
args.add("-A");
- args.add(hitsAlignmentFile.getAbsolutePath());
+ args.add(getFilePath(hitsAlignmentFile));
boolean dbFound = false;
String dbPath = "";
// writer.close();
}
- args.add(hmmFile.getAbsolutePath());
- args.add(databaseFile.getAbsolutePath());
+ args.add(getFilePath(hmmFile));
+ args.add(getFilePath(databaseFile));
return runCommand(args);
}
MessageManager.getString("label.trim_termini_desc"), true,
true, true, null));
}
- HMMAlign hmmalign = new HMMAlign(frame, alignArgs);
+ HmmerCommand hmmalign = new HMMAlign(frame, alignArgs);
hmmalign.run();
frame = null;
hmmTemp.delete();
* Runs a command as a separate process and waits for it to complete. Answers
* true if the process return status is zero, else false.
*
- * @param command
+ * @param commands
* the executable command and any arguments to it
* @throws IOException
*/
- public boolean runCommand(List<String> command)
+ public boolean runCommand(List<String> commands)
throws IOException
{
- List<String> commands = Platform.isWindows() ? wrapWithCygwin(command)
- : command;
+ List<String> args = Platform.isWindows() ? wrapWithCygwin(commands)
+ : commands;
try
{
- ProcessBuilder pb = new ProcessBuilder(commands);
+ ProcessBuilder pb = new ProcessBuilder(args);
pb.redirectErrorStream(true); // merge syserr to sysout
final Process p = pb.start();
new Thread(new Runnable()
if (exitValue != 0)
{
Cache.log.error("Command failed, return code = " + exitValue);
- Cache.log.error("Command/args were: " + commands.toString());
+ Cache.log.error("Command/args were: " + args.toString());
}
return exitValue == 0; // 0 is success, by convention
} catch (Exception e)
}
/**
- * Converts the given command to a Cygwin "run" command wrapper
+ * Converts the given command to a Cygwin "bash" command wrapper. The hmmer
+ * command and any arguments to it are converted into a single parameter to the
+ * bash command.
*
- * @param command
- * @return
+ * @param commands
*/
- protected List<String> wrapWithCygwin(List<String> command)
+ protected List<String> wrapWithCygwin(List<String> commands)
{
- File runCygwin = FileUtils.getExecutable("run",
+ File bash = FileUtils.getExecutable("bash",
Cache.getProperty(Preferences.CYGWIN_PATH));
- if (runCygwin == null)
+ if (bash == null)
{
Cache.log.error("Cygwin shell not found");
- return command;
+ return commands;
}
List<String> wrapped = new ArrayList<>();
- wrapped.add(runCygwin.getAbsolutePath());
- if (!command.isEmpty())
+ wrapped.add(bash.getAbsolutePath());
+ wrapped.add("-c");
+
+ /*
+ * combine hmmbuild/search/align and arguments to a single string
+ */
+ StringBuilder sb = new StringBuilder();
+ for (String cmd : commands)
{
- wrapped.add(command.get(0));
- // wrapped.add("--quote");
- StringBuilder args = new StringBuilder();
- for (String arg : command.subList(1, command.size()))
- {
- args.append(" ").append(arg);
- }
- wrapped.add(args.toString());
+ sb.append(" ").append(cmd);
}
- // TODO this doesn't yet pass parameters successfully
+ wrapped.add(sb.toString());
return wrapped;
}
MessageManager.getString("warn.hmm_command_failed"));
}
- return file == null ? null : file.getAbsolutePath();
+ return file == null ? null : getFilePath(file);
}
/**
writer.close();
}
}
+
+ /**
+ * Answers an absolute path to the given file, in a format suitable for
+ * processing by a hmmer command. On a Windows platform, the native Windows file
+ * path is converted to Cygwin format, by replacing '\'with '/' and drive letter
+ * X with /cygdrive/x.
+ *
+ * @param resultFile
+ * @return
+ */
+ protected String getFilePath(File resultFile)
+ {
+ String path = resultFile.getAbsolutePath();
+ if (Platform.isWindows())
+ {
+ // the first backslash escapes '\' for the regular expression argument
+ path = path.replaceAll("\\" + File.separator, "/");
+ int colon = path.indexOf(':');
+ if (colon > 0)
+ {
+ String drive = path.substring(0, colon);
+ path = path.replaceAll(drive + ":", "/cygdrive/" + drive);
+ }
+ }
+
+ return path;
+ }
}