private void applySelectionToCREGNetwork(CyNetwork network, Set<String> selection) {
   Set<CyNode> nodesSet = new HashSet<CyNode>();
   for (Object node : network.nodesList()) {
     CyNode cyNode = (CyNode) node;
     String pathway =
         Attributes.node.getStringAttribute(
             cyNode.getIdentifier(), ReactionAttribute.PATHWAY.toAttributeName());
     if (pathway != null && selection.contains(pathway)) {
       nodesSet.add(cyNode);
       for (Object neighbor : network.neighborsList(cyNode)) {
         CyNode neighborNode = (CyNode) neighbor;
         nodesSet.add(neighborNode);
         if (Attributes.node.getAttribute(neighborNode.getIdentifier(), "Type").equals("Enzyme")) {
           // get the genes
           for (Object enzymeNeighbor : network.neighborsList(neighborNode)) {
             CyNode enzymeNeighborNode = (CyNode) enzymeNeighbor;
             if (Attributes.node
                 .getAttribute(enzymeNeighborNode.getIdentifier(), "Type")
                 .equals("Gene")) nodesSet.add(enzymeNeighborNode);
           }
         }
       }
     }
   }
   network.setSelectedNodeState(nodesSet, true);
   network.setSelectedEdgeState(network.getConnectingEdges(new ArrayList<CyNode>(nodesSet)), true);
 }
Пример #2
0
 private void addLinks(LinkTriple[] links) {
   CyAttributes nodeAttr = Cytoscape.getNodeAttributes();
   // CyAttributes edgeAttr = Cytoscape.getEdgeAttributes();
   Map<CyNode, Boolean> updateList = new HashMap<CyNode, Boolean>();
   CyNetwork net = Cytoscape.getCurrentNetwork();
   for (LinkTriple link : links) {
     CyNode src = Cytoscape.getCyNode(link.subj.toString());
     CyNode dst = Cytoscape.getCyNode(link.obj.toString());
     if (src == null) {
       src = net.addNode(Cytoscape.getCyNode(link.subj.toString(), true));
       if (link.subj.getType() != null)
         nodeAttr.setAttribute(src.getIdentifier(), "NodeType", link.subj.getType());
     }
     if (dst == null) {
       dst = net.addNode(Cytoscape.getCyNode(link.obj.toString(), true));
       if (link.obj.getType() != null)
         nodeAttr.setAttribute(dst.getIdentifier(), "NodeType", link.obj.getType());
     }
     CyEdge edge =
         Cytoscape.getCyEdge(
             link.subj.toString(), "link", link.obj.toString(), link.pred.toString());
     // if ( link.pred != null )
     //	edgeAttr.setAttribute(edge.getIdentifier(), "EdgeType", link.pred.toString() );
     net.addEdge(edge);
     updateList.put(src, true);
     updateList.put(dst, true);
   }
   Cytoscape.getCurrentNetworkView()
       .applyLayout(new GridNodeLayout(), updateList.keySet().toArray(new CyNode[0]), null);
   Cytoscape.getCurrentNetworkView().redrawGraph(true, true);
 }
 private SortedSet<String> getPathwaySetFromReactionNodes(CyNetwork network) {
   SortedSet<String> pathwaySet = new TreeSet<String>();
   for (Object node : network.nodesList()) {
     CyNode cyNode = (CyNode) node;
     String pathway =
         Attributes.node.getStringAttribute(
             cyNode.getIdentifier(), ReactionAttribute.PATHWAY.toAttributeName());
     if (pathway != null) {
       pathwaySet.add(pathway);
     }
   }
   return pathwaySet;
 }
Пример #4
0
    @SuppressWarnings("unchecked")
    @Override
    public void actionPerformed(ActionEvent ae) {
      String action = ae.getActionCommand();

      LinkTriple[] addNodes = null;
      if (action.equals("Fetch")) {
        addNodes = iSparql.ExploreURI(urlText.getText());
        addLinks(addNodes);
        // Cytoscape.getCurrentNetwork().addNode( Cytoscape.getCyNode( urlText.getText(), true ) );
      }
      if (action.equals("Fetch Selected")) {
        CyNetwork network = Cytoscape.getCurrentNetwork();
        Set nodeset = network.getSelectedNodes();
        java.util.List<LinkTriple> nodeList = new LinkedList<LinkTriple>();
        for (Object o : nodeset) {
          CyNode node = (CyNode) o;
          for (LinkTriple newNode : iSparql.ExploreURI(node.getIdentifier())) {
            nodeList.add(newNode);
          }
        }
        if (filterCheckbox.getState())
          addLinks(iSparql.NodeFilter(null, nodeList.toArray(new LinkTriple[0])));
        else addLinks(nodeList.toArray(new LinkTriple[0]));
      }
      if (action.equals("Find Nodes")) {
        CyAttributes nodeAttr = Cytoscape.getNodeAttributes();

        CyNetwork network = Cytoscape.getCurrentNetwork();
        Set nodeset = network.getSelectedNodes();
        java.util.List<Map<String, Object>> nodeList = new LinkedList<Map<String, Object>>();
        for (Object o : nodeset) {
          CyNode node = (CyNode) o;
          Map<String, Object> map = new HashMap<String, Object>();
          String id = node.getIdentifier();
          map.put("ID", id);
          for (String attr : nodeAttr.getAttributeNames()) {
            if (nodeAttr.hasAttribute(id, attr)) {
              System.out.println(id + " " + attr + " " + nodeAttr.getType(attr));
              if (nodeAttr.getType(attr) == CyAttributes.TYPE_STRING) {
                Object iAttr = nodeAttr.getAttribute(id, attr);
                map.put(attr, iAttr);
              }
            }
          }
          nodeList.add(map);
        }
        LinkTriple[] links = iSparql.NodeSearch(null, nodeList, "ID");
        addLinks(links);
      }
      if (action.equals("Edit Namespaces")) {
        Map<String, String> nameMap = prefs.getNameSpaces();
        Map<String, String> newMap = NameSpaceEditor.EditDialog(nameMap);
        for (String key : nameMap.keySet()) {
          prefs.removeNameSpace(key);
        }
        for (String key : newMap.keySet()) {
          prefs.addNameSpace(key, newMap.get(key));
        }
      }
    }