Create BEL Edges from BEL Statement
779376
def edges(ctx, statement, rules, species, namespace_targets, version, api, config_fn):
    """"""

    if config_fn:
        config = bel.db.Config.merge_config(ctx.config, override_config_fn=config_fn)
    else:
        config = ctx.config

    # Configuration - will return the first truthy result in list else the default option
    if namespace_targets:
        namespace_targets = json.loads(namespace_targets)
    if rules:
        rules = rules.replace(" ", "").split(",")

    namespace_targets = utils.first_true(
        [namespace_targets, config["bel"]["lang"].get("canonical")], None
    )
    api_url = utils.first_true(
        [api, config["bel_api"]["servers"].get("api_url", None)], None
    )
    version = utils.first_true(
        [version, config["bel"]["lang"].get("default_bel_version", None)], None
    )

    print("------------------------------")
    print("BEL version: {}".format(version))
    print("API Endpoint: {}".format(api))
    print("------------------------------")

    bo = BEL(version=version, endpoint=api_url)
    if species:
        edges = (
            bo.parse(statement)
            .orthologize(species)
            .canonicalize(namespace_targets=namespace_targets)
            .compute_edges(rules=rules)
        )
    else:
        edges = (
            bo.parse(statement)
            .canonicalize(namespace_targets=namespace_targets)
            .compute_edges(rules=rules)
        )

    if edges is None:
        print(bo.original_bel_stmt)
        print(bo.parse_visualize_error)
        print(bo.validation_messages)
    else:
        print(json.dumps(edges, indent=4))

        if bo.validation_messages:
            print(bo.validation_messages)
        else:
            print("No problems found")
    return
707088
def _make_graph(self, max_insert):
        ''''''
        if len(self.partial_links) != 0:
            raise Error('Error in _make_graph(). Cannot continue because there are partial links')
        
        self.contig_links = {}
        for key in self.links:
            for l in self.links[key]:
                insert_size = l.insert_size()
                if insert_size <= max_insert:
                    if key not in self.contig_links:
                        self.contig_links[key] = {}
                    dirs = ''.join(l.dirs)
                    self.contig_links[key][dirs] = self.contig_links[key].get(dirs, 0) + 1
1231199
def add_edge(self, u, v, key=None, attr_dict=None, **attr):
        """"""
        if attr_dict is None:
            attr_dict = attr
        else:
            try:
                attr_dict.update(attr)
            except AttributeError:
                raise NetworkXError(
                    "The attr_dict argument must be a dictionary."
                )
        if u not in self.node:
            self.node[u] = {}
        if v not in self.node:
            self.node[v] = {}
        if v in self.succ[u]:
            keydict = self.adj[u][v]
            if key is None:
                key = len(keydict)
                while key in keydict:
                    key += 1
            datadict = keydict.get(key, {})
            datadict.update(attr_dict)
            keydict[key] = datadict
        else:
            if key is None:
                key = 0
            datadict = {}
            datadict.update(attr_dict)
            keydict = {key: datadict}
            self.succ[u][v] = keydict
        return key
1300220
def happy_edges(row, prefix=None):
    
    trans = maketrans("[](){}", "      ")
    row = row.strip().strip("+")
    row = row.translate(trans)
    scfs = [x.strip("+") for x in row.split(":")]
    for a, b in pairwise(scfs):
        oa = '<' if a.strip()[0] == '-' else '>'
        ob = '<' if b.strip()[0] == '-' else '>'

        is_uncertain = a[-1] == ' ' or b[0] == ' '

        a = a.strip().strip('-')
        b = b.strip().strip('-')

        if prefix:
            a = prefix + a
            b = prefix + b

        yield (a, b, oa, ob), is_uncertain
99222
def from_edges(edges):
        
        dag = DirectedGraph()
        for _u, _v in edges:
            dag.add_edge(_u, _v)
        return dag
593328
function edge(a, b) {
  if (a.row > b.row) { var t = a; a = b; b = t; }
  return {
    x0: a.column,
    y0: a.row,
    x1: b.column,
    y1: b.row,
    dx: b.column - a.column,
    dy: b.row - a.row
  };
}
871825
def frombools(cls, bools):
        """"""
        return cls.frombitsets(map(cls.BitSet.frombools, bools))
1261507
def filter_edges(graph: BELGraph, edge_predicates: EdgePredicates) -> EdgeIterator:
    
    compound_edge_predicate = and_edge_predicates(edge_predicates=edge_predicates)
    for u, v, k in graph.edges(keys=True):
        if compound_edge_predicate(graph, u, v, k):
            yield u, v, k
1358125
def edgesFromBoolImg(arr, dtype=None):
    '''
    
    '''
    out = np.zeros_like(arr, dtype=dtype)
    _calc(arr, out)
    _calc(arr.T, out.T)
    return out
128830
function line(l) {
    l
      .attr("x1",function(d){
        return d[vars.edges.source].d3plus.edges[d[vars.edges.target][vars.id.value]].x;
      })
      .attr("y1",function(d){
        return d[vars.edges.source].d3plus.edges[d[vars.edges.target][vars.id.value]].y;
      })
      .attr("x2",function(d){
        return d[vars.edges.target].d3plus.edges[d[vars.edges.source][vars.id.value]].x;
      })
      .attr("y2",function(d){
        return d[vars.edges.target].d3plus.edges[d[vars.edges.source][vars.id.value]].y;
      });
  }
897463
def edge_just(left, right, width, fillchar=' ', min_padding_length=1):
    
    assert unicode_width(fillchar) == 1, 'fillchar must be single-width char'
    padding = fillchar * max(min_padding_length, width - unicode_width(left + right))
    return left + padding + right
53948
def from_pickle(path: Union[str, BinaryIO], check_version: bool = True) -> BELGraph:
    
    graph = nx.read_gpickle(path)

    raise_for_not_bel(graph)
    if check_version:
        raise_for_old_graph(graph)

    return graph
1173617
def edges_dump(self):
        """"""
        self._flush_edges()
        for (
                graph, orig, dest, idx, branch, turn, tick, extant
        ) in self.sql('edges_dump'):
            yield (
                self.unpack(graph),
                self.unpack(orig),
                self.unpack(dest),
                idx,
                branch,
                turn,
                tick,
                bool(extant)
            )
752898
def split_bel_stmt(stmt: str, line_num) -> tuple:
    """"""

    m = re.match(f"^(.*?\))\s+([a-zA-Z=\->\|:]+)\s+([\w(]+.*?)$", stmt, flags=0)
    if m:
        return (m.group(1), m.group(2), m.group(3))
    else:
        log.info(
            f"Could not parse bel statement into components at line number: {line_num} assertion: {stmt}"
        )
        return (stmt, None, None)
70865
def _init_filled_edges(self, renderer, properties, edge_mapping):
        ""
        glyph_model = Patches if self.filled else Bezier
        allowed_properties = glyph_model.properties()
        for glyph_type in ('', 'selection_', 'nonselection_', 'hover_', 'muted_'):
            glyph = getattr(renderer.edge_renderer, glyph_type+'glyph', None)
            if glyph is None:
                continue
            group_properties = dict(properties)
            props = self._process_properties(self.edge_glyph, group_properties, {})
            filtered = self._filter_properties(props, glyph_type, allowed_properties)
            new_glyph = glyph_model(**dict(filtered, **edge_mapping))
            setattr(renderer.edge_renderer, glyph_type+'glyph', new_glyph)
626886
def to_bel_lines(graph) -> Iterable[str]:
    
    return itt.chain(
        _to_bel_lines_header(graph),
        _to_bel_lines_body(graph),
        _to_bel_lines_footer(graph),
    )
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)