From: Jim Procter Date: Mon, 16 Sep 2024 15:50:49 +0000 (+0100) Subject: JAL-4392 autohide the secondary structure consensus annotation by setting AlignmentAn... X-Git-Tag: Release_2_11_4_0~5^2~4^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fpatch%2FJAL-4392_hide_ssconsensus_if_no_data;p=jalview.git JAL-4392 autohide the secondary structure consensus annotation by setting AlignmentAnnotation.hasData to false so it is not displayed in view --- diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java index 0fa80b3..dd5cb91 100755 --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@ -189,7 +189,7 @@ public class AAFrequency result[column] = profile; } - return new Profiles(result); + return new Profiles(seqCount, result); // long elapsed = System.currentTimeMillis() - now; // jalview.bin.Console.outPrintln(elapsed); } @@ -234,7 +234,7 @@ public class AAFrequency int seqCount = sequences.length; ProfileI[] result = new ProfileI[width]; - + int maxSSannotcount=0; for (int column = start; column < end; column++) { @@ -290,8 +290,9 @@ public class AAFrequency } result[column] = profile; + maxSSannotcount=Math.max(maxSSannotcount, ssCount); } - return new Profiles(result); + return new Profiles(maxSSannotcount,result); } /** @@ -405,7 +406,7 @@ public class AAFrequency */ return; } - + for (int i = startCol; i < endCol; i++) { ProfileI profile = profiles.get(i); diff --git a/src/jalview/analysis/AlignmentAnnotationUtils.java b/src/jalview/analysis/AlignmentAnnotationUtils.java index f5626ce..ac1bda0 100644 --- a/src/jalview/analysis/AlignmentAnnotationUtils.java +++ b/src/jalview/analysis/AlignmentAnnotationUtils.java @@ -131,7 +131,7 @@ public class AlignmentAnnotationUtils */ { String rememberAs = calcId + "!" + displayLabel; - if (aa.visible && !addedToShown.contains(rememberAs)) + if (aa.isForDisplay() && !addedToShown.contains(rememberAs)) // exclude noData annotations { if (!shownTypes.containsKey(calcId)) { @@ -214,7 +214,7 @@ public class AlignmentAnnotationUtils BitSet result = new BitSet(); for (AlignmentAnnotation ann : annotations) { - if (ann.graph == AlignmentAnnotation.LINE_GRAPH && ann.visible) + if (ann.graph == AlignmentAnnotation.LINE_GRAPH && ann.visible) { int gg = ann.graphGroup; if (gg > -1) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index ba74f67..0a3ce71 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -3072,7 +3072,7 @@ public class AlignmentUtils for (AlignmentAnnotation annot : aa) { - if (annot.visible) + if (annot.isForDisplay()) { return annot; } diff --git a/src/jalview/analysis/Dna.java b/src/jalview/analysis/Dna.java index aa71eb7..9a99b69 100644 --- a/src/jalview/analysis/Dna.java +++ b/src/jalview/analysis/Dna.java @@ -316,7 +316,7 @@ public class Dna * protein we need a smarter way to 'translate' without generating * invalid (unbalanced) structure annotation. */ - if (annotation.autoCalculated || !annotation.visible + if (annotation.autoCalculated || !annotation.isForDisplay() || annotation.isRNA()) { continue; diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index d85c3d8..e31f292 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -289,6 +289,14 @@ public class AlignmentAnnotation /** is the row visible */ public boolean visible = true; + + /** + * is there data for this annotation row to display ? if not then hide it! + * For rows that are only shown when data is present (default true) + */ + public boolean hasData=true; + + public int graphGroup = -1; @@ -764,6 +772,7 @@ public class AlignmentAnnotation this.label = annotation.label; this.padGaps = annotation.padGaps; this.visible = annotation.visible; + this.hasData = annotation.hasData; this.centreColLabels = annotation.centreColLabels; this.scaleColLabel = annotation.scaleColLabel; this.showAllColLabels = annotation.showAllColLabels; @@ -1577,6 +1586,14 @@ public class AlignmentAnnotation { return graphMin < graphMax; } + + /** + * @return true if hasData and visible are true + */ + public boolean isForDisplay() + { + return hasData && visible; + } /** * delete any columns in alignmentAnnotation that are hidden (including diff --git a/src/jalview/datamodel/Profiles.java b/src/jalview/datamodel/Profiles.java index 14eae51..0d28e69 100644 --- a/src/jalview/datamodel/Profiles.java +++ b/src/jalview/datamodel/Profiles.java @@ -22,11 +22,13 @@ package jalview.datamodel; public class Profiles implements ProfilesI { - + int sourceCount; + private ProfileI[] profiles; - public Profiles(ProfileI[] p) + public Profiles(int sourceCount, ProfileI[] p) { + this.sourceCount=sourceCount; profiles = p; } @@ -61,4 +63,9 @@ public class Profiles implements ProfilesI return profiles == null ? 0 : profiles.length - 1; } + @Override + public int getCount() + { + return sourceCount; + } } diff --git a/src/jalview/datamodel/ProfilesI.java b/src/jalview/datamodel/ProfilesI.java index 82398d9..29108c2 100644 --- a/src/jalview/datamodel/ProfilesI.java +++ b/src/jalview/datamodel/ProfilesI.java @@ -28,5 +28,11 @@ public interface ProfilesI int getStartColumn(); int getEndColumn(); + + /** + * + * @return number of contributing sequences/annotation rows + */ + int getCount(); } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 0f5a9e8..83bd980 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -405,7 +405,7 @@ public class AlignmentPanel extends GAlignmentPanel implements for (i = 0; i < al.getAlignmentAnnotation().length; i++) { AlignmentAnnotation aa = al.getAlignmentAnnotation()[i]; - if (visibleOnly && !aa.visible) + if (visibleOnly && !aa.isForDisplay()) { continue; } diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 27417f0..32298ca 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -192,7 +192,7 @@ public class AnnotationLabels extends JPanel for (int i = 0; i < aa.length; i++) { selectedRow = -1; - if (!aa[i].visible) + if (!aa[i].isForDisplay()) { continue; } @@ -1379,7 +1379,7 @@ public class AnnotationLabels extends JPanel for (int i = 0; i < aa.length; i++) { visible = true; - if (!aa[i].visible && !includeHidden) + if (!aa[i].isForDisplay() && !includeHidden) { hasHiddenRows = true; continue; @@ -1387,7 +1387,7 @@ public class AnnotationLabels extends JPanel olY = y; // look ahead to next annotation for (nexAA = i + 1; nexAA < aa.length - && (!aa[nexAA].visible && includeHidden); nexAA++) + && (!aa[nexAA].isForDisplay() && includeHidden); nexAA++) ; y += aa[i].height; if (clip) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index ea32684..747eac3 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -564,7 +564,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, for (int i = 0; i < aa.length; i++) { - if (aa[i].visible) + if (aa[i].isForDisplay()) { height += aa[i].height; } @@ -1231,7 +1231,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, int height = 0, lheight = 0; for (int i = 0; i < aa.length; i++) { - if (aa[i].visible) + if (aa[i].isForDisplay()) { lheight = height; height += aa[i].height; diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 9e9329a..2f5b919 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -565,7 +565,7 @@ public class AnnotationRenderer } Annotation[] row_annotations = row.annotations; - if (!row.visible) + if (!row.isForDisplay()) { continue; } diff --git a/src/jalview/schemes/RNAHelicesColour.java b/src/jalview/schemes/RNAHelicesColour.java index 62b4579..7a53b1a 100644 --- a/src/jalview/schemes/RNAHelicesColour.java +++ b/src/jalview/schemes/RNAHelicesColour.java @@ -109,7 +109,7 @@ public class RNAHelicesColour extends ResidueColourScheme { // is this a sensible way of determining type of annotation? - if (annotations[i].visible && annotations[i].isRNA() + if (annotations[i].isForDisplay() && annotations[i].isRNA() && annotations[i].isValidStruc()) { annotation = annotations[i]; diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index f4201c1..a48616c 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -2213,7 +2213,7 @@ public abstract class AlignmentViewport jalview.bin.Console.errPrintln("Null annotation row: ignoring."); continue; } - if (!aa.visible) + if (!aa.isForDisplay()) { continue; } diff --git a/src/jalview/workers/SecondaryStructureConsensusThread.java b/src/jalview/workers/SecondaryStructureConsensusThread.java index 945d99b..1263133 100644 --- a/src/jalview/workers/SecondaryStructureConsensusThread.java +++ b/src/jalview/workers/SecondaryStructureConsensusThread.java @@ -206,6 +206,8 @@ public class SecondaryStructureConsensusThread extends AlignCalcWorker { deriveGap(gap, hSSConsensus); } + + ssConsensus.hasData=hSSConsensus.getCount()>0; } } diff --git a/src/jalview/workers/StrucConsensusThread.java b/src/jalview/workers/StrucConsensusThread.java index 61ec3d0..94c9771 100644 --- a/src/jalview/workers/StrucConsensusThread.java +++ b/src/jalview/workers/StrucConsensusThread.java @@ -98,7 +98,7 @@ public class StrucConsensusThread extends AlignCalcWorker { for (int i = 0; i < aa.length; i++) { - if (aa[i].visible && aa[i].isRNA() && aa[i].isValidStruc()) + if (aa[i].isForDisplay() && aa[i].isRNA() && aa[i].isValidStruc()) { rnaStruc = aa[i]; break; diff --git a/test/jalview/datamodel/SequenceGroupTest.java b/test/jalview/datamodel/SequenceGroupTest.java index 622ebb9..a99509a 100644 --- a/test/jalview/datamodel/SequenceGroupTest.java +++ b/test/jalview/datamodel/SequenceGroupTest.java @@ -260,7 +260,7 @@ public class SequenceGroupTest Collections. emptyList(), 3, 12); PA.setValue(cons, "consSequence", new Sequence("s", "abc")); sg.getGroupColourScheme().setConservation(cons); - sg.getGroupColourScheme().setConsensus(new Profiles(null)); + sg.getGroupColourScheme().setConsensus(new Profiles(0,null)); sg.setDisplayBoxes(false); sg.setDisplayText(false); sg.setColourText(true); diff --git a/test/jalview/renderer/ResidueShaderTest.java b/test/jalview/renderer/ResidueShaderTest.java index 528abed..d5384d6 100644 --- a/test/jalview/renderer/ResidueShaderTest.java +++ b/test/jalview/renderer/ResidueShaderTest.java @@ -63,7 +63,7 @@ public class ResidueShaderTest profiles[2] = new Profile(4, 4, 0, ""); profiles[3] = new Profile(4, 1, 2, "T"); ResidueShader ccs = new ResidueShader(new PIDColourScheme()); - ccs.setConsensus(new Profiles(profiles)); + ccs.setConsensus(new Profiles(3,profiles)); /* * no threshold @@ -389,6 +389,13 @@ public class ResidueShaderTest { return 0; } + + @Override + public int getCount() + { + // TODO Auto-generated method stub + return 0; + } }; return consensus;