Clover icon

Coverage Report

  1. Project Clover database Wed Dec 3 2025 17:03:17 GMT
  2. Package jalview.hmmer

File JackHMMER.java

 

Coverage histogram

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

Code metrics

12
46
4
1
180
121
11
0.24
11.5
4
2.75

Classes

Class Line # Actions
JackHMMER 27 46 11
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package jalview.hmmer;
2   
3    import jalview.bin.Cache;
4    import jalview.bin.Console;
5    import jalview.datamodel.Alignment;
6    import jalview.datamodel.AlignmentI;
7    import jalview.datamodel.SequenceI;
8    import jalview.gui.AlignFrame;
9    import jalview.gui.Desktop;
10    import jalview.gui.JvOptionPane;
11    import jalview.io.DataSourceType;
12    import jalview.io.FileParse;
13    import jalview.io.StockholmFile;
14    import jalview.util.FileUtils;
15    import jalview.util.MessageManager;
16    import jalview.ws.params.ArgumentI;
17   
18    import java.io.BufferedReader;
19    import java.io.File;
20    import java.io.FileReader;
21    import java.io.IOException;
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import javax.swing.JOptionPane;
26   
 
27    public class JackHMMER extends Search
28    {
29   
30    SequenceI seq = null;
31   
32    /**
33    * Constructor for the JackhmmerThread
34    *
35    * @param af
36    */
 
37  0 toggle public JackHMMER(AlignFrame af, List<ArgumentI> args)
38    {
39  0 super(af, args);
40    }
41   
42    /**
43    * Runs the JackhmmerThread: the data on the alignment or group is exported,
44    * then the command is executed in the command line and then the data is
45    * imported and displayed in a new frame. Call this method directly to execute
46    * synchronously, or via start() in a new Thread for asynchronously.
47    */
 
48  0 toggle @Override
49    public void run()
50    {
51  0 seq = getSequence();
52  0 if (seq == null)
53    {
54    // shouldn't happen if we got this far
55  0 Console.error("Error: no sequence for jackhmmer");
56  0 return;
57    }
58   
59  0 long msgId = System.currentTimeMillis();
60  0 af.setProgressBar(MessageManager.getString("status.running_search"),
61    msgId);
62   
63  0 try
64    {
65  0 File seqFile = FileUtils.createTempFile("seq", ".sto");
66  0 File hitsAlignmentFile = FileUtils.createTempFile("hitAlignment",
67    ".sto");
68  0 File searchOutputFile = FileUtils.createTempFile("searchOutput",
69    ".txt");
70   
71  0 exportStockholm(new SequenceI[] { seq }, seqFile.getAbsoluteFile(),
72    null);
73   
74  0 boolean ran = runCommand(searchOutputFile, hitsAlignmentFile,
75    seqFile);
76  0 if (!ran)
77    {
78  0 JvOptionPane.showInternalMessageDialog(af, MessageManager
79    .formatMessage("warn.command_failed", "jackhmmer"));
80  0 return;
81    }
82   
83  0 importData(hitsAlignmentFile, seqFile, searchOutputFile);
84    // TODO make realignment of search results a step at this level
85    // and make it conditional on this.realign
86    } catch (IOException | InterruptedException e)
87    {
88  0 e.printStackTrace();
89    } finally
90    {
91  0 af.setProgressBar("", msgId);
92    }
93    }
94   
95    /**
96    * Executes an jackhmmer search with the given sequence as input. The database
97    * to be searched is a local file as specified by the 'Database' parameter, or
98    * the current alignment (written to file) if none is specified.
99    *
100    * @param searchOutputFile
101    * @param hitsAlignmentFile
102    * @param seqFile
103    *
104    * @return
105    * @throws IOException
106    */
 
107  0 toggle private boolean runCommand(File searchOutputFile, File hitsAlignmentFile,
108    File seqFile) throws IOException
109    {
110  0 String command = getCommandPath(JACKHMMER);
111  0 if (command == null)
112    {
113  0 return false;
114    }
115   
116  0 List<String> args = new ArrayList<>();
117  0 args.add(command);
118  0 buildArguments(args, searchOutputFile, hitsAlignmentFile, seqFile);
119   
120  0 return runCommand(args);
121    }
122   
123    /**
124    * Imports the data from the temporary file to which the output of jackhmmer was
125    * directed.
126    */
 
127  0 toggle private void importData(File inputAlignmentTemp, File seqTemp,
128    File searchOutputFile) throws IOException, InterruptedException
129    {
130  0 BufferedReader br = new BufferedReader(
131    new FileReader(inputAlignmentTemp));
132  0 try
133    {
134  0 if (br.readLine() == null)
135    {
136  0 JOptionPane.showMessageDialog(af,
137    MessageManager.getString("label.no_sequences_found"));
138  0 return;
139    }
140  0 StockholmFile file = new StockholmFile(new FileParse(
141    inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE));
142  0 seqs = file.getSeqsAsArray();
143   
144  0 readDomainTable(searchOutputFile, true);
145   
146  0 if (searchAlignment)
147    {
148  0 recoverSequences(sequencesHash, seqs);
149    }
150   
151   
152   
153  0 int seqCount = seqs.length;
154   
155   
156  0 AlignmentI al = new Alignment(seqs);
157   
158  0 AlignFrame alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
159    AlignFrame.DEFAULT_HEIGHT);
160  0 String ttl = "jackhmmer search of " + databaseName + " using "
161    + seqs[0].getName();
162  0 Desktop.addInternalFrame(alignFrame, ttl, AlignFrame.DEFAULT_WIDTH,
163    AlignFrame.DEFAULT_HEIGHT);
164   
165  0 seqTemp.delete();
166  0 inputAlignmentTemp.delete();
167  0 searchOutputFile.delete();
168    } finally
169    {
170  0 if (br != null)
171    {
172  0 br.close();
173    }
174    }
175    }
176   
177   
178   
179   
180    }