X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fhmmer%2FHMMBuildThread.java;h=4e3dc2e4b775341604fb4fefcb0a0bee2eb212f5;hb=bd6ce8f5f9fc8e5bc8a6188d15987ce0ffd2c1ee;hp=8bdb00857f754bb585ff539b3147d102af777d1c;hpb=97d3ad401eb2bc5dba791f31616b87d88ea47e41;p=jalview.git diff --git a/src/jalview/hmmer/HMMBuildThread.java b/src/jalview/hmmer/HMMBuildThread.java index 8bdb008..4e3dc2e 100644 --- a/src/jalview/hmmer/HMMBuildThread.java +++ b/src/jalview/hmmer/HMMBuildThread.java @@ -1,7 +1,6 @@ package jalview.hmmer; - -import jalview.bin.Cache; +import jalview.analysis.SeqsetUtils; import jalview.datamodel.AlignmentI; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; @@ -9,30 +8,31 @@ 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.FileFormat; -import jalview.io.FileLoader; import jalview.io.FileParse; import jalview.io.HMMFile; import jalview.util.MessageManager; +import jalview.ws.params.ArgumentI; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.util.ArrayList; import java.util.List; 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 params; boolean forGroup = false; @@ -41,7 +41,7 @@ public class HMMBuildThread implements Runnable File stoTemp = null; long barID; - + /** * This is used for validation purposes. Do not use! * @@ -53,17 +53,11 @@ public class HMMBuildThread implements Runnable forGroup = false; } - public HMMBuildThread(AlignFrame af) + public HMMBuildThread(AlignFrame af, List args) { this.af = af; - if (af.getViewport().getSelectionGroup() != null) - { - group = af.getViewport().getSelectionGroup(); - forGroup = true; - } viewport = af.getViewport(); - alignment = viewport.getAlignment(); - + params = args; } /** @@ -75,15 +69,107 @@ public class HMMBuildThread implements Runnable barID = System.currentTimeMillis(); if (af != null) { - af.setProgressBar(MessageManager.getString("status.running_hmmbuild"), - barID); + af.setProgressBar(MessageManager.getString("status.running_hmmbuild"), + barID); + } + + List groups = new ArrayList<>(); + if (params != null) + { + 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()); + if (groups.size() > 0) + { + multiJob = true; + } + break; + } + else if ("All groups".equals(value)) + { + alignment = null; + groups = viewport.getAlignment().getGroups(); + if (groups.size() > 0) + { + multiJob = true; + } + 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; + } + } + } } - cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH); + else if (viewport != null) + { + alignment = viewport.getAlignment(); + } + + if (alignment != null) + { + forGroup = false; + runHMMBuild(); + } + + if (alignment == null) + { + alignment = viewport.getAlignment(); + } + + if (groups != null && groups.size() > 0) + { + for (SequenceGroup grp : groups) + { + group = grp; + forGroup = true; + runHMMBuild(); + } + } + + if (af != null) + { + af.setProgressBar("", barID); + } + } + + private void runHMMBuild() + { if (alignment == null && group == null) { JOptionPane.showMessageDialog(af, MessageManager.getString("warn.no_sequence_data")); - return; } try { @@ -98,30 +184,35 @@ public class HMMBuildThread implements Runnable try { - try - { + try + { SequenceI[] array; - List seqs = alignment - .getHMMConsensusSequences(true); - cmds.setHmmSeqs(seqs); + List 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(); } + if (array.length < 1) { if (af != null) { JOptionPane.showMessageDialog(af, - MessageManager.getString("warn.no_sequence_data")); + MessageManager.getString("warn.no_sequence_data")); } return; } @@ -133,58 +224,52 @@ public class HMMBuildThread implements Runnable index++; } - cmds.uniquifySequences(newArr); - cmds.exportData(newArr, stoTemp, null, null); - jalview.analysis.SeqsetUtils.deuniquify(cmds.hash, array); + uniquifySequences(newArr); - } catch (FileNotFoundException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); + if (forGroup) + { + exportData(newArr, stoTemp, null, null, group); + } + else + { + exportData(newArr, stoTemp, null, null, alignment); + } - } - try - { + SeqsetUtils.deuniquify(hash, array); + + } catch (FileNotFoundException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + + } + try + { boolean ran = runCommand(); if (!ran) { - if (af != null) - { - JvOptionPane.showInternalMessageDialog(af, - MessageManager.getString("warn.hmmbuild_failed")); - } return; } - } catch (IOException | InterruptedException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - try - { + } catch (IOException | InterruptedException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try + { - importData(); - } catch (IOException | InterruptedException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } + importData(); + } catch (IOException | InterruptedException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } } catch (Exception e) { e.printStackTrace(); - } finally - { - if (af != null) - { - af.setProgressBar( - MessageManager.getString("status.running_hmmbuild"), - barID); - } } } - - /** * Executes the hmmbuild command in the command line. * @@ -194,50 +279,69 @@ public class HMMBuildThread implements Runnable */ 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"); + return false; + } + String command = binaryPath + SPACE; + String name = null; + + if (params != null) + { + for (ArgumentI arg : params) { - if (!file.canExecute()) + String argName = arg.getName(); + switch (argName) { - return false; + case "HMM Name": + name = arg.getValue(); + name = name.trim(); + break; + case "Use Reference Annotation": + command += "--hand "; + break; + } } } - String command = cmds.HMMERFOLDER + cmds.HMMBUILD + cmds.NAME; - if (forGroup) + + if (forGroup && multiJob) { - command += group.getName(); + name = group.getName() + "_HMM"; } - else + + if (name == null || "".equals(name)) { - String name = null; if (af != null) { - name = af.getTitle(); + if (af.getTitle().length() < 15) + { + name = af.getTitle(); + } } - if (name == null || name == "" || name == " " || name == " ") + if (name == null || "".equals(name)) { name = "Alignment"; } - command += name; + } - command += 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. * @@ -246,25 +350,43 @@ public class HMMBuildThread implements Runnable */ 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(); + 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() - 1, '-'); + 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); + } + + if (viewport != null) + { + viewport.alignmentChanged(viewport.getAlignPanel()); + viewport.getAlignPanel().adjustAnnotationHeight(); + viewport.updateSequenceIdColours(); + + if (viewport.getAlignPanel().alignFrame.getSelectedHMM() == null) + { + viewport.getAlignPanel().alignFrame.setSelectedHMMSequence(seq); + } } hmmTemp.delete(); stoTemp.delete(); } - + /** * Runs hmmbuild, and waits for the results to be imported before continuing */