import jalview.bin.Cache;
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.JvOptionPane;
import jalview.gui.Preferences;
import jalview.io.DataSourceType;
import jalview.io.FileFormat;
import jalview.util.MessageManager;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.util.Map;
+import java.util.List;
+
+import javax.swing.JOptionPane;
public class HMMBuildThread implements Runnable
{
-
+ HMMERCommands cmds = new HMMERCommands();
AlignFrame af;
AlignmentI alignment;
+ SequenceGroup group;
- long barID;
+ boolean forGroup = false;
+ boolean canRun = true;
+
+ File hmmTemp = null;
+
+ File stoTemp = null;
- Map<Integer, SequenceI> hmmSeqs;
+ long barID;
public HMMBuildThread(AlignFrame af)
{
this.af = af;
+ if (af.getViewport().getSelectionGroup() != null)
+ {
+ group = af.getViewport().getSelectionGroup();
+ forGroup = true;
+ }
alignment = af.getViewport().getAlignment();
+
}
@Override
barID = System.currentTimeMillis();
af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
barID);
- HMMERCommands.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
+ cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
+ if (alignment == null && group == null)
+ {
+ JOptionPane.showMessageDialog(af,
+ MessageManager.getString("label.no_sequence_data"));
+ return;
+ }
+ try
+ {
+ hmmTemp = File.createTempFile("hmm", ".hmm");
+ hmmTemp.deleteOnExit();
+ stoTemp = File.createTempFile("output", ".sto");
+ stoTemp.deleteOnExit();
+ } catch (IOException e1)
+ {
+ e1.printStackTrace();
+ }
try
{
try
{
- hmmSeqs = alignment.getHMMConsensusSequences(true);
- HMMERCommands.exportData(alignment, true, false,
- new HiddenMarkovModel());
+ SequenceI[] array;
+ List<SequenceI> seqs = alignment
+ .getHMMConsensusSequences(true);
+ cmds.setHmmSeqs(seqs);
+ if (forGroup)
+ {
+ array = group.getSelectionAsNewSequences(alignment);
+ }
+ else
+ {
+ if (!alignment.isAligned())
+ {
+ alignment.padGaps();
+ }
+ array = alignment.getSequencesArray();
+ }
+
+ SequenceI[] newArr = new SequenceI[array.length];
+ int index = 0;
+ for (SequenceI seq : array)
+ {
+ newArr[index] = new Sequence(seq);
+ index++;
+ }
+
+ cmds.uniquifySequences(newArr);
+ cmds.exportData(newArr, stoTemp, null, null);
+ jalview.analysis.SeqsetUtils.deuniquify(cmds.hash, array);
+
} catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
}
try
{
- runCommand();
+ boolean ran = runCommand();
+ if (!ran)
+ {
+ JvOptionPane.showInternalMessageDialog(af,
+ MessageManager.getString("warn.hmmbuild_failed"));
+ return;
+ }
} catch (IOException | InterruptedException e)
{
// TODO Auto-generated catch block
}
try
{
+
importData();
} catch (IOException | InterruptedException e)
{
}
} catch (Exception e)
{
-
+ e.printStackTrace();
} finally
{
af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
- private void runCommand() throws IOException, InterruptedException
+ private boolean runCommand() throws IOException, InterruptedException
{
- final String command = HMMERCommands.HMMERFOLDER
- + HMMERCommands.HMMBUILD + HMMERCommands.NAME
- + af.getName() + HMMERCommands.SPACE
- + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.HMMBUFFER
- + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.ALIGNMENTBUFFER;
- HMMERCommands.runCommand(command);
+ File file = new File(cmds.HMMERFOLDER + "/binaries/hmmbuild.exe");
+ if (!file.canExecute())
+ {
+ return false;
+ }
+ String command = cmds.HMMERFOLDER + cmds.HMMBUILD + cmds.NAME;
+ if (forGroup)
+ {
+ command += group.getName();
+ }
+ else
+ {
+ String name = af.getName();
+ if (name == null)
+ {
+ name = "Alignment";
+ }
+ command += name;
+ }
+ command += cmds.SPACE;
+ if (!alignment.isNucleotide())
+ {
+ command += cmds.FORCEAMINO; // TODO check for rna
+ }
+ else
+ {
+ command += cmds.FORCEDNA;
+ }
+
+ command += hmmTemp.getAbsolutePath()
+ + cmds.SPACE + stoTemp.getAbsolutePath() + cmds.SPACE;
+ return cmds.runCommand(command);
}
private void importData() throws IOException, InterruptedException
{
- af.loadJalviewDataFile(HMMERCommands.HMMBUFFER, DataSourceType.FILE,
+ cmds.addHMMConsensusSequences(af);
+ af.loadJalviewDataFile(hmmTemp.getAbsolutePath(), DataSourceType.FILE,
FileFormat.HMMER3, null);
- for (Map.Entry<Integer, SequenceI> entry : hmmSeqs.entrySet())
- {
- SequenceI seq = entry.getValue();
- Integer pos = entry.getKey();
- HMMERCommands.addHMMConsensusSequence(af, seq, pos);
- }
- af.alignPanel.alignmentChanged();
+ hmmTemp.delete();
+ stoTemp.delete();
}
+ public boolean canRun()
+ {
+ return canRun;
+ }