package jalview.hmmer;
-import jalview.bin.Cache;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
import jalview.gui.JvOptionPane;
-import jalview.gui.Preferences;
import jalview.io.DataSourceType;
import jalview.io.FileParse;
import jalview.io.StockholmFile;
import javax.swing.JOptionPane;
-public class HMMSearchThread implements Runnable
+public class HMMSearchThread extends HmmerCommand implements Runnable
{
- /**
+ static final String HMMSEARCH = "hmmsearch";
+
+ /*
* feature settings from view that job was associated with
*/
protected FeatureRendererSettings featureSettings = null;
- /**
- * Object containing frequently used commands.
- */
- HMMERCommands cmds = new HMMERCommands();
+ HiddenMarkovModel hmm;
- AlignFrame af;
+ boolean newFrame;
- HiddenMarkovModel hmm;
+ boolean realign = false;
- boolean newFrame, realign = false, trim = false;
+ boolean trim = false;
Integer numberOfSequences = null;
long barID;
- SequenceI hmmSeq;
-
List<ArgumentI> params;
File hmmTemp = null;
File databaseFile = null;
-
-
SequenceI[] seqs;
-
/**
* Constructor for the HMMSearchThread. If create new frame is set to true, a
* new frame will be created.
hmm = af.getSelectedHMM();
}
- hmmSeq = af.getSelectedHMMSequence();
+ SequenceI hmmSeq = af.getSelectedHMMSequence();
barID = System.currentTimeMillis();
af.setProgressBar(MessageManager.getString("status.running_hmmsearch"),
barID);
- cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
try
{
}
try
{
- cmds.exportData(null, null, hmm, hmmTemp.getAbsoluteFile(), null);
+ exportData(null, null, hmm, hmmTemp.getAbsoluteFile(), null);
} catch (IOException e1)
{
e1.printStackTrace();
}
try
{
- importData();
+ importData(hmmSeq);
} catch (IOException | InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
- af.setProgressBar(MessageManager.getString("status.running_hmmsearch"),
- barID);
+ af.setProgressBar("", barID);
}
*/
private boolean runCommand() throws IOException, InterruptedException
{
- Boolean dbFound = false;
- String dbPath = "";
- File file = new File(cmds.HMMERFOLDER + "/hmmsearch");
- if (!file.canExecute())
+ String binaryPath = getCommandRoot(HMMSEARCH);
+ if (binaryPath == null)
{
- file = new File(cmds.HMMERFOLDER + "/hmmsearch.exe");
- {
- if (!file.canExecute())
- {
- return false;
- }
- }
+ return false;
}
- String command = cmds.HMMERFOLDER + "/hmmsearch -o "
+ String command = binaryPath + " -o "
+ inputTableTemp.getAbsolutePath() + " -A "
- + inputAlignmentTemp.getAbsolutePath() + cmds.SPACE;
+ + inputAlignmentTemp.getAbsolutePath() + SPACE;
+
+ boolean dbFound = false;
+ String dbPath = "";
if (params != null)
{
for (ArgumentI arg : params)
}
break;
case "Sequence E-value Cutoff":
- command += "--incE " + arg.getValue() + cmds.SPACE;
+ command += "--incE " + arg.getValue() + SPACE;
break;
case "Sequence Score Threshold":
- command += "-incT " + arg.getValue() + cmds.SPACE;
+ command += "-incT " + arg.getValue() + SPACE;
break;
case "Domain E-value Threshold":
- command += "--incdomE " + arg.getValue() + cmds.SPACE;
+ command += "--incdomE " + arg.getValue() + SPACE;
break;
case "Domain Score Threshold":
- command += "--incdomT " + arg.getValue() + cmds.SPACE;
+ command += "--incdomT " + arg.getValue() + SPACE;
break;
case "Trim Non-Matching Termini":
trim = true;
}
}
- if (dbFound == false || MessageManager.getString("label.this_alignment")
+ if (!dbFound || MessageManager.getString("label.this_alignment")
.equals(dbPath))
{
AlignmentI alignment = af.getViewport().getAlignment();
AlignmentI copy = new Alignment(alignment);
- copy.getHMMConsensusSequences(true);
+ List<SequenceI> hmms = copy.getHMMConsensusSequences();
+ for (SequenceI seq : hmms)
+ {
+ copy.deleteSequence(seq);
+ }
StockholmFile stoFile = new StockholmFile(copy);
stoFile.setSeqs(copy.getSequencesArray());
String alignmentString = stoFile.print();
writer.close();
}
- command += hmmTemp.getAbsolutePath() + cmds.SPACE
+ command += hmmTemp.getAbsolutePath() + SPACE
+ databaseFile.getAbsolutePath();
- return cmds.runCommand(command);
+ return runCommand(command);
}
/**
* Imports the data from the temporary file to which the output of hmmsearch
* is directed.
+ *
+ * @param hmmSeq
*/
- private void importData() throws IOException, InterruptedException
+ private void importData(SequenceI hmmSeq)
+ throws IOException, InterruptedException
{
BufferedReader br = new BufferedReader(
new FileReader(inputAlignmentTemp));
- if (br.readLine() == null)
+ try
{
- JOptionPane.showMessageDialog(af,
- MessageManager.getString("label.no_sequences_found"));
- return;
- }
- StockholmFile file = new StockholmFile(new FileParse(
- inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE));
- seqs = file.getSeqsAsArray();
+ if (br.readLine() == null)
+ {
+ JOptionPane.showMessageDialog(af,
+ MessageManager.getString("label.no_sequences_found"));
+ return;
+ }
+ StockholmFile file = new StockholmFile(new FileParse(
+ inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE));
+ seqs = file.getSeqsAsArray();
- readTable();
+ readTable();
- SequenceI[] hmmAndSeqs;
- if (numberOfSequences != null && numberOfSequences < seqs.length)
- {
- hmmAndSeqs = new SequenceI[numberOfSequences + 1];
- }
- else
- {
- hmmAndSeqs = new SequenceI[seqs.length + 1];
- }
- hmmAndSeqs[0] = hmmSeq;
+ SequenceI[] hmmAndSeqs;
+ if (numberOfSequences != null && numberOfSequences < seqs.length)
+ {
+ hmmAndSeqs = new SequenceI[numberOfSequences + 1];
+ }
+ else
+ {
+ hmmAndSeqs = new SequenceI[seqs.length + 1];
+ }
+ hmmAndSeqs[0] = hmmSeq;
- if (numberOfSequences != null && seqs.length > numberOfSequences)
- {
- System.arraycopy(seqs, 0, hmmAndSeqs, 1, numberOfSequences);
- }
- else
- {
- System.arraycopy(seqs, 0, hmmAndSeqs, 1, seqs.length);
- }
+ if (numberOfSequences != null && seqs.length > numberOfSequences)
+ {
+ System.arraycopy(seqs, 0, hmmAndSeqs, 1, numberOfSequences);
+ }
+ else
+ {
+ System.arraycopy(seqs, 0, hmmAndSeqs, 1, seqs.length);
+ }
- AlignmentI alignment = new Alignment(hmmAndSeqs);
- AlignFrame frame = new AlignFrame(alignment, 1, 1);
- frame.setSelectedHMMSequence(hmmSeq);
- List<ArgumentI> alignArgs = new ArrayList<>();
- if (trim)
+ AlignmentI alignment = new Alignment(hmmAndSeqs);
+ AlignFrame frame = new AlignFrame(alignment, 1, 1);
+ frame.setSelectedHMMSequence(hmmSeq);
+ List<ArgumentI> alignArgs = new ArrayList<>();
+ if (trim)
+ {
+ alignArgs.add(new BooleanOption(
+ MessageManager.getString("label.trim_termini"),
+ MessageManager.getString("label.trim_termini_desc"), true,
+ true, true, null));
+ }
+ HMMAlignThread hmmalign = new HMMAlignThread(frame, true, alignArgs);
+ hmmalign.hmmalignWaitTillComplete();
+ frame = null;
+ hmmTemp.delete();
+ inputAlignmentTemp.delete();
+ inputTableTemp.delete();
+ } finally
{
- alignArgs.add(new BooleanOption(
- MessageManager.getString("label.trim_termini"),
- MessageManager.getString("label.trim_termini_desc"), true,
- true, true, null));
+ if (br != null)
+ {
+ br.close();
+ }
}
- HMMAlignThread hmmalign = new HMMAlignThread(frame, true, alignArgs);
- hmmalign.hmmalignWaitTillComplete();
- frame = null;
- hmmTemp.delete();
- inputAlignmentTemp.delete();
- inputTableTemp.delete();
}
/**
}
- public void readTable() throws IOException
+ void readTable() throws IOException
{
BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
String line = "";
&& !"".equals(line))
{
Scanner scanner = new Scanner(line);
-
- String str = scanner.next();
- Annotation[] annots = new Annotation[seqs[index].getLength()];
- for (Annotation an : annots)
+
+ String str = scanner.next(); // full sequence eValue score
+ float eValue = Float.parseFloat(str);
+ int seqLength = seqs[index].getLength();
+ Annotation[] annots = new Annotation[seqLength];
+ for (int j = 0; j < seqLength; j++)
{
- an = new Annotation(Float.parseFloat(str));
+ annots[j] = new Annotation(eValue);
}
AlignmentAnnotation annot = new AlignmentAnnotation("E-value",
"Score", annots);
annot.setScore(Double.parseDouble(str));
annot.setSequenceRef(seqs[index]);
seqs[index].addAlignmentAnnotation(annot);
-
+
scanner.close();
line = br.readLine();
index++;
}
-
+
br.close();
}
-
}