Exemple #1
0
def comp_to_meta_node(meta_graph, c_id, go_id, c_name, out_comp, do_layout=True, n2xy=None):
    root = meta_graph.getRoot()
    ns = [n for n in meta_graph.getNodes() if root[COMPARTMENT_ID][n] == c_id]
    if not ns:
        return None
    comp_n = meta_graph.createMetaNode(ns, False)
    comp_graph = root[VIEW_META_GRAPH][comp_n]
    if do_layout:
        if n2xy:
            apply_node_coordinates(comp_graph, n2xy)
        else:
            layout(comp_graph)
    root[NAME][comp_n] = c_name
    root[COMPARTMENT_ID][comp_n] = out_comp
    root[TYPE][comp_n] = TYPE_COMPARTMENT
    root[VIEW_SHAPE][comp_n] = COMPARTMENT_SHAPE
    root[ID][comp_n] = c_id
    root[TERM][comp_n] = go_id
    root[VIEW_SIZE][comp_n] = get_n_size(meta_graph, comp_n)
    for meta_e in root.getInOutEdges(comp_n):
        sample_e = next((ee for ee in root[VIEW_META_GRAPH][meta_e] if not root[UBIQUITOUS][ee]),
                        next(iter(root[VIEW_META_GRAPH][meta_e])))
        root[UBIQUITOUS][meta_e] = root[UBIQUITOUS][sample_e]
        root[STOICHIOMETRY][meta_e] = sum(root[STOICHIOMETRY][ee] for ee in root[VIEW_META_GRAPH][meta_e])
        # todo: this is not True but will help with cycle detection
        root[REVERSIBLE][meta_e] = root[REVERSIBLE][sample_e] and not root[UBIQUITOUS][sample_e]
    return comp_n
def process_compartments(c_id2info, meta_graph, n2xy=None):
    # root = meta_graph.getRoot()
    factor_nodes(meta_graph)

    current_zoom_level = max({info[2][0] for info in c_id2info.values()})
    while current_zoom_level >= 0:
        for c_id in c_id2info.keys():
            (name, go, (l, out_c_id)) = c_id2info[c_id]
            if current_zoom_level == l:
                # ns = [n for n in meta_graph.getNodes() if root[COMPARTMENT_ID][n] == c_id]
                # factor_nodes(meta_graph, ns)
                comp_to_meta_node(meta_graph, c_id, go, name, out_c_id, True, n2xy)
        current_zoom_level -= 1
        if n2xy:
            apply_node_coordinates(meta_graph, n2xy)
        else:
            layout(meta_graph)
def process_compartments(c_id2info, meta_graph, n2xy=None):
    # root = meta_graph.getRoot()
    factor_nodes(meta_graph)

    current_zoom_level = max({info[2][0] for info in c_id2info.values()})
    while current_zoom_level >= 0:
        for c_id in c_id2info.keys():
            (name, go, (l, out_c_id)) = c_id2info[c_id]
            if current_zoom_level == l:
                # ns = [n for n in meta_graph.getNodes() if root[COMPARTMENT_ID][n] == c_id]
                # factor_nodes(meta_graph, ns)
                comp_to_meta_node(meta_graph, c_id, go, name, out_c_id, True,
                                  n2xy)
        current_zoom_level -= 1
        if n2xy:
            apply_node_coordinates(meta_graph, n2xy)
        else:
            layout(meta_graph)