Example #1
0
    def upload_model(self, ndex_cred=None, private=True, style='default'):
        """Creates a new NDEx network of the assembled CX model.

        To upload the assembled CX model to NDEx, you need to have
        a registered account on NDEx (http://ndexbio.org/) and have
        the `ndex` python package installed. The uploaded network
        is private by default.

        Parameters
        ----------
        ndex_cred : Optional[dict]
            A dictionary with the following entries:
            'user': NDEx user name
            'password': NDEx password
        private : Optional[bool]
            Whether or not the created network will be private on NDEX.
        style : Optional[str]
            This optional parameter can either be (1)
            The UUID of an existing NDEx network whose style should be applied
            to the new network. (2) Unspecified or 'default' to use
            the default INDRA-assembled network style. (3) None to
            not set a network style.

        Returns
        -------
        network_id : str
            The UUID of the NDEx network that was created by uploading
            the assembled CX model.
        """
        cx_str = self.print_cx()
        if not ndex_cred:
            username, password = ndex_client.get_default_ndex_cred({})
            ndex_cred = {'user': username, 'password': password}
        network_id = ndex_client.create_network(cx_str, ndex_cred, private)
        if network_id and style:
            template_id = None if style == 'default' else style
            nretries = 3
            for retry_idx in range(nretries):
                time.sleep(3)
                try:
                    ndex_client.set_style(network_id, ndex_cred, template_id)
                    break
                except Exception:
                    msg = 'Style setting failed, '
                    if retry_idx + 1 < nretries:
                        logger.info(msg + 'retrying %d more times' %
                                    (nretries - (retry_idx + 1)))
                    else:
                        logger.info(msg + 'the network will be missing style '
                                    'information.')
        return network_id
Example #2
0
    def upload_model(self, ndex_cred=None, private=True, style='default'):
        """Creates a new NDEx network of the assembled CX model.

        To upload the assembled CX model to NDEx, you need to have
        a registered account on NDEx (http://ndexbio.org/) and have
        the `ndex` python package installed. The uploaded network
        is private by default.

        Parameters
        ----------
        ndex_cred : Optional[dict]
            A dictionary with the following entries:
            'user': NDEx user name
            'password': NDEx password
        private : Optional[bool]
            Whether or not the created network will be private on NDEX.
        style : Optional[str]
            This optional parameter can either be (1)
            The UUID of an existing NDEx network whose style should be applied
            to the new network. (2) Unspecified or 'default' to use
            the default INDRA-assembled network style. (3) None to
            not set a network style.

        Returns
        -------
        network_id : str
            The UUID of the NDEx network that was created by uploading
            the assembled CX model.
        """
        cx_str = self.print_cx()
        if not ndex_cred:
            username, password = ndex_client.get_default_ndex_cred({})
            ndex_cred = {'user': username,
                         'password': password}
        network_id = ndex_client.create_network(cx_str, ndex_cred, private)
        if network_id and style:
            template_id = None if style == 'default' else style
            ndex_client.set_style(network_id, ndex_cred, template_id)
        return network_id
Example #3
0
    def upload_model(self, ndex_cred=None, private=True, style='default'):
        """Creates a new NDEx network of the assembled CX model.

        To upload the assembled CX model to NDEx, you need to have
        a registered account on NDEx (http://ndexbio.org/) and have
        the `ndex` python package installed. The uploaded network
        is private by default.

        Parameters
        ----------
        ndex_cred : Optional[dict]
            A dictionary with the following entries:
            'user': NDEx user name
            'password': NDEx password
        private : Optional[bool]
            Whether or not the created network will be private on NDEX.
        style : Optional[str]
            This optional parameter can either be (1)
            The UUID of an existing NDEx network whose style should be applied
            to the new network. (2) Unspecified or 'default' to use
            the default INDRA-assembled network style. (3) None to
            not set a network style.

        Returns
        -------
        network_id : str
            The UUID of the NDEx network that was created by uploading
            the assembled CX model.
        """
        cx_str = self.print_cx()
        if not ndex_cred:
            username, password = ndex_client.get_default_ndex_cred({})
            ndex_cred = {'user': username, 'password': password}
        network_id = ndex_client.create_network(cx_str, ndex_cred, private)
        if network_id and style:
            template_id = None if style == 'default' else style
            ndex_client.set_style(network_id, ndex_cred, style)
        return network_id
import sys
import pickle
from indra.databases import ndex_client
from indra.assemblers.cx import CxAssembler
from indra.assemblers.cx.hub_layout import add_semantic_hub_layout

if __name__ == '__main__':
    kinase = sys.argv[1]
    with open('dark_kinase_statements_assembled.pkl', 'rb') as fh:
        stmts = pickle.load(fh)
    cxa = CxAssembler(stmts[kinase])
    cxa.make_model()
    add_semantic_hub_layout(cxa.cx, kinase)
    model_id = cxa.upload_model()
    ndex_client.set_style(model_id)