group consensus/conservation calculated from start to end
[jalview.git] / src / jalview / gui / ConservationThread.java
1 /**
2  * 
3  */
4 package jalview.gui;
5
6 import jalview.analysis.Conservation;
7 import jalview.datamodel.Annotation;
8
9 import java.awt.Color;
10
11 class ConservationThread extends Thread
12 {
13   /**
14    * 
15    */
16   private AlignViewport alignViewport;
17   AlignmentPanel ap;
18
19   public ConservationThread(AlignViewport alignViewport, AlignmentPanel ap)
20   {
21     this.alignViewport = alignViewport;
22     this.ap = ap;
23   }
24
25   public void run()
26   {
27     try
28     {
29       this.alignViewport.updatingConservation = true;
30
31       while (AlignViewport.UPDATING_CONSERVATION)
32       {
33         try
34         {
35           if (ap != null)
36           {
37             ap.paintAlignment(false);
38           }
39           Thread.sleep(200);
40         } catch (Exception ex)
41         {
42           ex.printStackTrace();
43         }
44       }
45
46       AlignViewport.UPDATING_CONSERVATION = true;
47
48       int alWidth = this.alignViewport.alignment.getWidth();
49       if (alWidth < 0)
50       {
51         return;
52       }
53
54       Conservation cons = new jalview.analysis.Conservation("All",
55               jalview.schemes.ResidueProperties.propHash, 3, this.alignViewport.alignment
56                       .getSequences(), 0, alWidth - 1);
57
58       cons.calculate();
59       cons.verdict(false, this.alignViewport.ConsPercGaps);
60
61       if (this.alignViewport.quality != null)
62       {
63         cons.findQuality();
64       }
65       cons.completeAnnotations(alignViewport.conservation,alignViewport.quality, 0, alWidth);
66     } catch (OutOfMemoryError error)
67     {
68       new OOMWarning("calculating conservation", error);
69
70       this.alignViewport.conservation = null;
71       this.alignViewport.quality = null;
72
73     }
74
75     AlignViewport.UPDATING_CONSERVATION = false;
76     this.alignViewport.updatingConservation = false;
77
78     if (ap != null)
79     {
80       ap.paintAlignment(true);
81     }
82
83   }
84 }