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;
21 import java.io.FileNotFoundException;
22 import java.io.IOException;
23 import java.util.List;
25 import javax.swing.JOptionPane;
27 public class HMMBuildThread implements Runnable
29 HMMERCommands cmds = new HMMERCommands();
32 AlignViewport viewport;
37 boolean forGroup = false;
46 * This is used for validation purposes. Do not use!
50 public HMMBuildThread(AlignmentI alignment)
52 this.alignment = alignment;
56 public HMMBuildThread(AlignFrame af)
59 if (af.getViewport().getSelectionGroup() != null)
61 group = af.getViewport().getSelectionGroup();
64 viewport = af.getViewport();
65 alignment = viewport.getAlignment();
70 * Builds a HMM from an alignment, then imports and adds it to the alignment.
75 barID = System.currentTimeMillis();
78 af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
81 cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
82 if (alignment == null && group == null)
84 JOptionPane.showMessageDialog(af,
85 MessageManager.getString("warn.no_sequence_data"));
90 hmmTemp = File.createTempFile("hmm", ".hmm");
91 hmmTemp.deleteOnExit();
92 stoTemp = File.createTempFile("output", ".sto");
93 stoTemp.deleteOnExit();
94 } catch (IOException e1)
104 List<SequenceI> seqs = alignment
105 .getHMMConsensusSequences(true);
106 cmds.setHmmSeqs(seqs);
109 array = group.getSelectionAsNewSequences(alignment);
113 if (!alignment.isAligned())
117 array = alignment.getSequencesArray();
119 if (array.length < 1)
123 JOptionPane.showMessageDialog(af,
124 MessageManager.getString("warn.no_sequence_data"));
128 SequenceI[] newArr = new SequenceI[array.length];
130 for (SequenceI seq : array)
132 newArr[index] = new Sequence(seq);
136 cmds.uniquifySequences(newArr);
137 cmds.exportData(newArr, stoTemp, null, null);
138 jalview.analysis.SeqsetUtils.deuniquify(cmds.hash, array);
140 } catch (FileNotFoundException e)
142 // TODO Auto-generated catch block
148 boolean ran = runCommand();
153 JvOptionPane.showInternalMessageDialog(af,
154 MessageManager.getString("warn.hmmbuild_failed"));
158 } catch (IOException | InterruptedException e)
160 // TODO Auto-generated catch block
167 } catch (IOException | InterruptedException e)
169 // TODO Auto-generated catch block
172 } catch (Exception e)
180 MessageManager.getString("status.running_hmmbuild"),
189 * Executes the hmmbuild command in the command line.
192 * @throws IOException
193 * @throws InterruptedException
195 private boolean runCommand() throws IOException, InterruptedException
197 File file = new File(cmds.HMMERFOLDER + "/hmmbuild");
198 if (!file.canExecute())
200 file = new File(cmds.HMMERFOLDER + "/hmmbuild.exe");
202 if (!file.canExecute())
208 String command = cmds.HMMERFOLDER + cmds.HMMBUILD + cmds.NAME;
211 command += group.getName();
218 name = af.getTitle();
220 if (name == null || name == "" || name == " " || name == " ")
226 command += cmds.SPACE;
227 if (!alignment.isNucleotide())
229 command += cmds.FORCEAMINO; // TODO check for rna
233 command += cmds.FORCEDNA;
236 command += hmmTemp.getAbsolutePath()
237 + cmds.SPACE + stoTemp.getAbsolutePath() + cmds.SPACE;
238 return cmds.runCommand(command);
242 * Imports the .hmm file produced by hmmbuild.
244 * @throws IOException
245 * @throws InterruptedException
247 private void importData() throws IOException, InterruptedException
251 cmds.addHMMConsensusSequences(af);
253 FileLoader loader = new FileLoader();
254 loader.LoadFileOntoAlignmentWaitTillLoaded(viewport,
255 hmmTemp.getAbsolutePath(), DataSourceType.FILE,
260 HMMFile file = new HMMFile(new FileParse(hmmTemp.getAbsolutePath(),
261 DataSourceType.FILE));
262 alignment.addSequence(file.getSeqsAsArray()[0]);
269 * Runs hmmbuild, and waits for the results to be imported before continuing
271 public void hmmbuildWaitTillComplete()
273 Thread loader = new Thread(this);
276 while (loader.isAlive())
281 } catch (Exception ex)