Merge branch 'patch/JAL-4281_idwidthandannotHeight_in_project' into develop
authorJames Procter <j.procter@dundee.ac.uk>
Wed, 1 Nov 2023 20:47:20 +0000 (20:47 +0000)
committerJames Procter <j.procter@dundee.ac.uk>
Wed, 1 Nov 2023 20:47:20 +0000 (20:47 +0000)
help/markdown/releases/release-2_11_3_0.md
src/jalview/gui/AlignFrame.java
src/jalview/gui/FeatureEditor.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/FeatureTypeSettings.java
src/jalview/io/FileFormat.java
src/jalview/io/IdentifyFile.java
test/jalview/gui/FeatureSettingsTest.java

index d9ae228..7a2c878 100644 (file)
@@ -48,7 +48,7 @@ channel: "release"
 ### Other improvements
 - <!-- JAL-4250 --> Secondary structure annotation glyphs are rendered anti-aliasing when enabled
 - <!-- JAL-325 --> Helix and Sheet glyphs vertically centered with respect to grey coil secondary structure annotation track
-- <!-- JAL-4253 --> Lower line of the sequence group border does not align with vertical and background residue box
+- <!-- JAL-4317 --> feature should be displayed when its rendering and filtering settings are adjusted
 - <!-- JAL-4250 --> Updated JFreeSVG (https://www.jfree.org/jfreesvg) from 2.1 to 3.4.3
 - <!-- JAL-3119 --> Name of alignment and view included in overview window's title
 - <!-- JAL-4213 --> "add reference annotation" add all positions in reference annotation tracks, not just positions in the currently highlighted columns/selection range
@@ -57,6 +57,7 @@ channel: "release"
 - <!-- JAL-4206 --> Improved file chooser's 'recent files' view and added filter for 'All known alignment files'
 - <!-- JAL-4206 --> Relative files added to recent files list via import from command line are selected when Jalview opened from same location
 - <!-- JAL-4308 --> Reduce number of database crossreferences shown in tooltip
+- <!-- JAL-4315 --> Drag and drop feature colours file on an alignment to quickly apply feature settings
 - <!-- JAL-3676 --> Allow log level configuration via Jalview's Java Console, and a Copy to Clipboard button
 
 ### Development and Deployment
@@ -81,6 +82,7 @@ channel: "release"
 - <!-- JAL-4182 --> reference annotation not correctly transferred to alignment containing a sub-sequence when a selection is active
 - <!-- JAL-4177 --> Can press 'Add' or 'New View' multiple times when manually adding and viewing a 3D structure via structure chooser
 - <!-- JAL-4133 --> Jalview project does not preserve font aspect ratio when Viewport is zoomed with mouse
+- <!-- JAL-4253 --> Lower line of the sequence group border does not align with vertical and background residue box
 - <!-- JAL-4128 --> Resizing overview quickly with solid-drags enabled causes exception
 - <!-- JAL-4150 --> Sequences copied to clipboard from within Jalview cannot be pasted via the desktop's popup menu to a new alignment window
 - <!-- JAL-2528, JAL-1713 --> Overview window is saved in project file, and state of 'show hidden regions' is preserved.
index aca8baa..4f13a78 100644 (file)
@@ -4818,7 +4818,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
              * Object[] { String,SequenceI}
              */
             ArrayList<Object[]> filesmatched = new ArrayList<>();
-            ArrayList<Object> filesnotmatched = new ArrayList<>();
+            ArrayList<Object[]> filesnotmatched = new ArrayList<>();
             for (int i = 0; i < files.size(); i++)
             {
               // BH 2018
@@ -4864,9 +4864,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                   }
                   mtch = idm.findAllIdMatches(pdbfn);
                 }
+                FileFormatI type=null;
                 if (mtch != null)
                 {
-                  FileFormatI type;
                   try
                   {
                     type = new IdentifyFile().identify(file, protocol);
@@ -4882,7 +4882,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 }
                 // File wasn't named like one of the sequences or wasn't a PDB
                 // file.
-                filesnotmatched.add(file);
+                filesnotmatched.add(new Object[] { file, protocol, type});
               }
             }
             int assocfiles = 0;
@@ -4936,7 +4936,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                  */
                 for (Object[] o : filesmatched)
                 {
-                  filesnotmatched.add(o[0]);
+                  filesnotmatched.add(new Object[] { o[0], o[1]});
                 }
               }
             }
@@ -4958,9 +4958,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               {
                 return;
               }
-              for (Object fn : filesnotmatched)
+              for (Object[] fn : filesnotmatched)
               {
-                loadJalviewDataFile(fn, null, null, null);
+                loadJalviewDataFile(fn[0], (DataSourceType) fn[1], (FileFormatI)fn[2], null);
               }
 
             }
@@ -5056,7 +5056,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           {
             format = new IdentifyFile().identify(file, sourceType);
           }
-          if (FileFormat.ScoreMatrix == format)
+          if (FileFormat.FeatureSettings == format)
+          {
+            if (featureSettings != null)
+            {
+              featureSettings.load(file, sourceType);
+            }
+            else
+            {
+              FeatureSettings.loadFeatureSettingsFile(getFeatureRenderer(),
+                      fileObject, sourceType);
+            }
+          }
+          else if (FileFormat.ScoreMatrix == format)
           {
             ScoreMatrixFile sm = new ScoreMatrixFile(
                     new FileParse(file, sourceType));
index 7117508..606d843 100644 (file)
@@ -253,7 +253,7 @@ public class FeatureEditor
            */
           final String ft = features.get(featureIndex).getType();
           final String type = ft == null ? lastFeatureAdded : ft;
-          FeatureTypeSettings fcc = new FeatureTypeSettings(fr, type);
+          FeatureTypeSettings fcc = new FeatureTypeSettings(fr, type,true);
           fcc.setRequestFocusEnabled(true);
           fcc.requestFocus();
           fcc.addActionListener(new ActionListener()
index 4d31805..57e5943 100644 (file)
@@ -45,6 +45,7 @@ import java.io.FileOutputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.io.Reader;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -103,6 +104,8 @@ import jalview.datamodel.features.FeatureMatcherSet;
 import jalview.datamodel.features.FeatureMatcherSetI;
 import jalview.gui.Help.HelpId;
 import jalview.gui.JalviewColourChooser.ColourChooserListener;
+import jalview.io.DataSourceType;
+import jalview.io.FileParse;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.schemes.FeatureColour;
@@ -955,6 +958,65 @@ public class FeatureSettings extends JPanel
     chooser.showOpenDialog(this);
   }
 
+  public static boolean loadFeatureSettingsFile(FeatureRenderer fr,
+          File file) throws Exception
+  {
+    InputStreamReader in = new InputStreamReader(new FileInputStream(file),
+            "UTF-8");
+    return loadFeatureSettingsFile(fr, in);
+  }
+
+  public static void loadFeatureSettingsFile(
+          FeatureRenderer featureRenderer, Object fileObject,
+          DataSourceType sourceType) throws Exception
+  {
+    FileParse fp = new FileParse(fileObject, sourceType);
+    loadFeatureSettingsFile(featureRenderer, fp.getReader());
+  }
+
+  private static boolean loadFeatureSettingsFile(FeatureRenderer fr,
+          Reader in) throws Exception
+  {
+    JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.jalview");
+    javax.xml.bind.Unmarshaller um = jc.createUnmarshaller();
+    XMLStreamReader streamReader = XMLInputFactory.newInstance()
+            .createXMLStreamReader(in);
+    JAXBElement<JalviewUserColours> jbe = um.unmarshal(streamReader,
+            JalviewUserColours.class);
+    JalviewUserColours jucs = jbe.getValue();
+
+    // JalviewUserColours jucs = JalviewUserColours.unmarshal(in);
+
+    /*
+     * load feature colours
+     */
+    for (int i = jucs.getColour().size() - 1; i >= 0; i--)
+    {
+      Colour newcol = jucs.getColour().get(i);
+      FeatureColourI colour = jalview.project.Jalview2XML
+              .parseColour(newcol);
+      fr.setColour(newcol.getName(), colour);
+      fr.setOrder(newcol.getName(), i / (float) jucs.getColour().size());
+    }
+
+    /*
+     * load feature filters; loaded filters will replace any that are
+     * currently defined, other defined filters are left unchanged 
+     */
+    for (int i = 0; i < jucs.getFilter().size(); i++)
+    {
+      Filter filterModel = jucs.getFilter().get(i);
+      String featureType = filterModel.getFeatureType();
+      FeatureMatcherSetI filter = jalview.project.Jalview2XML
+              .parseFilter(featureType, filterModel.getMatcherSet());
+      if (!filter.isEmpty())
+      {
+        fr.setFeatureFilter(featureType, filter);
+      }
+    }
+    return true;
+  }
+
   /**
    * Loads feature colours and filters from XML stored in the given file
    * 
@@ -962,50 +1024,21 @@ public class FeatureSettings extends JPanel
    */
   void load(File file)
   {
+    load(file, DataSourceType.FILE);
+  }
+
+  /**
+   * Loads feature colours and filters from XML at a specified source
+   * 
+   * @param file
+   *          - string or file or other object that allows FileParse to be
+   *          created
+   */
+  void load(Object file, DataSourceType sourceType)
+  {
     try
     {
-      InputStreamReader in = new InputStreamReader(
-              new FileInputStream(file), "UTF-8");
-
-      JAXBContext jc = JAXBContext
-              .newInstance("jalview.xml.binding.jalview");
-      javax.xml.bind.Unmarshaller um = jc.createUnmarshaller();
-      XMLStreamReader streamReader = XMLInputFactory.newInstance()
-              .createXMLStreamReader(in);
-      JAXBElement<JalviewUserColours> jbe = um.unmarshal(streamReader,
-              JalviewUserColours.class);
-      JalviewUserColours jucs = jbe.getValue();
-
-      // JalviewUserColours jucs = JalviewUserColours.unmarshal(in);
-
-      /*
-       * load feature colours
-       */
-      for (int i = jucs.getColour().size() - 1; i >= 0; i--)
-      {
-        Colour newcol = jucs.getColour().get(i);
-        FeatureColourI colour = jalview.project.Jalview2XML
-                .parseColour(newcol);
-        fr.setColour(newcol.getName(), colour);
-        fr.setOrder(newcol.getName(), i / (float) jucs.getColour().size());
-      }
-
-      /*
-       * load feature filters; loaded filters will replace any that are
-       * currently defined, other defined filters are left unchanged 
-       */
-      for (int i = 0; i < jucs.getFilter().size(); i++)
-      {
-        Filter filterModel = jucs.getFilter().get(i);
-        String featureType = filterModel.getFeatureType();
-        FeatureMatcherSetI filter = jalview.project.Jalview2XML
-                .parseFilter(featureType, filterModel.getMatcherSet());
-        if (!filter.isEmpty())
-        {
-          fr.setFeatureFilter(featureType, filter);
-        }
-      }
-
+      loadFeatureSettingsFile(fr, file, sourceType);
       /*
        * update feature settings table
        */
@@ -1019,7 +1052,8 @@ public class FeatureSettings extends JPanel
       }
     } catch (Exception ex)
     {
-      jalview.bin.Console.outPrintln("Error loading User Colour File\n" + ex);
+      jalview.bin.Console
+              .outPrintln("Error loading User Colour File\n" + ex);
     }
   }
 
@@ -1885,6 +1919,8 @@ public class FeatureSettings extends JPanel
            */
           String ttl = MessageManager
                   .formatMessage("label.select_colour_for", type);
+          Object last=(Boolean)table.getValueAt(selectedRow, SHOW_COLUMN);
+          table.setValueAt(Boolean.TRUE, selectedRow, SHOW_COLUMN);
           ColourChooserListener listener = new ColourChooserListener()
           {
             @Override
@@ -1892,12 +1928,14 @@ public class FeatureSettings extends JPanel
             {
               currentColor = new FeatureColour(c);
               table.setValueAt(currentColor, rowSelected, COLOUR_COLUMN);
+              table.setValueAt(Boolean.TRUE, selectedRow, SHOW_COLUMN);
               fireEditingStopped();
             }
 
             @Override
             public void cancel()
             {
+              table.setValueAt(last, selectedRow, SHOW_COLUMN);
               fireEditingStopped();
             }
           };
@@ -1909,7 +1947,9 @@ public class FeatureSettings extends JPanel
           /*
            * variable colour and filters dialog
            */
-          chooser = new FeatureTypeSettings(fr, type);
+          boolean last=(Boolean)table.getValueAt(selectedRow, SHOW_COLUMN);
+          table.setValueAt(Boolean.TRUE, selectedRow, SHOW_COLUMN);
+          chooser = new FeatureTypeSettings(fr, type,last);
           if (!Platform.isJS())
           /**
            * Java only
@@ -2035,7 +2075,9 @@ public class FeatureSettings extends JPanel
     {
       if (button == e.getSource())
       {
-        FeatureTypeSettings chooser = new FeatureTypeSettings(fr, type);
+        boolean last = fr.getFeaturesDisplayed().isVisible(type);
+        ((FeatureTableModel) table.getModel()).setValueAt(Boolean.TRUE, rowSelected, SHOW_COLUMN);
+        FeatureTypeSettings chooser = new FeatureTypeSettings(fr, type,last);
         chooser.addActionListener(this);
         chooser.setRequestFocusEnabled(true);
         chooser.requestFocus();
@@ -2067,6 +2109,8 @@ public class FeatureSettings extends JPanel
                 .getData()[rowSelected];
         data[COLOUR_COLUMN] = currentColor;
         data[FILTER_COLUMN] = currentFilter;
+        data[SHOW_COLUMN] = fr.getFeaturesDisplayed().isVisible(type);
+                
         fireEditingStopped();
         // SwingJS needs an explicit repaint() here,
         // rather than relying upon no validation having
@@ -2119,7 +2163,6 @@ public class FeatureSettings extends JPanel
     refreshDisplay();
   }
 }
-
 class FeatureIcon implements Icon
 {
   FeatureColourI gcol;
index 327f6ca..79f4c88 100644 (file)
@@ -204,20 +204,23 @@ public class FeatureTypeSettings extends JalviewDialog
 
   private JPanel chooseFiltersPanel;
 
+  public boolean originalDisplay;
+
   /**
    * Constructor
    * 
    * @param frender
    * @param theType
+   * @param last - visibility of feature prior to adjustment
    */
-  public FeatureTypeSettings(FeatureRenderer frender, String theType)
+  public FeatureTypeSettings(FeatureRenderer frender, String theType, boolean last)
   {
     this.fr = frender;
     this.featureType = theType;
     ap = fr.ap;
     originalFilter = fr.getFeatureFilter(theType);
     originalColour = fr.getFeatureColours().get(theType);
-
+    originalDisplay = last;
     adjusting = true;
 
     try
@@ -1032,6 +1035,9 @@ public class FeatureTypeSettings extends JalviewDialog
   {
     fr.setColour(featureType, originalColour);
     fr.setFeatureFilter(featureType, originalFilter);
+    if (!originalDisplay) { 
+      fr.getFeaturesDisplayed().setHidden(featureType);
+    }
     refreshDisplay(true);
   }
 
index 43c6dcf..91ce527 100644 (file)
@@ -308,6 +308,21 @@ public enum FileFormat implements FileFormatI
       return new FeaturesFile();
     }
   },
+  FeatureSettings("Jalview Feature Settings File","fc",false,false)
+  {
+    @Override
+    public AlignmentFileReaderI getReader(FileParse source)
+            throws IOException
+    {
+      return null;
+    }
+
+    @Override
+    public AlignmentFileWriterI getWriter(AlignmentI al)
+    {
+      return null;
+    }    
+  },
   ScoreMatrix("Substitution matrix", "", false, false)
   {
     @Override
index ea87058..11d96a3 100755 (executable)
@@ -35,6 +35,8 @@ import jalview.bin.Console;
 public class IdentifyFile
 {
 
+  private static final String XMLHEADER = "<?XML VERSION=\"1.0\" ENCODING=\"UTF-8\" STANDALONE=\"YES\"?>";
+
   public FileFormatI identify(Object file, DataSourceType protocol)
           throws FileFormatException
   {
@@ -134,6 +136,7 @@ public class IdentifyFile
     String data;
     int bytesRead = 0;
     int trimmedLength = 0;
+    boolean isXml = false; // set true if first line is XMLHEADER
     boolean lineswereskipped = false;
     boolean isBinary = false; // true if length is non-zero and non-printable
     // characters are encountered
@@ -188,6 +191,10 @@ public class IdentifyFile
           reply = FileFormat.ScoreMatrix;
           break;
         }
+        if (data.startsWith(XMLHEADER) && !lineswereskipped)
+        {
+          isXml = true;
+        }
         if (data.startsWith("LOCUS"))
         {
           reply = FileFormat.GenBank;
@@ -346,6 +353,11 @@ public class IdentifyFile
             reply = FileFormat.Rnaml;
             break;
           }
+          if (isXml && data.contains("<NS2:JALVIEWUSERCOLOURS SCHEMENAME=\"SEQUENCE FEATURES\" XMLNS:NS2=\"WWW.JALVIEW.ORG/COLOURS\">"))
+          {
+            reply = FileFormat.FeatureSettings;
+            break;
+          }
         }
 
         if ((data.length() < 1) || (data.indexOf("#") == 0))
index 5ef693a..7cc4cc1 100644 (file)
@@ -42,7 +42,10 @@ import jalview.datamodel.features.FeatureMatcher;
 import jalview.datamodel.features.FeatureMatcherSet;
 import jalview.datamodel.features.FeatureMatcherSetI;
 import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
 import jalview.io.FileLoader;
+import jalview.io.IdentifyFile;
 import jalview.schemes.FeatureColour;
 import jalview.schemes.FeatureColourTest;
 import jalview.util.matcher.Condition;
@@ -278,4 +281,13 @@ public class FeatureSettingsTest
             "<html>By Score (&gt; 4.0)<br>" + simpleTooltip
                     + "</br></html>");
   }
+  String fsfile="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns2:JalviewUserColours schemeName=\"Sequence Features\" xmlns:ns2=\"www.jalview.org/colours\">",fsfile2="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<ns2:JalviewUserColours schemeName=\"Sequence Features\" xmlns:ns2=\"www.jalview.org/colours\">";
+  @Test(groups="Functional")
+  public void testIdentifyFeatureSettingsFile() throws Exception
+  {
+    FileFormatI type = new IdentifyFile().identify(fsfile, DataSourceType.PASTE);
+    assertTrue(FileFormat.FeatureSettings==type,"Feature settings file was identified as "+type);
+    type = new IdentifyFile().identify(fsfile2, DataSourceType.PASTE);
+    assertTrue(FileFormat.FeatureSettings==type,"Feature settings file with newline was identified as "+type);
+  }
 }