3 import jalview.bin.Cache;
4 import jalview.bin.Console;
5 import jalview.datamodel.Alignment;
6 import jalview.datamodel.AlignmentI;
7 import jalview.datamodel.SequenceI;
8 import jalview.gui.AlignFrame;
9 import jalview.gui.Desktop;
10 import jalview.gui.JvOptionPane;
11 import jalview.io.DataSourceType;
12 import jalview.io.FileParse;
13 import jalview.io.StockholmFile;
14 import jalview.util.FileUtils;
15 import jalview.util.MessageManager;
16 import jalview.ws.params.ArgumentI;
18 import java.io.BufferedReader;
20 import java.io.FileReader;
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.List;
25 import javax.swing.JOptionPane;
27 public class JackHMMER extends Search
33 * Constructor for the JackhmmerThread
37 public JackHMMER(AlignFrame af, List<ArgumentI> args)
43 * Runs the JackhmmerThread: the data on the alignment or group is exported,
44 * then the command is executed in the command line and then the data is
45 * imported and displayed in a new frame. Call this method directly to execute
46 * synchronously, or via start() in a new Thread for asynchronously.
54 // shouldn't happen if we got this far
55 Console.error("Error: no sequence for jackhmmer");
59 long msgId = System.currentTimeMillis();
60 af.setProgressBar(MessageManager.getString("status.running_search"),
65 File seqFile = FileUtils.createTempFile("seq", ".sto");
66 File hitsAlignmentFile = FileUtils.createTempFile("hitAlignment",
68 File searchOutputFile = FileUtils.createTempFile("searchOutput",
71 exportStockholm(new SequenceI[] { seq }, seqFile.getAbsoluteFile(),
74 boolean ran = runCommand(searchOutputFile, hitsAlignmentFile,
78 JvOptionPane.showInternalMessageDialog(af, MessageManager
79 .formatMessage("warn.command_failed", "jackhmmer"));
83 importData(hitsAlignmentFile, seqFile, searchOutputFile);
84 // TODO make realignment of search results a step at this level
85 // and make it conditional on this.realign
86 } catch (IOException | InterruptedException e)
91 af.setProgressBar("", msgId);
96 * Executes an jackhmmer search with the given sequence as input. The database
97 * to be searched is a local file as specified by the 'Database' parameter, or
98 * the current alignment (written to file) if none is specified.
100 * @param searchOutputFile
101 * @param hitsAlignmentFile
105 * @throws IOException
107 private boolean runCommand(File searchOutputFile, File hitsAlignmentFile,
108 File seqFile) throws IOException
110 String command = getCommandPath(JACKHMMER);
116 List<String> args = new ArrayList<>();
118 buildArguments(args, searchOutputFile, hitsAlignmentFile, seqFile);
120 return runCommand(args);
124 * Imports the data from the temporary file to which the output of jackhmmer was
127 private void importData(File inputAlignmentTemp, File seqTemp,
128 File searchOutputFile) throws IOException, InterruptedException
130 BufferedReader br = new BufferedReader(
131 new FileReader(inputAlignmentTemp));
134 if (br.readLine() == null)
136 JOptionPane.showMessageDialog(af,
137 MessageManager.getString("label.no_sequences_found"));
140 StockholmFile file = new StockholmFile(new FileParse(
141 inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE));
142 seqs = file.getSeqsAsArray();
144 readDomainTable(searchOutputFile, true);
148 recoverSequences(sequencesHash, seqs);
153 int seqCount = seqs.length;
156 AlignmentI al = new Alignment(seqs);
158 AlignFrame alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
159 AlignFrame.DEFAULT_HEIGHT);
160 String ttl = "jackhmmer search of " + databaseName + " using "
162 Desktop.addInternalFrame(alignFrame, ttl, AlignFrame.DEFAULT_WIDTH,
163 AlignFrame.DEFAULT_HEIGHT);
166 inputAlignmentTemp.delete();
167 searchOutputFile.delete();