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 (!" ------ inclusion threshold ------".equals(line)
76 Scanner scanner = new Scanner(line);
77 String evalue = scanner.next();
79 if (evalue.equals("+") || evalue.equals("-"))
81 evalue = scanner.next();
84 String score = scanner.next();
85 checkSequenceOrder(index, scanner);
86 SequenceI seq = seqs[index];
87 addScoreAnnotations(evalue, score, seq);
96 void checkSequenceOrder(int index, Scanner scanner)
98 String seqName = null;
100 for (int i = 0; i < 7; i++)
102 seqName = scanner.next();
105 if (!seqs[index].getName().equals(seqName))
107 SequenceI temp = seqs[index];
109 for (int j = 0; j < seqs.length; j++)
111 if (seqs[j].getName().equals(seqName))
113 seqs[index] = seqs[j];
121 void addScoreAnnotations(String eValue, String bitScore, SequenceI seq)
123 String label = "Search Scores";
124 String description = "Full sequence bit score and E-Value";
128 AlignmentAnnotation annot = new AlignmentAnnotation(label,
132 annot.description = description;
134 annot.setCalcId(JACKHMMER);
136 double dEValue = Double.parseDouble(eValue);
137 annot.setEValue(dEValue);
139 double dBitScore = Double.parseDouble(bitScore);
140 annot.setBitScore(dBitScore);
142 annot.setSequenceRef(seq);
143 seq.addAlignmentAnnotation(annot);
145 } catch (NumberFormatException e)
147 System.err.println("Error parsing " + label + " from " + eValue
152 void buildArguments(List<String> args, File searchOutputFile,
153 File hitsAlignmentFile, File queryFile) throws IOException
156 args.add(getFilePath(searchOutputFile, true));
158 args.add(getFilePath(hitsAlignmentFile, true));
160 File databaseFile = null;
162 boolean useEvalueCutoff = false;
163 boolean useScoreCutoff = false;
164 String seqReportingEvalueCutoff = null;
165 String domReportingEvalueCutoff = null;
166 String seqReportingScoreCutoff = null;
167 String domReportingScoreCutoff = null;
168 String seqInclusionEvalueCutoff = null;
169 String domInclusionEvalueCutoff = null;
170 String seqInclusionScoreCutoff = null;
171 String domInclusionScoreCutoff = null;
172 databaseName = "Alignment";
176 for (ArgumentI arg : params)
178 String name = arg.getName();
180 if (MessageManager.getString(REPORTING_CUTOFF_KEY).equals(name))
182 if (MessageManager.getString(CUTOFF_EVALUE)
183 .equals(arg.getValue()))
185 useEvalueCutoff = true;
187 else if (MessageManager.getString(CUTOFF_SCORE)
188 .equals(arg.getValue()))
190 useScoreCutoff = true;
193 else if (MessageManager.getString(REPORTING_SEQ_EVALUE_KEY)
196 seqReportingEvalueCutoff = arg.getValue();
198 else if (MessageManager.getString(REPORTING_SEQ_SCORE_KEY)
201 seqReportingScoreCutoff = arg.getValue();
203 else if (MessageManager.getString(REPORTING_DOM_EVALUE_KEY)
206 domReportingEvalueCutoff = arg.getValue();
208 else if (MessageManager.getString(REPORTING_DOM_SCORE_KEY)
211 domReportingScoreCutoff = arg.getValue();
213 else if (MessageManager.getString(INCLUSION_SEQ_EVALUE_KEY)
216 seqInclusionEvalueCutoff = arg.getValue();
218 else if (MessageManager.getString(INCLUSION_SEQ_SCORE_KEY)
221 seqInclusionScoreCutoff = arg.getValue();
223 else if (MessageManager.getString(INCLUSION_DOM_EVALUE_KEY)
226 domInclusionEvalueCutoff = arg.getValue();
228 else if (MessageManager.getString(INCLUSION_DOM_SCORE_KEY)
231 domInclusionScoreCutoff = arg.getValue();
233 else if (MessageManager.getString(DATABASE_KEY).equals(name))
235 databaseFile = new File(arg.getValue());
236 if (!arg.getValue().isEmpty())
238 searchAlignment = false;
247 args.add(seqReportingEvalueCutoff);
249 args.add(domReportingEvalueCutoff);
252 args.add(seqInclusionEvalueCutoff);
253 args.add("--incdomE");
254 args.add(domInclusionEvalueCutoff);
256 else if (useScoreCutoff)
259 args.add(seqReportingScoreCutoff);
261 args.add(domReportingScoreCutoff);
264 args.add(seqInclusionEvalueCutoff);
265 args.add("--incdomT");
266 args.add(domInclusionEvalueCutoff);
269 // if (!dbFound || MessageManager.getString(THIS_ALIGNMENT_KEY)
274 * no external database specified for search, so
275 * export current alignment as 'database' to search
277 databaseFile = FileUtils.createTempFile("database", ".sto");
278 AlignmentI al = af.getViewport().getAlignment();
279 AlignmentI copy = new Alignment(al);
281 deleteHmmSequences(copy);
285 sequencesHash = stashSequences(copy.getSequencesArray());
288 exportStockholm(copy.getSequencesArray(), databaseFile, null);
291 args.add(getFilePath(queryFile, true));
292 args.add(getFilePath(databaseFile, true));