Search in sources :

Example 11 with ClusterManager

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

the class KMeansCluster method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing " + getName());
    List<String> nodeAttributeList = context.attributeList.getNodeAttributeList();
    String edgeAttribute = context.attributeList.getEdgeAttribute();
    if (nodeAttributeList == null && edgeAttribute == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must select either one edge column or two or more node columns");
        return;
    }
    if (nodeAttributeList != null && nodeAttributeList.size() > 0 && edgeAttribute != null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Can't have both node and edge columns selected");
        return;
    }
    if (context.selectedOnly && CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true).size() < 3) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least three nodes to cluster");
        return;
    }
    createGroups = context.createGroups;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        // To make debugging easier, sort the attribute list
        Collections.sort(nodeAttributeList);
    }
    // Get our attributes we're going to use for the cluster
    String[] attributeArray;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        attributeArray = new String[nodeAttributeList.size()];
        int i = 0;
        for (String attr : nodeAttributeList) {
            attributeArray[i++] = "node." + attr;
        }
    } else {
        attributeArray = new String[1];
        attributeArray[0] = "edge." + edgeAttribute;
    }
    monitor.setStatusMessage("Initializing");
    // System.out.println("Initializing");
    resetAttributes(network, SHORTNAME);
    // Create a new clusterer
    RunKCluster algorithm = new RunKCluster(network, attributeArray, distanceMetric, monitor, context, this);
    // System.out.println("Algorithm defined");
    String resultsString = "K-Means results:";
    // Cluster the attributes, if requested
    if (context.clusterAttributes && attributeArray.length > 1) {
        monitor.setStatusMessage("Clustering attributes");
        // System.out.println("Clustering attributes: k="+context.kcluster.kNumber);
        Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, context.iterations, true, "kmeans", context.kcluster, false);
        attributeList = algorithm.getAttributeList();
        updateAttributes(network, SHORTNAME, rowOrder, attributeArray, attributeList, algorithm.getMatrix());
        attributeSilhouette = algorithm.getSilhouettes();
        attributeOrder = getOrder(rowOrder, algorithm.getMatrix());
    }
    // Cluster the nodes
    monitor.setStatusMessage("Clustering nodes");
    Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, context.iterations, false, "kmeans", context.kcluster, createGroups);
    nodeList = algorithm.getAttributeList();
    updateAttributes(network, SHORTNAME, rowOrder, attributeArray, nodeList, algorithm.getMatrix());
    nodeSilhouette = algorithm.getSilhouettes();
    nodeOrder = getOrder(rowOrder, algorithm.getMatrix());
    // System.out.println(resultsString);
    if (context.showUI) {
        insertTasksAfterCurrentTask(new KnnView(clusterManager));
    }
}
Also used : KnnView(edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)

Example 12 with ClusterManager

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

the class DendroView method getButtonBox.

private JPanel getButtonBox() {
    // Get our border
    JPanel buttonBox = new JPanel();
    buttonBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
    // Now add our buttons
    // The Settings button will bring up the Pixel Settings dialog
    {
        JButton settingsButton = createButton("Settings...");
        settingsButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                ColorExtractor ce = null;
                try {
                    ce = ((DoubleArrayDrawer) arrayDrawer).getColorExtractor();
                } catch (Exception e) {
                }
                PixelSettingsSelector pssSelector = new PixelSettingsSelector(globalXmap, globalYmap, getZoomXmap(), getZoomYmap(), ce, colorPresets);
                JDialog popup = new ModelessSettingsDialog(viewFrame, "Pixel Settings", pssSelector);
                popup.addWindowListener(PropertyConfig.getStoreOnWindowClose(getDataModel().getDocumentConfig()));
                popup.pack();
                popup.setVisible(true);
            }
        });
        buttonBox.add(settingsButton);
    }
    // The Save Data button brings up a file dialog and saves the .CDT, .GTR, and .ATR files
    {
        JButton saveButton = createButton("Save Data...");
        saveButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                JFileChooser chooser = new JFileChooser();
                int returnVal = chooser.showSaveDialog(viewFrame);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    // Save the data
                    // Get the name of the file
                    String filePath = chooser.getSelectedFile().getAbsolutePath();
                    if (filePath.length() == 0)
                        return;
                    DataModelWriter writer = new DataModelWriter(dataModel);
                    if (dataModel.aidFound())
                        writer.writeAtr(filePath + ".atr");
                    if (dataModel.gidFound())
                        writer.writeGtr(filePath + ".gtr");
                    writer.writeCdt(filePath + ".cdt");
                }
            }
        });
        buttonBox.add(saveButton);
    }
    // The Export Graphics button brings up a new dialog that allows the user
    // to produce images for publication
    {
        JButton exportButton = createButton("Export Graphics...");
        exportButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionevent) {
                GraphicsExportPanel graphicsExport = new GraphicsExportPanel(myView);
                graphicsExport.setGeneFont(textview.getFont());
                graphicsExport.setArrayFont(arraynameview.getFont());
                JDialog popup = new CancelableSettingsDialog(viewFrame, "Export Graphics", graphicsExport);
                popup.addWindowListener(PropertyConfig.getStoreOnWindowClose(getDataModel().getDocumentConfig()));
                popup.pack();
                popup.setVisible(true);
            }
        });
        buttonBox.add(exportButton);
    }
    if (dataModel.aidFound()) {
        JButton flipButton = createButton("Flip Tree Nodes");
        flipButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                flipSelectedATRNode();
            }
        });
        buttonBox.add(flipButton);
    }
    // Map the visual properties onto the network
    if (dataModel instanceof TreeViewModel) {
        final ClusterManager clusterManager = ((TreeViewModel) dataModel).getClusterManager();
        JButton vizMapButton = createButton("Map Colors Onto Network...");
        vizMapButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                // Get the colors from the view
                ColorExtractor ce = null;
                try {
                    ce = ((DoubleArrayDrawer) arrayDrawer).getColorExtractor();
                } catch (Exception e) {
                    // this shouldn't happen at this point!
                    ce = new ColorExtractor();
                    ce.setDefaultColorSet(colorPresets.getDefaultColorSet());
                }
                List<String> attributes = new ArrayList();
                if (dataModel.isSymmetrical()) {
                } else {
                    // Get the node attributes
                    int[] selections = arraySelection.getSelectedIndexes();
                    HeaderInfo arrayInfo = dataModel.getArrayHeaderInfo();
                    if (selections.length >= 1) {
                        for (int i = 0; i < selections.length; i++) {
                            attributes.add(arrayInfo.getHeader(selections[i])[0]);
                        }
                    } else {
                        // Nothing selected, add them all
                        int count = arrayInfo.getNumHeaders();
                        for (int i = 0; i < count; i++) {
                            attributes.add(arrayInfo.getHeader(i)[0]);
                        }
                    }
                }
                // Bring up the dialog
                NetworkColorDialog ncd = new NetworkColorDialog(null, ce, attributes, viewFrame, clusterManager, dataModel.getDataMatrix().getMinValue(), dataModel.getDataMatrix().getMaxValue(), dataModel.isSymmetrical());
            }
        });
        buttonBox.add(vizMapButton);
    }
    // The Close button exits clusterViz
    {
        JButton closeButton = createButton("Close");
        closeButton.addActionListener(new ActionListener() {

            // called when close button hit
            public void actionPerformed(ActionEvent evt) {
                viewFrame.closeWindow();
            }
        });
        // 
        buttonBox.add(closeButton);
    }
    return buttonBox;
}
Also used : ArrayList(java.util.ArrayList) LoadException(edu.ucsf.rbvi.clusterMaker2.internal.treeview.LoadException) ModelessSettingsDialog(edu.ucsf.rbvi.clusterMaker2.internal.treeview.ModelessSettingsDialog) DataModelWriter(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.DataModelWriter) HeaderInfo(edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo) NetworkColorDialog(edu.ucsf.rbvi.clusterMaker2.internal.ui.NetworkColorDialog) ArrayList(java.util.ArrayList) List(java.util.List) TreeViewModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.TreeViewModel) ClusterManager(edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterManager)

Example 13 with ClusterManager

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

the class BicFinder method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing " + getName());
    List<String> nodeAttributeList = context.attributeList.getNodeAttributeList();
    String edgeAttribute = context.attributeList.getEdgeAttribute();
    clusterAttributeName = "BicFinder_Bicluster";
    if (network.getRow(network, CyNetwork.LOCAL_ATTRS).getTable().getColumn(ClusterManager.CLUSTER_ATTRIBUTE) == null) {
        network.getRow(network, CyNetwork.LOCAL_ATTRS).getTable().createColumn(ClusterManager.CLUSTER_ATTRIBUTE, String.class, false);
    }
    network.getRow(network, CyNetwork.LOCAL_ATTRS).set(ClusterManager.CLUSTER_ATTRIBUTE, clusterAttributeName);
    if (nodeAttributeList == null && edgeAttribute == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must select either one edge column or two or more node columns");
        return;
    }
    if (nodeAttributeList != null && nodeAttributeList.size() > 0 && edgeAttribute != null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Can't have both node and edge columns selected");
        return;
    }
    if (context.selectedOnly && CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true).size() < 3) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least three nodes to cluster");
        return;
    }
    createGroups = context.createGroups;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        // To make debugging easier, sort the attribute list
        Collections.sort(nodeAttributeList);
    }
    // Get our attributes we're going to use for the cluster
    String[] attributeArray;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        attributeArray = new String[nodeAttributeList.size()];
        int i = 0;
        for (String attr : nodeAttributeList) {
            attributeArray[i++] = "node." + attr;
        }
    } else {
        attributeArray = new String[1];
        attributeArray[0] = "edge." + edgeAttribute;
    }
    monitor.setStatusMessage("Initializing");
    resetAttributes(network, SHORTNAME);
    // Create a new clusterer
    RunBicFinder algorithm = new RunBicFinder(network, attributeArray, monitor, context);
    String resultsString = "BicFinder results:";
    // Cluster the nodes
    monitor.setStatusMessage("Clustering nodes");
    Integer[] rowOrder = algorithm.cluster(false);
    CyMatrix biclusterMatrix = algorithm.getBiclusterMatrix();
    int[] clusters = new int[biclusterMatrix.nRows()];
    createBiclusterGroups(algorithm.getClusterNodes());
    // createGroups(network,biclusterMatrix,1, clusters, "bicfinder");
    updateAttributes(network, SHORTNAME, rowOrder, attributeArray, getAttributeList(), algorithm.getBiclusterMatrix());
    createBiclusterTable(algorithm.getClusterNodes(), algorithm.getClusterAttrs());
    // System.out.println(resultsString);
    if (context.showUI) {
        insertTasksAfterCurrentTask(new BiclusterView(clusterManager));
    }
}
Also used : BiclusterView(edu.ucsf.rbvi.clusterMaker2.internal.ui.BiclusterView) CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)

Example 14 with ClusterManager

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

the class ChengChurch method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing " + getName());
    List<String> nodeAttributeList = context.attributeList.getNodeAttributeList();
    String edgeAttribute = context.attributeList.getEdgeAttribute();
    clusterAttributeName = "CnC_Bicluster";
    if (network.getRow(network, CyNetwork.LOCAL_ATTRS).getTable().getColumn(ClusterManager.CLUSTER_ATTRIBUTE) == null) {
        network.getRow(network, CyNetwork.LOCAL_ATTRS).getTable().createColumn(ClusterManager.CLUSTER_ATTRIBUTE, String.class, false);
    }
    network.getRow(network, CyNetwork.LOCAL_ATTRS).set(ClusterManager.CLUSTER_ATTRIBUTE, clusterAttributeName);
    if (nodeAttributeList == null && edgeAttribute == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must select either one edge column or two or more node columns");
        return;
    }
    if (nodeAttributeList != null && nodeAttributeList.size() > 0 && edgeAttribute != null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Can't have both node and edge columns selected");
        return;
    }
    if (context.selectedOnly && CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true).size() < 3) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least three nodes to cluster");
        return;
    }
    createGroups = context.createGroups;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        // To make debugging easier, sort the attribute list
        Collections.sort(nodeAttributeList);
    }
    // Get our attributes we're going to use for the cluster
    String[] attributeArray;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        attributeArray = new String[nodeAttributeList.size()];
        int i = 0;
        for (String attr : nodeAttributeList) {
            attributeArray[i++] = "node." + attr;
        }
    } else {
        attributeArray = new String[1];
        attributeArray[0] = "edge." + edgeAttribute;
    }
    monitor.setStatusMessage("Initializing");
    resetAttributes(network, SHORTNAME);
    // Create a new clusterer
    RunChengChurch algorithm = new RunChengChurch(network, attributeArray, monitor, context);
    String resultsString = "ChengChurch results:";
    // Cluster the nodes
    monitor.setStatusMessage("Clustering nodes");
    Integer[] rowOrder = algorithm.cluster(false);
    CyMatrix biclusterMatrix = algorithm.getBiclusterMatrix();
    createGroups(network, biclusterMatrix, context.nClusters, algorithm.getRowClustersArray(), SHORTNAME);
    updateAttributes(network, SHORTNAME, rowOrder, attributeArray, getAttributeList(), algorithm.getBiclusterMatrix());
    // Build our attribute clustesrs
    List<String> arrayList = buildClusterHeaders(algorithm.getColClustersArray(), algorithm.getBiclusterMatrix(), true);
    ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_ATTR_ATTRIBUTE, arrayList, List.class, String.class);
    updateParams(network, context.getParams());
    // System.out.println(resultsString);
    if (context.showUI) {
        insertTasksAfterCurrentTask(new BiclusterView(clusterManager));
    }
}
Also used : BiclusterView(edu.ucsf.rbvi.clusterMaker2.internal.ui.BiclusterView) CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)

Example 15 with ClusterManager

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

the class DBSCAN method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing " + getName());
    List<String> nodeAttributeList = context.attributeList.getNodeAttributeList();
    String edgeAttribute = context.attributeList.getEdgeAttribute();
    if (nodeAttributeList == null && edgeAttribute == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must select either one edge column or two or more node columns");
        return;
    }
    if (nodeAttributeList != null && nodeAttributeList.size() > 0 && edgeAttribute != null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Can't have both node and edge columns selected");
        return;
    }
    if (context.selectedOnly && CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true).size() < 3) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least three nodes to cluster");
        return;
    }
    createGroups = context.createGroups;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        // To make debugging easier, sort the attribute list
        Collections.sort(nodeAttributeList);
    }
    // Get our attributes we're going to use for the cluster
    String[] attributeArray;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        attributeArray = new String[nodeAttributeList.size()];
        int i = 0;
        for (String attr : nodeAttributeList) {
            attributeArray[i++] = "node." + attr;
        }
    } else {
        attributeArray = new String[1];
        attributeArray[0] = "edge." + edgeAttribute;
    }
    monitor.setStatusMessage("Initializing");
    resetAttributes(network, SHORTNAME);
    distanceMetric = context.getDistanceMetric();
    // Create a new clusterer
    RunDBSCAN algorithm = new RunDBSCAN(network, attributeArray, distanceMetric, monitor, context);
    String resultsString = "DBSCAN results:";
    // Cluster the attributes, if requested
    if (context.clusterAttributes && attributeArray.length > 1) {
        monitor.setStatusMessage("Clustering attributes");
        int[] clusters = algorithm.cluster(true);
        if (!algorithm.getMatrix().isTransposed())
            createGroups(network, algorithm.getMatrix(), algorithm.getNClusters(), clusters, "dbscan");
        Integer[] rowOrder = MatrixUtils.indexSort(clusters, clusters.length);
        // Integer[] rowOrder = algorithm.cluster(context.kcluster.kNumber,1, true, "dbscan", context.kcluster);
        updateAttributes(network, SHORTNAME, rowOrder, attributeArray, getAttributeList(), algorithm.getMatrix());
    }
    // Cluster the nodes
    monitor.setStatusMessage("Clustering nodes");
    int[] clusters = algorithm.cluster(false);
    int nNodes = 0;
    for (int i = 0; i < clusters.length; i++) {
        if (clusters[i] >= 0)
            nNodes++;
    }
    monitor.setStatusMessage("Allocated " + nNodes + " nodes to " + algorithm.getNClusters() + " clusters");
    if (!algorithm.getMatrix().isTransposed()) {
        createGroups(network, algorithm.getMatrix(), algorithm.getNClusters(), clusters, "dbscan");
    }
    Integer[] rowOrder = MatrixUtils.indexSort(clusters, clusters.length);
    // In DBSCAN, not all nodes will be assigned to a cluster, so they will have a cluster # of -1.  Find
    // all of those and trim rowOrder accordingly.
    Integer[] newRowOrder = new Integer[nNodes];
    int newOrder = 0;
    for (int i = 0; i < rowOrder.length; i++) {
        int nodeIndex = rowOrder[i];
        if (clusters[nodeIndex] >= 0) {
            newRowOrder[newOrder] = nodeIndex;
            newOrder++;
        }
    }
    // Integer[] rowOrder = algorithm.cluster(context.kcluster.kNumber,1, false, "dbscan", context.kcluster);
    updateAttributes(network, SHORTNAME, newRowOrder, attributeArray, getAttributeList(), algorithm.getMatrix());
    // System.out.println(resultsString);
    if (context.showUI) {
        insertTasksAfterCurrentTask(new KnnView(clusterManager));
    }
}
Also used : KnnView(edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)

Aggregations

ArrayList (java.util.ArrayList)13 List (java.util.List)12 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)11 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)11 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)11 NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)8 KnnView (edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)5 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)3 BiclusterView (edu.ucsf.rbvi.clusterMaker2.internal.ui.BiclusterView)3 CyNode (org.cytoscape.model.CyNode)3 HashMap (java.util.HashMap)2 AttributeClusterTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.AttributeClusterTaskFactory)1 ChengChurchTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.ChengChurch.ChengChurchTaskFactory)1 DBSCANTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.DBSCAN.DBSCANTaskFactory)1 AutoSOMETaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.autosome.AutoSOMETaskFactory)1 FeatureVectorTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.featureVector.FeatureVectorTaskFactory)1 FFTTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.fft.FFTTaskFactory)1 HierarchicalTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.hierarchical.HierarchicalTaskFactory)1 HopachPAMTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.hopach.HopachPAMTaskFactory)1 KMeansTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.kmeans.KMeansTaskFactory)1