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.JvOptionPane;
import jalview.gui.Preferences;
import jalview.io.DataSourceType;
-import jalview.io.FileFormat;
-import jalview.io.FileLoader;
import jalview.io.FileParse;
import jalview.io.HMMFile;
import jalview.util.MessageManager;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
AlignFrame af;
AlignViewport viewport;
+
AlignmentI alignment;
SequenceGroup group;
-
List<ArgumentI> params;
public HMMBuildThread(AlignFrame af, List<ArgumentI> args)
{
this.af = af;
- if (af.getViewport().getSelectionGroup() != null)
- {
- group = af.getViewport().getSelectionGroup();
- forGroup = true;
- }
viewport = af.getViewport();
- alignment = viewport.getAlignment();
params = args;
-
}
/**
barID);
}
cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
- if (alignment == null && group == null)
+
+ List<SequenceGroup> groups = new ArrayList<>();
+ if (params != null)
{
- JOptionPane.showMessageDialog(af,
- MessageManager.getString("warn.no_sequence_data"));
- return;
+ for (ArgumentI arg : params)
+ {
+ String name = arg.getName();
+ if (MessageManager.getString("label.hmmbuild_for").equals(name))
+ {
+ String value = arg.getValue();
+ if ("Alignment".equals(value))
+ {
+ alignment = viewport.getAlignment();
+ break;
+ }
+ else if ("All groups and alignment".equals(value))
+ {
+ alignment = viewport.getAlignment();
+ groups.addAll(viewport.getAlignment().getGroups());
+ break;
+ }
+ else if ("All groups".equals(value))
+ {
+ alignment = null;
+ groups = viewport.getAlignment().getGroups();
+ break;
+ }
+ else if ("Selected group".equals(value))
+ {
+ alignment = null;
+ groups.add(viewport.getSelectionGroup());
+ break;
+ }
+ }
+ else if (MessageManager.getString("label.use_reference")
+ .equals(name))
+ {
+ if (!af.getViewport().hasReferenceAnnotation())
+ {
+ if (af != null)
+ {
+ af.setProgressBar(
+ MessageManager.getString("status.running_hmmbuild"),
+ barID);
+ }
+ JvOptionPane.showInternalMessageDialog(af, MessageManager
+ .getString("warn.no_reference_annotation"));
+ return;
+ }
+ }
+ }
}
- try
+
+ if (alignment != null)
{
- hmmTemp = File.createTempFile("hmm", ".hmm");
- hmmTemp.deleteOnExit();
- stoTemp = File.createTempFile("output", ".sto");
- stoTemp.deleteOnExit();
- } catch (IOException e1)
+ forGroup = false;
+ runHMMBuild();
+ }
+
+ if (alignment == null)
{
- e1.printStackTrace();
+ alignment = viewport.getAlignment();
}
- try
+ if (groups != null && groups.size() > 0)
+ {
+ for (SequenceGroup grp : groups)
+ {
+ group = grp;
+ forGroup = true;
+ runHMMBuild();
+ }
+ }
+
+
+ if (af != null)
{
+ af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
+ barID);
+ }
+ }
+
+ private void runHMMBuild()
+ {
+ if (alignment == null && group == null)
+ {
+ 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
{
+ try
+ {
SequenceI[] array;
- List<SequenceI> seqs = alignment
- .getHMMConsensusSequences(true);
- cmds.setHmmSeqs(seqs);
+ List<SequenceI> seqs = null;
if (forGroup)
{
+ seqs = group.getHMMConsensusSequences(true);
+ if (seqs.size() > 0)
+ {
+ return;
+ }
array = group.getSelectionAsNewSequences(alignment);
}
else
{
+ seqs = alignment.getHMMConsensusSequences(true);
if (!alignment.isAligned())
{
alignment.padGaps();
}
array = alignment.getSequencesArray();
}
+
+ cmds.setHmmSeqs(seqs);
+
if (array.length < 1)
- {
+ {
if (af != null)
{
JOptionPane.showMessageDialog(af,
- MessageManager.getString("warn.no_sequence_data"));
+ 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++;
+ }
- cmds.uniquifySequences(newArr);
- cmds.exportData(newArr, stoTemp, null, null);
- jalview.analysis.SeqsetUtils.deuniquify(cmds.hash, array);
+ cmds.uniquifySequences(newArr);
+ cmds.exportData(newArr, stoTemp, null, null);
+ jalview.analysis.SeqsetUtils.deuniquify(cmds.hash, array);
- } catch (FileNotFoundException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ } catch (FileNotFoundException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
- }
- try
- {
- boolean ran = runCommand();
- if (!ran)
- {
- return;
- }
- } catch (IOException | InterruptedException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try
- {
+ }
+ try
+ {
+ boolean ran = runCommand();
+ if (!ran)
+ {
+ return;
+ }
+ } catch (IOException | InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ try
+ {
- importData();
- } catch (IOException | InterruptedException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- } finally
- {
- if (af != null)
+ importData();
+ } catch (IOException | InterruptedException e)
{
- af.setProgressBar(
- MessageManager.getString("status.running_hmmbuild"),
- barID);
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
+ } catch (Exception e)
+ {
+ e.printStackTrace();
}
}
break;
case "Use Reference Annotation":
command += "--hand ";
- if (!af.getViewport().hasReferenceAnnotation())
- {
- JvOptionPane.showInternalMessageDialog(af, MessageManager
- .getString("warn.no_reference_annotation"));
- return false;
- }
break;
}
}
}
- if (name == null || name == "" || name == " ")
+ name = name.trim();
+
+ if (name == null || "".equals(name))
{
if (forGroup)
{
{
name = af.getTitle();
}
- if (name == null || name == "" || name == " " || name == " ")
+ if (name == null || "".equals(name))
{
name = "Alignment";
}
*/
private void importData() throws IOException, InterruptedException
{
- if (af != null)
+ 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)
{
- cmds.addHMMConsensusSequences(af);
-
- FileLoader loader = new FileLoader();
- loader.LoadFileOntoAlignmentWaitTillLoaded(viewport,
- hmmTemp.getAbsolutePath(), DataSourceType.FILE,
- FileFormat.HMMER3);
+ seq.insertCharAt(0, group.getStartRes(), '-');
+ seq.insertCharAt(group.getEndRes() + 1,
+ alignment.getWidth() - group.getEndRes(), '-');
+ seq.updateHMMMapping();
+ SequenceI topSeq = group.getSequencesInOrder(alignment)[0];
+ int topIndex = alignment.findIndex(topSeq);
+ alignment.insertSequenceAt(topIndex, seq);
+ group.setSeqrep(seq);
+ group.addSequence(seq, false);
}
else
{
- HMMFile file = new HMMFile(new FileParse(hmmTemp.getAbsolutePath(),
- DataSourceType.FILE));
- alignment.addSequence(file.getSeqsAsArray()[0]);
+ alignment.insertSequenceAt(0, seq);
+ }
+
+ viewport.alignmentChanged(viewport.getAlignPanel());
+ viewport.getAlignPanel().adjustAnnotationHeight();
+ viewport.updateSequenceIdColours();
+
+ if (viewport.getAlignPanel().alignFrame.getSelectedHMM() == null)
+ {
+ viewport.getAlignPanel().alignFrame.setSelectedHMMSequence(seq);
}
hmmTemp.delete();
stoTemp.delete();