4 import jalview.bin.Cache;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.Sequence;
7 import jalview.datamodel.SequenceGroup;
8 import jalview.datamodel.SequenceI;
9 import jalview.gui.AlignFrame;
10 import jalview.gui.AlignViewport;
11 import jalview.gui.JvOptionPane;
12 import jalview.gui.Preferences;
13 import jalview.io.DataSourceType;
14 import jalview.io.FileFormat;
15 import jalview.io.FileLoader;
16 import jalview.io.FileParse;
17 import jalview.io.HMMFile;
18 import jalview.util.MessageManager;
19 import jalview.ws.params.ArgumentI;
22 import java.io.FileNotFoundException;
23 import java.io.IOException;
24 import java.util.List;
26 import javax.swing.JOptionPane;
28 public class HMMBuildThread implements Runnable
30 HMMERCommands cmds = new HMMERCommands();
33 AlignViewport viewport;
37 List<ArgumentI> params;
40 boolean forGroup = false;
49 * This is used for validation purposes. Do not use!
53 public HMMBuildThread(AlignmentI alignment)
55 this.alignment = alignment;
59 public HMMBuildThread(AlignFrame af, List<ArgumentI> args)
62 if (af.getViewport().getSelectionGroup() != null)
64 group = af.getViewport().getSelectionGroup();
67 viewport = af.getViewport();
68 alignment = viewport.getAlignment();
74 * Builds a HMM from an alignment, then imports and adds it to the alignment.
79 barID = System.currentTimeMillis();
82 af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
85 cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
86 if (alignment == null && group == null)
88 JOptionPane.showMessageDialog(af,
89 MessageManager.getString("warn.no_sequence_data"));
94 hmmTemp = File.createTempFile("hmm", ".hmm");
95 hmmTemp.deleteOnExit();
96 stoTemp = File.createTempFile("output", ".sto");
97 stoTemp.deleteOnExit();
98 } catch (IOException e1)
100 e1.printStackTrace();
108 List<SequenceI> seqs = alignment
109 .getHMMConsensusSequences(true);
110 cmds.setHmmSeqs(seqs);
113 array = group.getSelectionAsNewSequences(alignment);
117 if (!alignment.isAligned())
121 array = alignment.getSequencesArray();
123 if (array.length < 1)
127 JOptionPane.showMessageDialog(af,
128 MessageManager.getString("warn.no_sequence_data"));
132 SequenceI[] newArr = new SequenceI[array.length];
134 for (SequenceI seq : array)
136 newArr[index] = new Sequence(seq);
140 cmds.uniquifySequences(newArr);
141 cmds.exportData(newArr, stoTemp, null, null);
142 jalview.analysis.SeqsetUtils.deuniquify(cmds.hash, array);
144 } catch (FileNotFoundException e)
146 // TODO Auto-generated catch block
152 boolean ran = runCommand();
157 } catch (IOException | InterruptedException e)
159 // TODO Auto-generated catch block
166 } catch (IOException | InterruptedException e)
168 // TODO Auto-generated catch block
171 } catch (Exception e)
179 MessageManager.getString("status.running_hmmbuild"),
188 * Executes the hmmbuild command in the command line.
191 * @throws IOException
192 * @throws InterruptedException
194 private boolean runCommand() throws IOException, InterruptedException
196 File file = new File(cmds.HMMERFOLDER + "/hmmbuild");
197 if (!file.canExecute())
199 file = new File(cmds.HMMERFOLDER + "/hmmbuild.exe");
201 if (!file.canExecute())
205 JvOptionPane.showInternalMessageDialog(af,
206 MessageManager.getString("warn.hmmbuild_failed"));
212 String command = cmds.HMMERFOLDER + cmds.HMMBUILD + cmds.SPACE;
217 for (ArgumentI arg : params)
219 String argName = arg.getName();
223 name = arg.getValue();
225 case "Use Reference Annotation":
226 command += "--hand ";
227 if (!af.getViewport().hasReferenceAnnotation())
229 JvOptionPane.showInternalMessageDialog(af, MessageManager
230 .getString("warn.no_reference_annotation"));
240 if (name == null || name == "" || name == " ")
244 name = group.getName();
250 name = af.getTitle();
252 if (name == null || name == "" || name == " " || name == " ")
259 command += "-n " + name + cmds.SPACE;
260 if (!alignment.isNucleotide())
262 command += cmds.FORCEAMINO; // TODO check for rna
266 command += cmds.FORCEDNA;
269 command += hmmTemp.getAbsolutePath()
270 + cmds.SPACE + stoTemp.getAbsolutePath() + cmds.SPACE;
271 return cmds.runCommand(command);
275 * Imports the .hmm file produced by hmmbuild.
277 * @throws IOException
278 * @throws InterruptedException
280 private void importData() throws IOException, InterruptedException
284 cmds.addHMMConsensusSequences(af);
286 FileLoader loader = new FileLoader();
287 loader.LoadFileOntoAlignmentWaitTillLoaded(viewport,
288 hmmTemp.getAbsolutePath(), DataSourceType.FILE,
293 HMMFile file = new HMMFile(new FileParse(hmmTemp.getAbsolutePath(),
294 DataSourceType.FILE));
295 alignment.addSequence(file.getSeqsAsArray()[0]);
302 * Runs hmmbuild, and waits for the results to be imported before continuing
304 public void hmmbuildWaitTillComplete()
306 Thread loader = new Thread(this);
309 while (loader.isAlive())
314 } catch (Exception ex)