From 0a871d8258ce41f9293615771b1c3dcf447f0eb6 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 15 Dec 2023 01:08:11 +0000 Subject: [PATCH] JAL-4290 Move some annotation visibility settings to after opening a structure. Set synchronously if in headless mode. --- src/jalview/bin/Commands.java | 130 +++++++++++++++++++++++++---------------- 1 file changed, 81 insertions(+), 49 deletions(-) diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index e01d40a..dbc5e23 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -210,8 +210,13 @@ public class Commands Boolean isError = Boolean.valueOf(false); - // set wrap scope here so it can be applied after structures are opened + // set wrap, showSSAnnotations, showAnnotations and hideTFrows scope here so + // it can be applied after structures are opened boolean wrap = false; + boolean showSSAnnotations = false; + boolean showAnnotations = false; + boolean hideTFrows = false; + AlignFrame af = null; if (avm.containsArg(Arg.APPEND) || avm.containsArg(Arg.OPEN)) { @@ -220,7 +225,6 @@ public class Commands boolean first = true; boolean progressBarSet = false; - AlignFrame af; // Combine the APPEND and OPEN files into one list, along with whether it // was APPEND or OPEN List openAvList = new ArrayList<>(); @@ -392,53 +396,17 @@ public class Commands } // Show secondary structure annotations? - boolean showSSAnnotations = avm.getFromSubValArgOrPref( + showSSAnnotations = avm.getFromSubValArgOrPref( Arg.SHOWSSANNOTATIONS, av.getSubVals(), null, "STRUCT_FROM_PDB", true); - // Show sequence annotations? - boolean showAnnotations = avm.getFromSubValArgOrPref( - Arg.SHOWANNOTATIONS, av.getSubVals(), null, - "SHOW_ANNOTATIONS", true); - - boolean hideTFrows = (avm.getBoolean(Arg.NOTEMPFAC)); - final AlignFrame _af = af; - // many of jalview's format/layout methods are only thread safe on the - // swingworker thread. - // all these methods should be on the alignViewController so it can - // coordinate such details - try - { - SwingUtilities.invokeAndWait(new Runnable() - { + showAnnotations = avm.getFromSubValArgOrPref(Arg.SHOWANNOTATIONS, + av.getSubVals(), null, "SHOW_ANNOTATIONS", true); + // hide the Temperature Factor row? + hideTFrows = (avm.getBoolean(Arg.NOTEMPFAC)); - @Override - public void run() - { - _af.setAnnotationsVisibility(showSSAnnotations, true, - false); - - _af.setAnnotationsVisibility(showAnnotations, false, true); - - // show temperature factor annotations? - if (hideTFrows) - { - // do this better (annotation types?) - List hideThese = new ArrayList<>(); - hideThese.add("Temperature Factor"); - hideThese.add(AlphaFoldAnnotationRowBuilder.LABEL); - AlignmentUtils.showOrHideSequenceAnnotations( - _af.getCurrentView().getAlignment(), hideThese, - null, false, false); - } - } - }); - } catch (Exception x) - { - Console.warn( - "Unexpected exception adjusting annotation row visibility.", - x); - } + // showSSAnnotations, showAnnotations, hideTFrows used after opening + // structure // wrap alignment? do this last for formatting reasons wrap = avm.getFromSubValArgOrPref(Arg.WRAP, sv, null, @@ -496,8 +464,10 @@ public class Commands // open the structure (from same PDB file or given PDBfile) if (!avm.getBoolean(Arg.NOSTRUCTURE)) { - - AlignFrame af = afMap.get(id); + if (af == null) + { + af = afMap.get(id); + } if (avm.containsArg(Arg.STRUCTURE)) { commandArgsProvided = true; @@ -867,10 +837,47 @@ public class Commands } } - if (wrap) + if (af == null) { + af = afMap.get(id); + } + // many of jalview's format/layout methods are only thread safe on the + // swingworker thread. + // all these methods should be on the alignViewController so it can + // coordinate such details + if (headless) + { + showOrHideAnnotations(af, showSSAnnotations, showAnnotations, + hideTFrows); + } + else + { + try + { + AlignFrame _af = af; + final boolean _showSSAnnotations = showSSAnnotations; + final boolean _showAnnotations = showAnnotations; + final boolean _hideTFrows = hideTFrows; + SwingUtilities.invokeAndWait(() -> { + showOrHideAnnotations(_af, _showSSAnnotations, _showAnnotations, + _hideTFrows); + } - AlignFrame af = afMap.get(id); + ); + } catch (Exception x) + { + Console.warn( + "Unexpected exception adjusting annotation row visibility.", + x); + } + } + + if (wrap) + { + if (af == null) + { + af = afMap.get(id); + } if (af != null) { af.setWrapFormat(wrap, true); @@ -897,6 +904,31 @@ public class Commands return theseArgsWereParsed && !isError; } + private static void showOrHideAnnotations(AlignFrame af, + boolean showSSAnnotations, boolean showAnnotations, + boolean hideTFrows) + { + Console.debug( + "##### Setting showSSAnnotations to " + showSSAnnotations); + Console.debug("##### Setting showAnnotations to " + showAnnotations); + Console.debug("##### Setting hideTFrows to " + hideTFrows); + af.setAnnotationsVisibility(showSSAnnotations, true, false); + + af.setAnnotationsVisibility(showAnnotations, false, true); + + // show temperature factor annotations? + if (hideTFrows) + { + // do this better (annotation types?) + List hideThese = new ArrayList<>(); + hideThese.add("Temperature Factor"); + hideThese.add(AlphaFoldAnnotationRowBuilder.LABEL); + AlignmentUtils.showOrHideSequenceAnnotations( + af.getCurrentView().getAlignment(), hideThese, null, false, + false); + } + } + protected void processGroovyScript(String id) { ArgValuesMap avm = argParser.getLinkedArgs(id); -- 1.7.10.2