Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.workers

File AnnotationWorker.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
20% of files have more coverage

Code metrics

8
26
4
1
125
70
9
0.35
6.5
4
2.25

Classes

Class Line # Actions
AnnotationWorker 37 26 9
0.736842173.7%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.workers;
22   
23    import jalview.api.AlignViewportI;
24    import jalview.api.AlignmentViewPanel;
25    import jalview.datamodel.AlignmentAnnotation;
26    import jalview.datamodel.AlignmentI;
27    import jalview.renderer.seqfeatures.FeatureRenderer;
28   
29    import java.util.ArrayList;
30    import java.util.List;
31   
32    /**
33    * A class to create and update one or more alignment annotations, given a
34    * 'calculator'. Intended to support a 'plug-in' annotation worker which
35    * implements the AnnotationProviderI interface.
36    */
 
37    class AnnotationWorker extends AlignCalcWorker
38    {
39    /*
40    * the provider of the annotation calculations
41    */
42    AnnotationProviderI counter;
43   
44    /**
45    * Constructor
46    *
47    * @param af
48    * @param counter
49    */
 
50  2 toggle public AnnotationWorker(AlignViewportI viewport, AlignmentViewPanel panel,
51    AnnotationProviderI counter)
52    {
53  2 super(viewport, panel);
54  2 ourAnnots = new ArrayList<>();
55  2 this.counter = counter;
56  2 calcMan.registerWorker(this);
57    }
58   
 
59  2 toggle @Override
60    public void run()
61    {
62  2 if (alignViewport.isClosed())
63    {
64  0 abortAndDestroy();
65  0 return;
66    }
67   
68    // removeAnnotation();
69  2 AlignmentI alignment = alignViewport.getAlignment();
70  2 if (alignment != null)
71    {
72  2 try
73    {
74  2 List<AlignmentAnnotation> anns = counter.calculateAnnotation(
75    alignment, new FeatureRenderer(alignViewport));
76  2 for (AlignmentAnnotation ann : anns)
77    {
78  2 AlignmentAnnotation theAnn = alignment.findOrCreateAnnotation(
79    ann.label, ann.description, false, null, null);
80  2 theAnn.showAllColLabels = true;
81  2 theAnn.graph = AlignmentAnnotation.BAR_GRAPH;
82  2 theAnn.scaleColLabel = true;
83  2 theAnn.annotations = ann.annotations;
84  2 setGraphMinMax(theAnn, theAnn.annotations);
85  2 theAnn.validateRangeAndDisplay();
86  2 if (!ourAnnots.contains(theAnn))
87    {
88  2 ourAnnots.add(theAnn);
89    }
90    // alignment.addAnnotation(ann);
91    }
92    } catch (IndexOutOfBoundsException x)
93    {
94    // probable race condition. just finish and return without any fuss.
95  0 return;
96    }
97    }
98   
99  2 if (ap != null)
100    {
101  2 ap.adjustAnnotationHeight();
102    // TODO: only need to update colour and geometry if panel height changes
103    // and view is coloured by annotation, and the annotation is actually
104    // changed!
105  2 ap.paintAlignment(true, true);
106    }
107    }
108   
 
109  0 toggle @Override
110    public void updateAnnotation()
111    {
112    // do nothing
113    }
114   
115    /**
116    * Answers true to indicate that if this worker's annotation is deleted from
117    * the display, the worker should also be removed. This prevents it running
118    * and recreating the annotation when the alignment changes.
119    */
 
120  0 toggle @Override
121    public boolean isDeletable()
122    {
123  0 return true;
124    }
125    }