3 import jalview.bin.Cache;
4 import jalview.datamodel.Alignment;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.SequenceI;
7 import jalview.gui.AlignFrame;
8 import jalview.gui.Desktop;
9 import jalview.gui.JvOptionPane;
10 import jalview.io.DataSourceType;
11 import jalview.io.FileParse;
12 import jalview.io.StockholmFile;
13 import jalview.util.FileUtils;
14 import jalview.util.MessageManager;
15 import jalview.ws.params.ArgumentI;
17 import java.io.BufferedReader;
19 import java.io.FileReader;
20 import java.io.IOException;
21 import java.util.ArrayList;
22 import java.util.List;
24 import javax.swing.JOptionPane;
26 public class JackHMMER extends Search
32 * Constructor for the JackhmmerThread
36 public JackHMMER(AlignFrame af, List<ArgumentI> args)
42 * Runs the JackhmmerThread: the data on the alignment or group is exported,
43 * then the command is executed in the command line and then the data is
44 * imported and displayed in a new frame. Call this method directly to execute
45 * synchronously, or via start() in a new Thread for asynchronously.
53 // shouldn't happen if we got this far
54 Cache.log.error("Error: no sequence for jackhmmer");
58 long msgId = System.currentTimeMillis();
59 af.setProgressBar(MessageManager.getString("status.running_search"),
64 File seqFile = FileUtils.createTempFile("seq", ".sto");
65 File hitsAlignmentFile = FileUtils.createTempFile("hitAlignment",
67 File searchOutputFile = FileUtils.createTempFile("searchOutput",
70 exportStockholm(new SequenceI[] { seq }, seqFile.getAbsoluteFile(),
73 boolean ran = runCommand(searchOutputFile, hitsAlignmentFile,
77 JvOptionPane.showInternalMessageDialog(af, MessageManager
78 .formatMessage("warn.command_failed", "jackhmmer"));
82 importData(hitsAlignmentFile, seqFile, searchOutputFile);
83 // TODO make realignment of search results a step at this level
84 // and make it conditional on this.realign
85 } catch (IOException | InterruptedException e)
90 af.setProgressBar("", msgId);
95 * Executes an jackhmmer search with the given sequence as input. The database
96 * to be searched is a local file as specified by the 'Database' parameter, or
97 * the current alignment (written to file) if none is specified.
99 * @param searchOutputFile
100 * @param hitsAlignmentFile
104 * @throws IOException
106 private boolean runCommand(File searchOutputFile, File hitsAlignmentFile,
107 File seqFile) throws IOException
109 String command = getCommandPath(JACKHMMER);
115 List<String> args = new ArrayList<>();
117 buildArguments(args, searchOutputFile, hitsAlignmentFile, seqFile);
119 return runCommand(args);
123 * Imports the data from the temporary file to which the output of jackhmmer was
126 private void importData(File inputAlignmentTemp, File seqTemp,
127 File searchOutputFile) throws IOException, InterruptedException
129 BufferedReader br = new BufferedReader(
130 new FileReader(inputAlignmentTemp));
133 if (br.readLine() == null)
135 JOptionPane.showMessageDialog(af,
136 MessageManager.getString("label.no_sequences_found"));
139 StockholmFile file = new StockholmFile(new FileParse(
140 inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE));
141 seqs = file.getSeqsAsArray();
143 readDomainTable(searchOutputFile, true);
147 recoverSequences(sequencesHash, seqs);
152 int seqCount = seqs.length;
155 AlignmentI al = new Alignment(seqs);
157 AlignFrame alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
158 AlignFrame.DEFAULT_HEIGHT);
159 String ttl = "jackhmmer search of " + databaseName + " using "
161 Desktop.addInternalFrame(alignFrame, ttl, AlignFrame.DEFAULT_WIDTH,
162 AlignFrame.DEFAULT_HEIGHT);
165 inputAlignmentTemp.delete();
166 searchOutputFile.delete();