JAL-4392 Bug fixing and code refactoring.
authorRenia Correya <rcorreya001@dundee.ac.uk>
Wed, 5 Jun 2024 10:03:04 +0000 (11:03 +0100)
committerRenia Correya <rcorreya001@dundee.ac.uk>
Wed, 5 Jun 2024 10:03:04 +0000 (11:03 +0100)
resources/lang/Messages.properties
src/jalview/analysis/AlignmentUtils.java
src/jalview/api/AlignViewportI.java
src/jalview/api/ViewStyleI.java
src/jalview/datamodel/Alignment.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/AnnotationLabels.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/viewmodel/styles/ViewStyle.java

index cd76e14..eb267d7 100644 (file)
@@ -279,13 +279,13 @@ label.show_selected_annotations = Show selected annotations
 label.group_consensus = Group Consensus
 label.group_conservation = Group Conservation
 label.show_consensus_histogram = Show Consensus Histogram
-label.show_ssconsensus_histogram = Show SS Consensus Histogram
 label.show_consensus_logo = Show Consensus Logo
 label.show_ssconsensus_logo = Show SS Consensus Logo
 label.norm_consensus_logo = Normalise Consensus Logo
 label.apply_all_groups = Apply to all groups
 label.autocalculated_annotation = Autocalculated Annotation
 label.show_secondary_structure = Show Secondary Structure
+label.show_secondary_structure_consensus = Show Secondary Structure Consensus
 label.show_first = Show first
 label.show_last = Show last
 label.struct_from_pdb = Process secondary structure from PDB
index 7da3ee0..f69864f 100644 (file)
@@ -3084,8 +3084,9 @@ public class AlignmentUtils
         for (AlignmentAnnotation annot : aa)
         {
 
-          if (ssSource
-                  .equals(extractSSSourceFromAnnotationDescription(annot)))
+          String ssSourceForAnnot = extractSSSourceFromAnnotationDescription(annot);
+          if (ssSourceForAnnot != null && ssSource
+                  .equals(ssSourceForAnnot))
           {
             ssAnnots.add(annot);
           }
@@ -3136,7 +3137,7 @@ public class AlignmentUtils
 
           String ssSource = AlignmentUtils
                   .extractSSSourceFromAnnotationDescription(aa);
-          if (ssSource.equals(selectedSSSource))
+          if (ssSource != null && ssSource.equals(selectedSSSource))
           {
 
             ssAlignmentAnnotationForSequences
index 126c8c1..2cdb251 100644 (file)
@@ -86,12 +86,8 @@ public interface AlignViewportI extends ViewStyleI
 
   boolean isShowConsensusHistogram();
   
-  boolean isShowSSConsensusHistogram();
-
   boolean isShowSequenceLogo();
   
-  boolean isShowSequenceSSLogo();
-
   boolean isNormaliseSequenceLogo();
 
   ColourSchemeI getGlobalColourScheme();
index a348300..9e87c87 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.api;
 
 import java.awt.Color;
+import java.util.List;
 
 public interface ViewStyleI
 {
@@ -278,4 +279,8 @@ public interface ViewStyleI
    * @return
    */
   void setProteinFontAsCdna(boolean b);
+
+  void setSecondaryStructureSources(List<String> secondaryStructureSources);
+
+  List<String> getSecondaryStructureSources();
 }
index ce9250c..5073912 100755 (executable)
@@ -72,8 +72,6 @@ public class Alignment implements AlignmentI, AutoCloseable
 
   private List<AlignedCodonFrame> codonFrameList;
   
-  private List<String> secondaryStructureSources;
-
   private void initAlignment(SequenceI[] seqs)
   {
     groups = Collections.synchronizedList(new ArrayList<SequenceGroup>());
@@ -2126,15 +2124,4 @@ public class Alignment implements AlignmentI, AutoCloseable
 
   }
 
-  public List<String> getSecondaryStructureSources()
-  {
-    return secondaryStructureSources;
-  }
-
-  public void setSecondaryStructureSources(
-          List<String> secondaryStructureSources)
-  {
-    this.secondaryStructureSources = secondaryStructureSources;
-  }
-
 }
index 8dfc2e6..0470a28 100644 (file)
@@ -5685,6 +5685,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     
     ssSources = AlignmentUtils.extractSSSourceInAlignmentAnnotation(anns);
     
+    if(ssSources == null) {
+      showSS.removeAll();
+      ssButtonGroup.clearSelection();
+      return;
+    }
+    
     List<String> selectedCheckBoxes = getSelectedOptions(checkboxMap);
     
     // Add checkboxes for categories
@@ -5781,7 +5787,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         if (label.equals(aa.label)) { 
 
             String ssSource = AlignmentUtils.extractSSSourceFromAnnotationDescription(aa);
-            if(ssSource.equals(ssSourceSelection) || ssSourceSelection.equals(noneOption)) {
+
+            if(ssSource != null && (ssSource.equals(ssSourceSelection) || ssSourceSelection.equals(noneOption))) {
               aa.visible = visible;
             }           
         }
@@ -5794,6 +5801,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       alignPanel.paintAlignment(true, true);
     
   }
+  
+  protected void showSSConsensus_actionPerformed(ActionEvent e)
+  {
+    viewport.setShowSSConsensus(showSSConsensus.getState());
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+    
+  }
 
 
   /*
@@ -5839,13 +5853,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
   }
   
-  @Override
-  protected void showSSConsensusHistogram_actionPerformed(ActionEvent e)
-  {
-    viewport.setShowSSConsensusHistogram(showSSConsensusHistogram.getState());
-    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
-  }
-
   /*
    * (non-Javadoc)
    * 
index 756a266..36812f1 100644 (file)
@@ -281,8 +281,6 @@ public class AlignViewport extends AlignmentViewport
       }
       showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
               true);
-      showSSConsensusHistogram = Cache.getDefault("SHOW_SSCONSENSUS_HISTOGRAM",
-              true);
       showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", true);
       normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
               false);
index 7c5afcd..79446e2 100755 (executable)
@@ -40,6 +40,7 @@ import java.awt.geom.AffineTransform;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Locale;
 
 import javax.swing.JCheckBoxMenuItem;
@@ -51,6 +52,7 @@ import javax.swing.ToolTipManager;
 
 import jalview.analysis.AlignSeq;
 import jalview.analysis.AlignmentUtils;
+import jalview.api.AlignCalcWorkerI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.datamodel.Alignment;
@@ -65,8 +67,10 @@ import jalview.datamodel.SequenceI;
 import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.util.Comparison;
+import jalview.util.Constants;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
+import jalview.workers.SecondaryStructureConsensusThread;
 
 /**
  * The panel that holds the labels for alignment annotations, providing
@@ -245,6 +249,15 @@ public class AnnotationLabels extends JPanel
     {
       ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
       ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
+      
+      
+      List<AlignCalcWorkerI> workers = ap.av.getCalcManager()
+              .getRegisteredWorkersOfClass(SecondaryStructureConsensusThread.class);
+      if (!workers.isEmpty()) {
+          
+        ap.alignFrame.getViewport().getCalcManager().startWorker(workers.remove(0));
+
+      }
     }
     else if (SHOWALL.equals(action))
     {
index c93c104..3d249bb 100755 (executable)
@@ -196,14 +196,14 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenuItem expandViews = new JMenuItem();
   
+  protected JCheckBoxMenuItem showSSConsensus = new JCheckBoxMenuItem(); 
+  
   protected JCheckBoxMenuItem showGroupConsensus = new JCheckBoxMenuItem();
 
   protected JCheckBoxMenuItem showGroupConservation = new JCheckBoxMenuItem();
 
   protected JCheckBoxMenuItem showConsensusHistogram = new JCheckBoxMenuItem();  
 
-  protected JCheckBoxMenuItem showSSConsensusHistogram = new JCheckBoxMenuItem();
-
   protected JCheckBoxMenuItem showSequenceLogo = new JCheckBoxMenuItem();
 
   protected JCheckBoxMenuItem normaliseSequenceLogo = new JCheckBoxMenuItem();
@@ -859,6 +859,19 @@ public class GAlignFrame extends JInternalFrame
 
     });
 
+    showSSConsensus
+            .setText(MessageManager.getString("label.show_secondary_structure_consensus"));
+    showSSConsensus.addActionListener(new ActionListener()
+    {
+    
+    @Override
+    public void actionPerformed(ActionEvent e)
+    {
+      showSSConsensus_actionPerformed(e);
+    }
+    
+    });
+
     showGroupConsensus
             .setText(MessageManager.getString("label.group_consensus"));
     showGroupConsensus.addActionListener(new ActionListener()
@@ -883,18 +896,6 @@ public class GAlignFrame extends JInternalFrame
       }
 
     });    
-    showSSConsensusHistogram.setText(
-            MessageManager.getString("label.show_ssconsensus_histogram"));
-    showSSConsensusHistogram.addActionListener(new ActionListener()
-    {
-
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        showConsensusHistogram_actionPerformed(e);
-      }
-
-    });
     showSequenceLogo
             .setText(MessageManager.getString("label.show_consensus_logo"));
     showSequenceLogo.addActionListener(new ActionListener()
@@ -1963,9 +1964,9 @@ public class GAlignFrame extends JInternalFrame
     autoAnnMenu.addSeparator();
     autoAnnMenu.add(applyAutoAnnotationSettings);
     autoAnnMenu.add(showConsensusHistogram);
-    autoAnnMenu.add(showSSConsensusHistogram);
     autoAnnMenu.add(showSequenceLogo);
     autoAnnMenu.add(normaliseSequenceLogo);
+    autoAnnMenu.add(showSSConsensus);
     autoAnnMenu.addSeparator();
     autoAnnMenu.add(showGroupConservation);
     autoAnnMenu.add(showGroupConsensus);
@@ -2050,6 +2051,12 @@ public class GAlignFrame extends JInternalFrame
     // selectMenu.add(listenToViewSelections);
   }
 
+  protected void showSSConsensus_actionPerformed(ActionEvent e)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
   protected void createPNG_actionPerformed(ActionEvent object)
   {
     // TODO Auto-generated method stub
@@ -2298,12 +2305,6 @@ public class GAlignFrame extends JInternalFrame
     // TODO Auto-generated method stub
 
   }
-  
-  protected void showSSConsensusHistogram_actionPerformed(ActionEvent e)
-  {
-    // TODO Auto-generated method stub
-
-  }
 
   protected void showSequenceLogo_actionPerformed(ActionEvent e)
   {
index 093410d..2f0244f 100644 (file)
@@ -703,8 +703,6 @@ public abstract class AlignmentViewport
   
   protected List<AlignmentAnnotation> secondaryStructureConsensus;
 
-  protected List<String> secondaryStructureSources;
-
   protected AlignmentAnnotation complementConsensus;
 
   protected AlignmentAnnotation gapcounts;
@@ -752,14 +750,14 @@ public abstract class AlignmentViewport
   @Override
   public List<String> getSecondaryStructureSources()
   {
-    return secondaryStructureSources;
+    return viewStyle.getSecondaryStructureSources();
   }
 
   @Override
   public void setSecondaryStructureSources(
           List<String> secondaryStructureSources)
   {
-    this.secondaryStructureSources = secondaryStructureSources;
+    viewStyle.setSecondaryStructureSources(secondaryStructureSources);
   }
   
   protected void setSecondaryStructureSources(AlignmentAnnotation[] aa)
@@ -770,7 +768,7 @@ public abstract class AlignmentViewport
       sources = AlignmentUtils.extractSSSourceInAlignmentAnnotation(aa);
       if(sources != null) {
         sources.add(0,MessageManager.getString("option.ss_providers_all"));
-        setSecondaryStructureSources(sources);
+        viewStyle.setSecondaryStructureSources(sources);
       }
     }
   }
@@ -970,9 +968,10 @@ public abstract class AlignmentViewport
     {
       return;
     }
-    if (secondaryStructureConsensus.size() != secondaryStructureSources.size()) {
+    List<String> ssSources = viewStyle.getSecondaryStructureSources();
+    if (secondaryStructureConsensus.size() != ssSources.size()) {
       
-      for(String source : secondaryStructureSources) {      
+      for(String source : ssSources) {      
         boolean ssConsensusForSourcePresent = false;
         for(AlignmentAnnotation aa : secondaryStructureConsensus) {
           if(aa.description.startsWith(source)) {
@@ -1118,8 +1117,6 @@ public abstract class AlignmentViewport
    */
   protected boolean showSequenceLogo = false;
   
-  protected boolean showSequenceSSLogo = false;
-
   /**
    * should consensus profile be rendered normalised to row height
    */
@@ -1130,13 +1127,6 @@ public abstract class AlignmentViewport
    */
   protected boolean showConsensusHistogram = true;
   
-  protected boolean showSSConsensusHistogram = true;
-
-  public void setShowSSConsensusHistogram(boolean showSSConsensusHistogram)
-  {
-    this.showSSConsensusHistogram = showSSConsensusHistogram;
-  }
-
   /**
    * @return the showConsensusProfile
    */
@@ -1146,12 +1136,6 @@ public abstract class AlignmentViewport
     return showSequenceLogo;
   }
   
-  @Override
-  public boolean isShowSequenceSSLogo()
-  {
-    return showSequenceSSLogo;
-  }
-
   /**
    * @param showSequenceLogo
    *          the new value
@@ -1166,22 +1150,14 @@ public abstract class AlignmentViewport
       calculator.updateAnnotationFor(ConsensusThread.class);
       calculator.updateAnnotationFor(ComplementConsensusThread.class);
       calculator.updateAnnotationFor(StrucConsensusThread.class);
+      
+      //to do
+
+      calculator.updateAnnotationFor(SecondaryStructureConsensusThread.class);
     }
     this.showSequenceLogo = showSequenceLogo;
   }
   
-  public void setShowSequenceSSLogo(boolean showSequenceSSLogo)
-  {
-    if (showSequenceSSLogo != this.showSequenceSSLogo)
-    {
-      // TODO: decouple settings setting from calculation when refactoring
-      // annotation update method from alignframe to viewport
-      this.showSequenceSSLogo = showSequenceSSLogo;
-      calculator.updateAnnotationFor(SecondaryStructureConsensusThread.class);
-    }
-    this.showSequenceSSLogo = showSequenceSSLogo;
-  }
-
   /**
    * @param showConsensusHistogram
    *          the showConsensusHistogram to set
@@ -1224,7 +1200,16 @@ public abstract class AlignmentViewport
   {
     this.showGroupConsensus = showGroupConsensus;
   }
-
+  
+  /**
+   * @param showSSConsensus
+   *          the showSSConsensus to set
+   */
+  public void setShowSSConsensus(boolean showSSConsensus)
+  {
+    this.showSSConsensus = showSSConsensus;
+  }
+  
   /**
    * 
    * @return flag to indicate if the consensus histogram should be rendered by
@@ -1235,12 +1220,6 @@ public abstract class AlignmentViewport
   {
     return this.showConsensusHistogram;
   }
-  
-  @Override
-  public boolean isShowSSConsensusHistogram()
-  {
-    return this.showSSConsensusHistogram;
-  }
 
   /**
    * when set, updateAlignment will always ensure sequences are of equal length
@@ -1467,7 +1446,7 @@ public abstract class AlignmentViewport
 
   protected boolean showConsensus = true;  
 
-  protected boolean showSSConsensus = false;
+  protected boolean showSSConsensus = true;
 
   protected boolean showOccupancy = true;
 
@@ -2349,9 +2328,7 @@ public abstract class AlignmentViewport
     boolean conv = isShowGroupConservation();
     boolean cons = isShowGroupConsensus();
     boolean showprf = isShowSequenceLogo();
-    boolean showSSprf = isShowSequenceSSLogo();
     boolean showConsHist = isShowConsensusHistogram();
-    boolean showSSConsHist = isShowSSConsensusHistogram();
     boolean normLogo = isNormaliseSequenceLogo();
 
     /**
@@ -2388,9 +2365,7 @@ public abstract class AlignmentViewport
         {
           // set defaults for this group's conservation/consensus
           sg.setshowSequenceLogo(showprf);
-          sg.setshowSequenceSSLogo(showSSprf);
           sg.setShowConsensusHistogram(showConsHist);
-          sg.setShowSSConsensusHistogram(showSSConsHist);
           sg.setNormaliseSequenceLogo(normLogo);
         }
         if (conv)
index 715645a..cba0923 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.viewmodel.styles;
 
 import java.awt.Color;
+import java.util.List;
 
 import jalview.api.ViewStyleI;
 
@@ -373,6 +374,11 @@ public class ViewStyle implements ViewStyleI
   private boolean showComplementFeatures;
 
   private boolean showComplementFeaturesOnTop;
+  
+  /**
+  * secondary structure annotation rows shown in the view
+  */
+  private List<String> secondaryStructureSources = List.of( new String[0] );
 
   /**
    * GUI state
@@ -1144,4 +1150,16 @@ public class ViewStyle implements ViewStyleI
   {
     return showComplementFeaturesOnTop;
   }
+  
+  @Override
+  public List<String> getSecondaryStructureSources()
+  {
+    return secondaryStructureSources;
+  }
+
+  @Override
+  public void setSecondaryStructureSources(List<String> secondaryStructureSources)
+  {
+    this.secondaryStructureSources = secondaryStructureSources;
+  }
 }