3 import jalview.datamodel.Alignment;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.AnnotatedCollectionI;
7 import jalview.datamodel.HiddenMarkovModel;
8 import jalview.datamodel.SequenceI;
9 import jalview.gui.AlignFrame;
10 import jalview.io.HMMFile;
11 import jalview.io.StockholmFile;
13 import java.io.BufferedReader;
15 import java.io.IOException;
16 import java.io.InputStreamReader;
17 import java.io.PrintWriter;
18 import java.util.Hashtable;
19 import java.util.List;
22 * Contains multiple commands and methods frequently used to run hmmbuild,
23 * hmmalign and hmmsearch
28 public class HMMERCommands
30 // Path of hmmer binaries directory
31 String HMMERFOLDER = "/Documents/";
33 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,
133 File stoLocation, HiddenMarkovModel hmm, File hmmLocation,
134 AnnotatedCollectionI al)
139 AlignmentI newAl = new Alignment(seqs);
140 if (stoLocation != null)
142 for (AlignmentAnnotation annot : al.getAlignmentAnnotation())
144 if (annot.label.contains("Reference") || "RF".equals(annot.label))
146 newAl.addAnnotation(annot);
150 StockholmFile file = new StockholmFile(newAl);
151 String output = file.print(seqs, false);
152 PrintWriter writer = new PrintWriter(stoLocation);
153 writer.println(output);
159 HMMFile file = new HMMFile(hmm);
160 PrintWriter writer = new PrintWriter(hmmLocation);
161 writer.print(file.print());
167 * Adds any HMM sequences removed before submitting the alignment as a job
168 * back into the alignment.
172 public void addHMMConsensusSequences(AlignFrame af)
174 AlignmentI al = af.getViewport().getAlignment();
175 if (hmmSeqs == null || hmmSeqs.size() < 1)
179 for (SequenceI seq : hmmSeqs)
181 Integer position = seq.getPreviousPosition();
182 al.getSequences().add(position, seq);
184 af.getViewport().setAlignment(al);
185 af.alignPanel.adjustAnnotationHeight();
186 af.getViewport().updateSequenceIdColours();
187 af.buildSortByAnnotationScoresMenu();
191 * Returns the list of HMM sequences removed
195 public List<SequenceI> getHmmSeqs()
201 * Sets the list of removed HMM sequences
205 public void setHmmSeqs(List<SequenceI> hmmSeqs)
207 this.hmmSeqs = hmmSeqs;