// 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);
}
/**
* 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");
@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"));
{
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());
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
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
try
{
JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"),
ImageMaker.EPS_EXTENSION, ImageMaker.EPS_EXTENSION);
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager
try
{
JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"),
ImageMaker.PNG_EXTENSION, ImageMaker.PNG_DESCRIPTION);
chooser.setFileView(new jalview.io.JalviewFileView());
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";
if (oldColourScheme instanceof UserColourScheme)
{
- schemeName.setText(((UserColourScheme) oldColourScheme).getSchemeName());
+ schemeName.setText(((UserColourScheme) oldColourScheme)
+ .getSchemeName());
}
resetButtonPanel(false);
* @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;
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"));
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());
}
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();
}
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
*/
public void registerFileFormat(FileFormatI format)
{
- registerFileFormat(format, false);
+ boolean isIdentifiable = format instanceof FileFormat
+ && ((FileFormat) format).isIdentifiable();
+ registerFileFormat(format, isIdentifiable);
}
protected void registerFileFormat(FileFormatI format,
package jalview.io;
import jalview.api.AlignExportSettingI;
-import jalview.bin.Cache;
import jalview.datamodel.AlignmentExportData;
import jalview.exceptions.NoFileSelectedException;
import jalview.gui.AlignmentPanel;
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
//////////////////////////////////////////////////////////////////
package jalview.io;
+import jalview.bin.Cache;
import jalview.gui.JvOptionPane;
import jalview.util.MessageManager;
import jalview.util.Platform;
/**
* 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,
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!! */
* 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
*
* @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;
}
}
}
- return new Matrix(out, cols, rows);
+ return new Matrix(out);
}
/**
}
}
- return new Matrix(tmp, in.rows, this.cols);
+ return new Matrix(tmp);
}
/**
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);
}
/**
*/
package jalview.util;
-import jalview.bin.Cache;
import jalview.bin.Jalview;
import jalview.gui.EPSOptions;
import jalview.gui.IProgressIndicator;
{
return null;
}
- return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
- PNG_EXTENSION, PNG_DESCRIPTION);
+ return new JalviewFileChooser(PNG_EXTENSION, PNG_DESCRIPTION);
}
static JalviewFileChooser getEPSChooser()
{
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)
{
return null;
}
- return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
- SVG_EXTENSION, SVG_DESCRIPTION);
+ return new JalviewFileChooser(SVG_EXTENSION, SVG_DESCRIPTION);
}
}
@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() + "'");
}
@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()));
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
/*
* re-register mmCIF format
- * it is reinstated (but now classed as 'dynamic')
+ * it is reinstated (still 'identifiable')
*/
formats.registerFileFormat(FileFormat.MMCif);
assertSame(FileFormat.MMCif,
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;
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;
@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
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 -
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 -
* (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]");
* (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);
* [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);
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
*
}
}
- Matrix origmat = new Matrix(in, n, n);
+ Matrix origmat = new Matrix(in);
// System.out.println(" --- Original matrix ---- ");
// / origmat.print(System.out);