def model_props(cell_id): cell_metadata = {} # download existing model (if exists) bp = BiophysicalApi() try: model_list = bp.get_neuronal_models(cell_id) model_dict = {key: '' for key in template_model_dict.keys()} for model_type, template_id in template_model_dict.items(): for model_meta in model_list: if model_meta['neuronal_model_template_id'] == template_id: model_dict[model_type] = model_meta['id'] except: logger.debug('No biophysical model available') api = allensdk.api.queries.rma_api.RmaApi() # Get the model metadata for model_type, model_id in model_dict.items(): if model_id != '': bp.cache_data(model_id, working_directory=model_dir[model_type]) model_metadata = api.model_query( "NeuronalModelRun", criteria="[neuronal_model_id$eq%s]" % model_id) model_metadata_select = [ model_metadata[0]['rheobase_feature_average'], model_metadata[0]['explained_variance_ratio'] ] model_path = glob.glob('%s/*fit*.json' % model_dir[model_type])[0] for file_ in glob.glob('%s/*' % model_dir[model_type]): if file_ != model_path: try: os.remove(file_) except: shutil.rmtree(file_, ignore_errors=True) cell_metadata['model_path_{}'.format( model_type)] = os.path.abspath(model_path) cell_metadata['{}_id'.format( model_dir[model_type])] = str(model_id) for i, metadata_key in enumerate(opt_metric_dict[model_type]): cell_metadata[metadata_key] = model_metadata_select[i] return cell_metadata
if os.path.isdir(s): shutil.copytree(s, d, symlinks, ignore) else: shutil.copy2(s, d) #%% Pick a cell and a sweep to run from the available set of protocols cell_id = 468193142 # get this from the web site: http://celltypes.brain-map.org sweep_num = 46 # Select a Long Square sweep : 1s DC #%% Download all-acive model sdk_model_templates = {'all_active': 491455321, 'perisomatic': 329230710} bp = BiophysicalApi() bp.cache_stimulus = True model_list = bp.get_neuronal_models(cell_id, model_type_ids=[sdk_model_templates['all_active']]) # Only get the all-active model for the cell model_dict = model_list[0] model_dir = 'all_active_models' bp.cache_data(model_dict['id'], working_directory=model_dir) new_model_file = 'fit_parameters_new.json' shutil.copyfile(new_model_file, os.path.join(model_dir, new_model_file)) copytree('modfiles', os.path.join(model_dir, 'modfiles')) #%% Running the legacy all-active models os.chdir(model_dir) subprocess.check_call(['nrnivmodl', 'modfiles/']) manifest_file = 'manifest.json' manifest_dict = json.load(open(manifest_file))