def make_model(self): """Make an EmmaaModel and upload it along with the config to S3.""" config = self.make_config() em = EmmaaModel(self.name, config) em.stmts = self.stmts ndex_uuid = em.upload_to_ndex() config['ndex'] = {'network': ndex_uuid} save_config_to_s3(self.name, config) em.save_to_s3()
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')
def update_cancer(cancer_type): """Update the model for the given cancer. A JSON config file must be present for the given cancer type, located in the models/<cancer_type>/config.json. Parameters ---------- cancer_type : str A short string which is the name of the cancer, and corresponds to a directory in the models directory, as described above. """ print(cancer_type) with open(f'models/{cancer_type}/prior_stmts.pkl', 'rb') as fh: stmts = pickle.load(fh) config = json.load(open(f'models/{cancer_type}/config.json', 'r')) em = EmmaaModel(cancer_type, config) ess = [EmmaaStatement(st, datetime.datetime.now(), []) for st in stmts] em.add_statements(ess) em.save_to_s3() return
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)
def make_model(self, estmts, upload_to_s3=False): """Return, and optionally upload to S3 an initial EMMAA Model. Parameters ---------- estmts : list of emmaa.statement.EmmaaStatement A list of prior EMMAA Statements to initialize the model with. upload_to_s3 : Optional[bool] If True, the model and the config are uploaded to S3, otherwise the model object is just returned without upload. Default: False Returns ------- emmaa.model.EmmaaModel The EMMAA Model object constructed from the generated config and the given EMMAA Statements. """ from emmaa.model import EmmaaModel config = self.make_config(upload_to_s3=upload_to_s3) model = EmmaaModel(name=self.name, config=config) model.add_statements(estmts) if upload_to_s3: model.save_to_s3() return model