From 3fd44a9b8f3e44b671ee26be26a8c1d541de3028 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 2 May 2014 10:43:26 +0100 Subject: [PATCH] JAL-1397 JAL-1066 JAL-1233 refactored annotation colours XML parsing code and support per group annotation colours --- src/jalview/gui/Jalview2XML.java | 316 ++++++++++++++++++++++---------------- 1 file changed, 185 insertions(+), 131 deletions(-) diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 400fd94..a1a009d 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -942,10 +942,10 @@ public class Jalview2XML } else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient) { - groups[i] - .setColour(ColourSchemeProperty - .getColourName(((jalview.schemes.AnnotationColourGradient) sg.cs) - .getBaseColour())); + groups[i].setColour("AnnotationColourGradient"); + groups[i].setAnnotationColours(constructAnnotationColours( + (jalview.schemes.AnnotationColourGradient) sg.cs, + userColours, jms)); } else if (sg.cs instanceof jalview.schemes.UserColourScheme) { @@ -1018,28 +1018,11 @@ public class Jalview2XML } else if (av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient) { - jalview.schemes.AnnotationColourGradient acg = (jalview.schemes.AnnotationColourGradient) av - .getGlobalColourScheme(); - - AnnotationColours ac = new AnnotationColours(); - ac.setAboveThreshold(acg.getAboveThreshold()); - ac.setThreshold(acg.getAnnotationThreshold()); - ac.setAnnotation(acg.getAnnotation()); - if (acg.getBaseColour() instanceof jalview.schemes.UserColourScheme) - { - ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(), - userColours, jms)); - } - else - { - ac.setColourScheme(ColourSchemeProperty.getColourName(acg - .getBaseColour())); - } + AnnotationColours ac = constructAnnotationColours( + (jalview.schemes.AnnotationColourGradient) av + .getGlobalColourScheme(), + userColours, jms); - ac.setMaxColour(acg.getMaxColour().getRGB()); - ac.setMinColour(acg.getMinColour().getRGB()); - ac.setPerSequence(acg.isSeqAssociated()); - ac.setPredefinedColours(acg.isPredefinedColours()); view.setAnnotationColours(ac); view.setBgColour("AnnotationColourGradient"); } @@ -1259,7 +1242,35 @@ public class Jalview2XML return object; } - private void storeAlignmentAnnotation(AlignmentAnnotation[] aa, IdentityHashMap groupRefs, AlignmentViewport av, Set calcIdSet, boolean storeDS, SequenceSet vamsasSet) + private AnnotationColours constructAnnotationColours( + AnnotationColourGradient acg, Vector userColours, + JalviewModelSequence jms) + { + AnnotationColours ac = new AnnotationColours(); + ac.setAboveThreshold(acg.getAboveThreshold()); + ac.setThreshold(acg.getAnnotationThreshold()); + ac.setAnnotation(acg.getAnnotation()); + if (acg.getBaseColour() instanceof jalview.schemes.UserColourScheme) + { + ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(), + userColours, jms)); + } + else + { + ac.setColourScheme(ColourSchemeProperty.getColourName(acg + .getBaseColour())); + } + + ac.setMaxColour(acg.getMaxColour().getRGB()); + ac.setMinColour(acg.getMinColour().getRGB()); + ac.setPerSequence(acg.isSeqAssociated()); + ac.setPredefinedColours(acg.isPredefinedColours()); + return ac; + } + + private void storeAlignmentAnnotation(AlignmentAnnotation[] aa, + IdentityHashMap groupRefs, AlignmentViewport av, + Set calcIdSet, boolean storeDS, SequenceSet vamsasSet) { for (int i = 0; i < aa.length; i++) @@ -2554,7 +2565,7 @@ public class Jalview2XML if (jms.getJGroupCount() > 0) { JGroup[] groups = jms.getJGroup(); - + boolean addAnnotSchemeGroup = false; for (int i = 0; i < groups.length; i++) { ColourSchemeI cs = null; @@ -2565,6 +2576,12 @@ public class Jalview2XML { cs = GetUserColourScheme(jms, groups[i].getColour()); } + else if (groups[i].getColour().equals("AnnotationColourGradient") + && groups[i].getAnnotationColours() != null) + { + addAnnotSchemeGroup = true; + cs = null; + } else { cs = ColourSchemeProperty.getColour(al, groups[i].getColour()); @@ -2663,7 +2680,12 @@ public class Jalview2XML } } al.addGroup(sg); - + if (addAnnotSchemeGroup) + { + // reconstruct the annotation colourscheme + sg.cs = constructAnnotationColour( + groups[i].getAnnotationColours(), null, al, jms, false); + } } } if (view == null) @@ -2714,6 +2736,13 @@ public class Jalview2XML } } + /** + * indicate that annotation colours are applied across all groups (pre + * Jalview 2.8.1 behaviour) + */ + boolean doGroupAnnColour = isVersionStringLaterThan("2.8.1", + object.getVersion()); + AlignmentPanel ap = null; boolean isnewview = true; if (viewId != null) @@ -3369,111 +3398,11 @@ public class Jalview2XML } else if (view.getBgColour().startsWith("Annotation")) { - // int find annotation - if (af.viewport.getAlignment().getAlignmentAnnotation() != null) - { - for (int i = 0; i < af.viewport.getAlignment() - .getAlignmentAnnotation().length; i++) - { - if (af.viewport.getAlignment().getAlignmentAnnotation()[i].label - .equals(view.getAnnotationColours().getAnnotation())) - { - if (af.viewport.getAlignment().getAlignmentAnnotation()[i] - .getThreshold() == null) - { - af.viewport.getAlignment().getAlignmentAnnotation()[i] - .setThreshold(new jalview.datamodel.GraphLine(view - .getAnnotationColours().getThreshold(), - "Threshold", java.awt.Color.black) + AnnotationColours viewAnnColour = view.getAnnotationColours(); + cs = constructAnnotationColour(viewAnnColour, af, al, jms, true); - ); - } - - if (view.getAnnotationColours().getColourScheme() - .equals("None")) - { - cs = new AnnotationColourGradient(af.viewport - .getAlignment().getAlignmentAnnotation()[i], - new java.awt.Color(view.getAnnotationColours() - .getMinColour()), new java.awt.Color(view - .getAnnotationColours().getMaxColour()), - view.getAnnotationColours().getAboveThreshold()); - } - else if (view.getAnnotationColours().getColourScheme() - .startsWith("ucs")) - { - cs = new AnnotationColourGradient(af.viewport - .getAlignment().getAlignmentAnnotation()[i], - GetUserColourScheme(jms, view - .getAnnotationColours().getColourScheme()), - view.getAnnotationColours().getAboveThreshold()); - } - else - { - cs = new AnnotationColourGradient(af.viewport - .getAlignment().getAlignmentAnnotation()[i], - ColourSchemeProperty.getColour(al, view - .getAnnotationColours().getColourScheme()), - view.getAnnotationColours().getAboveThreshold()); - } - if (view.getAnnotationColours().hasPerSequence()) - { - ((AnnotationColourGradient)cs).setSeqAssociated(view.getAnnotationColours().isPerSequence()); - } - if (view.getAnnotationColours().hasPredefinedColours()) - { - ((AnnotationColourGradient)cs).setPredefinedColours(view.getAnnotationColours().isPredefinedColours()); - } - // Also use these settings for all the groups - if (al.getGroups() != null) - { - for (int g = 0; g < al.getGroups().size(); g++) - { - jalview.datamodel.SequenceGroup sg = al.getGroups() - .get(g); - - if (sg.cs == null) - { - continue; - } - - /* - * if - * (view.getAnnotationColours().getColourScheme().equals("None" - * )) { sg.cs = new AnnotationColourGradient( - * af.viewport.getAlignment().getAlignmentAnnotation()[i], new - * java.awt.Color(view.getAnnotationColours(). - * getMinColour()), new - * java.awt.Color(view.getAnnotationColours(). - * getMaxColour()), - * view.getAnnotationColours().getAboveThreshold()); } else - */ - { - sg.cs = new AnnotationColourGradient(af.viewport - .getAlignment().getAlignmentAnnotation()[i], - sg.cs, view.getAnnotationColours() - .getAboveThreshold()); - if (cs instanceof AnnotationColourGradient) - { - if (view.getAnnotationColours().hasPerSequence()) - { - ((AnnotationColourGradient)cs).setSeqAssociated(view.getAnnotationColours().isPerSequence()); - } - if (view.getAnnotationColours().hasPredefinedColours()) - { - ((AnnotationColourGradient)cs).setPredefinedColours(view.getAnnotationColours().isPredefinedColours()); - } - } - } + // annpos - } - } - - break; - } - - } - } } else { @@ -3667,6 +3596,131 @@ public class Jalview2XML return af; } + private ColourSchemeI constructAnnotationColour( + AnnotationColours viewAnnColour, AlignFrame af, Alignment al, + JalviewModelSequence jms, boolean checkGroupAnnColour) + { + boolean propagateAnnColour = false; + ColourSchemeI cs = null; + AlignmentI annAlignment = af != null ? af.viewport.getAlignment() : al; + if (checkGroupAnnColour && al.getGroups() != null + && al.getGroups().size() > 0) + { + // pre 2.8.1 behaviour + // check to see if we should transfer annotation colours + propagateAnnColour = true; + for (jalview.datamodel.SequenceGroup sg : al.getGroups()) + { + if (sg.cs instanceof AnnotationColourGradient) + { + propagateAnnColour = false; + } + } + } + // int find annotation + if (annAlignment.getAlignmentAnnotation() != null) + { + for (int i = 0; i < annAlignment.getAlignmentAnnotation().length; i++) + { + if (annAlignment.getAlignmentAnnotation()[i].label + .equals(viewAnnColour.getAnnotation())) + { + if (annAlignment.getAlignmentAnnotation()[i].getThreshold() == null) + { + annAlignment.getAlignmentAnnotation()[i] + .setThreshold(new jalview.datamodel.GraphLine( + viewAnnColour.getThreshold(), "Threshold", + java.awt.Color.black) + + ); + } + + if (viewAnnColour.getColourScheme().equals("None")) + { + cs = new AnnotationColourGradient( + annAlignment.getAlignmentAnnotation()[i], + new java.awt.Color(viewAnnColour.getMinColour()), + new java.awt.Color(viewAnnColour.getMaxColour()), + viewAnnColour.getAboveThreshold()); + } + else if (viewAnnColour.getColourScheme().startsWith("ucs")) + { + cs = new AnnotationColourGradient( + annAlignment.getAlignmentAnnotation()[i], + GetUserColourScheme(jms, + viewAnnColour.getColourScheme()), + viewAnnColour.getAboveThreshold()); + } + else + { + cs = new AnnotationColourGradient( + annAlignment.getAlignmentAnnotation()[i], + ColourSchemeProperty.getColour(al, + viewAnnColour.getColourScheme()), + viewAnnColour.getAboveThreshold()); + } + if (viewAnnColour.hasPerSequence()) + { + ((AnnotationColourGradient) cs).setSeqAssociated(viewAnnColour + .isPerSequence()); + } + if (viewAnnColour.hasPredefinedColours()) + { + ((AnnotationColourGradient) cs) + .setPredefinedColours(viewAnnColour + .isPredefinedColours()); + } + if (propagateAnnColour && al.getGroups() != null) + { + // Also use these settings for all the groups + for (int g = 0; g < al.getGroups().size(); g++) + { + jalview.datamodel.SequenceGroup sg = al.getGroups().get(g); + + if (sg.cs == null) + { + continue; + } + + /* + * if (viewAnnColour.getColourScheme().equals("None" )) { sg.cs = + * new AnnotationColourGradient( + * annAlignment.getAlignmentAnnotation()[i], new + * java.awt.Color(viewAnnColour. getMinColour()), new + * java.awt.Color(viewAnnColour. getMaxColour()), + * viewAnnColour.getAboveThreshold()); } else + */ + { + sg.cs = new AnnotationColourGradient( + annAlignment.getAlignmentAnnotation()[i], sg.cs, + viewAnnColour.getAboveThreshold()); + if (cs instanceof AnnotationColourGradient) + { + if (viewAnnColour.hasPerSequence()) + { + ((AnnotationColourGradient) cs) + .setSeqAssociated(viewAnnColour.isPerSequence()); + } + if (viewAnnColour.hasPredefinedColours()) + { + ((AnnotationColourGradient) cs) + .setPredefinedColours(viewAnnColour + .isPredefinedColours()); + } + } + } + + } + } + + break; + } + + } + } + return cs; + } + private void reorderAutoannotation(AlignFrame af, Alignment al, ArrayList autoAlan) { -- 1.7.10.2