Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.hmmer

File Search.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

48
116
5
1
396
233
30
0.26
23.2
5
6

Classes

Class Line # Actions
22 116 30
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package jalview.hmmer;
2   
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;
12   
13    import java.io.BufferedReader;
14    import java.io.File;
15    import java.io.FileReader;
16    import java.io.IOException;
17    import java.util.Hashtable;
18    import java.util.List;
19    import java.util.Map;
20    import java.util.Scanner;
21   
 
22    public abstract class Search extends HmmerCommand
23    {
24   
25    static final String JACKHMMER = "jackhmmer";
26   
27    static final String HMMSEARCH = "hmmsearch";
28   
29    boolean realign = false;
30   
31    boolean trim = false;
32   
33    SequenceI[] seqs;
34   
35    String databaseName;
36   
37    boolean searchAlignment = true;
38   
39    Map<String, SequenceInfo> sequencesHash;
40   
 
41  0 toggle public Search(AlignFrame alignFrame, List<ArgumentI> args)
42    {
43  0 super(alignFrame, args);
44    }
45   
 
46  0 toggle @Override
47    public void run()
48    {
49    }
50   
51    /*
52    void readOutputFile(File inputTableTemp) throws IOException
53    {
54    BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
55   
56   
57    String line = "";
58    while (!line.startsWith("//"))
59    {
60   
61    while (!line.startsWith(">> ") && !line.startsWith("//"))
62    {
63    line = br.readLine();
64    }
65   
66    if (line.startsWith("//"))
67    {
68    break;
69    }
70   
71    Scanner scanner = new Scanner(line);
72    String name = scanner.next();
73    name = scanner.next();
74   
75    br.readLine();
76    br.readLine();
77   
78    List<SequenceI> domains = new ArrayList<>();
79   
80    for (SequenceI seq : seqs)
81    {
82    if (seq.getName().contains(name))
83    {
84    domains.add(seq);
85    }
86    }
87   
88    if (domains.contains(getSequence()))
89    {
90    domains.remove(getSequence());
91    }
92   
93    if (domains.size() > 0)
94    {
95    readOutputTable(br, domains);
96    }
97   
98    line = br.readLine();
99    }
100   
101    }
102   
103   
104    /**
105    * Reads in the scores table output by jackhmmer and adds annotation to
106    * sequences for E-value and bit score
107    *
108    * @param inputTableTemp
109    * @throws IOException
110    */
111    /*
112    void readOutputTable(BufferedReader br, List<SequenceI> seqs) throws IOException
113    {
114    String line = br.readLine();
115   
116    while (!"".equals(line) && line != null)
117    {
118    if (" ------ inclusion threshold ------".equals(line))
119    {
120    line = br.readLine();
121    continue;
122    }
123   
124    Scanner scanner = new Scanner(line);
125    scanner.next();
126    scanner.next();
127    String score = scanner.next();
128   
129    scanner.next();
130   
131    String evalue = scanner.next();
132   
133    scanner.next();
134    scanner.next();
135    scanner.next();
136    scanner.next();
137   
138    int start = scanner.nextInt();
139    int end = scanner.nextInt();
140   
141    SequenceI seq = null;
142    for (SequenceI sequence : seqs)
143    {
144    if (sequence.getStart() >= start && sequence.getEnd() <= end)
145    {
146    seq = sequence;
147    break;
148    }
149    }
150   
151    if (seq != null)
152    {
153    addScoreAnnotations(evalue, score, seq);
154    }
155   
156    scanner.close();
157    line = br.readLine();
158    }
159    }
160    */
161   
 
162  0 toggle void readDomainTable(File inputTableTemp, boolean includesQuery)
163    throws IOException
164    {
165  0 BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
166   
167  0 String line = br.readLine();
168  0 br.readLine();
169  0 br.readLine();
170  0 line = br.readLine();
171   
172  0 int index;
173   
174  0 if (includesQuery)
175    {
176  0 index = 1;
177    }
178    else
179    {
180  0 index = 0;
181    }
182  0 while (!line.startsWith("#"))
183    {
184  0 if (line.contains("inclusion threshold"))
185    {
186  0 line = br.readLine();
187  0 continue;
188    }
189   
190  0 Scanner scanner = new Scanner(line);
191  0 String name = scanner.next();
192   
193  0 for (int i = 0; i < 10; i++)
194    {
195  0 scanner.next();
196    }
197   
198  0 String evalue = scanner.next();
199  0 scanner.next();
200  0 String score = scanner.next();
201   
202  0 addScoreAnnotations(evalue, score, seqs[index]);
203  0 index++;
204   
205  0 scanner.close();
206  0 line = br.readLine();
207    }
208  0 br.close();
209    }
210   
211   
212   
213   
 
214  0 toggle void addScoreAnnotations(String eValue, String bitScore, SequenceI seq)
215    {
216  0 String label = "Search Scores";
217  0 String description = "Full sequence bit score and E-Value";
218   
219  0 try
220    {
221  0 AlignmentAnnotation annot = new AlignmentAnnotation(label,
222    description, null);
223   
224  0 annot.label = label;
225  0 annot.description = description;
226   
227  0 annot.setCalcId(JACKHMMER);
228   
229  0 double dEValue = Double.parseDouble(eValue);
230  0 annot.setEValue(dEValue);
231   
232  0 double dBitScore = Double.parseDouble(bitScore);
233  0 annot.setBitScore(dBitScore);
234   
235  0 annot.setSequenceRef(seq);
236  0 seq.addAlignmentAnnotation(annot);
237   
238    } catch (NumberFormatException e)
239    {
240  0 System.err.println("Error parsing " + label + " from " + eValue
241    + " & " + bitScore);
242    }
243    }
244   
 
245  0 toggle void buildArguments(List<String> args, File searchOutputFile,
246    File hitsAlignmentFile, File queryFile) throws IOException
247    {
248  0 args.add("--domtblout");
249  0 args.add(getFilePath(searchOutputFile, true));
250  0 args.add("-A");
251  0 args.add(getFilePath(hitsAlignmentFile, true));
252   
253  0 File databaseFile = null;
254   
255  0 boolean useEvalueCutoff = false;
256  0 boolean useScoreCutoff = false;
257  0 String seqReportingEvalueCutoff = null;
258  0 String domReportingEvalueCutoff = null;
259  0 String seqReportingScoreCutoff = null;
260  0 String domReportingScoreCutoff = null;
261  0 String seqInclusionEvalueCutoff = null;
262  0 String domInclusionEvalueCutoff = null;
263  0 String seqInclusionScoreCutoff = null;
264  0 String domInclusionScoreCutoff = null;
265  0 databaseName = "Alignment";
266   
267  0 if (params != null)
268    {
269  0 for (ArgumentI arg : params)
270    {
271  0 String name = arg.getName();
272   
273  0 if (MessageManager.getString(REPORTING_CUTOFF_KEY).equals(name))
274    {
275  0 if (MessageManager.getString(CUTOFF_EVALUE)
276    .equals(arg.getValue()))
277    {
278  0 useEvalueCutoff = true;
279    }
280  0 else if (MessageManager.getString(CUTOFF_SCORE)
281    .equals(arg.getValue()))
282    {
283  0 useScoreCutoff = true;
284    }
285    }
286  0 else if (MessageManager.getString(REPORTING_SEQ_EVALUE_KEY)
287    .equals(name))
288    {
289  0 seqReportingEvalueCutoff = arg.getValue();
290    }
291  0 else if (MessageManager.getString(REPORTING_SEQ_SCORE_KEY)
292    .equals(name))
293    {
294  0 seqReportingScoreCutoff = arg.getValue();
295    }
296  0 else if (MessageManager.getString(REPORTING_DOM_EVALUE_KEY)
297    .equals(name))
298    {
299  0 domReportingEvalueCutoff = arg.getValue();
300    }
301  0 else if (MessageManager.getString(REPORTING_DOM_SCORE_KEY)
302    .equals(name))
303    {
304  0 domReportingScoreCutoff = arg.getValue();
305    }
306  0 else if (MessageManager.getString(INCLUSION_SEQ_EVALUE_KEY)
307    .equals(name))
308    {
309  0 seqInclusionEvalueCutoff = arg.getValue();
310    }
311  0 else if (MessageManager.getString(INCLUSION_SEQ_SCORE_KEY)
312    .equals(name))
313    {
314  0 seqInclusionScoreCutoff = arg.getValue();
315    }
316  0 else if (MessageManager.getString(INCLUSION_DOM_EVALUE_KEY)
317    .equals(name))
318    {
319  0 domInclusionEvalueCutoff = arg.getValue();
320    }
321  0 else if (MessageManager.getString(INCLUSION_DOM_SCORE_KEY)
322    .equals(name))
323    {
324  0 domInclusionScoreCutoff = arg.getValue();
325    }
326  0 else if (MessageManager.getString(DATABASE_KEY).equals(name))
327    {
328  0 databaseFile = new File(arg.getValue());
329  0 if (!arg.getValue().isEmpty())
330    {
331  0 searchAlignment = false;
332    }
333    }
334  0 else if (MessageManager.getString(NUMBER_OF_ITERATIONS)
335    .equals(name))
336    {
337  0 if (!arg.getValue().isEmpty())
338    {
339  0 args.add("-N");
340  0 args.add(arg.getValue());
341    }
342    }
343    }
344    }
345   
346  0 if (useEvalueCutoff)
347    {
348  0 args.add("-E");
349  0 args.add(seqReportingEvalueCutoff);
350  0 args.add("--domE");
351  0 args.add(domReportingEvalueCutoff);
352   
353  0 args.add("--incE");
354  0 args.add(seqInclusionEvalueCutoff);
355  0 args.add("--incdomE");
356  0 args.add(domInclusionEvalueCutoff);
357    }
358  0 else if (useScoreCutoff)
359    {
360  0 args.add("-T");
361  0 args.add(seqReportingScoreCutoff);
362  0 args.add("--domT");
363  0 args.add(domReportingScoreCutoff);
364   
365  0 args.add("--incT");
366  0 args.add(seqInclusionEvalueCutoff);
367  0 args.add("--incdomT");
368  0 args.add(domInclusionEvalueCutoff);
369    }
370   
371    // if (!dbFound || MessageManager.getString(THIS_ALIGNMENT_KEY)
372    // .equals(dbPath))
373  0 if (searchAlignment)
374    {
375    /*
376    * no external database specified for search, so
377    * export current alignment as 'database' to search
378    */
379  0 databaseFile = FileUtils.createTempFile("database", ".sto");
380  0 AlignmentI al = af.getViewport().getAlignment();
381  0 AlignmentI copy = new Alignment(al);
382   
383  0 deleteHmmSequences(copy);
384   
385  0 if (searchAlignment)
386    {
387  0 sequencesHash = stashSequences(copy.getSequencesArray());
388    }
389   
390  0 exportStockholm(copy.getSequencesArray(), databaseFile, null);
391    }
392   
393  0 args.add(getFilePath(queryFile, true));
394  0 args.add(getFilePath(databaseFile, true));
395    }
396    }