Ejemplo n.º 1
0
def create_nice_cx_from_server(server,
                               username=None,
                               password=None,
                               uuid=None):
    """
    Create a :py:func:`~ndex2.nice_cx_network.NiceCXNetwork` based on a network
    retrieved from NDEx, specified by its UUID.
    If the network is not public, then username and password arguments for an account on
    the server with permission to access the network must be supplied.

    :param server: the URL of the NDEx server hosting the network.
    :param username: the user name of an account with permission to access the network.
    :param password: the password of an account with permission to access the network.
    :param uuid: the UUID of the network.
    :return: NiceCXNetwork
    :rtype: :py:func:`~ndex2.nice_cx_network.NiceCXNetwork`
    """

    niceCxBuilder = NiceCXBuilder()

    if server and uuid:
        my_nicecx = NiceCXNetwork()

        # ===================
        # METADATA
        # ===================
        available_aspects = []
        md_aspect_iter = my_nicecx.get_aspect(uuid, 'metaData', server,
                                              username, password)
        if md_aspect_iter:
            for ae in (o for o in md_aspect_iter):
                available_aspects.append(ae.get('name'))
        else:
            if not username or not password:
                raise Exception(
                    'Network is not available.  Username and/or password not supplied'
                )
            else:
                raise Exception('Network not available')

        opaque_aspects = set(available_aspects).difference(known_aspects_min)

        # ====================
        # NETWORK ATTRIBUTES
        # ====================
        if 'networkAttributes' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'networkAttributes', server,
                                           username, password)
            for network_item in objects:
                niceCxBuilder._add_network_attributes_from_fragment(
                    network_item)
                #niceCxBuilder.add_network_attribute(network_item.get('n'), network_item.get('v'), network_item.get('d'))

        # ===================
        # @CONTEXT
        # ===================
        if '@context' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, '@context', server, username,
                                           password)

            niceCxBuilder.set_context(
                objects)  #nice_cx.set_namespaces(objects)
            #niceCxBuilder.set_context(objects)

        # ===================
        # NODES
        # ===================
        if 'nodes' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'nodes', server, username,
                                           password)
            for node_item in objects:
                niceCxBuilder._add_node_from_fragment(node_item)
                #niceCxBuilder.add_node(node_item.get('n'), node_item.get('r'), id=node_item.get('@id'))

        # ===================
        # EDGES
        # ===================
        if 'edges' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'edges', server, username,
                                           password)
            for edge_item in objects:
                niceCxBuilder._add_edge_from_fragment(edge_item)

                #niceCxBuilder.add_edge(source=edge_item.get('s'), target=edge_item.get('t'),
                #                       interaction=edge_item.get('i'), id=edge_item.get('@id'))

        # ===================
        # NODE ATTRIBUTES
        # ===================
        if 'nodeAttributes' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'nodeAttributes', server,
                                           username, password)
            for att in objects:
                niceCxBuilder._add_node_attribute_from_fragment(att)

                #niceCxBuilder.add_node_attribute(att.get('po'), att.get('n'), att.get('v'), type=att.get('d'))

        # ===================
        # EDGE ATTRIBUTES
        # ===================
        if 'edgeAttributes' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'edgeAttributes', server,
                                           username, password)
            for att in objects:
                niceCxBuilder._add_edge_attribute_from_fragment(att)

                #niceCxBuilder.add_edge_attribute(property_of=att.get('po'), name=att.get('n'),
                #                                 values=att.get('v'), type=att.get('d'))

        # ===================
        # CITATIONS
        # ===================
        if 'citations' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'citations', server, username,
                                           password)
            for cit in objects:
                niceCxBuilder._add_citation_from_fragment(cit)
                #my_nicecx.citations[cit.get('@id')] = cit

            #my_nicecx.add_metadata_stub('citations')

        # ===================
        # SUPPORTS
        # ===================
        if 'supports' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'supports', server, username,
                                           password)
            for sup in objects:
                niceCxBuilder._add_supports_from_fragment(sup)

                #my_nicecx.supports[sup.get('@id')] = sup

            #my_nicecx.add_metadata_stub('supports')

        # ===================
        # EDGE SUPPORTS
        # ===================
        if 'edgeSupports' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'edgeSupports', server,
                                           username, password)
            for add_this_edge_sup in objects:
                niceCxBuilder._add_edge_supports_from_fragment(
                    add_this_edge_sup)

                #for po_id in add_this_edge_sup.get('po'):
                #    my_nicecx.edgeSupports[po_id] = add_this_edge_sup.get('supports')

            #my_nicecx.add_metadata_stub('edgeSupports')

        # ===================
        # NODE CITATIONS
        # ===================
        if 'nodeCitations' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'nodeCitations', server,
                                           username, password)
            for node_cit in objects:
                niceCxBuilder._add_node_citations_from_fragment(node_cit)

                #for po_id in node_cit.get('po'):
                #    my_nicecx.nodeCitations[po_id] = node_cit.get('citations')

            #my_nicecx.add_metadata_stub('nodeCitations')

        # ===================
        # EDGE CITATIONS
        # ===================
        if 'edgeCitations' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'edgeCitations', server,
                                           username, password)
            for edge_cit in objects:
                niceCxBuilder._add_edge_citations_from_fragment(edge_cit)
                #for po_id in edge_cit.get('po'):
                #    my_nicecx.nodeCitations[po_id] = edge_cit.get('citations')

            #my_nicecx.add_metadata_stub('edgeCitations')

        # ===================
        # OPAQUE ASPECTS
        # ===================
        for oa in opaque_aspects:
            objects = my_nicecx.get_aspect(uuid, oa, server, username,
                                           password)
            niceCxBuilder.add_opaque_aspect(oa, objects)

    else:
        raise Exception('Server and uuid not specified')

    return niceCxBuilder.get_nice_cx()
Ejemplo n.º 2
0
def create_nice_cx_from_raw_cx(cx):
    """
    Create a :py:func:`~ndex2.nice_cx_network.NiceCXNetwork` from a
    as a `list` of `dict` objects in
    `CX format <https://www.home.ndexbio.org/data-model/>`__

    Example:

    .. code-block:: python

        import json
        import ndex2

        # cx_as_str is a str containing JSON in CX format above
        net_cx = ndex2.create_nice_cx_from_raw_cx(json.loads(cx_as_str))



    :param cx: CX as a `list` of `dict` objects
    :type cx: list
    :return: NiceCXNetwork
    :rtype: :py:func:`~ndex2.nice_cx_network.NiceCXNetwork`
    """
    if not cx:
        raise Exception('CX is empty')

    niceCxBuilder = NiceCXBuilder()

    # ===================
    # METADATA
    # ===================
    available_aspects = []
    for ae in (
            o
            for o in niceCxBuilder.get_frag_from_list_by_key(cx, 'metaData')):
        available_aspects.append(ae.get('name'))

    opaque_aspects = set(available_aspects).difference(known_aspects_min)

    # ====================
    # NETWORK ATTRIBUTES
    # ====================
    if 'networkAttributes' in available_aspects:
        objects = niceCxBuilder.get_frag_from_list_by_key(
            cx, 'networkAttributes')
        for network_item in objects:
            niceCxBuilder._add_network_attributes_from_fragment(network_item)

    # ===================
    # NODES
    # ===================
    if 'nodes' in available_aspects:
        objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'nodes')
        for node_item in objects:
            niceCxBuilder._add_node_from_fragment(node_item)

    # ===================
    # EDGES
    # ===================
    if 'edges' in available_aspects:
        objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'edges')
        for edge_item in objects:
            niceCxBuilder._add_edge_from_fragment(edge_item)

    # ===================
    # NODE ATTRIBUTES
    # ===================
    if 'nodeAttributes' in available_aspects:
        objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'nodeAttributes')
        for att in objects:
            niceCxBuilder._add_node_attribute_from_fragment(att)

    # ===================
    # EDGE ATTRIBUTES
    # ===================
    if 'edgeAttributes' in available_aspects:
        objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'edgeAttributes')
        for att in objects:
            niceCxBuilder._add_edge_attribute_from_fragment(att)

    # ===================
    # CITATIONS
    # ===================
    if 'citations' in available_aspects:
        objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'citations')
        for cit in objects:
            niceCxBuilder._add_citation_from_fragment(cit)

    # ===================
    # SUPPORTS
    # ===================
    if 'supports' in available_aspects:
        objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'supports')
        for sup in objects:
            niceCxBuilder._add_supports_from_fragment(sup)

    # ===================
    # EDGE SUPPORTS
    # ===================
    if 'edgeSupports' in available_aspects:
        objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'edgeSupports')
        for add_this_edge_sup in objects:
            niceCxBuilder._add_edge_supports_from_fragment(add_this_edge_sup)

    # ===================
    # NODE CITATIONS
    # ===================
    if 'nodeCitations' in available_aspects:
        objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'nodeCitations')
        for node_cit in objects:
            niceCxBuilder._add_node_citations_from_fragment(node_cit)

    # ===================
    # EDGE CITATIONS
    # ===================
    if 'edgeCitations' in available_aspects:
        objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'edgeCitations')
        for edge_cit in objects:
            niceCxBuilder._add_edge_citations_from_fragment(edge_cit)

    # ===================
    # OPAQUE ASPECTS
    # ===================
    for oa in opaque_aspects:
        #TODO - Add context to builder
        if oa == '@context':
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, oa)
            niceCxBuilder.set_context(
                objects)  #nice_cx.set_namespaces(objects)
        else:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, oa)
            niceCxBuilder.add_opaque_aspect(oa, objects)

    return niceCxBuilder.get_nice_cx()
Ejemplo n.º 3
0
def create_nice_cx_from_server(server, username=None, password=None, uuid=None):
    """
    Create a NiceCXNetwork based on a network retrieved from NDEx, specified by its UUID.
    If the network is not public, then username and password arguments for an account on
    the server with permission to access the network must be supplied.

    :param server: the URL of the NDEx server hosting the network.
    :param username: the user name of an account with permission to access the network.
    :param password: the password of an account with permission to access the network.
    :param uuid: the UUID of the network.
    :return: NiceCXNetwork
    """

    niceCxBuilder = NiceCXBuilder()

    if server and uuid:
        my_nicecx = NiceCXNetwork()

        # ===================
        # METADATA
        # ===================
        available_aspects = []
        md_aspect_iter = my_nicecx.get_aspect(uuid, 'metaData', server, username, password)
        if md_aspect_iter:
            for ae in (o for o in md_aspect_iter):
                available_aspects.append(ae.get('name'))
        else:
            if not username or not password:
                raise Exception('Network is not available.  Username and/or password not supplied')
            else:
                raise Exception('Network not available')

        opaque_aspects = set(available_aspects).difference(known_aspects_min)

        # ====================
        # NETWORK ATTRIBUTES
        # ====================
        if 'networkAttributes' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'networkAttributes', server, username, password)
            for network_item in objects:
                niceCxBuilder._add_network_attributes_from_fragment(network_item)
                #niceCxBuilder.add_network_attribute(network_item.get('n'), network_item.get('v'), network_item.get('d'))

        # ===================
        # @CONTEXT
        # ===================
        if '@context' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, '@context', server, username, password)

            niceCxBuilder.set_context(objects) #nice_cx.set_namespaces(objects)
            #niceCxBuilder.set_context(objects)

        # ===================
        # NODES
        # ===================
        if 'nodes' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'nodes', server, username, password)
            for node_item in objects:
                niceCxBuilder._add_node_from_fragment(node_item)
                #niceCxBuilder.add_node(node_item.get('n'), node_item.get('r'), id=node_item.get('@id'))

        # ===================
        # EDGES
        # ===================
        if 'edges' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'edges', server, username, password)
            for edge_item in objects:
                niceCxBuilder._add_edge_from_fragment(edge_item)

                #niceCxBuilder.add_edge(source=edge_item.get('s'), target=edge_item.get('t'),
                #                       interaction=edge_item.get('i'), id=edge_item.get('@id'))

        # ===================
        # NODE ATTRIBUTES
        # ===================
        if 'nodeAttributes' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'nodeAttributes', server, username, password)
            for att in objects:
                niceCxBuilder._add_node_attribute_from_fragment(att)

                #niceCxBuilder.add_node_attribute(att.get('po'), att.get('n'), att.get('v'), type=att.get('d'))

        # ===================
        # EDGE ATTRIBUTES
        # ===================
        if 'edgeAttributes' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'edgeAttributes', server, username, password)
            for att in objects:
                niceCxBuilder._add_edge_attribute_from_fragment(att)

                #niceCxBuilder.add_edge_attribute(property_of=att.get('po'), name=att.get('n'),
                #                                 values=att.get('v'), type=att.get('d'))

        # ===================
        # CITATIONS
        # ===================
        if 'citations' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'citations', server, username, password)
            for cit in objects:
                niceCxBuilder._add_citation_from_fragment(cit)
                #my_nicecx.citations[cit.get('@id')] = cit

            #my_nicecx.add_metadata_stub('citations')

        # ===================
        # SUPPORTS
        # ===================
        if 'supports' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'supports', server, username, password)
            for sup in objects:
                niceCxBuilder._add_supports_from_fragment(sup)

                #my_nicecx.supports[sup.get('@id')] = sup

            #my_nicecx.add_metadata_stub('supports')

        # ===================
        # EDGE SUPPORTS
        # ===================
        if 'edgeSupports' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'edgeSupports', server, username, password)
            for add_this_edge_sup in objects:
                niceCxBuilder._add_edge_supports_from_fragment(add_this_edge_sup)

                #for po_id in add_this_edge_sup.get('po'):
                #    my_nicecx.edgeSupports[po_id] = add_this_edge_sup.get('supports')

            #my_nicecx.add_metadata_stub('edgeSupports')

        # ===================
        # NODE CITATIONS
        # ===================
        if 'nodeCitations' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'nodeCitations', server, username, password)
            for node_cit in objects:
                niceCxBuilder._add_node_citations_from_fragment(node_cit)

                #for po_id in node_cit.get('po'):
                #    my_nicecx.nodeCitations[po_id] = node_cit.get('citations')

            #my_nicecx.add_metadata_stub('nodeCitations')

        # ===================
        # EDGE CITATIONS
        # ===================
        if 'edgeCitations' in available_aspects:
            objects = my_nicecx.get_aspect(uuid, 'edgeCitations', server, username, password)
            for edge_cit in objects:
                niceCxBuilder._add_edge_citations_from_fragment(edge_cit)
                #for po_id in edge_cit.get('po'):
                #    my_nicecx.nodeCitations[po_id] = edge_cit.get('citations')

            #my_nicecx.add_metadata_stub('edgeCitations')

        # ===================
        # OPAQUE ASPECTS
        # ===================
        for oa in opaque_aspects:
            objects = my_nicecx.get_aspect(uuid, oa, server, username, password)
            niceCxBuilder.add_opaque_aspect(oa, objects)

    else:
        raise Exception('Server and uuid not specified')

    return niceCxBuilder.get_nice_cx()
Ejemplo n.º 4
0
def create_nice_cx_from_raw_cx(cx):
    """
    Create a NiceCXNetwork from a CX json object. (see http://www.home.ndexbio.org/data-model)

    :param cx: a valid CX document
    :return: NiceCXNetwork
    """

    niceCxBuilder = NiceCXBuilder()

    #my_nicecx = NiceCXNetwork()

    if cx:
        # ===================
        # METADATA
        # ===================
        available_aspects = []
        for ae in (o for o in niceCxBuilder.get_frag_from_list_by_key(
                cx, 'metaData')):
            available_aspects.append(ae.get('name'))

        opaque_aspects = set(available_aspects).difference(known_aspects_min)

        # ====================
        # NETWORK ATTRIBUTES
        # ====================
        if 'networkAttributes' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(
                cx, 'networkAttributes')
            for network_item in objects:
                niceCxBuilder._add_network_attributes_from_fragment(
                    network_item)

        # ===================
        # NODES
        # ===================
        if 'nodes' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'nodes')
            for node_item in objects:
                niceCxBuilder._add_node_from_fragment(node_item)

        # ===================
        # EDGES
        # ===================
        if 'edges' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'edges')
            for edge_item in objects:
                niceCxBuilder._add_edge_from_fragment(edge_item)

        # ===================
        # NODE ATTRIBUTES
        # ===================
        if 'nodeAttributes' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(
                cx, 'nodeAttributes')
            for att in objects:
                niceCxBuilder._add_node_attribute_from_fragment(att)

        # ===================
        # EDGE ATTRIBUTES
        # ===================
        if 'edgeAttributes' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(
                cx, 'edgeAttributes')
            for att in objects:
                niceCxBuilder._add_edge_attribute_from_fragment(att)

        # ===================
        # CITATIONS
        # ===================
        if 'citations' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'citations')
            for cit in objects:
                niceCxBuilder._add_citation_from_fragment(cit)

        # ===================
        # SUPPORTS
        # ===================
        if 'supports' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'supports')
            for sup in objects:
                niceCxBuilder._add_supports_from_fragment(sup)

        # ===================
        # EDGE SUPPORTS
        # ===================
        if 'edgeSupports' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(
                cx, 'edgeSupports')
            for add_this_edge_sup in objects:
                niceCxBuilder._add_edge_supports_from_fragment(
                    add_this_edge_sup)

        # ===================
        # NODE CITATIONS
        # ===================
        if 'nodeCitations' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(
                cx, 'nodeCitations')
            for node_cit in objects:
                niceCxBuilder._add_node_citations_from_fragment(node_cit)

        # ===================
        # EDGE CITATIONS
        # ===================
        if 'edgeCitations' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(
                cx, 'edgeCitations')
            for edge_cit in objects:
                niceCxBuilder._add_edge_citations_from_fragment(edge_cit)

        # ===================
        # OPAQUE ASPECTS
        # ===================
        for oa in opaque_aspects:
            #TODO - Add context to builder
            if oa == '@context':
                objects = niceCxBuilder.get_frag_from_list_by_key(cx, oa)
                niceCxBuilder.set_context(
                    objects)  #nice_cx.set_namespaces(objects)
            else:
                objects = niceCxBuilder.get_frag_from_list_by_key(cx, oa)
                niceCxBuilder.add_opaque_aspect(oa, objects)

        return niceCxBuilder.get_nice_cx()
    else:
        raise Exception('CX is empty')
Ejemplo n.º 5
0
def create_nice_cx_from_raw_cx(cx):
    """
    Create a NiceCXNetwork from a CX json object. (see http://www.home.ndexbio.org/data-model)

    :param cx: a valid CX document
    :return: NiceCXNetwork
    """

    niceCxBuilder = NiceCXBuilder()

    #my_nicecx = NiceCXNetwork()

    if cx:
        # ===================
        # METADATA
        # ===================
        available_aspects = []
        for ae in (o for o in niceCxBuilder.get_frag_from_list_by_key(cx, 'metaData')):
            available_aspects.append(ae.get('name'))

        opaque_aspects = set(available_aspects).difference(known_aspects_min)

        # ====================
        # NETWORK ATTRIBUTES
        # ====================
        if 'networkAttributes' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'networkAttributes')
            for network_item in objects:
                niceCxBuilder._add_network_attributes_from_fragment(network_item)

        # ===================
        # NODES
        # ===================
        if 'nodes' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'nodes')
            for node_item in objects:
                niceCxBuilder._add_node_from_fragment(node_item)

        # ===================
        # EDGES
        # ===================
        if 'edges' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'edges')
            for edge_item in objects:
                niceCxBuilder._add_edge_from_fragment(edge_item)

        # ===================
        # NODE ATTRIBUTES
        # ===================
        if 'nodeAttributes' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'nodeAttributes')
            for att in objects:
                niceCxBuilder._add_node_attribute_from_fragment(att)

        # ===================
        # EDGE ATTRIBUTES
        # ===================
        if 'edgeAttributes' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'edgeAttributes')
            for att in objects:
                niceCxBuilder._add_edge_attribute_from_fragment(att)

        # ===================
        # CITATIONS
        # ===================
        if 'citations' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'citations')
            for cit in objects:
                niceCxBuilder._add_citation_from_fragment(cit)

        # ===================
        # SUPPORTS
        # ===================
        if 'supports' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'supports')
            for sup in objects:
                niceCxBuilder._add_supports_from_fragment(sup)

        # ===================
        # EDGE SUPPORTS
        # ===================
        if 'edgeSupports' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'edgeSupports')
            for add_this_edge_sup in objects:
                niceCxBuilder._add_edge_supports_from_fragment(add_this_edge_sup)

        # ===================
        # NODE CITATIONS
        # ===================
        if 'nodeCitations' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'nodeCitations')
            for node_cit in objects:
                niceCxBuilder._add_node_citations_from_fragment(node_cit)

        # ===================
        # EDGE CITATIONS
        # ===================
        if 'edgeCitations' in available_aspects:
            objects = niceCxBuilder.get_frag_from_list_by_key(cx, 'edgeCitations')
            for edge_cit in objects:
                niceCxBuilder._add_edge_citations_from_fragment(edge_cit)

        # ===================
        # OPAQUE ASPECTS
        # ===================
        for oa in opaque_aspects:
            #TODO - Add context to builder
            if oa == '@context':
                objects = niceCxBuilder.get_frag_from_list_by_key(cx, oa)
                niceCxBuilder.set_context(objects) #nice_cx.set_namespaces(objects)
            else:
                objects = niceCxBuilder.get_frag_from_list_by_key(cx, oa)
                niceCxBuilder.add_opaque_aspect(oa, objects)

        return niceCxBuilder.get_nice_cx()
    else:
        raise Exception('CX is empty')