Search in sources :

Example 41 with Clusters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.

the class ClusteringManager method runClustering.

/**
 * Runs the clustering with the given configurations in the config class: {@link TaskConfig}.
 * Clusters each {@link ConnectedComponent} separately and waits until all are done.
 * Differes between the modes clustering and general training. Creates a Config file if
 * the training mode is used.
 * @throws InvalidInputFileException If the file/directory given produces an error.
 * @throws InvalidTypeException An incorrect method implementation was given, or some
 * other error occured with this.
 */
public void runClustering() throws InvalidInputFileException, InvalidTypeException {
    /* initialise ClusterFile if in clustering mode */
    ClusterFile clusterFile = null;
    if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE) {
        log.fine("Running clustering in clustering mode!");
        clusterFile = new ClusterFile();
        clusterFile.instantiateFile(TaskConfig.clustersPath);
        clusterFile.printPreProcessingClusters(TaskConfig.transitiveConnectedComponents);
        /* check whether connectedComponents has been initialised */
        if (this.connectedComponents == null) {
            if (TaskConfig.transitiveConnectedComponents == null) {
                log.warning("Incorrect use of the ClusteringManager, the connected components list" + "hadn't been initialised. Called method to initialise this and the parameters from " + "the config. Or only a TCC file was given and no connected components.");
                this.initParametersAndCCs();
            } else {
                log.info("No cost matrices were given, just a transitive connected components file, which" + "is converted to a clusters file. NO CLUSTERING IS PERFORMED!");
                InfoFile.appendToProjectDetails("No cost matrices were given, just a transitive connected components file, which" + "is converted to a clusters file. NO CLUSTERING IS PERFORMED!");
            }
        }
    }
    if (this.connectedComponents != null) {
        /* go through cc list and start training for each and control thread use */
        ArrayList<Semaphore> allSemaphores = new ArrayList<Semaphore>();
        Semaphore maxThreadSemaphore = new Semaphore(TaskConfig.maxNoThreads, true);
        for (int i = 0; i < this.connectedComponents.size(); i++) {
            Semaphore semaphore = new Semaphore(1);
            allSemaphores.add(semaphore);
            long time = System.currentTimeMillis();
            CostMatrixReader cmReader = new CostMatrixReader(this.connectedComponents.get(i));
            ConnectedComponent cc = cmReader.getConnectedComponent();
            runClusteringForOneConnectedComponent(cc, clusterFile, semaphore, maxThreadSemaphore, time);
        }
        /* wait for all clustering tasks to finish */
        for (Semaphore s : allSemaphores) {
            try {
                s.acquire();
            } catch (InterruptedException e) {
                log.severe(e.getMessage());
                e.printStackTrace();
            }
        }
    }
    if (clusterFile != null)
        clusterFile.closeFile();
    /* END OF CLUSTERING */
    log.info("Clustering scores sum: " + totalScoreSum);
    if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE) {
        InfoFile.appendLnProjectResults("Total sum of clustering scores for given input: " + TaskUtility.round(totalScoreSum, 2));
    }
    /* set score to IParameters objects for general training mode */
    if (TaskConfig.mode == TaskConfig.GENERAL_TRAINING_MODE) {
        log.fine("Setting parameters score for training mode!");
        for (IParameters parameter : this.layouterParameters) {
            parameter.setScore(totalScoreSum);
        }
    }
    totalScoreSum = 0;
}
Also used : IParameters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters) ConnectedComponent(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent) ArrayList(java.util.ArrayList) CostMatrixReader(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.CostMatrixReader) Semaphore(java.util.concurrent.Semaphore) ClusterFile(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ClusterFile)

Example 42 with Clusters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.

the class ResultPanelPCA method initComponents.

private void initComponents() {
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setAutoCreateRowSorter(true);
    table.setDefaultRenderer(StringBuffer.class, new ResultsPanel.JTextAreaRenderer(defaultRowHeight));
    // gives a little vertical room between clusters
    table.setIntercellSpacing(new Dimension(0, 4));
    // removes an outline that appears when the user clicks on the images
    table.setFocusable(false);
    // Ask to be notified of selection changes.
    ListSelectionModel rowSM = table.getSelectionModel();
    rowSM.addListSelectionListener(this);
    JScrollPane tableScrollPane = new JScrollPane(table);
    // System.out.println("CBP: after creating JScrollPane");
    tableScrollPane.getViewport().setBackground(Color.WHITE);
    add(tableScrollPane, BorderLayout.CENTER);
// System.out.println("CBP: after adding JScrollPane");
}
Also used : JScrollPane(javax.swing.JScrollPane) ResultsPanel(edu.ucsf.rbvi.clusterMaker2.internal.ui.ResultsPanel) ListSelectionModel(javax.swing.ListSelectionModel) Dimension(java.awt.Dimension)

Example 43 with Clusters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.

the class ResultsPanelTask method getClusters.

public List<NodeCluster> getClusters() {
    List<NodeCluster> clusters = new ArrayList<NodeCluster>();
    // List<List<CyNode>> clusterList = new ArrayList<List<CyNode>>();
    /*
		System.out.println(network.NAME);
		System.out.println(CyNetwork.LOCAL_ATTRS);
		System.out.println(ClusterManager.CLUSTER_ATTRIBUTE);
		*/
    clusterAttribute = network.getRow(network, CyNetwork.LOCAL_ATTRS).get(ClusterManager.CLUSTER_ATTRIBUTE, String.class);
    // Create a temporary cluster map
    Map<Integer, ArrayList<CyNode>> clusterMap = new HashMap<Integer, ArrayList<CyNode>>();
    for (CyNode node : (List<CyNode>) network.getNodeList()) {
        // For each node -- see if it's in a cluster.  If so, add it to our map
        if (ModelUtils.hasAttribute(network, node, clusterAttribute)) {
            Integer cluster = network.getRow(node).get(clusterAttribute, Integer.class);
            if (!clusterMap.containsKey(cluster))
                clusterMap.put(cluster, new ArrayList<CyNode>());
            clusterMap.get(cluster).add(node);
        }
    }
    // See if this algorithm provided it's own scores
    List<Double> scores = null;
    if (network.getDefaultNetworkTable().getColumn(clusterAttribute + "_Scores") != null) {
        scores = network.getRow(network, CyNetwork.LOCAL_ATTRS).getList(clusterAttribute + "_Scores", Double.class);
    }
    for (int clustNum : clusterMap.keySet()) {
        NodeCluster cluster = new NodeCluster(clusterMap.get(clustNum));
        cluster.setClusterNumber(clustNum);
        if (scores != null)
            cluster.setClusterScore(scores.get(clustNum - 1));
        clusters.add(cluster);
    }
    // calculating the scores for each cluster
    clusterResults = new AbstractClusterResults(network, clusters);
    List<Double> modularityList;
    if (scores == null) {
        modularityList = clusterResults.getModularityList();
    } else {
        modularityList = scores;
    }
    for (int i = 0; i < clusters.size(); i++) {
        clusters.get(i).setClusterScore(modularityList.get(i));
    }
    return clusters;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) CyNode(org.cytoscape.model.CyNode) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 44 with Clusters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.

the class ClusterUtils method fetchClusters.

public static List<NodeCluster> fetchClusters(CyNetwork network) {
    List<NodeCluster> clusters = new ArrayList<>();
    String clusterAttribute = getClusterAttribute(network);
    Map<Integer, ArrayList<CyNode>> clusterMap = new HashMap<>();
    for (CyNode node : network.getNodeList()) {
        if (ModelUtils.hasAttribute(network, node, clusterAttribute)) {
            Integer cluster = network.getRow(node).get(clusterAttribute, Integer.class);
            if (!clusterMap.containsKey(cluster)) {
                clusterMap.put(cluster, new ArrayList<>());
            }
            clusterMap.get(cluster).add(node);
        }
    }
    for (int clusterNum : clusterMap.keySet()) {
        NodeCluster cluster = new NodeCluster(clusterMap.get(clusterNum));
        cluster.setClusterNumber(clusterNum);
        clusters.add(cluster);
    }
    return clusters;
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 45 with Clusters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.

the class ClusterUtils method setNodeScoresInCluster.

public static List<NodeCluster> setNodeScoresInCluster(CyNetwork network, List<NodeCluster> clusters, List<String> nodeAttributes, String clusterColumnName, boolean multiplicative) {
    List<CyNode> nodes = network.getNodeList();
    CyTable table = network.getDefaultNodeTable();
    for (String nodeAttr : nodeAttributes) {
        for (CyNode node : nodes) {
            CyRow row = table.getRow(node.getSUID());
            int nodeClusterNumber = row.get(clusterColumnName, Integer.class, -1);
            for (NodeCluster cluster : clusters) {
                if (cluster.getClusterNumber() == nodeClusterNumber) {
                    if (multiplicative) {
                        setRankScoreMultiplicative(nodeAttr, row, cluster);
                    } else {
                        setRankScore(nodeAttr, row, cluster);
                    }
                }
            }
        }
    }
    return clusters;
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)

Aggregations

ArrayList (java.util.ArrayList)30 NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)27 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)22 Clusters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)21 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)16 HashMap (java.util.HashMap)16 List (java.util.List)15 CyNode (org.cytoscape.model.CyNode)13 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)10 Test (org.junit.Test)9 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)8 ConnectedComponent (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent)6 Random (java.util.Random)5 Vector (java.util.Vector)5 Semaphore (java.util.concurrent.Semaphore)5 Edges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.dataTypes.Edges)3 ICCEdges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ICCEdges)3 IParameters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters)3 ClusteringManager (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.ClusteringManager)3 PREdge (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PREdge)3