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 NAME = "-n ";
44 public final String SPACE = " ";
46 public final String ALLCOL = "--allcol ";
48 public final String TRIM = "--trim ";
50 public final String FORCEAMINO = "--amino ";
52 public final String FORCEDNA = "--dna ";
54 public final String FORCERNA = "--rna ";
56 Hashtable hash = new Hashtable();
58 List<SequenceI> hmmSeqs;
61 * Uniquifies the sequences when exporting and stores their details in a
66 public void uniquifySequences(SequenceI[] seqs)
68 hash = jalview.analysis.SeqsetUtils.uniquify(seqs, true);
72 * Recover the sequence data lost by uniquifying.
76 public void recoverSequenceNames(SequenceI[] seqs)
78 jalview.analysis.SeqsetUtils.deuniquify(hash, seqs);
82 * Runs a command in the command line.
86 * @throws InterruptedException
88 public boolean runCommand(String command)
89 throws IOException, InterruptedException
93 final Process p = Runtime.getRuntime().exec(command);
95 new Thread(new Runnable()
100 BufferedReader input = new BufferedReader(
101 new InputStreamReader(p.getInputStream()));
106 while ((line = input.readLine()) != null)
108 System.out.println(line);
110 } catch (IOException e)
118 } catch (Exception e)
127 * Exports an alignment and/or HMM to the specified file.
130 * @throws IOException
132 public void exportData(SequenceI[] seqs,
133 File stoLocation, HiddenMarkovModel hmm, File hmmLocation)
138 StockholmFile file = new StockholmFile(new Alignment(seqs));
139 boolean removeAnnots = false;
144 String output = file.print(seqs, false);
145 PrintWriter writer = new PrintWriter(stoLocation);
146 writer.println(output);
152 HMMFile file = new HMMFile(hmm);
153 file.exportFile(hmmLocation);
158 * Adds any HMM sequences removed before submitting the alignment as a job
159 * back into the alignment.
163 public void addHMMConsensusSequences(AlignFrame af)
165 AlignmentI al = af.getViewport().getAlignment();
166 for (SequenceI seq : hmmSeqs)
168 Integer position = seq.getPreviousPosition();
169 al.getSequences().add(position, seq);
171 af.getViewport().setAlignment(al);
172 af.alignPanel.adjustAnnotationHeight();
173 af.getViewport().updateSequenceIdColours();
174 af.buildSortByAnnotationScoresMenu();
178 * Returns the list of HMM sequences removed
182 public List<SequenceI> getHmmSeqs()
188 * Sets the list of removed HMM sequences
192 public void setHmmSeqs(List<SequenceI> hmmSeqs)
194 this.hmmSeqs = hmmSeqs;