Search in sources :

Example 6 with HeaderInfo

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo in project clusterMaker2 by RBVI.

the class DendroView method bindTrees.

/**
 * this is meant to be called from setupViews.
 * It make sure that the trees are generated from the current model,
 * and enables/disables them as required.
 *
 * I factored it out because it is common betwen DendroView and KnnDendroView.
 */
protected void bindTrees() {
    DataModel tvmodel = getDataModel();
    if ((tvmodel != null) && tvmodel.aidFound()) {
        try {
            atrview.setEnabled(true);
            atrzview.setEnabled(true);
            invertedTreeDrawer.setData(tvmodel.getAtrHeaderInfo(), tvmodel.getArrayHeaderInfo());
            HeaderInfo trHeaderInfo = tvmodel.getAtrHeaderInfo();
            if (trHeaderInfo.getIndex("NODECOLOR") >= 0) {
                TreeColorer.colorUsingHeader(invertedTreeDrawer.getRootNode(), trHeaderInfo, trHeaderInfo.getIndex("NODECOLOR"));
            }
        } catch (DendroException e) {
            throw new RuntimeException("Had problem setting up the array tree: " + e.getMessage());
        /*
				//				LogPanel.println("Had problem setting up the array tree : " + e.getMessage());
				//				e.printStackTrace();
				Box mismatch = new Box(BoxLayout.Y_AXIS); mismatch.add(new JLabel(e.getMessage()));
				mismatch.add(new JLabel("Perhaps there is a mismatch between your ATR and CDT files?"));
				mismatch.add(new JLabel("Ditching Array Tree, since it's lame."));
				JOptionPane.showMessageDialog(viewFrame, mismatch, "Tree Construction Error", JOptionPane.ERROR_MESSAGE);
				atrview.setEnabled(false);
				atrzview.setEnabled(false);
				try{invertedTreeDrawer.setData(null, null);} catch (DendroException ex) {}
				*/
        }
    } else {
        atrview.setEnabled(false);
        atrzview.setEnabled(false);
        try {
            invertedTreeDrawer.setData(null, null);
        } catch (DendroException ex) {
        }
    }
    invertedTreeDrawer.notifyObservers();
    if ((tvmodel != null) && tvmodel.gidFound()) {
        try {
            leftTreeDrawer.setData(tvmodel.getGtrHeaderInfo(), tvmodel.getGeneHeaderInfo());
            HeaderInfo gtrHeaderInfo = tvmodel.getGtrHeaderInfo();
            if (gtrHeaderInfo.getIndex("NODECOLOR") >= 0) {
                TreeColorer.colorUsingHeader(leftTreeDrawer.getRootNode(), tvmodel.getGtrHeaderInfo(), gtrHeaderInfo.getIndex("NODECOLOR"));
            } else {
                TreeColorer.colorUsingLeaf(leftTreeDrawer.getRootNode(), tvmodel.getGeneHeaderInfo(), tvmodel.getGeneHeaderInfo().getIndex("FGCOLOR"));
            }
            gtrview.setEnabled(true);
        } catch (DendroException e) {
            throw new RuntimeException("Had problem setting up the gene tree: " + e.getMessage());
        // LogPanel.println("Had problem setting up the gene tree : " + e.getMessage());
        // e.printStackTrace();
        /*
				Box mismatch = new Box(BoxLayout.Y_AXIS); mismatch.add(new JLabel(e.getMessage()));
				mismatch.add(new JLabel("Perhaps there is a mismatch between your GTR and CDT files?"));
				mismatch.add(new JLabel("Ditching Gene Tree, since it's lame."));
				JOptionPane.showMessageDialog(viewFrame, mismatch, "Tree Construction Error", JOptionPane.ERROR_MESSAGE);
				gtrview.setEnabled(false);
				try{leftTreeDrawer.setData(null, null);} catch (DendroException ex) {}
				*/
        }
    } else {
        gtrview.setEnabled(false);
        try {
            leftTreeDrawer.setData(null, null);
        } catch (DendroException ex) {
        }
    }
    leftTreeDrawer.notifyObservers();
}
Also used : HeaderInfo(edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo) DataModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.DataModel) ReorderedDataModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.ReorderedDataModel)

Example 7 with HeaderInfo

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo 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 8 with HeaderInfo

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo in project clusterMaker2 by RBVI.

the class ATRView method getStatus.

// method from ModelView
/**
 *  Gets the status attribute of the ATRView object The status is some information
 *  which the user might find useful.
 *
 * @return    The status value
 */
public String[] getStatus() {
    String[] status;
    if (selectedNode != null) {
        if (selectedNode.isLeaf()) {
            status = new String[2];
            status[0] = "Leaf Node " + selectedNode.getId();
            status[1] = "Pos " + selectedNode.getCorr();
        } else {
            int[] nameIndex = getHeaderSummary().getIncluded();
            status = new String[nameIndex.length * 2];
            HeaderInfo atrInfo = getViewFrame().getDataModel().getAtrHeaderInfo();
            String[] names = atrInfo.getNames();
            for (int i = 0; i < nameIndex.length; i++) {
                status[2 * i] = names[nameIndex[i]] + ":";
                status[2 * i + 1] = " " + atrInfo.getHeader(atrInfo.getHeaderIndex(selectedNode.getId()))[nameIndex[i]];
            }
        }
    } else {
        status = new String[2];
        status[0] = "Select Node to ";
        status[1] = "view annotation.";
    }
    return status;
}
Also used : HeaderInfo(edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo)

Example 9 with HeaderInfo

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo in project clusterMaker2 by RBVI.

the class ATRZoomView method getStatus.

/**
 *  Gets some user-interpretatble status information for the ATRZoomView object
 *
 * @return    Text describing selected node correlation
 */
public String[] getStatus() {
    String[] status;
    if (selectedNode != null) {
        int[] nameIndex = getHeaderSummary().getIncluded();
        status = new String[nameIndex.length * 2];
        HeaderInfo atrInfo = getViewFrame().getDataModel().getAtrHeaderInfo();
        String[] names = atrInfo.getNames();
        for (int i = 0; i < nameIndex.length; i++) {
            status[2 * i] = names[nameIndex[i]] + ":";
            int index = atrInfo.getHeaderIndex(selectedNode.getId());
            if (index >= 0)
                status[2 * i + 1] = " " + atrInfo.getHeader(atrInfo.getHeaderIndex(selectedNode.getId()))[nameIndex[i]];
            else
                status[2 * i + 1] = " ";
        }
    } else {
        status = new String[2];
        status[0] = "Select Node to ";
        status[1] = "view annotation.";
    }
    return status;
}
Also used : HeaderInfo(edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo)

Example 10 with HeaderInfo

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo in project clusterMaker2 by RBVI.

the class TreeDrawer method setBranchHeightsIter.

public void setBranchHeightsIter(HeaderInfo nodeInfo, int nameIndex, int type, TreeDrawerNode start) {
    Stack remaining = new Stack();
    remaining.push(start);
    while (remaining.empty() == false) {
        TreeDrawerNode current = (TreeDrawerNode) remaining.pop();
        if (current.isLeaf()) {
        // will get handled in a linear-time routine...
        } else {
            int j = nodeInfo.getHeaderIndex(current.getId());
            Double d = new Double(nodeInfo.getHeader(j)[nameIndex]);
            double corr = d.doubleValue();
            if (type == CORRELATION) {
                // Account for a litle arithmetic fudge
                if (corr > 1.0)
                    corr = 1.0;
                else if (corr < -1.0)
                    corr = -1.0;
                // if ((corr  < -1.0) || (corr > 1.0)) {
                // System.out.println("Got illegal correlation " + corr + " at line "+j);
                // }
                current.setCorr(corr);
            } else {
                current.setCorr(corr);
            }
            remaining.push(current.getLeft());
            remaining.push(current.getRight());
        }
    }
}
Also used : TreeDrawerNode(edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode)

Aggregations

HeaderInfo (edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo)12 CyNode (org.cytoscape.model.CyNode)6 CyEdge (org.cytoscape.model.CyEdge)4 TreeDrawerNode (edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode)3 HashMap (java.util.HashMap)2 CyEventHelper (org.cytoscape.event.CyEventHelper)2 CyNetwork (org.cytoscape.model.CyNetwork)2 CyNetworkView (org.cytoscape.view.model.CyNetworkView)2 ClusterManager (edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterManager)1 DataModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.DataModel)1 LoadException (edu.ucsf.rbvi.clusterMaker2.internal.treeview.LoadException)1 ModelessSettingsDialog (edu.ucsf.rbvi.clusterMaker2.internal.treeview.ModelessSettingsDialog)1 AtrTVModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.AtrTVModel)1 DataModelWriter (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.DataModelWriter)1 ReorderedDataModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.ReorderedDataModel)1 TVModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.TVModel)1 TreeViewModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.TreeViewModel)1 NetworkColorDialog (edu.ucsf.rbvi.clusterMaker2.internal.ui.NetworkColorDialog)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1