From: Jim Procter Date: Fri, 17 Sep 2021 12:12:34 +0000 (+0100) Subject: JAL-2226 new method to search for annotation matching particular description as well... X-Git-Tag: Release_2_11_2_0~34^2~3^2~15 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ca47e4d0e1176893b414fba3fbe8a308e24cc52e;p=jalview.git JAL-2226 new method to search for annotation matching particular description as well as calcId and label --- diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 552349f..3bd7b4b 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -1799,13 +1799,32 @@ public class Sequence extends ASequence implements SequenceI public List getAlignmentAnnotations(String calcId, String label) { + return getAlignmentAnnotations(calcId, label, null, true); + } + + @Override + public List getAlignmentAnnotations(String calcId, + String label, String description) + { + return getAlignmentAnnotations(calcId, label, description, false); + } + + private List getAlignmentAnnotations(String calcId, + String label, String description, boolean nullWildcard) + { List result = new ArrayList<>(); if (this.annotation != null) { for (AlignmentAnnotation ann : annotation) { - if (ann.calcId != null && ann.calcId.equals(calcId) - && ann.label != null && ann.label.equals(label)) + if (((nullWildcard && calcId == null) + || (ann.calcId != null && ann.calcId.equals(calcId))) + && ((nullWildcard && label == null) + || (ann.label != null && ann.label.equals(label))) + && ((nullWildcard && description == null) + || (ann.description != null + && ann.description.equals(description)))) + { result.add(ann); } diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index 933f332..7c3eb41 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -446,6 +446,17 @@ public interface SequenceI extends ASequenceI String label); /** + * Returns a (possibly empty) list of any annotations that match on given + * calcId (source), label (type) and description (observation instance). + * Null values do not match. + * + * @param calcId + * @param label + * @param description + */ + public List getAlignmentAnnotations(String calcId, + String label, String description); + /** * create a new dataset sequence (if necessary) for this sequence and sets * this sequence to refer to it. This call will move any features or * references on the sequence onto the dataset. It will also make a duplicate diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index 6d07113..eb75645 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -192,6 +192,35 @@ public class SequenceTest assertTrue(seq.getAlignmentAnnotations(null, null).isEmpty()); } + + @Test(groups = { "Functional" }) + public void testGetAlignmentAnnotations_forCalcIdLabelAndDescription() + { + addAnnotation("label1", "desc1", "calcId1", 1f); + AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2", + 1f); + addAnnotation("label2", "desc3", "calcId3", 1f); + AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2", + 1f); + addAnnotation("label5", "desc3", null, 1f); + addAnnotation(null, "desc3", "calcId3", 1f); + + List anns = seq.getAlignmentAnnotations("calcId2", + "label2", "desc3"); + assertEquals(1, anns.size()); + assertSame(ann4, anns.get(0)); + /** + * null matching should fail + */ + assertTrue(seq.getAlignmentAnnotations("calcId3", "label2",null).isEmpty()); + + assertTrue(seq.getAlignmentAnnotations("calcId2", "label3",null).isEmpty()); + assertTrue(seq.getAlignmentAnnotations("calcId3", "label5",null).isEmpty()); + assertTrue(seq.getAlignmentAnnotations("calcId2", null,null).isEmpty()); + assertTrue(seq.getAlignmentAnnotations(null, "label3",null).isEmpty()); + assertTrue(seq.getAlignmentAnnotations(null, null,null).isEmpty()); + } + /** * Tests for addAlignmentAnnotation. Note this method has the side-effect of * setting the sequenceRef on the annotation. Adding the same annotation twice