def assemble_cx(stmts_with_counts):
    for channel, (stmts, ev_counts,
                  source_counts) in stmts_with_counts.items():
        cxa = CxAssembler(stmts, network_name='%s INDRA interactome' % channel)
        cxa.make_model()
        add_semantic_hub_layout(cxa.cx, channel)
        model_id = cxa.upload_model()
Beispiel #2
0
 def upload_to_ndex(self):
     """Upload the assembled model as CX to NDEx, creates new network."""
     if not self.assembled_stmts:
         self.run_assembly()
     cxa = CxAssembler(self.assembled_stmts, network_name=self.name)
     cxa.make_model()
     model_uuid = cxa.upload_model()
     self.ndex_network = model_uuid
     return model_uuid
Beispiel #3
0
def upload_ndex_network(kinase, stmts):
    network_set_id = '9d9d4f66-e3da-11eb-b666-0ac135e8bacf'
    name = '%s INDRA network' % kinase
    cxa = CxAssembler(stmts, name)
    cxa.make_model()
    add_semantic_hub_layout(cxa.cx, kinase)
    network_id = cxa.upload_model(private=False)
    # Style setting already done as part of upload
    # ndex_client.set_style(network_id)
    ndex_client.add_to_network_set(network_id, network_set_id)
    return network_id
Beispiel #4
0
def share_model_ndex():
    """Upload the model to NDEX"""
    if request.method == 'OPTIONS':
        return {}
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    stmts_str = body.get('stmts')
    stmts_json = json.loads(stmts_str)
    stmts = stmts_from_json(stmts_json["statements"])
    ca = CxAssembler(stmts)
    for n, v in body.items():
        ca.cx['networkAttributes'].append({'n': n, 'v': v, 'd': 'string'})
    ca.make_model()
    network_id = ca.upload_model(private=False)
    return {'network_id': network_id}
Beispiel #5
0
def share_model_ndex():
    """Upload the model to NDEX"""
    if request.method == 'OPTIONS':
        return {}
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    stmts_str = body.get('stmts')
    stmts_json = json.loads(stmts_str)
    stmts = stmts_from_json(stmts_json["statements"])
    ca = CxAssembler(stmts)
    for n, v in body.items():
        ca.cx['networkAttributes'].append({'n': n, 'v': v, 'd': 'string'})
    ca.make_model()
    network_id = ca.upload_model(private=False)
    return {'network_id': network_id}
Beispiel #6
0
def create_upload_model(model_name, full_name, indra_stmts, ndex_id=None):
    """Make and upload an EMMAA model from a list of INDRA Statements.

    Parameters
    ----------
    short_name : str
        Short name of the model to use on S3.
    full_name : str
        Human-readable model name to use in EMMAA dashboard.
    indra_stmts : list of indra.statement
        INDRA Statements to be used to populate the EMMAA model.
    ndex_id : str
        UUID of the network corresponding to the model on NDex. If provided,
        the NDex network will be updated with the latest model content.
        If None (default), a new network will be created and the UUID stored
        in the model config files on S3.
    """
    emmaa_stmts = to_emmaa_stmts(indra_stmts, datetime.datetime.now(), [])
    # Get updated CX content for the INDRA Statements
    cxa = CxAssembler(indra_stmts)
    cx_str = cxa.make_model()
    # If we don't have an NDex ID, create network and upload to Ndex
    if ndex_id is None:
        ndex_id = cxa.upload_model(private=False)
        print(f'NDex ID for {model_name} is {ndex_id}.')
    # If the NDEx ID is provided, update the existing network
    else:
        ndex_client.update_network(cx_str, ndex_id)
    # Create the config dictionary
    config_dict = {'ndex': {'network': ndex_id}, 'search_terms': []}
    # Create EMMAA model
    emmaa_model = EmmaaModel(model_name, config_dict)
    emmaa_model.add_statements(emmaa_stmts)
    # Upload model to S3 with config as YAML and JSON
    emmaa_model.save_to_s3()
    s3_client = boto3.client('s3')
    config_json = json.dumps(config_dict)
    s3_client.put_object(Body=config_json.encode('utf8'),
                         Key='models/%s/config.json' % model_name,
                         Bucket='emmaa')
    config_json = json.dumps(config_dict)
    s3_client.put_object(Body=config_json.encode('utf8'),
                         Key='models/%s/config.json' % model_name,
                         Bucket='emmaa')
Beispiel #7
0
def create_upload_model(model_name, indra_stmts, config_file):
    """Make and upload an EMMAA model from a list of INDRA Statements.

    Parameters
    ----------
    model_name : str
        Name of the model to use on S3.
    indra_stmts : list of indra.statement
        INDRA Statements to be used to populate the EMMAA model.
    config_file : str
        Path to the local config.json file.
    """
    emmaa_stmts = to_emmaa_stmts(indra_stmts, datetime.datetime.now(), [],
                                 {'internal': True})
    # Load config information
    with open(config_file, 'rt') as f:
        config_json = json.load(f)
    # If there is no ndex entry in the config, create a new network and update
    # the config file with the NDex network ID
    if 'ndex' not in config_json:
        cxa = CxAssembler(indra_stmts)
        cx_str = cxa.make_model()
        ndex_id = cxa.upload_model(private=False)
        print(f'NDex ID for {model_name} is {ndex_id}.')
        config_json['ndex'] = {'network': ndex_id}
        updated_config_file = f'{config_file}.updated'
        with open(updated_config_file, 'wt') as f:
            json.dump(config_json, f, indent=2)
    # If the NDEx ID is provided we don't need to update the existing network
    # because this will occur as part of the model assembly/update procedure
    # on EMMAA itself.
    # Create the config dictionary
    # Create EMMAA model
    emmaa_model = EmmaaModel(model_name, config_json)
    emmaa_model.add_statements(emmaa_stmts)
    # Upload model to S3
    emmaa_model.save_to_s3()
    # Upload config JSON
    s3_client = boto3.client('s3')
    save_config_to_s3(model_name, config_json)
Beispiel #8
0
    def post(self):
        """Upload the model to NDEX.

        Parameters
        ----------
        statements : list[indra.statements.Statement.to_json()]
            A list of INDRA Statements to assemble.

        Returns
        -------
        network_id : str
            ID of uploaded NDEx network.
        """
        args = request.json
        stmts_json = args.get('statements')
        stmts = stmts_from_json(stmts_json)
        ca = CxAssembler(stmts)
        for n, v in args.items():
            ca.cx['networkAttributes'].append({'n': n, 'v': v, 'd': 'string'})
        ca.make_model()
        network_id = ca.upload_model(private=False)
        return {'network_id': 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)