Refactored alignment viewport to use common base, extended viewport API with getters...
[jalview.git] / src / jalview / workers / ConservationThread.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.workers;
19
20 import jalview.analysis.Conservation;
21 import jalview.api.AlignCalcWorkerI;
22 import jalview.api.AlignmentViewPanel;
23 import jalview.api.AlignViewportI;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.AlignmentI;
26
27 public class ConservationThread extends AlignCalcWorker implements AlignCalcWorkerI
28 {
29
30   private int ConsPercGaps = 25; // JBPNote : This should be a configurable property!
31   
32   public ConservationThread(AlignViewportI alignViewport, AlignmentViewPanel alignPanel)
33   {
34     super(alignViewport, alignPanel);
35     ConsPercGaps = alignViewport.getConsPercGaps();
36   }
37
38   public void run()
39   {
40     try
41     {
42       calcMan.notifyStart(this); // updatingConservation = true;
43
44       while (calcMan.alreadyDoing(this)) //UPDATING_CONSERVATION)
45       {
46         try
47         {
48           if (ap != null)
49           {
50             ap.paintAlignment(false);
51           }
52           Thread.sleep(200);
53         } catch (Exception ex)
54         {
55           ex.printStackTrace();
56         }
57       }
58       calcMan.notifyWorking(this);
59       if (alignViewport.isClosed()) {
60         abortAndDestroy();
61       }
62
63       AlignmentI alignment=alignViewport.getAlignment();
64       AlignmentAnnotation conservation=alignViewport.getAlignmentConservationAnnotation();
65       AlignmentAnnotation quality=alignViewport.getAlignmentQualityAnnot();
66       // AlignViewport.UPDATING_CONSERVATION = true;
67
68       int alWidth;
69       
70       if (alignment==null || (alWidth=alignment.getWidth())< 0)
71       {
72         calcMan.workerComplete(this);
73         //.updatingConservation = false;
74         //AlignViewport.UPDATING_CONSERVATION = false;
75         
76         return;
77       }
78
79       Conservation cons = Conservation.calculateConservation("All",
80               jalview.schemes.ResidueProperties.propHash, 3,
81               alignment.getSequences(), 0, alWidth - 1, false, ConsPercGaps, quality!=null);
82       cons.completeAnnotations(conservation,
83               quality, 0, alWidth);
84     } catch (OutOfMemoryError error)
85     {
86       ap.raiseOOMWarning("calculating conservation", error);
87       calcMan.workerCannotRun(this);
88       // alignViewport.conservation = null;
89       // this.alignViewport.quality = null;
90
91     }
92     calcMan.workerComplete(this);
93
94     if (ap != null)
95     {
96       ap.paintAlignment(true);
97     }
98
99   }
100 }