Merge branch 'develop' into features/JAL-2360colourSchemeApplicability
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 26 Jan 2017 11:34:04 +0000 (11:34 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 26 Jan 2017 11:34:04 +0000 (11:34 +0000)
Conflicts:
src/jalview/gui/UserDefinedColours.java

14 files changed:
src/jalview/analysis/PCA.java
src/jalview/gui/Desktop.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/TreePanel.java
src/jalview/gui/UserDefinedColours.java
src/jalview/gui/WsParamSetManager.java
src/jalview/io/FileFormats.java
src/jalview/io/HTMLOutput.java
src/jalview/io/JalviewFileChooser.java
src/jalview/math/Matrix.java
src/jalview/util/ImageMaker.java
src/jalview/ws/rest/params/Alignment.java
test/jalview/io/FileFormatsTest.java
test/jalview/math/MatrixTest.java

index 06a139b..eaea7bf 100755 (executable)
@@ -144,8 +144,8 @@ public class PCA implements Runnable
     // System.out.println("Created array");
     // printMemory(rt);
     // System.out.println(" --- Original matrix ---- ");
-    m = new Matrix(seqmat, count, bs[0].getDBinary().length);
-    m2 = new Matrix(seqmat2, count, bs2[0].getDBinary().length);
+    m = new Matrix(seqmat);
+    m2 = new Matrix(seqmat2);
 
   }
 
@@ -252,15 +252,18 @@ public class PCA implements Runnable
   /**
    * DOCUMENT ME!
    */
+  @Override
   public void run()
   {
     PrintStream ps = new PrintStream(System.out)
     {
+      @Override
       public void print(String x)
       {
         details.append(x);
       }
 
+      @Override
       public void println()
       {
         details.append("\n");
index 4ce42dc..0321662 100644 (file)
@@ -1531,8 +1531,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   @Override
   public void saveState_actionPerformed(ActionEvent e)
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project");
+    JalviewFileChooser chooser = new JalviewFileChooser("jvp",
+            "Jalview Project");
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.save_state"));
@@ -2185,8 +2185,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   {
     if (v_client != null)
     {
-      JalviewFileChooser chooser = new JalviewFileChooser(
-              Cache.getProperty("LAST_DIRECTORY"), "vdj",// TODO: VAMSAS DOCUMENT EXTENSION is VDJ
+   // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
+      JalviewFileChooser chooser = new JalviewFileChooser("vdj",
               "Vamsas Document");
 
       chooser.setFileView(new JalviewFileView());
index bb5f13c..26f9964 100644 (file)
@@ -748,8 +748,7 @@ public class FeatureSettings extends JPanel implements
 
   void load()
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty("LAST_DIRECTORY"), "fc",
+    JalviewFileChooser chooser = new JalviewFileChooser("fc",
             "Sequence Feature Colours");
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
@@ -841,8 +840,7 @@ public class FeatureSettings extends JPanel implements
 
   void save()
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty("LAST_DIRECTORY"), "fc",
+    JalviewFileChooser chooser = new JalviewFileChooser("fc",
             "Sequence Feature Colours");
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
index 6fa4493..25f4c1b 100755 (executable)
@@ -749,7 +749,6 @@ public class TreePanel extends GTreePanel
     try
     {
       JalviewFileChooser chooser = new JalviewFileChooser(
-              Cache.getProperty("LAST_DIRECTORY"),
               ImageMaker.EPS_EXTENSION, ImageMaker.EPS_EXTENSION);
       chooser.setFileView(new JalviewFileView());
       chooser.setDialogTitle(MessageManager
@@ -796,7 +795,6 @@ public class TreePanel extends GTreePanel
     try
     {
       JalviewFileChooser chooser = new JalviewFileChooser(
-              Cache.getProperty("LAST_DIRECTORY"),
               ImageMaker.PNG_EXTENSION, ImageMaker.PNG_DESCRIPTION);
 
       chooser.setFileView(new jalview.io.JalviewFileView());
index 012edb6..5314c5c 100755 (executable)
@@ -64,7 +64,8 @@ import javax.swing.event.ChangeListener;
 public class UserDefinedColours extends GUserDefinedColours implements
         ChangeListener
 {
-  private static final Font VERDANA_BOLD_10 = new Font("Verdana", Font.BOLD, 10);
+  private static final Font VERDANA_BOLD_10 = new Font("Verdana",
+          Font.BOLD, 10);
 
   public static final String USER_DEFINED_COLOURS = "USER_DEFINED_COLOURS";
 
@@ -150,7 +151,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
 
     if (oldColourScheme instanceof UserColourScheme)
     {
-      schemeName.setText(((UserColourScheme) oldColourScheme).getSchemeName());
+      schemeName.setText(((UserColourScheme) oldColourScheme)
+              .getSchemeName());
     }
 
     resetButtonPanel(false);
@@ -403,8 +405,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
    * @param buttonIndex
    *          the button's position in the list
    */
-  JButton makeButton(String label, String residue,
-          List<JButton> buttons, int buttonIndex)
+  JButton makeButton(String label, String residue, List<JButton> buttons,
+          int buttonIndex)
   {
     final JButton button;
     Color col;
@@ -605,8 +607,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
     upperCaseButtons = new ArrayList<JButton>();
     lowerCaseButtons = new ArrayList<JButton>();
 
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty(LAST_DIRECTORY), "jc", "Jalview User Colours");
+    JalviewFileChooser chooser = new JalviewFileChooser("jc",
+            "Jalview User Colours");
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.load_colour_scheme"));
@@ -621,7 +623,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
     File choice = chooser.getSelectedFile();
     Cache.setProperty(LAST_DIRECTORY, choice.getParent());
 
-    UserColourScheme ucs = ColourSchemes.loadColourScheme(choice.getAbsolutePath());
+    UserColourScheme ucs = ColourSchemes.loadColourScheme(choice
+            .getAbsolutePath());
     Color[] colors = ucs.getColours();
     schemeName.setText(ucs.getSchemeName());
 
@@ -713,8 +716,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
       }
       ColourSchemes.getInstance().removeColourScheme(name);
     }
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty(LAST_DIRECTORY), "jc",
+    JalviewFileChooser chooser = new JalviewFileChooser("jc",
             "Jalview User Colours");
 
     JalviewFileView fileView = new JalviewFileView();
index b260e1b..1aa0803 100644 (file)
@@ -183,8 +183,7 @@ public class WsParamSetManager implements ParamManager
     }
     if (filename == null)
     {
-      JalviewFileChooser chooser = new JalviewFileChooser(
-              Cache.getProperty("LAST_DIRECTORY"), "wsparams",
+      JalviewFileChooser chooser = new JalviewFileChooser("wsparams",
               "Web Service Parameter File");
       chooser.setFileView(new JalviewFileView());
       chooser.setDialogTitle(MessageManager
index 158489e..19a61cf 100644 (file)
@@ -74,7 +74,9 @@ public class FileFormats
    */
   public void registerFileFormat(FileFormatI format)
   {
-    registerFileFormat(format, false);
+    boolean isIdentifiable = format instanceof FileFormat
+            && ((FileFormat) format).isIdentifiable();
+    registerFileFormat(format, isIdentifiable);
   }
 
   protected void registerFileFormat(FileFormatI format,
index b0ca25b..68f3e2c 100755 (executable)
@@ -1,7 +1,6 @@
 package jalview.io;
 
 import jalview.api.AlignExportSettingI;
-import jalview.bin.Cache;
 import jalview.datamodel.AlignmentExportData;
 import jalview.exceptions.NoFileSelectedException;
 import jalview.gui.AlignmentPanel;
@@ -243,8 +242,8 @@ public abstract class HTMLOutput implements Runnable
               pSessionId);
     }
 
-    JalviewFileChooser jvFileChooser = new JalviewFileChooser(
-            Cache.getProperty("LAST_DIRECTORY"), "html", "HTML files");
+    JalviewFileChooser jvFileChooser = new JalviewFileChooser("html",
+            "HTML files");
     jvFileChooser.setFileView(new JalviewFileView());
 
     jvFileChooser.setDialogTitle(MessageManager
index 2a0f8b1..98cd162 100755 (executable)
@@ -21,6 +21,7 @@
 //////////////////////////////////////////////////////////////////
 package jalview.io;
 
+import jalview.bin.Cache;
 import jalview.gui.JvOptionPane;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
@@ -124,16 +125,13 @@ public class JalviewFileChooser extends JFileChooser
   /**
    * Constructor for a single choice of file extension and description
    * 
-   * @param dir
    * @param extension
    * @param desc
    */
-  public JalviewFileChooser(String dir, String extension, String desc)
+  public JalviewFileChooser(String extension, String desc)
   {
-    // TODO inline dir as Cache.getProperty("LAST_DIRECTORY") ? if applet
-    // builds ok
-    this(dir, new String[] { extension }, new String[] { desc }, desc,
-            true);
+    this(Cache.getProperty("LAST_DIRECTORY"), new String[] { extension },
+            new String[] { desc }, desc, true);
   }
 
   JalviewFileChooser(String dir, String[] extensions, String[] descs,
index 28b9d67..647fc3a 100755 (executable)
@@ -26,22 +26,23 @@ import jalview.util.MessageManager;
 import java.io.PrintStream;
 
 /**
- * DOCUMENT ME!
- * 
- * @author $author$
- * @version $Revision$
+ * A class to model rectangular matrices of double values and operations on them
  */
 public class Matrix
 {
-  /**
-   * SMJSPUBLIC
+  /*
+   * the cell values in row-major order
    */
   public double[][] value;
 
-  /** DOCUMENT ME!! */
+  /*
+   * the number of rows
+   */
   public int rows;
 
-  /** DOCUMENT ME!! */
+  /*
+   * the number of columns
+   */
   public int cols;
 
   /** DOCUMENT ME!! */
@@ -60,10 +61,10 @@ public class Matrix
    * Creates a new Matrix object. For example
    * 
    * <pre>
-   *   new Matrix(new double[][] {{2, 3}, {4, 5}, 2, 2)
+   *   new Matrix(new double[][] {{2, 3, 4}, {5, 6, 7})
    * constructs
-   *   (2 3)
-   *   (4 5)
+   *   (2 3 4)
+   *   (5 6 7)
    * </pre>
    * 
    * Note that ragged arrays (with not all rows, or columns, of the same
@@ -72,13 +73,11 @@ public class Matrix
    * 
    * @param values
    *          the matrix values in row-major order
-   * @param rows
-   * @param cols
    */
-  public Matrix(double[][] values, int rows, int cols)
+  public Matrix(double[][] values)
   {
-    this.rows = rows;
-    this.cols = cols;
+    this.rows = values.length;
+    this.cols = this.rows == 0 ? 0 : values[0].length;
     this.value = values;
   }
 
@@ -99,7 +98,7 @@ public class Matrix
       }
     }
 
-    return new Matrix(out, cols, rows);
+    return new Matrix(out);
   }
 
   /**
@@ -155,7 +154,7 @@ public class Matrix
       }
     }
 
-    return new Matrix(tmp, in.rows, this.cols);
+    return new Matrix(tmp);
   }
 
   /**
@@ -218,13 +217,9 @@ public class Matrix
     for (int i = 0; i < rows; i++)
     {
       System.arraycopy(value[i], 0, newmat[i], 0, value[i].length);
-      // for (int j = 0; j < cols; j++)
-      // {
-      // newmat[i][j] = value[i][j];
-      // }
     }
 
-    return new Matrix(newmat, rows, cols);
+    return new Matrix(newmat);
   }
 
   /**
index 8f8af54..fa2533f 100755 (executable)
@@ -20,7 +20,6 @@
  */
 package jalview.util;
 
-import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.gui.EPSOptions;
 import jalview.gui.IProgressIndicator;
@@ -310,8 +309,7 @@ public class ImageMaker
     {
       return null;
     }
-    return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
-            PNG_EXTENSION, PNG_DESCRIPTION);
+    return new JalviewFileChooser(PNG_EXTENSION, PNG_DESCRIPTION);
   }
 
   static JalviewFileChooser getEPSChooser()
@@ -320,8 +318,7 @@ public class ImageMaker
     {
       return null;
     }
-    return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
-            EPS_EXTENSION, EPS_DESCRIPTION);
+    return new JalviewFileChooser(EPS_EXTENSION, EPS_DESCRIPTION);
   }
 
   private void setProgressMessage(String message)
@@ -338,7 +335,6 @@ public class ImageMaker
     {
       return null;
     }
-    return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
-            SVG_EXTENSION, SVG_DESCRIPTION);
+    return new JalviewFileChooser(SVG_EXTENSION, SVG_DESCRIPTION);
   }
 }
index a8258e2..b85073f 100644 (file)
@@ -108,8 +108,8 @@ public class Alignment extends InputType
   @Override
   public List<String> getURLEncodedParameter()
   {
-    ArrayList<String> prms = new ArrayList<String>();
-    prms.add("format='" + format + "'");
+    List<String> prms = new ArrayList<String>();
+    prms.add("format='" + format.getName() + "'");
     if (type != null)
     {
       prms.add("type='" + type.toString() + "'");
index 8df228f..ffc844c 100644 (file)
@@ -21,17 +21,21 @@ public class FileFormatsTest
   }
 
   @Test(groups = "Functional")
-  public void testIsDynamic()
+  public void testIsIdentifiable()
   {
     FileFormats formats = FileFormats.getInstance();
-    for (FileFormatI ff : FileFormat.values())
-    {
-      assertFalse(formats.isIdentifiable(ff));
-    }
-    assertTrue(formats.isIdentifiable(null));
+    assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Fasta
+            .getName())));
+    assertTrue(formats.isIdentifiable(formats.forName(FileFormat.MMCif
+            .getName())));
+    assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Jnet
+            .getName())));
+    assertFalse(formats.isIdentifiable(formats.forName(FileFormat.Jalview
+            .getName())));
+    assertFalse(formats.isIdentifiable(null));
 
     /*
-     * remove and re-add a format: it is now considered 'dynamically added'
+     * remove and re-add a format: it is still 'identifiable'
      */
     formats.deregisterFileFormat(FileFormat.Fasta.getName());
     assertNull(formats.forName(FileFormat.Fasta.getName()));
@@ -104,7 +108,7 @@ public class FileFormatsTest
     FileFormats formats = FileFormats.getInstance();
     assertSame(FileFormat.MMCif,
             formats.forName(FileFormat.MMCif.getName()));
-    assertFalse(formats.isIdentifiable(FileFormat.MMCif));
+    assertTrue(formats.isIdentifiable(FileFormat.MMCif));
 
     /*
      * deregister mmCIF format
@@ -114,7 +118,7 @@ public class FileFormatsTest
 
     /*
      * re-register mmCIF format
-     * it is reinstated (but now classed as 'dynamic')
+     * it is reinstated (still 'identifiable')
      */
     formats.registerFileFormat(FileFormat.MMCif);
     assertSame(FileFormat.MMCif,
index 795b2fa..a4acbd0 100644 (file)
@@ -1,9 +1,11 @@
 package jalview.math;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
 import java.util.Arrays;
+import java.util.Random;
 
 import org.testng.annotations.Test;
 
@@ -16,8 +18,8 @@ public class MatrixTest
     int cols = 1000;
     double[][] d1 = new double[rows][cols];
     double[][] d2 = new double[cols][rows];
-    Matrix m1 = new Matrix(d1, rows, cols);
-    Matrix m2 = new Matrix(d2, cols, rows);
+    Matrix m1 = new Matrix(d1);
+    Matrix m2 = new Matrix(d2);
     long start = System.currentTimeMillis();
     m1.preMultiply(m2);
     long elapsed = System.currentTimeMillis() - start;
@@ -28,8 +30,8 @@ public class MatrixTest
   @Test(groups = "Functional")
   public void testPreMultiply()
   {
-    Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 } }, 1, 3); // 1x3
-    Matrix m2 = new Matrix(new double[][] { { 5 }, { 6 }, { 7 } }, 3, 1); // 3x1
+    Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 } }); // 1x3
+    Matrix m2 = new Matrix(new double[][] { { 5 }, { 6 }, { 7 } }); // 3x1
 
     /*
      * 1x3 times 3x1 is 1x1
@@ -56,8 +58,7 @@ public class MatrixTest
     expectedExceptions = { IllegalArgumentException.class })
   public void testPreMultiply_tooManyColumns()
   {
-    Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }, 2,
-            3); // 2x3
+    Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3
 
     /*
      * 2x3 times 2x3 invalid operation - 
@@ -72,8 +73,7 @@ public class MatrixTest
     expectedExceptions = { IllegalArgumentException.class })
   public void testPreMultiply_tooFewColumns()
   {
-    Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }, 2,
-            3); // 2x3
+    Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3
 
     /*
      * 3x2 times 3x2 invalid operation - 
@@ -99,9 +99,8 @@ public class MatrixTest
      * (3020 30200)
      * (5040 50400)
      */
-    Matrix m1 = new Matrix(new double[][] { { 2, 3 }, { 4, 5 } }, 2, 2);
-    Matrix m2 = new Matrix(new double[][] { { 10, 100 }, { 1000, 10000 } },
-            2, 2);
+    Matrix m1 = new Matrix(new double[][] { { 2, 3 }, { 4, 5 } });
+    Matrix m2 = new Matrix(new double[][] { { 10, 100 }, { 1000, 10000 } });
     Matrix m3 = m1.postMultiply(m2);
     assertEquals(Arrays.toString(m3.value[0]), "[3020.0, 30200.0]");
     assertEquals(Arrays.toString(m3.value[1]), "[5040.0, 50400.0]");
@@ -118,8 +117,8 @@ public class MatrixTest
      * (2).(10 100 1000) = (20 200 2000)
      * (3)                 (30 300 3000)
      */
-    m1 = new Matrix(new double[][] { { 2 }, { 3 } }, 2, 1);
-    m2 = new Matrix(new double[][] { { 10, 100, 1000 } }, 1, 3);
+    m1 = new Matrix(new double[][] { { 2 }, { 3 } });
+    m2 = new Matrix(new double[][] { { 10, 100, 1000 } });
     m3 = m1.postMultiply(m2);
     assertEquals(m3.rows, 2);
     assertEquals(m3.cols, 3);
@@ -139,8 +138,8 @@ public class MatrixTest
      * [0, 0] = 2*5 + 3*6 + 4*7 = 56
      * [0, 1] = 2*4 + 3*3 + 4*2 = 25  
      */
-    m1 = new Matrix(new double[][] { { 2, 3, 4 } }, 1, 3);
-    m2 = new Matrix(new double[][] { { 5, 4 }, { 6, 3 }, { 7, 2 } }, 3, 2);
+    m1 = new Matrix(new double[][] { { 2, 3, 4 } });
+    m2 = new Matrix(new double[][] { { 5, 4 }, { 6, 3 }, { 7, 2 } });
     m3 = m1.postMultiply(m2);
     assertEquals(m3.rows, 1);
     assertEquals(m3.cols, 2);
@@ -157,6 +156,26 @@ public class MatrixTest
     assertEquals(m3.value[0][1], 25d);
   }
 
+  @Test(groups = "Functional")
+  public void testCopy()
+  {
+    Random r = new Random();
+    int rows = 5;
+    int cols = 11;
+    double[][] in = new double[rows][cols];
+
+    for (int i = 0; i < rows; i++)
+    {
+      for (int j = 0; j < cols; j++)
+      {
+        in[i][j] = r.nextDouble();
+      }
+    }
+    Matrix m1 = new Matrix(in);
+    Matrix m2 = m1.copy();
+    assertTrue(matrixEquals(m1, m2));
+  }
+
   /**
    * main method extracted from Matrix
    * 
@@ -175,7 +194,7 @@ public class MatrixTest
       }
     }
   
-    Matrix origmat = new Matrix(in, n, n);
+    Matrix origmat = new Matrix(in);
   
     // System.out.println(" --- Original matrix ---- ");
     // / origmat.print(System.out);