Get the top hubs in the graph by BEL.

    :param pybel.BELGraph graph: A BEL graph
    :param n: The number of top hubs to return. If None, returns all nodes
335080
def get_top_hubs(graph, *, n: Optional[int] = 15) -> List[Tuple[BaseEntity, int]]:
    
    return Counter(dict(graph.degree())).most_common(n=n)
1261728
def inc_edges(self, node):
        
        try:
            return list(self.nodes[node][0])
        except KeyError:
            raise GraphError('Invalid node %s' % node)

        return None
1296383
def get_nodes_by_namespace(graph: BELGraph, namespaces: Strings) -> Set[BaseEntity]:
    """"""
    return get_nodes(graph, namespace_inclusion_builder(namespaces))
257946
def full_subgraph(self, vertices):
        
        obj_map = {vertex.id: vertex for vertex in vertices}
        edges = [
            edge for vertex_id in obj_map
            for edge in self._out_edges[vertex_id]
            if edge.head in obj_map
        ]

        return AnnotatedGraph(
            vertices=obj_map.values(),
            edges=edges,
        )
106151
def _bfs_subgraph(self, start_id, forward=True):
        
        if forward:
            get_bfs  = self.forw_bfs
            get_nbrs = self.out_nbrs
        else:
            get_bfs  = self.back_bfs
            get_nbrs = self.inc_nbrs

        g = Graph()
        bfs_list = get_bfs(start_id)
        for node in bfs_list:
            g.add_node(node)

        for node in bfs_list:
            for nbr_id in get_nbrs(node):
                g.add_edge(node, nbr_id)

        return g
1145869
def get_downstream_causal_subgraph(graph, nbunch: Union[BaseEntity, Iterable[BaseEntity]]):
    
    return get_subgraph_by_edge_filter(graph, build_downstream_edge_predicate(nbunch))
658439
def get_all_edge_nodes(self):
        """"""
        edge_nodes = set(e for es in self.edges for e in es)
        for edges in self.edges_rel.values():
            rel_nodes = set(e for es in edges for e in es)
            edge_nodes.update(rel_nodes)
        return edge_nodes
665417
def get_top_level_links(self, data, many):
        """"""
        self_link = None

        if many:
            if self.opts.self_url_many:
                self_link = self.generate_url(self.opts.self_url_many)
        else:
            if self.opts.self_url:
                self_link = data.get('links', {}).get('self', None)

        return {'self': self_link}
364136
def get_neighborhood_network(self, node_name: str, order: int = 1) -> Graph:
        
        logger.info("In get_neighborhood_graph()")
        neighbors = list(self.get_neighbor_names(node_name, order))
        neighbor_network = self.graph.copy()
        neighbor_network.delete_vertices(self.graph.vs.select(name_notin=neighbors))
        return neighbor_network
858547
def breadth_first_vertex_order(vertices_resources, nets):
    
    # Special case: no vertices, just stop immediately
    if len(vertices_resources) == 0:
        return

    # Enumerate the set of nets attached to each vertex
    vertex_neighbours = defaultdict(set)
    for net in nets:
        # Note: Iterating over a Net object produces the set of vertices
        # involved in the net.
        vertex_neighbours[net.source].update(net)
        for sink in net.sinks:
            vertex_neighbours[sink].update(net)

    # Perform a breadth-first iteration over the vertices.
    unplaced_vertices = set(vertices_resources)
    vertex_queue = deque()
    while vertex_queue or unplaced_vertices:
        if not vertex_queue:
            vertex_queue.append(unplaced_vertices.pop())
        vertex = vertex_queue.popleft()

        yield vertex

        vertex_queue.extend(v for v in vertex_neighbours[vertex]
                            if v in unplaced_vertices)
        unplaced_vertices.difference_update(vertex_neighbours[vertex])
111506
def get_nodes(self):
        

        return [node for node in foundations.walkers.nodes_walker(self.model().root_node)]
398050
def network(n):
    
    tpm(n.tpm)
    connectivity_matrix(n.cm)
    if n.cm.shape[0] != n.size:
        raise ValueError("Connectivity matrix must be NxN, where N is the "
                         "number of nodes in the network.")
    return True
692745
def get_graph_by_name_version(self, name: str, version: str) -> Optional[BELGraph]:
        """"""
        network = self.get_network_by_name_version(name, version)

        if network is None:
            return

        return network.as_bel()
759443
def nodes(self, type=None, failed=False, participant_id=None):
        
        if type is None:
            type = Node

        if not issubclass(type, Node):
            raise TypeError("{} is not a valid node type.".format(type))

        if failed not in ["all", False, True]:
            raise ValueError("{} is not a valid node failed".format(failed))

        if participant_id is not None:
            if failed == "all":
                return type.query.filter_by(
                    network_id=self.id, participant_id=participant_id
                ).all()
            else:
                return type.query.filter_by(
                    network_id=self.id, participant_id=participant_id, failed=failed
                ).all()
        else:
            if failed == "all":
                return type.query.filter_by(network_id=self.id).all()
            else:
                return type.query.filter_by(failed=failed, network_id=self.id).all()
1154052
def get_upstream_causal_subgraph(graph, nbunch: Union[BaseEntity, Iterable[BaseEntity]]):
    
    return get_subgraph_by_edge_filter(graph, build_upstream_edge_predicate(nbunch))
694214
def graph_nodes_sorted(self):
        
        return sorted(self._graph.nodes(), key=lambda _: repr(_))
1032150
def get_root_graph(self,root):
      """"""
      children = self.get_children(root)
      g = Graph()
      nodes = [root]+children
      for node in nodes: g.add_node(node)
      node_ids = [x.id for x in nodes]
      edges = [x for x in self._edges.values() if x.node1.id in node_ids and x.node2.id in node_ids]
      for e in edges: g.add_edge(e)
      return g