3 import jalview.bin.Cache;
4 import jalview.datamodel.AlignmentI;
5 import jalview.datamodel.Sequence;
6 import jalview.datamodel.SequenceGroup;
7 import jalview.datamodel.SequenceI;
8 import jalview.gui.AlignFrame;
9 import jalview.gui.JvOptionPane;
10 import jalview.gui.Preferences;
11 import jalview.io.DataSourceType;
12 import jalview.io.FileFormat;
13 import jalview.io.FileLoader;
14 import jalview.util.MessageManager;
17 import java.io.FileNotFoundException;
18 import java.io.IOException;
19 import java.util.List;
21 import javax.swing.JOptionPane;
23 public class HMMBuildThread implements Runnable
25 HMMERCommands cmds = new HMMERCommands();
30 boolean forGroup = false;
31 boolean canRun = true;
39 public HMMBuildThread(AlignFrame af)
42 if (af.getViewport().getSelectionGroup() != null)
44 group = af.getViewport().getSelectionGroup();
47 alignment = af.getViewport().getAlignment();
54 barID = System.currentTimeMillis();
55 af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
57 cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
58 if (alignment == null && group == null)
60 JOptionPane.showMessageDialog(af,
61 MessageManager.getString("label.no_sequence_data"));
66 hmmTemp = File.createTempFile("hmm", ".hmm");
67 hmmTemp.deleteOnExit();
68 stoTemp = File.createTempFile("output", ".sto");
69 stoTemp.deleteOnExit();
70 } catch (IOException e1)
80 List<SequenceI> seqs = alignment
81 .getHMMConsensusSequences(true);
82 cmds.setHmmSeqs(seqs);
85 array = group.getSelectionAsNewSequences(alignment);
89 if (!alignment.isAligned())
93 array = alignment.getSequencesArray();
96 SequenceI[] newArr = new SequenceI[array.length];
98 for (SequenceI seq : array)
100 newArr[index] = new Sequence(seq);
104 cmds.uniquifySequences(newArr);
105 cmds.exportData(newArr, stoTemp, null, null);
106 jalview.analysis.SeqsetUtils.deuniquify(cmds.hash, array);
108 } catch (FileNotFoundException e)
110 // TODO Auto-generated catch block
116 boolean ran = runCommand();
119 JvOptionPane.showInternalMessageDialog(af,
120 MessageManager.getString("warn.hmmbuild_failed"));
123 } catch (IOException | InterruptedException e)
125 // TODO Auto-generated catch block
132 } catch (IOException | InterruptedException e)
134 // TODO Auto-generated catch block
137 } catch (Exception e)
142 af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
150 private boolean runCommand() throws IOException, InterruptedException
152 File file = new File(cmds.HMMERFOLDER + "/binaries/hmmbuild");
153 if (!file.canExecute())
157 String command = cmds.HMMERFOLDER + cmds.HMMBUILD + cmds.NAME;
160 command += group.getName();
164 String name = af.getName();
171 command += cmds.SPACE;
172 if (!alignment.isNucleotide())
174 command += cmds.FORCEAMINO; // TODO check for rna
178 command += cmds.FORCEDNA;
181 command += hmmTemp.getAbsolutePath()
182 + cmds.SPACE + stoTemp.getAbsolutePath() + cmds.SPACE;
183 return cmds.runCommand(command);
186 private void importData() throws IOException, InterruptedException
188 cmds.addHMMConsensusSequences(af);
189 FileLoader loader = new FileLoader();
190 loader.LoadFileOntoAlignmentWaitTillLoaded(af.getViewport(),
191 hmmTemp.getAbsolutePath(), DataSourceType.FILE,
197 public boolean canRun()