From c3b91c81342d21498ffcb4639c3597a25aa2753c Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 4 Oct 2018 14:54:40 +0100 Subject: [PATCH] JAL-3132 status message for sequence and/or graph group annotation --- src/jalview/gui/AnnotationLabels.java | 55 ++++++++++++++++++++++++++-- src/jalview/gui/IdPanel.java | 8 ++-- test/jalview/gui/AnnotationLabelsTest.java | 48 ++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 6 deletions(-) diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 0ff6b73..6da6cc3 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -674,16 +674,65 @@ public class AnnotationLabels extends JPanel if (selectedRow > -1 && ap.av.getAlignment() .getAlignmentAnnotation().length > selectedRow) { - AlignmentAnnotation aa = ap.av.getAlignment() - .getAlignmentAnnotation()[selectedRow]; + AlignmentAnnotation[] anns = ap.av.getAlignment() + .getAlignmentAnnotation(); + AlignmentAnnotation aa = anns[selectedRow]; String desc = getTooltip(aa); this.setToolTipText(desc); - ap.alignFrame.setStatus(aa.label); + String msg = getStatusMessage(aa, anns); + ap.alignFrame.setStatus(msg); } } /** + * Constructs suitable text to show in the status bar when over an annotation + * label, containing the associated sequence name (if any), and the annotation + * labels (or all labels for a graph group annotation) + * + * @param aa + * @param anns + * @return + */ + static String getStatusMessage(AlignmentAnnotation aa, + AlignmentAnnotation[] anns) + { + if (aa == null) + { + return null; + } + + StringBuilder msg = new StringBuilder(32); + if (aa.sequenceRef != null) + { + msg.append(aa.sequenceRef.getName()).append(" : "); + } + + if (aa.graphGroup == -1) + { + msg.append(aa.label); + } + else if (anns != null) + { + boolean first = true; + for (int i = anns.length - 1; i >= 0; i--) + { + if (anns[i].graphGroup == aa.graphGroup) + { + if (!first) + { + msg.append(", "); + } + msg.append(anns[i].label); + first = false; + } + } + } + + return msg.toString(); + } + + /** * Answers a tooltip, formatted as html, containing the annotation description * (prefixed by associated sequence id if applicable), and the annotation * (non-positional) score if it has one. Answers null if neither description diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 579229c..e29330e 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -110,10 +110,12 @@ public class IdPanel extends JPanel /* * mouse is over an annotation label in wrapped mode */ - AlignmentAnnotation annotation = av.getAlignment() - .getAlignmentAnnotation()[pos.annotationIndex]; + AlignmentAnnotation[] anns = av.getAlignment() + .getAlignmentAnnotation(); + AlignmentAnnotation annotation = anns[pos.annotationIndex]; setToolTipText(AnnotationLabels.getTooltip(annotation)); - alignPanel.alignFrame.setStatus(annotation.label); + alignPanel.alignFrame.setStatus( + AnnotationLabels.getStatusMessage(annotation, anns)); } else { diff --git a/test/jalview/gui/AnnotationLabelsTest.java b/test/jalview/gui/AnnotationLabelsTest.java index 31839a9..616a1a6 100644 --- a/test/jalview/gui/AnnotationLabelsTest.java +++ b/test/jalview/gui/AnnotationLabelsTest.java @@ -102,4 +102,52 @@ public class AnnotationLabelsTest ann.sequenceRef = null; assertNull(AnnotationLabels.getTooltip(ann)); } + + @Test(groups = "Functional") + public void testGetStatusMessage() + { + assertNull(AnnotationLabels.getStatusMessage(null, null)); + + /* + * simple label + */ + AlignmentAnnotation aa = new AlignmentAnnotation("IUPredWS Short", + "Protein disorder", null); + assertEquals(AnnotationLabels.getStatusMessage(aa, null), + "IUPredWS Short"); + + /* + * with sequence ref + */ + aa.setSequenceRef(new Sequence("FER_CAPAA", "MIGRKQL")); + assertEquals(AnnotationLabels.getStatusMessage(aa, null), + "FER_CAPAA : IUPredWS Short"); + + /* + * with graph group (degenerate, one annotation only) + */ + aa.graphGroup = 1; + AlignmentAnnotation aa2 = new AlignmentAnnotation("IUPredWS Long", + "Protein disorder", null); + assertEquals( + AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[] + { aa, aa2 }), "FER_CAPAA : IUPredWS Short"); + + /* + * graph group with two members; note labels are appended in + * reverse order (matching rendering order on screen) + */ + aa2.graphGroup = 1; + assertEquals( + AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[] + { aa, aa2 }), "FER_CAPAA : IUPredWS Long, IUPredWS Short"); + + /* + * graph group with no sequence ref + */ + aa.sequenceRef = null; + assertEquals( + AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[] + { aa, aa2 }), "IUPredWS Long, IUPredWS Short"); + } } -- 1.7.10.2