Search in sources :

Example 1 with ScatterPlotDialog

use of edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog in project clusterMaker2 by RBVI.

the class RunPCA method runOnNodeToAttributeMatrix.

// this method assumes that eigen values
// are sorted in increasing order
public void runOnNodeToAttributeMatrix() {
    // System.out.println("runOnNodeToAttributeMatrix");
    CyMatrix matrix = CyMatrixFactory.makeLargeMatrix(network, weightAttributes, context.selectedOnly, context.ignoreMissing, false, false);
    // System.out.println("Computing principle components");
    components = computePCs(matrix);
    final Matrix loadingMatrix = calculateLoadingMatrix(matrix);
    if (context.pcaResultPanel) {
        CyServiceRegistrar registrar = manager.getService(CyServiceRegistrar.class);
        CySwingApplication swingApplication = manager.getService(CySwingApplication.class);
        ResultPanelPCA panel = new ResultPanelPCA(components, variance, network, networkView);
        CytoPanel cytoPanel = swingApplication.getCytoPanel(CytoPanelName.EAST);
        registrar.registerService(panel, CytoPanelComponent.class, new Properties());
        if (cytoPanel.getState() == CytoPanelState.HIDE)
            cytoPanel.setState(CytoPanelState.DOCK);
    }
    if (context.pcaPlot) {
        if (components.length < 2) {
            monitor.showMessage(TaskMonitor.Level.ERROR, "Only found " + components.length + " components. Need 2 for scatterplot. " + "Perhaps minimum variance is set too high?");
            return;
        }
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                // System.out.println("Scatter plot dialog call");
                ScatterPlotDialog dialog = new ScatterPlotDialog(manager, "PCA", monitor, components, loadingMatrix, variance);
            }
        });
    }
}
Also used : CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) Matrix(edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix) ColtMatrix(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.matrix.ColtMatrix) CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) CySwingApplication(org.cytoscape.application.swing.CySwingApplication) ScatterPlotDialog(edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog) CytoPanel(org.cytoscape.application.swing.CytoPanel) Properties(java.util.Properties) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar)

Example 2 with ScatterPlotDialog

use of edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog in project clusterMaker2 by RBVI.

the class RunPCoA method run.

public void run() {
    long startTime = System.currentTimeMillis();
    long time = startTime;
    // System.out.println("Calculating values");
    // double data[][]=matrix.toArray();
    // System.out.println("Length "+ distanceMatrix.nRows());
    // 
    distanceMatrix.updateMinMax();
    double max = distanceMatrix.getMaxValue() * 10;
    // the way the initial matrix is built.  Set those to Double.MAX.
    for (int row = 0; row < distanceMatrix.nRows(); row++) {
        for (int col = 0; col < distanceMatrix.nColumns(); col++) {
            double value = distanceMatrix.doubleValue(row, col);
            if (value == 0.0 || Double.isNaN(value))
                distanceMatrix.setValue(row, col, max);
        }
    }
    Matrix mean = distanceMatrix.like(distanceMatrix.nColumns(), 1);
    // TODO: center the matrix?
    for (int j = 0; j < mean.nRows(); j++) {
        mean.setValue(j, 0, CommonOps.columnMean(distanceMatrix, j));
    }
    for (int i = 0; i < distanceMatrix.nRows(); i++) {
        for (int j = 0; j < distanceMatrix.nColumns(); j++) {
            distanceMatrix.setValue(i, j, distanceMatrix.doubleValue(i, j) - mean.doubleValue(j, 0));
        }
    }
    // System.out.println("Checking CyMatrix symmetrical "+distanceMatrix.isSymmetrical());
    monitor.showMessage(TaskMonitor.Level.INFO, "Calculating Gower's Matrix");
    // Get the Gower's Matrix
    Matrix G = GowersMatrix.getGowersMatrix(distanceMatrix);
    long delta = System.currentTimeMillis() - time;
    time = System.currentTimeMillis();
    monitor.showMessage(TaskMonitor.Level.INFO, "Constructed Gower's Matrix in " + delta + "ms");
    monitor.showMessage(TaskMonitor.Level.INFO, "Doing Singlular Value Decomposition (SVD)");
    // System.out.println("Got GowersMatrix in "+delta+"ms");
    G.ops().svdInit();
    Matrix V_t = CommonOps.transpose(G.ops().svdV());
    // Get the singular values
    Matrix S = G.ops().svdS();
    double[] variances = getVariance(S);
    V_t = reshape(V_t, 2, mean.nRows());
    double[][] trafoed = new double[distanceMatrix.nRows()][2];
    result = CyMatrixFactory.makeLargeMatrix(distanceMatrix.getNetwork(), distanceMatrix.nRows(), 2);
    result.setRowNodes(distanceMatrix.getRowNodes());
    result.setRowLabels(Arrays.asList(distanceMatrix.getRowLabels()));
    result.setColumnLabel(0, "X");
    result.setColumnLabel(1, "Y");
    for (int i = 0; i < distanceMatrix.nRows(); i++) {
        trafoed[i] = sampleToEigenSpace(V_t, distanceMatrix, mean, i);
        for (int j = 0; j < trafoed[i].length; j++) {
            result.setValue(i, j, trafoed[i][j] *= -1);
        }
    }
    delta = System.currentTimeMillis() - time;
    time = System.currentTimeMillis();
    monitor.showMessage(TaskMonitor.Level.INFO, "Completed SVD Analysis in " + delta + "ms");
    monitor.showMessage(TaskMonitor.Level.INFO, String.format("Variance explained by first three axes: %2.2f%%, %2.2f%%, and %2.2f%%", variances[0], variances[1], variances[2]));
    if (context.pcoaPlot) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                // System.out.println("Scatter plot dialog call");
                ScatterPlotDialog dialog = new ScatterPlotDialog(manager, "PCoA", monitor, result);
            }
        });
    }
}
Also used : CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) Matrix(edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix) ScatterPlotDialog(edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog)

Example 3 with ScatterPlotDialog

use of edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog in project clusterMaker2 by RBVI.

the class RuntSNE method run.

public void run() {
    context.cancelled = false;
    context.setXin(matrix.toArray());
    TSne tsne;
    // System.out.println("Is Symmetrical "+matrix.isSymmetrical());
    if (context.useBarnesHut) {
        monitor.setTitle("Running t-Distributed Stochastic Neighbor (tSNE) using Barnes-Hut approximation");
        tsne = new BHTSne();
    } else {
        monitor.setTitle("Running t-Distributed Stochastic Neighbor (tSNE)");
        tsne = new FastTSne();
    }
    double[][] result = tsne.tsne(context, monitor);
    if (result == null && context.cancelled) {
        monitor.setStatusMessage("Cancelled by user");
        return;
    }
    Y = matrix.copy();
    Y.initialize(result.length, result[0].length, result);
    if (context.showScatterPlot) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                ScatterPlotDialog dialog = new ScatterPlotDialog(manager, "tSNE", monitor, Y);
            }
        });
    }
}
Also used : TSne(com.jujutsu.tsne.TSne) BHTSne(com.jujutsu.tsne.barneshut.BHTSne) FastTSne(com.jujutsu.tsne.FastTSne) BHTSne(com.jujutsu.tsne.barneshut.BHTSne) FastTSne(com.jujutsu.tsne.FastTSne) ScatterPlotDialog(edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog)

Aggregations

ScatterPlotDialog (edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog)3 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)2 Matrix (edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix)2 FastTSne (com.jujutsu.tsne.FastTSne)1 TSne (com.jujutsu.tsne.TSne)1 BHTSne (com.jujutsu.tsne.barneshut.BHTSne)1 ColtMatrix (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.matrix.ColtMatrix)1 Properties (java.util.Properties)1 CySwingApplication (org.cytoscape.application.swing.CySwingApplication)1 CytoPanel (org.cytoscape.application.swing.CytoPanel)1 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)1