From: gmungoc Date: Tue, 15 May 2018 11:02:12 +0000 (+0100) Subject: JAL-1264 exclude score-only from 'Add Reference Annotations' X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=039594a00b40c65c2864485c1c6ea939a49399a9;hp=49b68fe2a01763c44661e2012363f9847bfc789f;p=jalview.git JAL-1264 exclude score-only from 'Add Reference Annotations' --- diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index d1217bf..87aaf08 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -1461,28 +1461,31 @@ public class AlignmentUtils final List result = new ArrayList<>(); for (AlignmentAnnotation dsann : datasetAnnotations) { - /* - * Find matching annotations on the alignment. If none is found, then - * add this annotation to the list of 'addable' annotations for this - * sequence. - */ - final Iterable matchedAlignmentAnnotations = al - .findAnnotations(seq, dsann.getCalcId(), dsann.label); - if (!matchedAlignmentAnnotations.iterator().hasNext()) + if (dsann.annotations != null) // ignore non-positional annotation { - result.add(dsann); - if (labelForCalcId != null) + /* + * Find matching annotations on the alignment. If none is found, then + * add this annotation to the list of 'addable' annotations for this + * sequence. + */ + final Iterable matchedAlignmentAnnotations = al + .findAnnotations(seq, dsann.getCalcId(), dsann.label); + if (!matchedAlignmentAnnotations.iterator().hasNext()) { - labelForCalcId.put(dsann.getCalcId(), dsann.label); + result.add(dsann); + if (labelForCalcId != null) + { + labelForCalcId.put(dsann.getCalcId(), dsann.label); + } } } - } - /* - * Save any addable annotations for this sequence - */ - if (!result.isEmpty()) - { - candidates.put(seq, result); + /* + * Save any addable annotations for this sequence + */ + if (!result.isEmpty()) + { + candidates.put(seq, result); + } } } } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 89066cb..3f74327 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -139,9 +139,9 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; -import java.util.Enumeration; -import java.util.Hashtable; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.Vector; import javax.swing.JCheckBoxMenuItem; @@ -3903,35 +3903,33 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (viewport.getAlignment().getAlignmentAnnotation() - .hashCode() != _annotationScoreVectorHash) + .hashCode() == _annotationScoreVectorHash) { - sortByAnnotScore.removeAll(); - // almost certainly a quicker way to do this - but we keep it simple - Hashtable scoreSorts = new Hashtable(); - AlignmentAnnotation aann[]; - for (SequenceI sqa : viewport.getAlignment().getSequences()) + return; + } + + sortByAnnotScore.removeAll(); + Set scoreSorts = new HashSet<>(); + for (SequenceI sqa : viewport.getAlignment().getSequences()) + { + AlignmentAnnotation[] anns = sqa.getAnnotation(); + for (int i = 0; anns != null && i < anns.length; i++) { - aann = sqa.getAnnotation(); - for (int i = 0; aann != null && i < aann.length; i++) + AlignmentAnnotation aa = anns[i]; + if (aa != null && aa.hasScore() && aa.sequenceRef != null) { - if (aann[i].hasScore() && aann[i].sequenceRef != null) - { - scoreSorts.put(aann[i].label, aann[i].label); - } + scoreSorts.add(aa.label); } } - Enumeration labels = scoreSorts.keys(); - while (labels.hasMoreElements()) - { - addSortByAnnotScoreMenuItem(sortByAnnotScore, - (String) labels.nextElement()); - } - sortByAnnotScore.setVisible(scoreSorts.size() > 0); - scoreSorts.clear(); - - _annotationScoreVectorHash = viewport.getAlignment() - .getAlignmentAnnotation().hashCode(); } + for (String label : scoreSorts) + { + addSortByAnnotScoreMenuItem(sortByAnnotScore, label); + } + sortByAnnotScore.setVisible(!scoreSorts.isEmpty()); + + _annotationScoreVectorHash = viewport.getAlignment() + .getAlignmentAnnotation().hashCode(); } /**