JAL-2629 add ability to select hmmer binaries folder
[jalview.git] / src / jalview / hmmer / HMMERCommands.java
1 package jalview.hmmer;
2
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;
10
11 import java.io.BufferedReader;
12 import java.io.IOException;
13 import java.io.InputStreamReader;
14 import java.io.PrintWriter;
15 import java.util.List;
16
17 public class HMMERCommands
18 {
19   // Path of hmmer binaries directory
20   static String HMMERFOLDER = "/Documents/";
21
22   static final String JALVIEWDIRECTORY = System.getProperty("user.dir")
23           + "/";
24
25   static String HMMALIGN = "/hmmalign ";
26
27   static String HMMBUILD = "/hmmbuild ";
28
29   static String HMMSEARCH = "/hmmsearch ";
30
31   static final String HMMBUFFER = "src/jalview/hmmer/hmm_buffer.hmm ";
32
33   static final String ALIGNMENTBUFFER = "src/jalview/hmmer/alignment_buffer.sto ";
34
35   static final String ALIGNMENTINPUT = "src/jalview/hmmer/alignment_input.sto ";
36
37   static final String OUTPUTALIGNMENT = "-o " + JALVIEWDIRECTORY
38           + ALIGNMENTINPUT;
39
40   static final String NAME = "-n ";
41
42   static final String SPACE = " ";
43
44   static final String ALLCOL = "--allcol ";
45
46   static final String TRIM = "--trim ";
47
48
49   /**
50    * Runs a command in the terminal.
51    * 
52    * @param command
53    * @throws IOException
54    * @throws InterruptedException
55    */
56   public static void runCommand(String command)
57           throws IOException, InterruptedException
58   {
59     final Process p = Runtime.getRuntime().exec(command);
60
61     new Thread(new Runnable()
62     {
63       @Override
64       public void run()
65       {
66         BufferedReader input = new BufferedReader(
67                 new InputStreamReader(p.getInputStream()));
68         String line = null;
69
70         try
71         {
72           while ((line = input.readLine()) != null)
73           {
74             System.out.println(line);
75           }
76         } catch (IOException e)
77         {
78           e.printStackTrace();
79         }
80       }
81     }).start();
82
83     p.waitFor();
84   }
85
86   /**
87    * Exports an alignment to the buffer location in Jalview.
88    * 
89    * @param alignment
90    * @throws IOException
91    */
92   public static void exportData(AlignmentI alignment,
93           boolean exportAlignment, boolean exportHMM, HiddenMarkovModel hmm)
94           throws IOException
95   {
96     if (exportAlignment)
97     {
98       if (!alignment.isAligned())
99       {
100         alignment.padGaps();
101       }
102       List<SequenceI> list = alignment.getSequences();
103       SequenceI[] array = new SequenceI[list.size()];
104       list.toArray(array);
105       StockholmFile file = new StockholmFile(new Alignment(array));
106       file.setSeqs(array);
107       String output = file.print();
108       PrintWriter writer = new PrintWriter(ALIGNMENTBUFFER);
109       writer.println(output);
110       writer.close();
111     }
112
113     if (exportHMM)
114     {
115       HMMFile file = new HMMFile(hmm);
116       file.exportFile(HMMBUFFER);
117     }
118   }
119
120   public static void addHMMConsensusSequence(AlignFrame af, SequenceI seq,
121           Integer position)
122   {
123     seq.getHMM().initHMMSequence(af, position);
124     AlignmentI al = af.getViewport().getAlignment();
125     af.getViewport().setAlignment(al);
126     af.alignPanel.adjustAnnotationHeight();
127     af.getViewport().updateSequenceIdColours();
128     af.buildSortByAnnotationScoresMenu();
129   }
130
131
132 }