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
30 * Constructor for the JackhmmerThread
34 public JackHMMER(AlignFrame af, List<ArgumentI> args)
40 * Runs the JackhmmerThread: the data on the alignment or group is exported,
41 * then the command is executed in the command line and then the data is
42 * imported and displayed in a new frame. Call this method directly to execute
43 * synchronously, or via start() in a new Thread for asynchronously.
48 SequenceI seq = getSequence();
51 // shouldn't happen if we got this far
52 Cache.log.error("Error: no sequence for jackhmmer");
56 long msgId = System.currentTimeMillis();
57 af.setProgressBar(MessageManager.getString("status.running_search"),
62 File seqFile = FileUtils.createTempFile("seq", ".sto");
63 File hitsAlignmentFile = FileUtils.createTempFile("hitAlignment",
65 File searchOutputFile = FileUtils.createTempFile("searchOutput",
68 exportStockholm(new SequenceI[] { seq }, seqFile.getAbsoluteFile(),
71 boolean ran = runCommand(searchOutputFile, hitsAlignmentFile,
75 JvOptionPane.showInternalMessageDialog(af, MessageManager
76 .formatMessage("warn.command_failed", "jackhmmer"));
80 importData(hitsAlignmentFile, seqFile, searchOutputFile);
81 // TODO make realignment of search results a step at this level
82 // and make it conditional on this.realign
83 } catch (IOException | InterruptedException e)
88 af.setProgressBar("", msgId);
93 * Executes an jackhmmer search with the given sequence as input. The database
94 * to be searched is a local file as specified by the 'Database' parameter, or
95 * the current alignment (written to file) if none is specified.
97 * @param searchOutputFile
98 * @param hitsAlignmentFile
102 * @throws IOException
104 private boolean runCommand(File searchOutputFile, File hitsAlignmentFile,
105 File seqFile) throws IOException
107 String command = getCommandPath(JACKHMMER);
113 List<String> args = new ArrayList<>();
115 buildArguments(args, searchOutputFile, hitsAlignmentFile, seqFile);
117 return runCommand(args);
121 * Imports the data from the temporary file to which the output of jackhmmer was
124 private void importData(File inputAlignmentTemp, File seqTemp,
125 File searchOutputFile) throws IOException, InterruptedException
127 BufferedReader br = new BufferedReader(
128 new FileReader(inputAlignmentTemp));
131 if (br.readLine() == null)
133 JOptionPane.showMessageDialog(af,
134 MessageManager.getString("label.no_sequences_found"));
137 StockholmFile file = new StockholmFile(new FileParse(
138 inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE));
139 seqs = file.getSeqsAsArray();
143 recoverSequences(sequencesHash, seqs);
146 readTable(searchOutputFile);
148 int seqCount = seqs.length;
150 AlignmentI al = new Alignment(seqs);
152 AlignFrame alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
153 AlignFrame.DEFAULT_HEIGHT);
154 String ttl = "jackhmmer search of " + databaseName + " using "
156 Desktop.addInternalFrame(alignFrame, ttl, AlignFrame.DEFAULT_WIDTH,
157 AlignFrame.DEFAULT_HEIGHT);
160 inputAlignmentTemp.delete();
161 searchOutputFile.delete();