Search in sources :

Example 36 with CyMatrix

use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix in project clusterMaker2 by RBVI.

the class tSNE method getResults.

@Override
public <R> R getResults(Class<? extends R> type) {
    CyMatrix results = runtsne.getResult();
    if (type.equals(String.class)) {
        results.setColumnLabel(0, "X");
        results.setColumnLabel(1, "Y");
        CyNetwork net = results.getNetwork();
        for (int row = 0; row < results.nRows(); row++) {
            CyNode node = results.getRowNode(row);
            results.setRowLabel(row, ModelUtils.getName(net, node));
        }
        return (R) results.printMatrix();
    } else if (type.equals(Map.class)) {
        Map<CyNode, Point2D> resultsMap = new HashMap<>();
        for (int row = 0; row < results.nRows(); row++) {
            CyNode node = results.getRowNode(row);
            resultsMap.put(node, new Point2D.Double(results.doubleValue(row, 0), results.doubleValue(row, 1)));
        }
        return (R) resultsMap;
    }
    return (R) results;
}
Also used : CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 37 with CyMatrix

use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix in project clusterMaker2 by RBVI.

the class ScatterPlotDialog method copyLayoutToCytoscape.

private void copyLayoutToCytoscape() {
    CyMatrix coordinates = scores[0];
    CyNetworkView view = manager.getNetworkView(coordinates.getNetwork());
    UndoSupport undo = manager.getService(UndoSupport.class);
    ScatterPlotLayoutTask splt = new ScatterPlotLayoutTask(manager, title + " Layout", view, coordinates, undo);
    splt.execute();
}
Also used : CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) CyNetworkView(org.cytoscape.view.model.CyNetworkView) UndoSupport(org.cytoscape.work.undo.UndoSupport)

Example 38 with CyMatrix

use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix in project clusterMaker2 by RBVI.

the class RunFuzzifier method getFuzzyCenters.

/**
 * The method calculates the centers of fuzzy clusters
 *
 * @param cData matrix to store the data for cluster centers
 */
public void getFuzzyCenters(CyMatrix cData) {
    // To store the sum of memberships(raised to fuzziness index) corresponding to each cluster
    int nelements = distanceMatrix.nRows();
    for (NodeCluster cluster : Clusters) {
        int c = Clusters.indexOf(cluster);
        double numerator = 0;
        Double distance = 0.0;
        int i = 0;
        for (int e = 0; e < nelements; e++) {
            numerator = 0;
            for (CyNode node : cluster) {
                i = nodeList.indexOf(node);
                distance = distanceMatrix.doubleValue(i, e);
                numerator += distance;
            }
            cData.setValue(c, e, (numerator / cluster.size()));
        }
    }
}
Also used : FuzzyNodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) CyNode(org.cytoscape.model.CyNode)

Example 39 with CyMatrix

use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix in project clusterMaker2 by RBVI.

the class ConnectedComponentsCluster method run.

public void run(TaskMonitor monitor) {
    monitor.setTitle("Performing ConnectedComponents cluster");
    this.monitor = monitor;
    if (network == null)
        network = clusterManager.getNetwork();
    // Make sure to update the context
    context.setNetwork(network);
    NodeCluster.init();
    CyMatrix matrix = context.edgeAttributeHandler.getMatrix();
    if (matrix == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Can't get distance matrix: no attribute value?");
        return;
    }
    // Update our tunable results
    clusterAttributeName = context.getClusterAttribute();
    createGroups = context.advancedAttributes.createGroups;
    if (canceled)
        return;
    Map<Integer, List<CyNode>> components = MatrixUtils.findConnectedComponents(matrix);
    // Create the NodeClusters
    Map<Integer, NodeCluster> clusterMap = new HashMap<Integer, NodeCluster>();
    for (Integer cluster : components.keySet()) {
        clusterMap.put(cluster, new NodeCluster(components.get(cluster)));
    }
    // Now get the sorted cluster map
    int clusterNumber = 1;
    HashMap<NodeCluster, NodeCluster> cMap = new HashMap<NodeCluster, NodeCluster>();
    for (NodeCluster cluster : NodeCluster.sortMap(clusterMap)) {
        if (cMap.containsKey(cluster))
            continue;
        cMap.put(cluster, cluster);
        cluster.setClusterNumber(clusterNumber);
        clusterNumber++;
    }
    List<NodeCluster> clusters = new ArrayList<NodeCluster>(cMap.keySet());
    monitor.showMessage(TaskMonitor.Level.INFO, "Removing groups");
    // Remove any leftover groups from previous runs
    removeGroups(network, GROUP_ATTRIBUTE);
    monitor.showMessage(TaskMonitor.Level.INFO, "Creating groups");
    params = new ArrayList<String>();
    context.edgeAttributeHandler.setParams(params);
    List<List<CyNode>> nodeClusters = createGroups(network, clusters, GROUP_ATTRIBUTE);
    results = new AbstractClusterResults(network, clusters);
    monitor.showMessage(TaskMonitor.Level.INFO, "ConnectedComponent results:\n" + results);
    if (context.vizProperties.showUI) {
        monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
        insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, context.vizProperties.restoreEdges, !context.edgeAttributeHandler.selectedOnly));
    }
}
Also used : CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 40 with CyMatrix

use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix in project clusterMaker2 by RBVI.

the class CyColtMatrix method getDistanceMatrix.

public CyMatrix getDistanceMatrix(DistanceMetric metric) {
    CyColtMatrix dist = new CyColtMatrix(network, nRows, nRows);
    if (rowNodes != null) {
        dist.rowNodes = Arrays.copyOf(rowNodes, nRows);
        dist.columnNodes = Arrays.copyOf(rowNodes, nRows);
    }
    Matrix cMatrix = super.getDistanceMatrix(metric);
    return dist.copy(cMatrix);
}
Also used : Matrix(edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix) CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)

Aggregations

CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)47 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 CyNode (org.cytoscape.model.CyNode)13 Clusters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)11 NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)10 Test (org.junit.Test)10 Matrix (edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix)9 List (java.util.List)8 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)6 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)6 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)4 CyTable (org.cytoscape.model.CyTable)4 ColtMatrix (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.matrix.ColtMatrix)3 BiclusterView (edu.ucsf.rbvi.clusterMaker2.internal.ui.BiclusterView)3 Map (java.util.Map)3 CyNetwork (org.cytoscape.model.CyNetwork)3 MedianSummarizer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.MedianSummarizer)2 ScatterPlotDialog (edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog)2 CyEdge (org.cytoscape.model.CyEdge)2