3 import jalview.datamodel.Alignment;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.AnnotatedCollectionI;
7 import jalview.datamodel.Annotation;
8 import jalview.datamodel.HiddenMarkovModel;
9 import jalview.datamodel.SequenceI;
10 import jalview.gui.AlignFrame;
11 import jalview.io.HMMFile;
12 import jalview.io.StockholmFile;
14 import java.io.BufferedReader;
16 import java.io.IOException;
17 import java.io.InputStreamReader;
18 import java.io.PrintWriter;
19 import java.util.Hashtable;
20 import java.util.List;
23 * Contains multiple commands and methods frequently used to run hmmbuild,
24 * hmmalign and hmmsearch
29 public class HMMERCommands
31 // Path of hmmer binaries directory
32 String HMMERFOLDER = "/Documents/";
34 public String JALVIEWDIRECTORY = System.getProperty("user.dir") + "/";
36 public final String HMMALIGN = "/hmmalign ";
38 public final String HMMBUILD = "/hmmbuild ";
40 public final String HMMSEARCH = "/hmmsearch ";
42 public String OUTPUTALIGNMENT;
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, File stoLocation,
133 HiddenMarkovModel hmm, File hmmLocation, AnnotatedCollectionI al)
138 AlignmentI newAl = new Alignment(seqs);
139 if (stoLocation != null)
141 for (AlignmentAnnotation annot : al.getAlignmentAnnotation())
143 if (annot.label.contains("Reference") || "RF".equals(annot.label))
145 AlignmentAnnotation newRF;
146 if (annot.annotations.length > newAl.getWidth())
148 Annotation[] rfAnnots = new Annotation[newAl.getWidth()];
149 System.arraycopy(annot.annotations, 0, rfAnnots, 0,
151 newRF = new AlignmentAnnotation("RF", "Reference Positions",
156 newRF = new AlignmentAnnotation(annot);
158 newAl.addAnnotation(newRF);
163 StockholmFile file = new StockholmFile(newAl);
164 String output = file.print(seqs, false);
165 PrintWriter writer = new PrintWriter(stoLocation);
166 writer.println(output);
172 HMMFile file = new HMMFile(hmm);
173 PrintWriter writer = new PrintWriter(hmmLocation);
174 writer.print(file.print());
180 * Adds any HMM sequences removed before submitting the alignment as a job
181 * back into the alignment.
185 public void addHMMConsensusSequences(AlignFrame af)
187 AlignmentI al = af.getViewport().getAlignment();
188 if (hmmSeqs == null || hmmSeqs.size() < 1)
192 for (SequenceI seq : hmmSeqs)
194 Integer position = seq.getPreviousPosition();
195 al.getSequences().add(position, seq);
197 af.getViewport().setAlignment(al);
198 af.alignPanel.adjustAnnotationHeight();
199 af.getViewport().updateSequenceIdColours();
200 af.buildSortByAnnotationScoresMenu();
204 * Returns the list of HMM sequences removed
208 public List<SequenceI> getHmmSeqs()
214 * Sets the list of removed HMM sequences
218 public void setHmmSeqs(List<SequenceI> hmmSeqs)
220 this.hmmSeqs = hmmSeqs;