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