package jalview.hmmer;
-
-import jalview.bin.Cache;
+import jalview.analysis.SeqsetUtils;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
import jalview.gui.AlignViewport;
import jalview.gui.JvOptionPane;
-import jalview.gui.Preferences;
import jalview.io.DataSourceType;
import jalview.io.FileParse;
import jalview.io.HMMFile;
import javax.swing.JOptionPane;
-public class HMMBuildThread implements Runnable
+public class HMMBuildThread extends HmmerCommand implements Runnable
{
- HMMERCommands cmds = new HMMERCommands();
- AlignFrame af;
-
AlignViewport viewport;
boolean multiJob = false;
+
AlignmentI alignment;
+
SequenceGroup group;
- List<ArgumentI> params;
+ List<ArgumentI> params;
boolean forGroup = false;
File stoTemp = null;
long barID;
-
+
/**
* This is used for validation purposes. Do not use!
*
barID = System.currentTimeMillis();
if (af != null)
{
- af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
- barID);
+ af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
+ barID);
}
- cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
List<SequenceGroup> groups = new ArrayList<>();
if (params != null)
}
}
-
if (af != null)
{
- af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
- barID);
+ af.setProgressBar("", barID);
}
}
private void runHMMBuild()
{
if (alignment == null && group == null)
- {
- JOptionPane.showMessageDialog(af,
+ {
+ JOptionPane.showMessageDialog(af,
MessageManager.getString("warn.no_sequence_data"));
- }
- try
- {
- hmmTemp = File.createTempFile("hmm", ".hmm");
- hmmTemp.deleteOnExit();
- stoTemp = File.createTempFile("output", ".sto");
- stoTemp.deleteOnExit();
- } catch (IOException e1)
- {
- e1.printStackTrace();
- }
+ }
+ try
+ {
+ hmmTemp = File.createTempFile("hmm", ".hmm");
+ hmmTemp.deleteOnExit();
+ stoTemp = File.createTempFile("output", ".sto");
+ stoTemp.deleteOnExit();
+ } catch (IOException e1)
+ {
+ e1.printStackTrace();
+ }
try
{
array = alignment.getSequencesArray();
}
- cmds.setHmmSeqs(seqs);
-
if (array.length < 1)
- {
+ {
if (af != null)
{
JOptionPane.showMessageDialog(af,
MessageManager.getString("warn.no_sequence_data"));
}
return;
- }
- SequenceI[] newArr = new SequenceI[array.length];
- int index = 0;
- for (SequenceI seq : array)
- {
- newArr[index] = new Sequence(seq);
- index++;
- }
+ }
+ SequenceI[] newArr = new SequenceI[array.length];
+ int index = 0;
+ for (SequenceI seq : array)
+ {
+ newArr[index] = new Sequence(seq);
+ index++;
+ }
+
+ uniquifySequences(newArr);
- cmds.uniquifySequences(newArr);
- cmds.exportData(newArr, stoTemp, null, null);
- jalview.analysis.SeqsetUtils.deuniquify(cmds.hash, array);
+ if (forGroup)
+ {
+ exportData(newArr, stoTemp, null, null, group);
+ }
+ else
+ {
+ exportData(newArr, stoTemp, null, null, alignment);
+ }
+
+ SeqsetUtils.deuniquify(hash, array);
} catch (FileNotFoundException e)
{
}
try
{
- boolean ran = runCommand();
- if (!ran)
- {
- return;
- }
+ boolean ran = runCommand();
+ if (!ran)
+ {
+ return;
+ }
} catch (IOException | InterruptedException e)
{
// TODO Auto-generated catch block
// TODO Auto-generated catch block
e.printStackTrace();
}
- } catch (Exception e)
- {
- e.printStackTrace();
+ } catch (Exception e)
+ {
+ e.printStackTrace();
}
}
-
-
/**
* Executes the hmmbuild command in the command line.
*
*/
private boolean runCommand() throws IOException, InterruptedException
{
- File file = new File(cmds.HMMERFOLDER + "/hmmbuild");
- if (!file.canExecute())
+ String binaryPath = getCommandRoot(HMMBUILD);
+ if (binaryPath == null)
{
- file = new File(cmds.HMMERFOLDER + "/hmmbuild.exe");
- {
- if (!file.canExecute())
- {
- if (af != null)
- {
- JvOptionPane.showInternalMessageDialog(af,
- MessageManager.getString("warn.hmmbuild_failed"));
- }
- return false;
- }
- }
+ return false;
}
- String command = cmds.HMMERFOLDER + cmds.HMMBUILD + cmds.SPACE;
+ String command = binaryPath + SPACE;
String name = null;
if (params != null)
break;
}
-
}
}
name = group.getName() + "_HMM";
}
-
if (name == null || "".equals(name))
{
- if (af != null)
+ if (af != null)
+ {
+ if (af.getTitle().length() < 15)
{
name = af.getTitle();
}
- if (name == null || "".equals(name))
- {
- name = "Alignment";
- }
+ }
+ if (name == null || "".equals(name))
+ {
+ name = "Alignment";
+ }
}
- command += "-n " + name.replace(' ', '_') + cmds.SPACE;
+ command += "-n " + name.replace(' ', '_') + SPACE;
if (!alignment.isNucleotide())
{
- command += cmds.FORCEAMINO; // TODO check for rna
+ command += FORCEAMINO; // TODO check for rna
}
else
{
- command += cmds.FORCEDNA;
+ command += FORCEDNA;
}
- command += hmmTemp.getAbsolutePath()
- + cmds.SPACE + stoTemp.getAbsolutePath() + cmds.SPACE;
- return cmds.runCommand(command);
+ command += hmmTemp.getAbsolutePath() + SPACE + stoTemp.getAbsolutePath()
+ + SPACE;
+ return runCommand(command);
}
-
+
/**
* Imports the .hmm file produced by hmmbuild.
*
*/
private void importData() throws IOException, InterruptedException
{
- HMMFile file = new HMMFile(new FileParse(hmmTemp.getAbsolutePath(),
- DataSourceType.FILE));
+ HMMFile file = new HMMFile(
+ new FileParse(hmmTemp.getAbsolutePath(), DataSourceType.FILE));
SequenceI[] seqs = file.getSeqsAsArray();
SequenceI seq = seqs[0];
seq.createDatasetSequence();
- HiddenMarkovModel hmm = file.getHMM();
if (group != null)
{
seq.insertCharAt(0, group.getStartRes(), '-');
seq.insertCharAt(group.getEndRes() + 1,
- alignment.getWidth() - group.getEndRes(), '-');
+ alignment.getWidth() - group.getEndRes() - 1, '-');
seq.updateHMMMapping();
SequenceI topSeq = group.getSequencesInOrder(alignment)[0];
int topIndex = alignment.findIndex(topSeq);
hmmTemp.delete();
stoTemp.delete();
}
-
+
/**
* Runs hmmbuild, and waits for the results to be imported before continuing
*/