3 import jalview.datamodel.Alignment;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.SequenceI;
7 import jalview.gui.AlignFrame;
8 import jalview.util.FileUtils;
9 import jalview.util.MessageManager;
10 import jalview.ws.params.ArgumentI;
12 import java.io.BufferedReader;
14 import java.io.FileReader;
15 import java.io.IOException;
16 import java.util.Hashtable;
17 import java.util.List;
18 import java.util.Scanner;
20 public abstract class Search extends HmmerCommand
23 static final String JACKHMMER = "jackhmmer";
25 static final String HMMSEARCH = "hmmsearch";
27 boolean realign = false;
35 boolean searchAlignment = true;
37 Hashtable sequencesHash;
39 public Search(AlignFrame alignFrame, List<ArgumentI> args)
41 super(alignFrame, args);
50 void readOutputFile(File inputTableTemp) throws IOException
52 BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
56 while (!line.startsWith("//"))
59 while (!line.startsWith(">> ") && !line.startsWith("//"))
64 if (line.startsWith("//"))
69 Scanner scanner = new Scanner(line);
70 String name = scanner.next();
71 name = scanner.next();
76 List<SequenceI> domains = new ArrayList<>();
78 for (SequenceI seq : seqs)
80 if (seq.getName().contains(name))
86 if (domains.contains(getSequence()))
88 domains.remove(getSequence());
91 if (domains.size() > 0)
93 readOutputTable(br, domains);
103 * Reads in the scores table output by jackhmmer and adds annotation to
104 * sequences for E-value and bit score
106 * @param inputTableTemp
107 * @throws IOException
110 void readOutputTable(BufferedReader br, List<SequenceI> seqs) throws IOException
112 String line = br.readLine();
114 while (!"".equals(line) && line != null)
116 if (" ------ inclusion threshold ------".equals(line))
118 line = br.readLine();
122 Scanner scanner = new Scanner(line);
125 String score = scanner.next();
129 String evalue = scanner.next();
136 int start = scanner.nextInt();
137 int end = scanner.nextInt();
139 SequenceI seq = null;
140 for (SequenceI sequence : seqs)
142 if (sequence.getStart() >= start && sequence.getEnd() <= end)
151 addScoreAnnotations(evalue, score, seq);
155 line = br.readLine();
160 void readDomainTable(File inputTableTemp, boolean includesQuery)
163 BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
165 String line = br.readLine();
168 line = br.readLine();
180 while (!line.startsWith("#"))
182 if (line.contains("inclusion threshold"))
184 line = br.readLine();
188 Scanner scanner = new Scanner(line);
189 String name = scanner.next();
191 for (int i = 0; i < 10; i++)
196 String evalue = scanner.next();
198 String score = scanner.next();
200 addScoreAnnotations(evalue, score, seqs[index]);
204 line = br.readLine();
212 void addScoreAnnotations(String eValue, String bitScore, SequenceI seq)
214 String label = "Search Scores";
215 String description = "Full sequence bit score and E-Value";
219 AlignmentAnnotation annot = new AlignmentAnnotation(label,
223 annot.description = description;
225 annot.setCalcId(JACKHMMER);
227 double dEValue = Double.parseDouble(eValue);
228 annot.setEValue(dEValue);
230 double dBitScore = Double.parseDouble(bitScore);
231 annot.setBitScore(dBitScore);
233 annot.setSequenceRef(seq);
234 seq.addAlignmentAnnotation(annot);
236 } catch (NumberFormatException e)
238 System.err.println("Error parsing " + label + " from " + eValue
243 void buildArguments(List<String> args, File searchOutputFile,
244 File hitsAlignmentFile, File queryFile) throws IOException
246 args.add("--domtblout");
247 args.add(getFilePath(searchOutputFile, true));
249 args.add(getFilePath(hitsAlignmentFile, true));
251 File databaseFile = null;
253 boolean useEvalueCutoff = false;
254 boolean useScoreCutoff = false;
255 String seqReportingEvalueCutoff = null;
256 String domReportingEvalueCutoff = null;
257 String seqReportingScoreCutoff = null;
258 String domReportingScoreCutoff = null;
259 String seqInclusionEvalueCutoff = null;
260 String domInclusionEvalueCutoff = null;
261 String seqInclusionScoreCutoff = null;
262 String domInclusionScoreCutoff = null;
263 databaseName = "Alignment";
267 for (ArgumentI arg : params)
269 String name = arg.getName();
271 if (MessageManager.getString(REPORTING_CUTOFF_KEY).equals(name))
273 if (MessageManager.getString(CUTOFF_EVALUE)
274 .equals(arg.getValue()))
276 useEvalueCutoff = true;
278 else if (MessageManager.getString(CUTOFF_SCORE)
279 .equals(arg.getValue()))
281 useScoreCutoff = true;
284 else if (MessageManager.getString(REPORTING_SEQ_EVALUE_KEY)
287 seqReportingEvalueCutoff = arg.getValue();
289 else if (MessageManager.getString(REPORTING_SEQ_SCORE_KEY)
292 seqReportingScoreCutoff = arg.getValue();
294 else if (MessageManager.getString(REPORTING_DOM_EVALUE_KEY)
297 domReportingEvalueCutoff = arg.getValue();
299 else if (MessageManager.getString(REPORTING_DOM_SCORE_KEY)
302 domReportingScoreCutoff = arg.getValue();
304 else if (MessageManager.getString(INCLUSION_SEQ_EVALUE_KEY)
307 seqInclusionEvalueCutoff = arg.getValue();
309 else if (MessageManager.getString(INCLUSION_SEQ_SCORE_KEY)
312 seqInclusionScoreCutoff = arg.getValue();
314 else if (MessageManager.getString(INCLUSION_DOM_EVALUE_KEY)
317 domInclusionEvalueCutoff = arg.getValue();
319 else if (MessageManager.getString(INCLUSION_DOM_SCORE_KEY)
322 domInclusionScoreCutoff = arg.getValue();
324 else if (MessageManager.getString(DATABASE_KEY).equals(name))
326 databaseFile = new File(arg.getValue());
327 if (!arg.getValue().isEmpty())
329 searchAlignment = false;
332 else if (MessageManager.getString(NUMBER_OF_ITERATIONS)
335 if (!arg.getValue().isEmpty())
338 args.add(arg.getValue());
347 args.add(seqReportingEvalueCutoff);
349 args.add(domReportingEvalueCutoff);
352 args.add(seqInclusionEvalueCutoff);
353 args.add("--incdomE");
354 args.add(domInclusionEvalueCutoff);
356 else if (useScoreCutoff)
359 args.add(seqReportingScoreCutoff);
361 args.add(domReportingScoreCutoff);
364 args.add(seqInclusionEvalueCutoff);
365 args.add("--incdomT");
366 args.add(domInclusionEvalueCutoff);
369 // if (!dbFound || MessageManager.getString(THIS_ALIGNMENT_KEY)
374 * no external database specified for search, so
375 * export current alignment as 'database' to search
377 databaseFile = FileUtils.createTempFile("database", ".sto");
378 AlignmentI al = af.getViewport().getAlignment();
379 AlignmentI copy = new Alignment(al);
381 deleteHmmSequences(copy);
385 sequencesHash = stashSequences(copy.getSequencesArray());
388 exportStockholm(copy.getSequencesArray(), databaseFile, null);
391 args.add(getFilePath(queryFile, true));
392 args.add(getFilePath(databaseFile, true));