AlignmentViewPanel panel, FeatureSetCounterI counter)
{
super(viewport, panel);
- ourAnnots = new ArrayList<AlignmentAnnotation>();
+ ourAnnots = new ArrayList<>();
this.counter = counter;
calcMan.registerWorker(this);
}
@Override
public void run()
{
+ boolean annotationAdded = false;
try
{
calcMan.notifyStart(this);
{
try
{
- computeAnnotations();
+ annotationAdded = computeAnnotations();
} catch (IndexOutOfBoundsException x)
{
// probable race condition. just finish and return without any fuss.
if (ap != null)
{
- ap.adjustAnnotationHeight();
- ap.paintAlignment(true);
+ if (annotationAdded)
+ {
+ ap.adjustAnnotationHeight();
+ }
+ ap.paintAlignment(true, true);
}
}
/**
* Scan each column of the alignment to calculate a count by feature type. Set
* the count as the value of the alignment annotation for that feature type.
+ *
+ * @return
*/
- void computeAnnotations()
+ boolean computeAnnotations()
{
FeatureRenderer fr = new FeatureRenderer(alignViewport);
// TODO use the commented out code once JAL-2075 is fixed
{
max[crow] = 0;
}
+
+ int[] minC = counter.getMinColour();
+ int[] maxC = counter.getMaxColour();
+ Color minColour = new Color(minC[0], minC[1], minC[2]);
+ Color maxColour = new Color(maxC[0], maxC[1], maxC[2]);
+
for (int col = 0; col < width; col++)
{
int[] count = counts[col];
max[crow] = Math.max(count[crow], max[crow]);
}
}
+
+ boolean annotationAdded = false;
+
for (int anrow = 0; anrow < rows; anrow++)
{
Annotation[] anns = new Annotation[width];
+ long rmax = 0;
/*
- * add non-zero counts as annotations
+ * add counts as annotations. zeros are needed since select-by-annotation ignores empty annotation positions
*/
for (int i = 0; i < counts.length; i++)
{
int count = counts[i][anrow];
- if (count > 0)
- {
- Color color = ColorUtils.getGraduatedColour(count, 0, Color.cyan,
- max[anrow], Color.blue);
- String str = String.valueOf(count);
- anns[i] = new Annotation(str, str, '0', count, color);
- }
+
+ Color color = ColorUtils.getGraduatedColour(count, 0, minColour,
+ max[anrow], maxColour);
+ String str = String.valueOf(count);
+ anns[i] = new Annotation(str, str, '0', count, color);
+ rmax = Math.max(count, rmax);
}
/*
* construct or update the annotation
*/
- AlignmentAnnotation ann = alignViewport.getAlignment()
- .findOrCreateAnnotation(counter.getNames()[anrow],
- counter.getDescriptions()[anrow], false, null,
- null);
- ann.description = counter.getDescriptions()[anrow];
+ String description = counter.getDescriptions()[anrow];
+ if (!alignment.findAnnotation(description).iterator().hasNext())
+ {
+ annotationAdded = true;
+ }
+ AlignmentAnnotation ann = alignment.findOrCreateAnnotation(
+ counter.getNames()[anrow], description, false, null, null);
+ ann.description = description;
ann.showAllColLabels = true;
ann.scaleColLabel = true;
ann.graph = AlignmentAnnotation.BAR_GRAPH;
ann.annotations = anns;
- setGraphMinMax(ann, anns);
+ ann.graphMin = 0f; // minimum always zero count
+ ann.graphMax = rmax; // maximum count from loop over feature columns
ann.validateRangeAndDisplay();
if (!ourAnnots.contains(ann))
{
ourAnnots.add(ann);
}
}
+ return annotationAdded;
}
/**
*
* @param alignment
* @param col
+ * (0..)
* @param row
* @param fr
*/
{
return null;
}
- int pos = seq.findPosition(col);
/*
* compute a count for any displayed features at residue
*/
- // NB have to adjust pos if using AlignmentView.getVisibleAlignment
// see JAL-2075
- List<SequenceFeature> features = fr.findFeaturesAtRes(seq, pos);
+ List<SequenceFeature> features = fr.findFeaturesAtColumn(seq, col + 1);
int[] count = this.counter.count(String.valueOf(res), features);
return count;
}