Search in sources :

Example 1 with DataModel

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

the class HeatMapView method startup.

protected void startup() {
    CyProperty cyProperty = manager.getService(CyProperty.class, "(cyPropertyName=cytoscape3.props)");
    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 (nodeAttributeList != null && nodeAttributeList.size() < 2) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least two node columns for cluster weighting");
        return;
    }
    String[] nodeArray;
    // Handle selected only
    if (!context.selectedOnly) {
        nodeArray = new String[myNetwork.getNodeCount()];
        int index = 0;
        for (CyNode node : myNetwork.getNodeList()) {
            nodeArray[index++] = ModelUtils.getName(myNetwork, node);
        }
    } else {
        if (edgeAttribute != null && edgeAttribute.length() > 0) {
            List<CyEdge> selectedEdges = CyTableUtil.getEdgesInState(myNetwork, CyNetwork.SELECTED, true);
            Set<CyNode> nodesSeen = new HashSet<CyNode>();
            for (CyEdge edge : selectedEdges) {
                nodesSeen.add(edge.getSource());
                nodesSeen.add(edge.getTarget());
            }
            int index = 0;
            nodeArray = new String[nodesSeen.size()];
            for (CyNode node : nodesSeen) nodeArray[index++] = ModelUtils.getName(myNetwork, node);
        } else {
            List<CyNode> selectedNodes = CyTableUtil.getNodesInState(myNetwork, CyNetwork.SELECTED, true);
            nodeArray = new String[selectedNodes.size()];
            int index = 0;
            for (CyNode node : selectedNodes) {
                nodeArray[index++] = ModelUtils.getName(myNetwork, node);
            }
        }
    }
    Arrays.sort(nodeArray);
    ModelUtils.createAndSetLocal(myNetwork, myNetwork, ClusterManager.NODE_ORDER_ATTRIBUTE, Arrays.asList(nodeArray), List.class, String.class);
    // Edge attribute?
    if (edgeAttribute != null && edgeAttribute.length() > 0) {
        ModelUtils.createAndSetLocal(myNetwork, myNetwork, ClusterManager.ARRAY_ORDER_ATTRIBUTE, Arrays.asList(nodeArray), List.class, String.class);
        ModelUtils.createAndSetLocal(myNetwork, myNetwork, ClusterManager.CLUSTER_EDGE_ATTRIBUTE, "edge." + edgeAttribute, String.class, null);
    } else {
        int index = 0;
        Collections.sort(nodeAttributeList);
        ModelUtils.createAndSetLocal(myNetwork, myNetwork, ClusterManager.ARRAY_ORDER_ATTRIBUTE, nodeAttributeList, List.class, String.class);
    }
    // Get our data model
    dataModel = new TreeViewModel(monitor, myNetwork, myView, manager);
    // Set up the global config
    setConfigDefaults(new PropertyConfig(cyProperty, globalConfigName(), "ProgramConfig"));
    // Set up our configuration
    PropertyConfig documentConfig = new PropertyConfig(cyProperty, getShortName(), "DocumentConfig");
    dataModel.setDocumentConfig(documentConfig);
    // Create our view frame
    TreeViewFrame frame = new TreeViewFrame(this, appName);
    // Set the data model
    frame.setDataModel(dataModel);
    frame.setLoaded(true);
    frame.addWindowListener(this);
    frame.setVisible(true);
    geneSelection = frame.getGeneSelection();
    geneSelection.addObserver(this);
    arraySelection = frame.getArraySelection();
    arraySelection.addObserver(this);
    manager.registerService(this, RowsSetListener.class, new Properties());
}
Also used : Properties(java.util.Properties) CyEdge(org.cytoscape.model.CyEdge) CyProperty(org.cytoscape.property.CyProperty) TreeViewFrame(edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeViewFrame) PropertyConfig(edu.ucsf.rbvi.clusterMaker2.internal.treeview.PropertyConfig) CyNode(org.cytoscape.model.CyNode) TreeViewModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.TreeViewModel) HashSet(java.util.HashSet)

Example 2 with DataModel

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

the class KnnView method startup.

protected void startup() {
    CyProperty cyProperty = manager.getService(CyProperty.class, "(cyPropertyName=cytoscape3.props)");
    // Get our data model
    dataModel = new KnnViewModel(monitor, myNetwork, myView, manager);
    // Set up the global config
    setConfigDefaults(new PropertyConfig(cyProperty, globalConfigName(), "ProgramConfig"));
    // Set up our configuration
    PropertyConfig documentConfig = new PropertyConfig(cyProperty, getShortName(), "DocumentConfig");
    dataModel.setDocumentConfig(documentConfig);
    // Create our view frame
    KnnViewFrame frame = new KnnViewFrame(this, appName);
    // Set the data model
    frame.setDataModel(dataModel);
    frame.setLoaded(true);
    frame.addWindowListener(this);
    frame.setVisible(true);
    geneSelection = frame.getGeneSelection();
    geneSelection.addObserver(this);
    arraySelection = frame.getArraySelection();
    arraySelection.addObserver(this);
    manager.registerService(this, RowsSetListener.class, new Properties());
}
Also used : KnnViewFrame(edu.ucsf.rbvi.clusterMaker2.internal.treeview.KnnViewFrame) CyProperty(org.cytoscape.property.CyProperty) KnnViewModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.KnnViewModel) PropertyConfig(edu.ucsf.rbvi.clusterMaker2.internal.treeview.PropertyConfig) Properties(java.util.Properties)

Example 3 with DataModel

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

the class BiclusterView method startup.

protected void startup() {
    CyProperty cyProperty = manager.getService(CyProperty.class, "(cyPropertyName=cytoscape3.props)");
    /*
		Map<Integer, List<String>> clusterNodes = getBiclusterNodes();
		Map<Integer, List<String>> clusterAttrs = getBiclusterAttributes();
		
		
		ArrayList<String> nodeArrayL = new ArrayList<String>();
		for(Integer key:clusterNodes.keySet()){
			List<String> bicluster =  clusterNodes.get(key);
			for(String node:bicluster){
				nodeArrayL.add(node);
			}			
		}
		
		// ModelUtils.createAndSetLocal(myNetwork, myNetwork, ClusterManager.NODE_ORDER_ATTRIBUTE, 
    //             nodeArrayL, List.class, String.class);
		
		ArrayList<String> attrArrayL = new ArrayList<String>();
		for(Integer key:clusterAttrs.keySet()){
			List<String> bicluster =  clusterAttrs.get(key);
			for(String attr:bicluster){
				attrArrayL.add(attr);
			}			
		}
		// ModelUtils.createAndSetLocal(myNetwork, myNetwork, ClusterManager.ARRAY_ORDER_ATTRIBUTE, 
		// 		attrArrayL, List.class, String.class);
		*/
    /*
		//Using the overlapping and reordering for node and array order attributes
		mergeBiclusters(clusterNodes,clusterAttrs);
		ModelUtils.createAndSetLocal(myNetwork, myNetwork, ClusterManager.NODE_ORDER_ATTRIBUTE, 
                rowList, List.class, String.class);
		ModelUtils.createAndSetLocal(myNetwork, myNetwork, ClusterManager.ARRAY_ORDER_ATTRIBUTE, 
				colList, List.class, String.class);
		*/
    // Get our data model
    // FIXME: Can't use the KnnViewModel because it's going to
    // fill in all of the data for each cell and we only want to
    // fill in the data for the cells within the bicluster
    dataModel = new KnnViewModel(monitor, myNetwork, myView, manager);
    // Set up the global config
    setConfigDefaults(new PropertyConfig(cyProperty, globalConfigName(), "ProgramConfig"));
    // Set up our configuration
    PropertyConfig documentConfig = new PropertyConfig(cyProperty, getShortName(), "DocumentConfig");
    dataModel.setDocumentConfig(documentConfig);
    // Create our view frame
    KnnViewFrame frame = new KnnViewFrame(this, appName);
    // Set the data model
    frame.setDataModel(dataModel);
    frame.setLoaded(true);
    frame.addWindowListener(this);
    frame.setVisible(true);
    geneSelection = frame.getGeneSelection();
    geneSelection.addObserver(this);
    arraySelection = frame.getArraySelection();
    arraySelection.addObserver(this);
    manager.registerService(this, RowsSetListener.class, new Properties());
}
Also used : KnnViewFrame(edu.ucsf.rbvi.clusterMaker2.internal.treeview.KnnViewFrame) CyProperty(org.cytoscape.property.CyProperty) KnnViewModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.KnnViewModel) PropertyConfig(edu.ucsf.rbvi.clusterMaker2.internal.treeview.PropertyConfig) Properties(java.util.Properties)

Example 4 with DataModel

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

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.DataModel 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)

Aggregations

PropertyConfig (edu.ucsf.rbvi.clusterMaker2.internal.treeview.PropertyConfig)4 Properties (java.util.Properties)4 CyProperty (org.cytoscape.property.CyProperty)4 TreeViewModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.TreeViewModel)3 DataModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.DataModel)2 HeaderInfo (edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo)2 KnnViewFrame (edu.ucsf.rbvi.clusterMaker2.internal.treeview.KnnViewFrame)2 TreeViewFrame (edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeViewFrame)2 KnnViewModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.KnnViewModel)2 ReorderedDataModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.ReorderedDataModel)2 ClusterManager (edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterManager)1 DataMatrix (edu.ucsf.rbvi.clusterMaker2.internal.treeview.DataMatrix)1 LoadException (edu.ucsf.rbvi.clusterMaker2.internal.treeview.LoadException)1 MessagePanel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.MessagePanel)1 ModelessSettingsDialog (edu.ucsf.rbvi.clusterMaker2.internal.treeview.ModelessSettingsDialog)1 DataModelWriter (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.DataModelWriter)1 NetworkColorDialog (edu.ucsf.rbvi.clusterMaker2.internal.ui.NetworkColorDialog)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1