Search in sources :

Example 21 with NodeCluster

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

the class MultipleAttributeAddition method run.

@Override
public void run(TaskMonitor taskMonitor) {
    taskMonitor.setProgress(0.0);
    taskMonitor.setTitle("Multiple Node Edge Additive ranking of clusters");
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Fetching clusters...");
    taskMonitor.setProgress(0.1);
    List<NodeCluster> clusters = ClusterUtils.fetchClusters(network);
    taskMonitor.setProgress(0.5);
    String clusterColumnName = ClusterUtils.getClusterAttribute(network);
    List<String> nodeAttributes = context.getSelectedNodeAttributes();
    List<String> edgeAttributes = context.getSelectedEdgeAttributes();
    taskMonitor.setProgress(0.6);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting node scores in clusters");
    clusters = ClusterUtils.setNodeScoresInCluster(network, clusters, nodeAttributes, clusterColumnName, false);
    taskMonitor.setProgress(0.75);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting edge scores in clusters");
    clusters = ClusterUtils.setEdgeScoresInCluster(network, clusters, edgeAttributes, clusterColumnName, false);
    taskMonitor.setProgress(0.80);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Sorting and ranking clusters");
    ClusterUtils.ascendingSort(clusters);
    NodeCluster.setClusterRanks(clusters);
    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) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 22 with NodeCluster

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

the class MultipleAttributeMultiplicative method run.

@Override
public void run(TaskMonitor taskMonitor) {
    taskMonitor.setProgress(0.0);
    taskMonitor.setTitle("Multiple Node Edge Multiplum ranking of clusters");
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Fetching clusters...");
    taskMonitor.setProgress(0.1);
    List<NodeCluster> clusters = ClusterUtils.fetchClusters(network);
    taskMonitor.setProgress(0.5);
    String clusterColumnName = ClusterUtils.getClusterAttribute(network);
    List<String> nodeAttributes = context.getSelectedNodeAttributes();
    List<String> edgeAttributes = context.getSelectedEdgeAttributes();
    taskMonitor.setProgress(0.6);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting node scores in clusters");
    clusters = ClusterUtils.setNodeScoresInCluster(network, clusters, nodeAttributes, clusterColumnName, true);
    taskMonitor.setProgress(0.75);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting edge scores in clusters");
    clusters = ClusterUtils.setEdgeScoresInCluster(network, clusters, edgeAttributes, clusterColumnName, true);
    taskMonitor.setProgress(0.80);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Sorting and ranking clusters");
    ClusterUtils.ascendingSort(clusters);
    NodeCluster.setClusterRanks(clusters);
    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) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 23 with NodeCluster

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

the class PR method run.

@Override
public void run(TaskMonitor taskMonitor) {
    taskMonitor.setProgress(0.0);
    taskMonitor.setTitle("PRWP with Priors ranking of clusters");
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Fetching clusters...");
    taskMonitor.setProgress(0.1);
    List<NodeCluster> 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, "Calculating PageRank scores");
    PageRank<PRNode, PREdge> pageRank = performPageRank();
    taskMonitor.setProgress(0.8);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Inserting scores into clusters");
    insertScores(clusters, pageRank);
    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)

Example 24 with NodeCluster

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

the class PRWP method run.

@Override
public void run(TaskMonitor taskMonitor) {
    taskMonitor.setProgress(0.0);
    taskMonitor.setTitle("PRWP with Priors ranking of clusters");
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Fetching clusters...");
    taskMonitor.setProgress(0.1);
    List<NodeCluster> 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, "Calculating PageRank scores");
    PageRankWithPriors<PRNode, PREdge> pageRank = performPageRank();
    taskMonitor.setProgress(0.8);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Inserting scores into clusters");
    insertScores(clusters, pageRank);
    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)

Example 25 with NodeCluster

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

the class RunAutoSOME method run.

public List<NodeCluster> run(TaskMonitor monitor) {
    long startTime = System.currentTimeMillis();
    debugln("Initial matrix:");
    // printMatrix(matrix);
    // Normalize
    // normalize(matrix, clusteringThresh, false);
    debugln("Normalized matrix:");
    if (dataAttributes == null || dataAttributes.isEmpty()) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Error: no attribute list selected");
        return null;
    }
    if (selectedOnly && network.getDefaultNodeTable().countMatchingRows(CyNetwork.SELECTED, true) == 0) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Error: no nodes selected from network");
        return null;
    }
    Settings s = new Settings();
    // get parameter settings
    s.ensemble_runs = settings.ensemble_runs;
    s.mst_pval = settings.mst_pval;
    s.threads = settings.threads;
    s.logNorm = settings.logNorm;
    s.unitVar = settings.unitVar;
    s.medCenter = settings.medCenter;
    s.medCenterCol = settings.medCenterCol;
    s.sumSqrRows = settings.sumSqrRows;
    s.sumSqrCol = settings.sumSqrCol;
    s.som_iters = settings.som_iters;
    s.de_resolution = settings.de_resolution;
    s.distMatrix = settings.distMatrix;
    s.dmDist = settings.dmDist;
    s.FCNrows = settings.FCNrows;
    s.som_maxGrid = 20;
    s.htmlOut = false;
    s.textOut = false;
    // System.out.println("network "+network.toString()+" has "+network.getNodeCount()+" nodes");
    // System.out.println("attributes: "+dataAttributes);
    String[] attrArray = new String[dataAttributes.size()];
    int att = 0;
    for (String attribute : dataAttributes) {
        attrArray[att++] = "node." + attribute;
    }
    // Create the matrix
    CyMatrix matrix = CyMatrixFactory.makeSmallMatrix(network, attrArray, selectedOnly, ignoreMissing, false, false);
    if (!selectedOnly) {
        nodes = network.getNodeList();
    } else {
        nodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true);
    }
    s.input = new dataItem[matrix.nRows()];
    // matrix.printMatrix();
    Map<String, Integer> key = new HashMap<String, Integer>();
    for (int i = 0; i < nodes.size(); i++) {
        String id = ModelUtils.getNodeName(network, nodes.get(i));
        if (!key.containsKey(id))
            key.put(id, i);
    }
    for (int k = 0, itor = 0; k < matrix.nRows(); k++) {
        float[] f = new float[matrix.nColumns()];
        // System.out.println(matrix.getRowLabels()[k]+" "+nodes.get(k).getIdentifier());
        if (k == 0) {
            s.columnHeaders = new String[f.length + 1];
            s.columnHeaders[0] = "NAME";
        }
        for (int l = 0; l < f.length; l++) {
            if (k == 0) {
                s.columnHeaders[l + 1] = matrix.getColumnLabel(l);
                s.columnHeaders[l + 1] = s.columnHeaders[l + 1].replace("\"", "");
                s.columnHeaders[l + 1] = s.columnHeaders[l + 1].replace(",", "");
            // System.out.println(s.columnHeaders[l+1]);
            }
            // System.out.println(matrix.getValue(k,l).floatValue());
            if (matrix.getValue(k, l) != null) {
                f[l] = matrix.getValue(k, l).floatValue();
            } else {
                f[l] = -99999999;
                s.fillMissing = true;
            }
        }
        s.input[itor++] = new dataItem(f, matrix.getRowLabel(k));
    }
    if (s.FCNrows && s.distMatrix)
        s = transpose(s);
    if (s.input == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Insufficient data for clustering (1 or less rows or columns)");
        return null;
    } else if (s.input.length < 2) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Insufficient data for clustering (1 or less rows or columns)");
        return null;
    } else if (s.input[0].getValues() == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Insufficient data for clustering (1 or less rows or columns)");
        return null;
    } else if (s.input[0].getValues().length < 2) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Insufficient data for clustering (1 or less rows or columns)");
        return null;
    }
    autRun = new Run();
    cr = autRun.runAutoSOMEBasic(s, monitor);
    if (cr == null) {
        monitor.setStatusMessage("Clustering failed!");
        return null;
    }
    monitor.setStatusMessage("Assigning nodes to clusters");
    clusterCount = cr.c.length;
    Map<NodeCluster, NodeCluster> cMap = (!s.distMatrix) ? getNodeClusters(cr, key, matrix, s) : getNodeClustersFCN(cr, matrix, s);
    if (canceled) {
        monitor.setStatusMessage("canceled");
        return null;
    }
    // Update node attributes in network to include clusters. Create cygroups from clustered nodes
    monitor.setStatusMessage("Created " + clusterCount + " clusters");
    // 
    if (clusterCount == 0) {
        monitor.showMessage(TaskMonitor.Level.WARN, "Created 0 clusters!!!!");
        return null;
    }
    Set<NodeCluster> clusters = cMap.keySet();
    return new ArrayList<NodeCluster>(clusters);
}
Also used : CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)

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