8de3fe196dd4f6358ea815b8770dd86c2a4b7622
[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.File;
13 import java.io.IOException;
14 import java.io.InputStreamReader;
15 import java.io.PrintWriter;
16 import java.util.List;
17
18 public class HMMERCommands
19 {
20   // Path of hmmer binaries directory
21   String HMMERFOLDER = "/Documents/";
22
23   public String JALVIEWDIRECTORY = System.getProperty("user.dir")
24           + "/";
25
26   public String HMMALIGN = "/hmmalign ";
27
28   public String HMMBUILD = "/hmmbuild ";
29
30   public String HMMSEARCH = "/hmmsearch ";
31
32   public String HMMBUFFER;
33
34   public String ALIGNMENTBUFFER;
35
36   public String ALIGNMENTINPUT;
37
38   public String OUTPUTALIGNMENT;
39
40   public String NAME = "-n ";
41
42   public String SPACE = " ";
43
44   public String ALLCOL = "--allcol ";
45
46   public 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 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 void exportData(AlignmentI alignment,
93           File stoLocation, HiddenMarkovModel hmm, File hmmLocation)
94           throws IOException
95   {
96     if (alignment != null)
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(stoLocation);
109       writer.println(output);
110       writer.close();
111     }
112
113     if (hmm != null)
114     {
115       HMMFile file = new HMMFile(hmm);
116       file.exportFile(hmmLocation);
117     }
118   }
119
120   public 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 }