Get a combine BEL Graph from a list of network identifiers.
769593
def get_graph_by_ids(self, network_ids: List[int]) -> BELGraph:
        """"""
        if len(network_ids) == 1:
            return self.get_graph_by_id(network_ids[0])

        log.debug('getting graph by identifiers: %s', network_ids)
        graphs = self.get_graphs_by_ids(network_ids)

        log.debug('getting union of graphs: %s', network_ids)
        rv = union(graphs)

        return rv
1090478
def _getMultigraphID(self, graph_name, subgraph_name=None):
        
        if self.isMultiInstance and self._instanceName is not None:
            if subgraph_name is None:
                return "%s_%s" % (graph_name, self._instanceName)
            else:
                return "%s_%s.%s_%s" % (graph_name, self._instanceName, 
                                        subgraph_name, self._instanceName)
        else:
            if subgraph_name is None:
                return graph_name
            else:
                return "%s.%s" % (graph_name, subgraph_name)
777569
def _get_annotation_entries_from_data(self, graph: BELGraph, data: EdgeData) -> Optional[List[NamespaceEntry]]:
        """"""
        annotations_dict = data.get(ANNOTATIONS)
        if annotations_dict is not None:
            return [
                entry
                for url, names in self._iter_from_annotations_dict(graph, annotations_dict=annotations_dict)
                for entry in self.get_annotation_entries_by_names(url, names)
            ]
261764
def __read_graph(self, network_filename):
        
        self.g = nx.read_edgelist(network_filename, nodetype=int)
38026
def from_jgif(graph_jgif_dict):
    
    graph = BELGraph()

    root = graph_jgif_dict['graph']

    if 'label' in root:
        graph.name = root['label']

    if 'metadata' in root:
        metadata = root['metadata']

        for key in METADATA_INSERT_KEYS:
            if key in metadata:
                graph.document[key] = metadata[key]

    parser = BELParser(graph)
    parser.bel_term.addParseAction(parser.handle_term)

    for node in root['nodes']:
        node_label = node.get('label')

        if node_label is None:
            log.warning('node missing label: %s', node)
            continue

        try:
            parser.bel_term.parseString(node_label)
        except NakedNameWarning as e:
            log.info('Naked name: %s', e)
        except ParseException:
            log.info('Parse exception for %s', node_label)

    for i, edge in enumerate(root['edges']):
        relation = edge.get('relation')
        if relation is None:
            log.warning('no relation for edge: %s', edge)

        if relation in {'actsIn', 'translocates'}:
            continue  # don't need legacy BEL format

        edge_metadata = edge.get('metadata')
        if edge_metadata is None:
            log.warning('no metadata for edge: %s', edge)
            continue

        bel_statement = edge.get('label')
        if bel_statement is None:
            log.debug('No BEL statement for edge %s', edge)

        evidences = edge_metadata.get('evidences')

        if relation in UNQUALIFIED_EDGES:
            pass  # FIXME?

        else:
            if not evidences:  # is none or is empty list
                log.debug('No evidence for edge %s', edge)
                continue

            for evidence in evidences:
                citation = evidence.get('citation')

                if not citation:
                    continue

                if 'type' not in citation or 'id' not in citation:
                    continue

                summary_text = evidence['summary_text'].strip()

                if not summary_text or summary_text == placeholder_evidence:
                    continue

                parser.control_parser.clear()
                parser.control_parser.citation = reformat_citation(citation)
                parser.control_parser.evidence = summary_text
                parser.control_parser.annotations.update(evidence[EXPERIMENT_CONTEXT])

                try:
                    parser.parseString(bel_statement, line_number=i)
                except Exception as e:
                    log.warning('JGIF relation parse error: %s for %s', e, bel_statement)

    return graph
664653
def get_graph_by_most_recent(self, name: str) -> Optional[BELGraph]:
        """"""
        network = self.get_most_recent_network_by_name(name)

        if network is None:
            return

        return network.as_bel()
1222781
def parse_identifiers_url(url):
    """"""
    url_pattern = 'http://identifiers.org/([A-Za-z]+)/([A-Za-z0-9:]+)'
    match = re.match(url_pattern, url)
    if match is not None:
        g = match.groups()
        if not len(g) == 2:
            return (None, None)
        ns_map = {'hgnc': 'HGNC', 'uniprot': 'UP', 'chebi':'CHEBI',
                  'interpro':'IP', 'pfam':'XFAM', 'fplx': 'FPLX',
                  'go': 'GO', 'mesh': 'MESH', 'pubchem.compound': 'PUBCHEM'}
        ns = g[0]
        id = g[1]
        if not ns in ns_map.keys():
            return (None, None)
        if ns == 'hgnc':
            if id.startswith('HGNC:'):
                id = id[5:]
            else:
                logger.warning('HGNC URL missing "HGNC:" prefix: %s' % url)
                return (None, None)
        indra_ns = ns_map[ns]
        return (indra_ns, id)
    return (None, None)
457277
def get_digraph(ont, relations=None, writecache=False):
    
    digraph = networkx.MultiDiGraph()
    logging.info("Getting edges (may be cached)")
    for (s,p,o) in get_edges(ont):
        p = map_legacy_pred(p)
        if relations is None or p in relations:
            digraph.add_edge(o,s,pred=p)
    logging.info("Getting labels (may be cached)")
    for (n,label) in fetchall_labels(ont):
        digraph.add_node(n, **{'label':label})
    return digraph
300036
def from_edges(edges, source_key='source', target_key='target', weight_key='weight', directed=True):
    
    raw = list(map(lambda x: [x[source_key], x[target_key], int(x[weight_key])], edges))
    g = IGraph.TupleList(raw, weights=True, directed=directed)
    g.vs['indegree'] = g.degree(mode="in")
    g.vs['outdegree'] = g.degree(mode="out")
    g.vs['label'] = g.vs['name']
    if 'group' not in g.vs.attributes():
        g.vs['group'] = labels_to_groups(g.vs['label'])
    return g
133889
def get_xref_graph(ont):
    
    g = networkx.MultiGraph()
    for (c,x) in fetchall_xrefs(ont):
        g.add_edge(c,x,source=c)
    return g
495944
def extract_descriptor(self):
        """"""
        main_chain = self.get_main_chain()
        index_in_main_chain = {}
        for index, u in enumerate(main_chain):
            index_in_main_chain[u] = index

        ret = NetworkDescriptor()
        for u in main_chain:
            for v, layer_id in self.adj_list[u]:
                if v not in index_in_main_chain:
                    continue
                layer = self.layer_list[layer_id]
                copied_layer = copy(layer)
                copied_layer.weights = None
                ret.add_layer(deepcopy(copied_layer))

        for u in index_in_main_chain:
            for v, layer_id in self.adj_list[u]:
                if v not in index_in_main_chain:
                    temp_u = u
                    temp_v = v
                    temp_layer_id = layer_id
                    skip_type = None
                    while not (temp_v in index_in_main_chain and temp_u in index_in_main_chain):
                        if is_layer(self.layer_list[temp_layer_id], "Concatenate"):
                            skip_type = NetworkDescriptor.CONCAT_CONNECT
                        if is_layer(self.layer_list[temp_layer_id], "Add"):
                            skip_type = NetworkDescriptor.ADD_CONNECT
                        temp_u = temp_v
                        temp_v, temp_layer_id = self.adj_list[temp_v][0]
                    ret.add_skip_connection(
                        index_in_main_chain[u], index_in_main_chain[temp_u], skip_type
                    )

                elif index_in_main_chain[v] - index_in_main_chain[u] != 1:
                    skip_type = None
                    if is_layer(self.layer_list[layer_id], "Concatenate"):
                        skip_type = NetworkDescriptor.CONCAT_CONNECT
                    if is_layer(self.layer_list[layer_id], "Add"):
                        skip_type = NetworkDescriptor.ADD_CONNECT
                    ret.add_skip_connection(
                        index_in_main_chain[u], index_in_main_chain[v], skip_type
                    )

        return ret
1373526
def find_biconnected_components_as_subgraphs(graph):
    """"""
    list_of_graphs = []

    list_of_components = find_biconnected_components(graph)
    for edge_list in list_of_components:
        subgraph = get_subgraph_from_edge_list(graph, edge_list)
        list_of_graphs.append(subgraph)

    return list_of_graphs
391194
def get_graph_by_id(self, network_id: int) -> BELGraph:
        """"""
        network = self.get_network_by_id(network_id)
        log.debug('converting network [id=%d] %s to bel graph', network_id, network)
        return network.as_bel()
746386
def from_json(graph_json_dict: Mapping[str, Any], check_version=True) -> BELGraph:
    """"""
    graph = node_link_graph(graph_json_dict)
    return ensure_version(graph, check_version=check_version)
1010882
def parse_networks_output(out):
    
    if not out:
        return []
    line_iter = islice(out.splitlines(), 1, None)  # Skip header
    return list(map(_network_info, line_iter))
969683
def _get_ips(networks):
    '''
    
    '''
    v4s = networks.get('v4')
    v6s = networks.get('v6')
    public_ips = []
    private_ips = []

    if v4s:
        for item in v4s:
            ip_type = item.get('type')
            ip_address = item.get('ip_address')
            if ip_type == 'public':
                public_ips.append(ip_address)
            if ip_type == 'private':
                private_ips.append(ip_address)

    if v6s:
        for item in v6s:
            ip_type = item.get('type')
            ip_address = item.get('ip_address')
            if ip_type == 'public':
                public_ips.append(ip_address)
            if ip_type == 'private':
                private_ips.append(ip_address)

    return public_ips, private_ips
174486
def _match_net(self, net):
        """"""
        if self.network:
            return match_list(self.network, net)
        else:
            return True