(self, name=None, directed=False, keep_canonical_names=False)
return Graph(
            n,
            edge_list,
            directed=directed,
            graph_attrs=graph_attrs,
            vertex_attrs=vertex_attrs,
            edge_attrs=edge_attrs,
        )
Fetches the network with the given name from Cytoscape.

        When fetching networks from Cytoscape, the C{canonicalName} attributes
        of vertices and edges are not converted by default. Use the
        C{keep_canonical_names} parameter to retrieve these attributes as well.

        @param name: the name of the network in Cytoscape.
        @param directed: whether the network is directed.
        @param keep_canonical_names: whether to keep the C{canonicalName}
            vertex/edge attributes that are added automatically by Cytoscape
        @return: an appropriately constructed igraph L{Graph}.
Fetches the network with the given name from Cytoscape.
Fetches the network with the given name from Cytoscape .
def fetch(self, name=None, directed=False, keep_canonical_names=False):
        """Fetches the network with the given name from Cytoscape.

        When fetching networks from Cytoscape, the C{canonicalName} attributes
        of vertices and edges are not converted by default. Use the
        C{keep_canonical_names} parameter to retrieve these attributes as well.

        @param name: the name of the network in Cytoscape.
        @param directed: whether the network is directed.
        @param keep_canonical_names: whether to keep the C{canonicalName}
            vertex/edge attributes that are added automatically by Cytoscape
        @return: an appropriately constructed igraph L{Graph}."""
        from igraph import Graph

        cy = self.service

        # Check the version number. Anything older than 1.3 is bad.
        version = cy.version()
        if " " in version:
            version = version.split(" ")[0]
        version = tuple(map(int, version.split(".")[:2]))
        if version < (1, 3):
            raise NotImplementedError(
                "CytoscapeGraphDrawer requires " "Cytoscape-RPC 1.3 or newer"
            )

        # Find out the ID of the network we are interested in
        if name is None:
            network_id = cy.getNetworkID()
        else:
            network_id = [k for k, v in cy.getNetworkList().items() if v == name]
            if not network_id:
                raise ValueError("no such network: %r" % name)
            elif len(network_id) > 1:
                raise ValueError("more than one network exists with name: %r" % name)
            network_id = network_id[0]

        # Fetch the list of all the nodes and edges
        vertices = cy.getNodes(network_id)
        edges = cy.getEdges(network_id)
        n, m = len(vertices), len(edges)

        # Fetch the graph attributes
        graph_attrs = cy.getNetworkAttributes(network_id)

        # Fetch the vertex attributes
        vertex_attr_names = cy.getNodeAttributeNames()
        vertex_attrs = {}
        for attr_name in vertex_attr_names:
            if attr_name == "canonicalName" and not keep_canonical_names:
                continue
            has_attr = cy.nodesHaveAttribute(attr_name, vertices)
            filtered = [idx for idx, ok in enumerate(has_attr) if ok]
            values = cy.getNodesAttributes(
                attr_name, [name for name, ok in zip(vertices, has_attr) if ok]
            )
            attrs = [None] * n
            for idx, value in zip(filtered, values):
                attrs[idx] = value
            vertex_attrs[attr_name] = attrs

        # Fetch the edge attributes
        edge_attr_names = cy.getEdgeAttributeNames()
        edge_attrs = {}
        for attr_name in edge_attr_names:
            if attr_name == "canonicalName" and not keep_canonical_names:
                continue
            has_attr = cy.edgesHaveAttribute(attr_name, edges)
            filtered = [idx for idx, ok in enumerate(has_attr) if ok]
            values = cy.getEdgesAttributes(
                attr_name, [name for name, ok in zip(edges, has_attr) if ok]
            )
            attrs = [None] * m
            for idx, value in zip(filtered, values):
                attrs[idx] = value
            edge_attrs[attr_name] = attrs

        # Create a vertex name index
        vertex_name_index = dict((v, k) for k, v in enumerate(vertices))
        del vertices

        # Remap the edges list to numeric IDs
        edge_list = []
        for edge in edges:
            parts = edge.split()
            edge_list.append((vertex_name_index[parts[0]], vertex_name_index[parts[2]]))
        del edges

        return Graph(
            n,
            edge_list,
            directed=directed,
            graph_attrs=graph_attrs,
            vertex_attrs=vertex_attrs,
            edge_attrs=edge_attrs,
        )
def fetch ( self , name = None , directed = False , keep_canonical_names = False ) : from igraph import Graph cy = self . service # Check the version number. Anything older than 1.3 is bad. version = cy . version ( ) if " " in version : version = version . split ( " " ) [ 0 ] version = tuple ( map ( int , version . split ( "." ) [ : 2 ] ) ) if version < ( 1 , 3 ) : raise NotImplementedError ( "CytoscapeGraphDrawer requires " "Cytoscape-RPC 1.3 or newer" ) # Find out the ID of the network we are interested in if name is None : network_id = cy . getNetworkID ( ) else : network_id = [ k for k , v in cy . getNetworkList ( ) . items ( ) if v == name ] if not network_id : raise ValueError ( "no such network: %r" % name ) elif len ( network_id ) > 1 : raise ValueError ( "more than one network exists with name: %r" % name ) network_id = network_id [ 0 ] # Fetch the list of all the nodes and edges vertices = cy . getNodes ( network_id ) edges = cy . getEdges ( network_id ) n , m = len ( vertices ) , len ( edges ) # Fetch the graph attributes graph_attrs = cy . getNetworkAttributes ( network_id ) # Fetch the vertex attributes vertex_attr_names = cy . getNodeAttributeNames ( ) vertex_attrs = { } for attr_name in vertex_attr_names : if attr_name == "canonicalName" and not keep_canonical_names : continue has_attr = cy . nodesHaveAttribute ( attr_name , vertices ) filtered = [ idx for idx , ok in enumerate ( has_attr ) if ok ] values = cy . getNodesAttributes ( attr_name , [ name for name , ok in zip ( vertices , has_attr ) if ok ] ) attrs = [ None ] * n for idx , value in zip ( filtered , values ) : attrs [ idx ] = value vertex_attrs [ attr_name ] = attrs # Fetch the edge attributes edge_attr_names = cy . getEdgeAttributeNames ( ) edge_attrs = { } for attr_name in edge_attr_names : if attr_name == "canonicalName" and not keep_canonical_names : continue has_attr = cy . edgesHaveAttribute ( attr_name , edges ) filtered = [ idx for idx , ok in enumerate ( has_attr ) if ok ] values = cy . getEdgesAttributes ( attr_name , [ name for name , ok in zip ( edges , has_attr ) if ok ] ) attrs = [ None ] * m for idx , value in zip ( filtered , values ) : attrs [ idx ] = value edge_attrs [ attr_name ] = attrs # Create a vertex name index vertex_name_index = dict ( ( v , k ) for k , v in enumerate ( vertices ) ) del vertices # Remap the edges list to numeric IDs edge_list = [ ] for edge in edges : parts = edge . split ( ) edge_list . append ( ( vertex_name_index [ parts [ 0 ] ] , vertex_name_index [ parts [ 2 ] ] ) ) del edges return Graph ( n , edge_list , directed = directed , graph_attrs = graph_attrs , vertex_attrs = vertex_attrs , edge_attrs = edge_attrs , )