Search in sources :

Example 6 with CyProperty

use of org.cytoscape.property.CyProperty 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 7 with CyProperty

use of org.cytoscape.property.CyProperty 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 8 with CyProperty

use of org.cytoscape.property.CyProperty 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 9 with CyProperty

use of org.cytoscape.property.CyProperty in project cytoscape-api by cytoscape.

the class CySessionTest method checkProps.

private void checkProps(Set<CyProperty<?>> set) {
    assertNotNull(set);
    assertEquals(1, set.size());
    CyProperty<?> cyProps = set.toArray(new CyProperty[set.size()])[0];
    assertNotNull(cyProps);
    assertEquals("test", cyProps.getName());
    assertEquals(CyProperty.SavePolicy.SESSION_FILE, cyProps.getSavePolicy());
    assertTrue(Properties.class.isAssignableFrom(cyProps.getPropertyType()));
    Properties p = (Properties) cyProps.getProperties();
    assertEquals(2, p.size());
    assertEquals("value1", p.getProperty("key1"));
    assertEquals("value2", p.getProperty("key2"));
}
Also used : SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) Properties(java.util.Properties)

Example 10 with CyProperty

use of org.cytoscape.property.CyProperty in project cytoscape-impl by cytoscape.

the class CySessionManagerImpl method setCurrentSession.

@Override
public void setCurrentSession(CySession sess, final String fileName) {
    // Always remove the current session first
    if (!disposed)
        disposeCurrentSession();
    if (sess == null) {
        logger.debug("Creating empty session...");
        final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
        final Set<VisualStyle> styles = vmMgr.getAllVisualStyles();
        final Set<CyProperty<?>> props = getAllProperties();
        sess = new CySession.Builder().properties(props).visualStyles(styles).build();
    } else {
        logger.debug("Restoring the session...");
        // Save the selected networks first, so the selection state can be restored later.
        final List<CyNetwork> selectedNetworks = new ArrayList<>();
        final Set<CyNetwork> networks = sess.getNetworks();
        for (CyNetwork n : networks) {
            final Boolean selected = n.getDefaultNetworkTable().getRow(n.getSUID()).get(CyNetwork.SELECTED, Boolean.class);
            if (Boolean.TRUE.equals(selected))
                selectedNetworks.add(n);
        }
        restoreProperties(sess);
        restoreNetworks(sess);
        restoreTables(sess);
        restoreNetworkViews(sess, selectedNetworks);
        restoreNetworkSelection(sess, selectedNetworks);
        restoreVisualStyles(sess);
        restoreCurrentVisualStyle();
    }
    currentFileName = fileName;
    disposed = false;
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.fireEvent(new SessionLoadedEvent(this, sess, getCurrentSessionFileName()));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) SessionLoadedEvent(org.cytoscape.session.events.SessionLoadedEvent)

Aggregations

CyProperty (org.cytoscape.property.CyProperty)11 Properties (java.util.Properties)8 SimpleCyProperty (org.cytoscape.property.SimpleCyProperty)5 PropertyConfig (edu.ucsf.rbvi.clusterMaker2.internal.treeview.PropertyConfig)4 ArrayList (java.util.ArrayList)3 CyNetwork (org.cytoscape.model.CyNetwork)3 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)3 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)3 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 TreeViewModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.TreeViewModel)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 CyEventHelper (org.cytoscape.event.CyEventHelper)2 CyNetworkView (org.cytoscape.view.model.CyNetworkView)2 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 List (java.util.List)1