Search in sources :

Example 16 with NodeCluster

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

the class CuttingEdgeFilter method doFilter.

public NodeCluster doFilter(List<CyNode> nodeList, Map<NodeCluster, List<CyNode>> addedNodeMap) {
    // Get the total number of edges for all nodes
    Set<CyEdge> allEdges = new HashSet<CyEdge>();
    for (CyNode node : nodeList) {
        List<CyEdge> edgeList = network.getAdjacentEdgeList(node, CyEdge.Type.ANY);
        if (edgeList == null && edgeList.size() == 0)
            continue;
        allEdges.addAll(edgeList);
    }
    int totalEdges = allEdges.size();
    if (totalEdges == 0)
        return null;
    // Get the number of edges within the cluster
    List<CyEdge> edgeList = ModelUtils.getConnectingEdges(network, nodeList);
    if (edgeList == null)
        return null;
    int innerEdges = edgeList.size();
    double ep = (double) innerEdges / (double) totalEdges;
    System.out.println("innerEdges = " + innerEdges + ", totalEdges = " + totalEdges);
    System.out.println("Ratio = " + ep + ", edgeProportion = " + context.edgeProportion);
    if (ep >= context.edgeProportion)
        return new NodeCluster(nodeList);
    else
        return null;
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) HashSet(java.util.HashSet)

Example 17 with NodeCluster

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

the class RunAutoSOME method getNodeClusters.

private Map<NodeCluster, NodeCluster> getNodeClusters(clusterRun cr, Map<String, Integer> key, CyMatrix matrix, Settings s) {
    Map<NodeCluster, NodeCluster> cMap = new HashMap<NodeCluster, NodeCluster>();
    attrList = new ArrayList<String>();
    attrOrderList = new ArrayList<String>();
    nodeOrderList = new ArrayList<String>();
    for (int i = 0; i < matrix.nColumns(); i++) attrOrderList.add(matrix.getColumnLabel(i));
    for (int i = 0; i < clusterCount; i++) {
        if (cr.c[i].ids.isEmpty())
            continue;
        NodeCluster nc = new NodeCluster();
        nc.setClusterNumber(i);
        for (int j = 0; j < cr.c[i].ids.size(); j++) {
            int dataID = cr.c[i].ids.get(j).intValue();
            int nodeDataID = key.get(matrix.getRowLabels()[dataID]).intValue();
            CyNode cn = nodes.get(nodeDataID);
            nc.add(cn);
            attrList.add(ModelUtils.getNodeName(network, cn) + "\t" + i);
            nodeOrderList.add(ModelUtils.getNodeName(network, cn));
        }
        cMap.put(nc, nc);
    }
    return cMap;
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) HashMap(java.util.HashMap) CyNode(org.cytoscape.model.CyNode)

Example 18 with NodeCluster

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

the class RunAutoSOME method getNodeClustersFCN.

private Map<NodeCluster, NodeCluster> getNodeClustersFCN(clusterRun cr, CyMatrix matrix, Settings s) {
    attrList = new ArrayList<String>();
    attrOrderList = new ArrayList<String>();
    nodeOrderList = new ArrayList<String>();
    HashMap<NodeCluster, NodeCluster> cMap = new HashMap<NodeCluster, NodeCluster>();
    storeNodes = new HashMap<String, CyNode>();
    storeClust = new HashMap<String, String>();
    int currClust = -1;
    NodeCluster nc = new NodeCluster();
    Map<String, CyNode> storeOrigNodes = new HashMap<String, CyNode>();
    for (int i = 0; i < nodes.size(); i++) {
        CyNode cn = (CyNode) nodes.get(i);
        storeOrigNodes.put(ModelUtils.getNodeName(network, cn), cn);
    }
    if (!s.FCNrows)
        for (int i = 1; i < s.columnHeaders.length; i++) attrOrderList.add(s.columnHeaders[i]);
    else {
        for (int i = 0; i < matrix.nColumns(); i++) attrOrderList.add(matrix.getColumnLabel(i));
    }
    for (int i = 0; i < cr.fcn_nodes.length; i++) {
        String[] fcn = cr.fcn_nodes[i];
        if (currClust != Integer.valueOf(fcn[1])) {
            if (nc.size() > 0)
                cMap.put(nc, nc);
            nc = new NodeCluster();
            currClust = Integer.valueOf(fcn[1]);
            nc.setClusterNumber(currClust);
        // System.out.println(currClust+"\t"+nc.getClusterNumber());
        }
        String temp = fcn[0];
        // System.out.println(temp);
        String[] tokens = temp.split("_");
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < tokens.length - 1; j++) sb.append(tokens[j] + "_");
        temp = sb.substring(0, sb.length() - 1);
        CyNode cn = network.addNode();
        network.getRow(cn).set(CyNetwork.NAME, temp);
        network.getRow(cn).set(CyRootNetwork.SHARED_NAME, temp);
        nodeOrderList.add(temp);
        attrList.add(temp + "\t" + currClust);
        if (s.FCNrows) {
            CyNode orig = (CyNode) storeOrigNodes.get(fcn[2]);
            CyTable nodeAttrs = network.getDefaultNodeTable();
            Set<String> atts = CyTableUtil.getColumnNames(nodeAttrs);
            for (String attribute : atts) {
                Class type = nodeAttrs.getColumn(attribute).getType();
                Object att = nodeAttrs.getRow(orig).getRaw(attribute);
                if (att == null)
                    continue;
                nodeAttrs.getRow(cn).set(attribute, att);
            }
        }
        storeNodes.put(fcn[0], cn);
        storeClust.put(fcn[0], fcn[1]);
        nc.add(cn);
    /*
			CyAttributes netAttr = Cytoscape.getNetworkAttributes();
			String netID = Cytoscape.getCurrentNetwork().getIdentifier();
			netAttr.setListAttribute(netID, ClusterMaker.CLUSTER_NODE_ATTRIBUTE, attrList);
			netAttr.setListAttribute(netID, ClusterMaker.ARRAY_ORDER_ATTRIBUTE, attrOrderList);
			netAttr.setListAttribute(netID, ClusterMaker.NODE_ORDER_ATTRIBUTE, nodeOrderList);
			*/
    }
    if (nc.size() > 0)
        cMap.put(nc, nc);
    return cMap;
}
Also used : HashMap(java.util.HashMap) CyTable(org.cytoscape.model.CyTable) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) CyNode(org.cytoscape.model.CyNode)

Example 19 with NodeCluster

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

the class HairCutFilter method doFilter.

public NodeCluster doFilter(List<CyNode> nodeList, Map<NodeCluster, List<CyNode>> addedNodeMap) {
    // Get the number of edges within the cluster
    List<CyEdge> edgeList = ModelUtils.getConnectingEdges(network, nodeList);
    Map<CyNode, Integer> degreeMap = new HashMap<CyNode, Integer>();
    for (CyEdge edge : edgeList) {
        updateMap(degreeMap, edge.getSource());
        updateMap(degreeMap, edge.getTarget());
    }
    List<CyNode> newNodeList = new ArrayList<CyNode>();
    // Now, drop any nodes with a degree less than minimumDegree
    for (CyNode node : degreeMap.keySet()) {
        if (degreeMap.get(node) > context.minimumDegree)
            newNodeList.add(node);
    }
    if (newNodeList.size() > 1)
        return new NodeCluster(newNodeList);
    return null;
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge)

Example 20 with NodeCluster

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

the class HyperlinkInducedTopicSearch method run.

@Override
public void run(TaskMonitor taskMonitor) {
    taskMonitor.setProgress(0.0);
    taskMonitor.setTitle("Hyperlink-Induced Topic Search ranking of clusters");
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Fetching clusters...");
    taskMonitor.setProgress(0.1);
    clusters = ClusterUtils.fetchClusters(network);
    taskMonitor.setProgress(0.5);
    initVariables();
    clusters.forEach(NodeCluster::initNodeScores);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting node scores in clusters");
    addNodes();
    taskMonitor.setProgress(0.6);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting edge scores in clusters");
    addEdges();
    taskMonitor.setProgress(0.7);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Performing HITS algorithm");
    HITS<PRNode, PREdge> hyperlinkInducedTopicSearchPriors = performHITS(graph);
    taskMonitor.setProgress(0.8);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting cluster scores");
    insertScores(clusters, graph, hyperlinkInducedTopicSearchPriors);
    taskMonitor.setProgress(0.9);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Insert cluster information in tables");
    ClusterUtils.insertResultsInColumns(network, clusters, SHORTNAME);
    results = new AbstractClusterResults(network, clusters);
    taskMonitor.setProgress(1.0);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Done...");
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) PREdge(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PREdge) PRNode(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PRNode) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Aggregations

NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)39 ArrayList (java.util.ArrayList)25 CyNode (org.cytoscape.model.CyNode)18 HashMap (java.util.HashMap)17 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)15 List (java.util.List)15 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)9 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)7 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)5 DoubleArrayList (cern.colt.list.tdouble.DoubleArrayList)3 IntArrayList (cern.colt.list.tint.IntArrayList)3 PREdge (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PREdge)3 PRNode (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PRNode)3 CyEdge (org.cytoscape.model.CyEdge)3 DoubleMatrix2D (cern.colt.matrix.tdouble.DoubleMatrix2D)2 HashSet (java.util.HashSet)2 Edges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.dataTypes.Edges)1 IteratorThread (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.iterativeclustering.IteratorThread)1 ClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterResults)1 Matrix (edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix)1