3 import jalview.datamodel.Alignment;
4 import jalview.datamodel.AlignmentI;
5 import jalview.datamodel.HiddenMarkovModel;
6 import jalview.datamodel.SequenceI;
7 import jalview.gui.AlignFrame;
8 import jalview.io.HMMFile;
9 import jalview.io.StockholmFile;
11 import java.io.BufferedReader;
13 import java.io.IOException;
14 import java.io.InputStreamReader;
15 import java.io.PrintWriter;
16 import java.util.Hashtable;
17 import java.util.List;
20 * Contains multiple commands and methods frequently used to run hmmbuild,
21 * hmmalign and hmmsearch
26 public class HMMERCommands
28 // Path of hmmer binaries directory
29 String HMMERFOLDER = "/Documents/";
31 public String JALVIEWDIRECTORY = System.getProperty("user.dir")
34 public final String HMMALIGN = "/hmmalign ";
36 public final String HMMBUILD = "/hmmbuild ";
38 public final String HMMSEARCH = "/hmmsearch ";
40 public String OUTPUTALIGNMENT;
42 public final String SPACE = " ";
44 public final String ALLCOL = "--allcol ";
46 public final String TRIM = "--trim ";
48 public final String FORCEAMINO = "--amino ";
50 public final String FORCEDNA = "--dna ";
52 public final String FORCERNA = "--rna ";
54 Hashtable hash = new Hashtable();
56 List<SequenceI> hmmSeqs;
59 * Uniquifies the sequences when exporting and stores their details in a
64 public void uniquifySequences(SequenceI[] seqs)
66 hash = jalview.analysis.SeqsetUtils.uniquify(seqs, true);
70 * Recover the sequence data lost by uniquifying.
74 public void recoverSequenceNames(SequenceI[] seqs)
76 jalview.analysis.SeqsetUtils.deuniquify(hash, seqs);
80 * Runs a command in the command line.
84 * @throws InterruptedException
86 public boolean runCommand(String command)
87 throws IOException, InterruptedException
91 final Process p = Runtime.getRuntime().exec(command);
93 new Thread(new Runnable()
98 BufferedReader input = new BufferedReader(
99 new InputStreamReader(p.getInputStream()));
104 while ((line = input.readLine()) != null)
106 System.out.println(line);
108 } catch (IOException e)
116 } catch (Exception e)
125 * Exports an alignment and/or HMM to the specified file.
128 * @throws IOException
130 public void exportData(SequenceI[] seqs,
131 File stoLocation, HiddenMarkovModel hmm, File hmmLocation)
136 StockholmFile file = new StockholmFile(new Alignment(seqs));
137 String output = file.print(seqs, false);
138 PrintWriter writer = new PrintWriter(stoLocation);
139 writer.println(output);
145 HMMFile file = new HMMFile(hmm);
146 PrintWriter writer = new PrintWriter(hmmLocation);
147 writer.print(file.print());
153 * Adds any HMM sequences removed before submitting the alignment as a job
154 * back into the alignment.
158 public void addHMMConsensusSequences(AlignFrame af)
160 AlignmentI al = af.getViewport().getAlignment();
161 if (hmmSeqs == null || hmmSeqs.size() < 1)
165 for (SequenceI seq : hmmSeqs)
167 Integer position = seq.getPreviousPosition();
168 al.getSequences().add(position, seq);
170 af.getViewport().setAlignment(al);
171 af.alignPanel.adjustAnnotationHeight();
172 af.getViewport().updateSequenceIdColours();
173 af.buildSortByAnnotationScoresMenu();
177 * Returns the list of HMM sequences removed
181 public List<SequenceI> getHmmSeqs()
187 * Sets the list of removed HMM sequences
191 public void setHmmSeqs(List<SequenceI> hmmSeqs)
193 this.hmmSeqs = hmmSeqs;