3 import jalview.analysis.SeqsetUtils.SequenceInfo;
4 import jalview.datamodel.Alignment;
5 import jalview.datamodel.AlignmentAnnotation;
6 import jalview.datamodel.AlignmentI;
7 import jalview.datamodel.SequenceI;
8 import jalview.gui.AlignFrame;
9 import jalview.util.FileUtils;
10 import jalview.util.MessageManager;
11 import jalview.ws.params.ArgumentI;
13 import java.io.BufferedReader;
15 import java.io.FileReader;
16 import java.io.IOException;
17 import java.util.Hashtable;
18 import java.util.List;
20 import java.util.Scanner;
22 public abstract class Search extends HmmerCommand
25 static final String JACKHMMER = "jackhmmer";
27 static final String HMMSEARCH = "hmmsearch";
29 boolean realign = false;
37 boolean searchAlignment = true;
39 Map<String, SequenceInfo> sequencesHash;
41 public Search(AlignFrame alignFrame, List<ArgumentI> args)
43 super(alignFrame, args);
52 void readOutputFile(File inputTableTemp) throws IOException
54 BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
58 while (!line.startsWith("//"))
61 while (!line.startsWith(">> ") && !line.startsWith("//"))
66 if (line.startsWith("//"))
71 Scanner scanner = new Scanner(line);
72 String name = scanner.next();
73 name = scanner.next();
78 List<SequenceI> domains = new ArrayList<>();
80 for (SequenceI seq : seqs)
82 if (seq.getName().contains(name))
88 if (domains.contains(getSequence()))
90 domains.remove(getSequence());
93 if (domains.size() > 0)
95 readOutputTable(br, domains);
105 * Reads in the scores table output by jackhmmer and adds annotation to
106 * sequences for E-value and bit score
108 * @param inputTableTemp
109 * @throws IOException
112 void readOutputTable(BufferedReader br, List<SequenceI> seqs) throws IOException
114 String line = br.readLine();
116 while (!"".equals(line) && line != null)
118 if (" ------ inclusion threshold ------".equals(line))
120 line = br.readLine();
124 Scanner scanner = new Scanner(line);
127 String score = scanner.next();
131 String evalue = scanner.next();
138 int start = scanner.nextInt();
139 int end = scanner.nextInt();
141 SequenceI seq = null;
142 for (SequenceI sequence : seqs)
144 if (sequence.getStart() >= start && sequence.getEnd() <= end)
153 addScoreAnnotations(evalue, score, seq);
157 line = br.readLine();
162 void readDomainTable(File inputTableTemp, boolean includesQuery)
165 BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
167 String line = br.readLine();
170 line = br.readLine();
182 while (!line.startsWith("#"))
184 if (line.contains("inclusion threshold"))
186 line = br.readLine();
190 Scanner scanner = new Scanner(line);
191 String name = scanner.next();
193 for (int i = 0; i < 10; i++)
198 String evalue = scanner.next();
200 String score = scanner.next();
202 addScoreAnnotations(evalue, score, seqs[index]);
206 line = br.readLine();
214 void addScoreAnnotations(String eValue, String bitScore, SequenceI seq)
216 String label = "Search Scores";
217 String description = "Full sequence bit score and E-Value";
221 AlignmentAnnotation annot = new AlignmentAnnotation(label,
225 annot.description = description;
227 annot.setCalcId(JACKHMMER);
229 double dEValue = Double.parseDouble(eValue);
230 annot.setEValue(dEValue);
232 double dBitScore = Double.parseDouble(bitScore);
233 annot.setBitScore(dBitScore);
235 annot.setSequenceRef(seq);
236 seq.addAlignmentAnnotation(annot);
238 } catch (NumberFormatException e)
240 System.err.println("Error parsing " + label + " from " + eValue
245 void buildArguments(List<String> args, File searchOutputFile,
246 File hitsAlignmentFile, File queryFile) throws IOException
248 args.add("--domtblout");
249 args.add(getFilePath(searchOutputFile, true));
251 args.add(getFilePath(hitsAlignmentFile, true));
253 File databaseFile = null;
255 boolean useEvalueCutoff = false;
256 boolean useScoreCutoff = false;
257 String seqReportingEvalueCutoff = null;
258 String domReportingEvalueCutoff = null;
259 String seqReportingScoreCutoff = null;
260 String domReportingScoreCutoff = null;
261 String seqInclusionEvalueCutoff = null;
262 String domInclusionEvalueCutoff = null;
263 String seqInclusionScoreCutoff = null;
264 String domInclusionScoreCutoff = null;
265 databaseName = "Alignment";
269 for (ArgumentI arg : params)
271 String name = arg.getName();
273 if (MessageManager.getString(REPORTING_CUTOFF_KEY).equals(name))
275 if (MessageManager.getString(CUTOFF_EVALUE)
276 .equals(arg.getValue()))
278 useEvalueCutoff = true;
280 else if (MessageManager.getString(CUTOFF_SCORE)
281 .equals(arg.getValue()))
283 useScoreCutoff = true;
286 else if (MessageManager.getString(REPORTING_SEQ_EVALUE_KEY)
289 seqReportingEvalueCutoff = arg.getValue();
291 else if (MessageManager.getString(REPORTING_SEQ_SCORE_KEY)
294 seqReportingScoreCutoff = arg.getValue();
296 else if (MessageManager.getString(REPORTING_DOM_EVALUE_KEY)
299 domReportingEvalueCutoff = arg.getValue();
301 else if (MessageManager.getString(REPORTING_DOM_SCORE_KEY)
304 domReportingScoreCutoff = arg.getValue();
306 else if (MessageManager.getString(INCLUSION_SEQ_EVALUE_KEY)
309 seqInclusionEvalueCutoff = arg.getValue();
311 else if (MessageManager.getString(INCLUSION_SEQ_SCORE_KEY)
314 seqInclusionScoreCutoff = arg.getValue();
316 else if (MessageManager.getString(INCLUSION_DOM_EVALUE_KEY)
319 domInclusionEvalueCutoff = arg.getValue();
321 else if (MessageManager.getString(INCLUSION_DOM_SCORE_KEY)
324 domInclusionScoreCutoff = arg.getValue();
326 else if (MessageManager.getString(DATABASE_KEY).equals(name))
328 databaseFile = new File(arg.getValue());
329 if (!arg.getValue().isEmpty())
331 searchAlignment = false;
334 else if (MessageManager.getString(NUMBER_OF_ITERATIONS)
337 if (!arg.getValue().isEmpty())
340 args.add(arg.getValue());
349 args.add(seqReportingEvalueCutoff);
351 args.add(domReportingEvalueCutoff);
354 args.add(seqInclusionEvalueCutoff);
355 args.add("--incdomE");
356 args.add(domInclusionEvalueCutoff);
358 else if (useScoreCutoff)
361 args.add(seqReportingScoreCutoff);
363 args.add(domReportingScoreCutoff);
366 args.add(seqInclusionEvalueCutoff);
367 args.add("--incdomT");
368 args.add(domInclusionEvalueCutoff);
371 // if (!dbFound || MessageManager.getString(THIS_ALIGNMENT_KEY)
376 * no external database specified for search, so
377 * export current alignment as 'database' to search
379 databaseFile = FileUtils.createTempFile("database", ".sto");
380 AlignmentI al = af.getViewport().getAlignment();
381 AlignmentI copy = new Alignment(al);
383 deleteHmmSequences(copy);
387 sequencesHash = stashSequences(copy.getSequencesArray());
390 exportStockholm(copy.getSequencesArray(), databaseFile, null);
393 args.add(getFilePath(queryFile, true));
394 args.add(getFilePath(databaseFile, true));