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 * Reads in the scores table output by jackhmmer and adds annotation to
51 * sequences for E-value and bit score
53 * @param inputTableTemp
56 void readTable(File inputTableTemp) throws IOException
58 BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
60 while (!line.startsWith("Query:"))
64 while (!line.contains("-------"))
72 while (!"".equals(line) && line != null)
74 if (" ------ inclusion threshold ------".equals(line))
80 Scanner scanner = new Scanner(line);
81 String evalue = scanner.next();
83 if (evalue.equals("+") || evalue.equals("-"))
85 evalue = scanner.next();
89 String score = scanner.next();
90 checkSequenceOrder(index, scanner);
91 SequenceI seq = seqs[index];
92 addScoreAnnotations(evalue, score, seq);
101 void checkSequenceOrder(int index, Scanner scanner)
103 String seqName = null;
105 for (int i = 0; i < 7; i++)
107 seqName = scanner.next();
110 if (!seqs[index].getName().equals(seqName))
112 SequenceI temp = seqs[index];
114 for (int j = 0; j < seqs.length; j++)
116 if (seqs[j].getName().equals(seqName))
118 seqs[index] = seqs[j];
126 void addScoreAnnotations(String eValue, String bitScore, SequenceI seq)
128 String label = "Search Scores";
129 String description = "Full sequence bit score and E-Value";
133 AlignmentAnnotation annot = new AlignmentAnnotation(label,
137 annot.description = description;
139 annot.setCalcId(JACKHMMER);
141 double dEValue = Double.parseDouble(eValue);
142 annot.setEValue(dEValue);
144 double dBitScore = Double.parseDouble(bitScore);
145 annot.setBitScore(dBitScore);
147 annot.setSequenceRef(seq);
148 seq.addAlignmentAnnotation(annot);
150 } catch (NumberFormatException e)
152 System.err.println("Error parsing " + label + " from " + eValue
157 void buildArguments(List<String> args, File searchOutputFile,
158 File hitsAlignmentFile, File queryFile) throws IOException
161 args.add(getFilePath(searchOutputFile, true));
163 args.add(getFilePath(hitsAlignmentFile, true));
165 File databaseFile = null;
167 boolean useEvalueCutoff = false;
168 boolean useScoreCutoff = false;
169 String seqReportingEvalueCutoff = null;
170 String domReportingEvalueCutoff = null;
171 String seqReportingScoreCutoff = null;
172 String domReportingScoreCutoff = null;
173 String seqInclusionEvalueCutoff = null;
174 String domInclusionEvalueCutoff = null;
175 String seqInclusionScoreCutoff = null;
176 String domInclusionScoreCutoff = null;
177 databaseName = "Alignment";
181 for (ArgumentI arg : params)
183 String name = arg.getName();
185 if (MessageManager.getString(REPORTING_CUTOFF_KEY).equals(name))
187 if (MessageManager.getString(CUTOFF_EVALUE)
188 .equals(arg.getValue()))
190 useEvalueCutoff = true;
192 else if (MessageManager.getString(CUTOFF_SCORE)
193 .equals(arg.getValue()))
195 useScoreCutoff = true;
198 else if (MessageManager.getString(REPORTING_SEQ_EVALUE_KEY)
201 seqReportingEvalueCutoff = arg.getValue();
203 else if (MessageManager.getString(REPORTING_SEQ_SCORE_KEY)
206 seqReportingScoreCutoff = arg.getValue();
208 else if (MessageManager.getString(REPORTING_DOM_EVALUE_KEY)
211 domReportingEvalueCutoff = arg.getValue();
213 else if (MessageManager.getString(REPORTING_DOM_SCORE_KEY)
216 domReportingScoreCutoff = arg.getValue();
218 else if (MessageManager.getString(INCLUSION_SEQ_EVALUE_KEY)
221 seqInclusionEvalueCutoff = arg.getValue();
223 else if (MessageManager.getString(INCLUSION_SEQ_SCORE_KEY)
226 seqInclusionScoreCutoff = arg.getValue();
228 else if (MessageManager.getString(INCLUSION_DOM_EVALUE_KEY)
231 domInclusionEvalueCutoff = arg.getValue();
233 else if (MessageManager.getString(INCLUSION_DOM_SCORE_KEY)
236 domInclusionScoreCutoff = arg.getValue();
238 else if (MessageManager.getString(DATABASE_KEY).equals(name))
240 databaseFile = new File(arg.getValue());
241 if (!arg.getValue().isEmpty())
243 searchAlignment = false;
252 args.add(seqReportingEvalueCutoff);
254 args.add(domReportingEvalueCutoff);
257 args.add(seqInclusionEvalueCutoff);
258 args.add("--incdomE");
259 args.add(domInclusionEvalueCutoff);
261 else if (useScoreCutoff)
264 args.add(seqReportingScoreCutoff);
266 args.add(domReportingScoreCutoff);
269 args.add(seqInclusionEvalueCutoff);
270 args.add("--incdomT");
271 args.add(domInclusionEvalueCutoff);
274 // if (!dbFound || MessageManager.getString(THIS_ALIGNMENT_KEY)
279 * no external database specified for search, so
280 * export current alignment as 'database' to search
282 databaseFile = FileUtils.createTempFile("database", ".sto");
283 AlignmentI al = af.getViewport().getAlignment();
284 AlignmentI copy = new Alignment(al);
286 deleteHmmSequences(copy);
290 sequencesHash = stashSequences(copy.getSequencesArray());
293 exportStockholm(copy.getSequencesArray(), databaseFile, null);
296 args.add(getFilePath(queryFile, true));
297 args.add(getFilePath(databaseFile, true));