import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
-import jalview.io.DataSourceType;
-import jalview.io.FileFormat;
-import jalview.io.FileLoader;
import jalview.io.HMMFile;
import jalview.io.StockholmFile;
-import jalview.util.MessageManager;
import java.io.BufferedReader;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.List;
-import java.util.Map;
-
-import javax.swing.JOptionPane;
public class HMMERCommands
{
// Path of hmmer binaries directory
- private static final String HMMERFOLDER = "H:/Documents/";
+ static String HMMERFOLDER = "/Documents/";
- private static final String HMMALIGN = HMMERFOLDER + "hmmalign ";
+ static final String JALVIEWDIRECTORY = System.getProperty("user.dir")
+ + "/";
- private static final String HMMBUILD = HMMERFOLDER + "hmmbuild ";
+ static String HMMALIGN = "/hmmalign ";
- private static final String HMMSEARCH = HMMERFOLDER + "hmmsearch ";
+ static String HMMBUILD = "/hmmbuild ";
- private static final String JALVIEWDIRECTORY = "C:/Users/TZVanaalten/git/jalview/";
+ static String HMMSEARCH = "/hmmsearch ";
- private static final String HMMBUFFER = "src/jalview/hmmer/hmm_buffer.hmm ";
+ static final String HMMBUFFER = "src/jalview/hmmer/hmm_buffer.hmm ";
- private static final String ALIGNMENTBUFFER = "src/jalview/hmmer/alignment_buffer.sto ";
+ static final String ALIGNMENTBUFFER = "src/jalview/hmmer/alignment_buffer.sto ";
- private static final String ALIGNMENTINPUT = "src/jalview/hmmer/alignment_input.sto ";
+ static final String ALIGNMENTINPUT = "src/jalview/hmmer/alignment_input.sto ";
- private static final String OUTPUTALIGNMENT = "-o " + JALVIEWDIRECTORY
+ static final String OUTPUTALIGNMENT = "-o " + JALVIEWDIRECTORY
+ ALIGNMENTINPUT;
- private static final String NAME = "-n ";
-
- private static final String SPACE = " ";
-
- private static final String ALLCOL = "--allcol ";
-
- private static final String TRIM = "--trim ";
-
- public static void hmmBuild(AlignFrame af)
- throws IOException, InterruptedException
- {
-
- PrintWriter clearer = new PrintWriter(HMMBUFFER);
- clearer.print("");
- clearer.close();
- AlignmentI alignment = af.getViewport().getAlignment();
- Map<Integer, SequenceI> seqs = alignment.getHMMConsensusSequences(true);
- exportAlignment(alignment);
- final String command = HMMBUILD + NAME + af.getName() + SPACE
- + JALVIEWDIRECTORY + HMMBUFFER
- + JALVIEWDIRECTORY + ALIGNMENTBUFFER;
-
- runCommand(command);
-
- af.loadJalviewDataFile(HMMBUFFER, DataSourceType.FILE,
- FileFormat.HMMER3, null);
- for (Map.Entry<Integer, SequenceI> entry : seqs.entrySet())
- {
- SequenceI seq = entry.getValue();
- Integer pos = entry.getKey();
- addHMMConsensusSequence(af, seq, pos);
- }
- af.alignPanel.alignmentChanged();
- }
-
- public static void hmmAlign(AlignFrame af, boolean createNewFrame,
- HiddenMarkovModel hmm)
- throws IOException, InterruptedException
- {
-
- PrintWriter clearer = new PrintWriter(ALIGNMENTINPUT);
- clearer.print("");
- clearer.close();
-
- AlignmentI al = af.getViewport().getAlignment();
- Map<Integer, SequenceI> seqs = al.getHMMConsensusSequences(true);
- int index = 0;
- if (hmm == null)
- {
- JOptionPane.showMessageDialog(af,
- MessageManager.getString("warn.null_hmm"));
- return;
- }
- exportAlignment(al);
-
- HMMFile file = new HMMFile(hmm);
- file.exportFile(HMMBUFFER);
-
- String command = HMMALIGN;
- if (!hmm.getFileHeader().contains("HMMER3/f"))
- {
- command += ALLCOL;
- }
- command += TRIM + OUTPUTALIGNMENT + JALVIEWDIRECTORY + HMMBUFFER
- + JALVIEWDIRECTORY + ALIGNMENTBUFFER;
+ static final String NAME = "-n ";
- runCommand(command);
+ static final String SPACE = " ";
- if (createNewFrame)
- {
- FileLoader loader = new FileLoader();
- AlignFrame newFrame = loader.LoadFileWaitTillLoaded(ALIGNMENTINPUT,
- DataSourceType.FILE);
- for (Map.Entry<Integer, SequenceI> entry : seqs.entrySet())
- {
- SequenceI seq = entry.getValue();
- Integer pos = entry.getKey();
- addHMMConsensusSequence(newFrame, seq, pos);
- }
- newFrame.alignPanel.alignmentChanged();
- }
- else
- {
- af.getViewport().getAlignment().getSequences().clear();
- af.loadJalviewDataFile(ALIGNMENTBUFFER, DataSourceType.FILE,
- FileFormat.Stockholm, null);
- for (Map.Entry<Integer, SequenceI> entry : seqs.entrySet())
- {
- SequenceI seq = entry.getValue();
- Integer pos = entry.getKey();
- addHMMConsensusSequence(af, seq, pos);
- }
+ static final String ALLCOL = "--allcol ";
- }
-
-
- }
+ static final String TRIM = "--trim ";
/**
* @throws IOException
* @throws InterruptedException
*/
- private static void runCommand(String command)
+ public static void runCommand(String command)
throws IOException, InterruptedException
{
final Process p = Runtime.getRuntime().exec(command);
* Exports an alignment to the buffer location in Jalview.
*
* @param alignment
- * @throws FileNotFoundException
+ * @throws IOException
*/
- private static void exportAlignment(AlignmentI alignment)
- throws FileNotFoundException
+ public static void exportData(AlignmentI alignment,
+ boolean exportAlignment, boolean exportHMM, HiddenMarkovModel hmm)
+ throws IOException
{
- List<SequenceI> list = alignment.getSequences();
- SequenceI[] array = new SequenceI[list.size()];
- list.toArray(array);
-
- StockholmFile file = new StockholmFile(new Alignment(array));
- file.setSeqs(array);
- String output = file.print();
- PrintWriter writer = new PrintWriter(ALIGNMENTBUFFER);
- writer.println(output);
- writer.close();
+ if (exportAlignment)
+ {
+ if (!alignment.isAligned())
+ {
+ alignment.padGaps();
+ }
+ List<SequenceI> list = alignment.getSequences();
+ SequenceI[] array = new SequenceI[list.size()];
+ list.toArray(array);
+ StockholmFile file = new StockholmFile(new Alignment(array));
+ file.setSeqs(array);
+ String output = file.print();
+ PrintWriter writer = new PrintWriter(ALIGNMENTBUFFER);
+ writer.println(output);
+ writer.close();
+ }
+
+ if (exportHMM)
+ {
+ HMMFile file = new HMMFile(hmm);
+ file.exportFile(HMMBUFFER);
+ }
}
- private static void addHMMConsensusSequence(AlignFrame af, SequenceI seq,
+ public static void addHMMConsensusSequence(AlignFrame af, SequenceI seq,
Integer position)
{
seq.getHMM().initHMMSequence(af, position);