package jalview.hmmer;
+import jalview.analysis.SeqsetUtils;
import jalview.bin.Cache;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.io.HMMFile;
import jalview.io.StockholmFile;
import jalview.util.MessageManager;
+import jalview.ws.params.ArgumentI;
import java.io.BufferedReader;
import java.io.File;
{
public static final String HMMBUILD = "hmmbuild";
- public String JALVIEWDIRECTORY = System.getProperty("user.dir")
- + File.separator;
+ private Hashtable hash = new Hashtable();
- public String OUTPUTALIGNMENT;
-
- public final String SPACE = " ";
-
- public final String ALLCOL = "--allcol ";
-
- public final String TRIM = "--trim ";
-
- public final String FORCEAMINO = "--amino ";
-
- public final String FORCEDNA = "--dna ";
-
- public final String FORCERNA = "--rna ";
-
- Hashtable hash = new Hashtable();
+ protected AlignFrame af;
- List<SequenceI> hmmSeqs;
+ protected List<ArgumentI> params;
- protected AlignFrame af;
+ public HmmerCommand(AlignFrame alignFrame, List<ArgumentI> args)
+ {
+ af = alignFrame;
+ params = args;
+ }
public static boolean isHmmerAvailable()
{
/**
* Uniquifies the sequences when exporting and stores their details in a
- * hashtable.
+ * hashtable
*
* @param seqs
*/
- public void uniquifySequences(SequenceI[] seqs)
+ protected void stashSequences(SequenceI[] seqs)
{
- hash = jalview.analysis.SeqsetUtils.uniquify(seqs, true);
+ hash = SeqsetUtils.uniquify(seqs, true);
}
/**
- * Recover the sequence data lost by uniquifying.
+ * Restores the sequence data lost by uniquifying
*
* @param seqs
*/
- public void recoverSequenceNames(SequenceI[] seqs)
+ protected void recoverSequences(SequenceI[] seqs)
{
- jalview.analysis.SeqsetUtils.deuniquify(hash, seqs);
+ SeqsetUtils.deuniquify(hash, seqs);
}
/**
- * Runs a command in the command line.
+ * Runs a command as a separate process
*
* @param command
+ * the executable command and any arguments to it
* @throws IOException
- * @throws InterruptedException
*/
- public boolean runCommand(String command)
- throws IOException, InterruptedException
+ public boolean runCommand(List<String> command)
+ throws IOException
{
try
{
- final Process p = Runtime.getRuntime().exec(command);
-
+ ProcessBuilder pb = new ProcessBuilder(command);
+ pb.redirectErrorStream(true); // send syserr to sysout
+ final Process p = pb.start();
new Thread(new Runnable()
{
@Override
{
BufferedReader input = new BufferedReader(
new InputStreamReader(p.getInputStream()));
- String line = null;
-
try
{
- while ((line = input.readLine()) != null)
+ String line = input.readLine();
+ while (line != null)
{
System.out.println(line);
+ line = input.readLine();
}
} catch (IOException e)
{
}).start();
p.waitFor();
+ return p.exitValue() == 0; // 0 is success, by convention
} catch (Exception e)
{
e.printStackTrace();
return false;
}
- return true;
}
/**
- * Exports an alignment and/or HMM to the specified file.
+ * Exports an alignment (and possibly annotation) to the specified file, in
+ * Stockholm format
*
- * @param alignment
+ * @param seqs
+ * @param toFile
+ * @param annotated
* @throws IOException
*/
- public void exportData(SequenceI[] seqs, File stoLocation,
- HiddenMarkovModel hmm, File hmmLocation, AnnotatedCollectionI al)
+ public void exportStockholm(SequenceI[] seqs, File toFile,
+ AnnotatedCollectionI annotated)
throws IOException
{
if (seqs != null)
{
AlignmentI newAl = new Alignment(seqs);
- if (stoLocation != null && al != null)
+ if (toFile != null && annotated != null)
{
- for (AlignmentAnnotation annot : al.getAlignmentAnnotation())
+ for (AlignmentAnnotation annot : annotated.getAlignmentAnnotation())
{
if (annot.label.contains("Reference") || "RF".equals(annot.label))
{
StockholmFile file = new StockholmFile(newAl);
String output = file.print(seqs, false);
- PrintWriter writer = new PrintWriter(stoLocation);
+ PrintWriter writer = new PrintWriter(toFile);
writer.println(output);
writer.close();
}
-
- if (hmm != null)
- {
- HMMFile file = new HMMFile(hmm);
- PrintWriter writer = new PrintWriter(hmmLocation);
- writer.print(file.print());
- writer.close();
- }
- }
-
- /**
- * Returns the list of HMM sequences removed
- *
- * @return
- */
- public List<SequenceI> getHmmSeqs()
- {
- return hmmSeqs;
- }
-
- /**
- * Sets the list of removed HMM sequences
- *
- * @param hmmSeqs
- */
- public void setHmmSeqs(List<SequenceI> hmmSeqs)
- {
- this.hmmSeqs = hmmSeqs;
}
/**
* command short name e.g. hmmalign
* @return
*/
- protected String getCommandRoot(String cmd)
+ protected String getCommandPath(String cmd)
{
String binariesFolder = Cache.getProperty(Preferences.HMMER_PATH);
File file = getExecutable(cmd, binariesFolder);
}
return file;
}
+
+ /**
+ * A convenience method to create a temporary file that is deleted on exit of
+ * the JVM
+ *
+ * @param prefix
+ * @param suffix
+ * @return
+ * @throws IOException
+ */
+ protected File createTempFile(String prefix, String suffix)
+ throws IOException
+ {
+ File f = File.createTempFile(prefix, suffix);
+ f.deleteOnExit();
+ return f;
+
+ }
+
+ /**
+ * Exports an HMM to the specified file
+ *
+ * @param hmm
+ * @param hmmFile
+ * @throws IOException
+ */
+ public void exportHmm(HiddenMarkovModel hmm, File hmmFile)
+ throws IOException
+ {
+ if (hmm != null)
+ {
+ HMMFile file = new HMMFile(hmm);
+ PrintWriter writer = new PrintWriter(hmmFile);
+ writer.print(file.print());
+ writer.close();
+ }
+ }
}