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 JvOptionPane.showInternalMessageDialog(af,
158 MessageManager.getString("warn.hmmbuild_failed"));
162 } catch (IOException | InterruptedException e)
164 // TODO Auto-generated catch block
171 } catch (IOException | InterruptedException e)
173 // TODO Auto-generated catch block
176 } catch (Exception e)
184 MessageManager.getString("status.running_hmmbuild"),
193 * Executes the hmmbuild command in the command line.
196 * @throws IOException
197 * @throws InterruptedException
199 private boolean runCommand() throws IOException, InterruptedException
201 File file = new File(cmds.HMMERFOLDER + "/hmmbuild");
202 if (!file.canExecute())
204 file = new File(cmds.HMMERFOLDER + "/hmmbuild.exe");
206 if (!file.canExecute())
212 String command = cmds.HMMERFOLDER + cmds.HMMBUILD + cmds.NAME;
215 command += group.getName();
222 // name = af.getTitle();
225 if (name == null || name == "" || name == " " || name == " ")
231 command += cmds.SPACE;
232 if (!alignment.isNucleotide())
234 command += cmds.FORCEAMINO; // TODO check for rna
238 command += cmds.FORCEDNA;
241 command += hmmTemp.getAbsolutePath()
242 + cmds.SPACE + stoTemp.getAbsolutePath() + cmds.SPACE;
243 return cmds.runCommand(command);
247 * Imports the .hmm file produced by hmmbuild.
249 * @throws IOException
250 * @throws InterruptedException
252 private void importData() throws IOException, InterruptedException
256 cmds.addHMMConsensusSequences(af);
258 FileLoader loader = new FileLoader();
259 loader.LoadFileOntoAlignmentWaitTillLoaded(viewport,
260 hmmTemp.getAbsolutePath(), DataSourceType.FILE,
265 HMMFile file = new HMMFile(new FileParse(hmmTemp.getAbsolutePath(),
266 DataSourceType.FILE));
267 alignment.addSequence(file.getSeqsAsArray()[0]);
274 * Runs hmmbuild, and waits for the results to be imported before continuing
276 public void hmmbuildWaitTillComplete()
278 Thread loader = new Thread(this);
281 while (loader.isAlive())
286 } catch (Exception ex)