package jalview.hmmer; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.gui.Preferences; import jalview.io.DataSourceType; import jalview.io.FileFormat; import jalview.util.MessageManager; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; public class HMMBuildThread implements Runnable { AlignFrame af; AlignmentI alignment; long barID; Map hmmSeqs; public HMMBuildThread(AlignFrame af) { this.af = af; alignment = af.getViewport().getAlignment(); } @Override public void run() { barID = System.currentTimeMillis(); af.setProgressBar(MessageManager.getString("status.running_hmmbuild"), barID); HMMERCommands.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH); try { try { hmmSeqs = alignment.getHMMConsensusSequences(true); HMMERCommands.exportData(alignment, true, false, new HiddenMarkovModel()); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { runCommand(); } catch (IOException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { importData(); } catch (IOException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (Exception e) { } finally { af.setProgressBar(MessageManager.getString("status.running_hmmbuild"), barID); } } private void runCommand() throws IOException, InterruptedException { final String command = HMMERCommands.HMMERFOLDER + HMMERCommands.HMMBUILD + HMMERCommands.NAME + af.getName() + HMMERCommands.SPACE + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.HMMBUFFER + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.ALIGNMENTBUFFER; HMMERCommands.runCommand(command); } private void importData() throws IOException, InterruptedException { af.loadJalviewDataFile(HMMERCommands.HMMBUFFER, DataSourceType.FILE, FileFormat.HMMER3, null); for (Map.Entry entry : hmmSeqs.entrySet()) { SequenceI seq = entry.getValue(); Integer pos = entry.getKey(); HMMERCommands.addHMMConsensusSequence(af, seq, pos); } af.alignPanel.alignmentChanged(); } }