JAL-2629 fixed hmmalign failing due to differing sequence lengths
[jalview.git] / src / jalview / hmmer / HMMBuildThread.java
1 package jalview.hmmer;
2
3 import jalview.datamodel.AlignmentI;
4 import jalview.datamodel.HiddenMarkovModel;
5 import jalview.datamodel.SequenceI;
6 import jalview.gui.AlignFrame;
7 import jalview.io.DataSourceType;
8 import jalview.io.FileFormat;
9 import jalview.util.MessageManager;
10
11 import java.io.FileNotFoundException;
12 import java.io.IOException;
13 import java.util.Map;
14
15 public class HMMBuildThread implements Runnable
16 {
17
18   AlignFrame af;
19   AlignmentI alignment;
20
21   long barID;
22
23   Map<Integer, SequenceI> hmmSeqs;
24   
25   public HMMBuildThread(AlignFrame af)
26   {
27     this.af = af;
28     alignment = af.getViewport().getAlignment();
29   }
30
31   @Override
32   public void run()
33   {
34     barID = System.currentTimeMillis();
35     af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
36             barID);
37
38     try
39     {
40     try
41     {
42         hmmSeqs = alignment.getHMMConsensusSequences(true);
43         HMMERCommands.exportData(alignment, true, false,
44                 new HiddenMarkovModel());
45     } catch (FileNotFoundException e)
46     {
47       // TODO Auto-generated catch block
48       e.printStackTrace();
49
50     }
51     try
52     {
53       runCommand();
54     } catch (IOException | InterruptedException e)
55     {
56       // TODO Auto-generated catch block
57       e.printStackTrace();
58     }
59     try
60     {
61       importData();
62     } catch (IOException | InterruptedException e)
63     {
64       // TODO Auto-generated catch block
65       e.printStackTrace();
66     }
67     } catch (Exception e)
68     {
69
70     } finally
71     {
72       af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
73               barID);
74     }
75   }
76
77   
78
79   
80   private void runCommand() throws IOException, InterruptedException
81   {
82     final String command = HMMERCommands.HMMBUILD + HMMERCommands.NAME
83             + af.getName() + HMMERCommands.SPACE
84             + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.HMMBUFFER
85             + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.ALIGNMENTBUFFER;
86     HMMERCommands.runCommand(command);
87   }
88   
89   private void importData() throws IOException, InterruptedException
90   {
91     af.loadJalviewDataFile(HMMERCommands.HMMBUFFER, DataSourceType.FILE,
92             FileFormat.HMMER3, null);
93     for (Map.Entry<Integer, SequenceI> entry : hmmSeqs.entrySet())
94     {
95       SequenceI seq = entry.getValue();
96       Integer pos = entry.getKey();
97       HMMERCommands.addHMMConsensusSequence(af, seq, pos);
98     }
99     af.alignPanel.alignmentChanged();
100   }
101   
102   
103   
104  
105 }