Import & Export Assets
This Jupyter notebook demonstrate two workflows: Export and import assets. This workflow showcases the reusability of assets in GastroPlus X and is particularly useful for: - Sharing asset libraries between projects - Creating standardized asset collections - Backing up specific assets - Collaborating across different research teams
The specified assets will be exported to intermediate project and then be imported from there to another project. The script utilizes the gastroPlusAPI package to communicate with the GastroPlus X 10.2 service.
To customize your study with this script for a different assets / project, please make changes to the “Setup Input Information” section.
Load required libraries
import gastroplus_api as gp
import pandas as pd
from pprint import pprint
import os
Start the GastroPlus service
start_service() starts the GastroPlus service and stores the port the service is listening on. Alternatively, you can start the service externally and set the port variable below.
try:
gastroplus_service = gp.start_service(verbose=False)
except Exception as e:
print(f"Error starting GastroPlus service: {e}")
GastroPlus Service configured. Listening on port: 8700
Configure and create the gastroplus client instance. The gastroplus object will used to interact with the GastroPlus Service.
If not using start_service() to start the GastroPlus service (i.e., starting externally from this script), adjust the port variable below to match the port of the GastroPlus Service instance
The port set here must match the listening port of the running GastroPlus Service.
#port=8700
port = gastroplus_service.port
host = f"http://localhost:{port}"
client = gp.ApiClient(gp.Configuration(host = host))
gastroplus = gp.GpxApiWrapper(client)
Setup Input Information
Make modification to the variables in this chunk to customize workflow.
INITIAL_PROJECT_PATH: Location of the project containing the assets to be exported
INITIAL_PROJECT_NAME: Name of the project which from which the assets will be exported
EXPORT_PROJECT_PATH: Location of the intermediate project, which will be created to store the exported assets
EXPORT_PROJECT_NAME: Name of the intermediate project, which will be created to store the exported assets
ASSET_TYPE_TO_BE_EXPORTED: Type of the assets to be exported (e.g., gp.AssetType.Compound)
ASSETS_TO_BE_EXPORTED: List of assets which will be exported. Details can be retrieved by get_assets()
INITIAL_PROJECT_PATH = os.path.abspath("../../ProjectFiles")
INITIAL_PROJECT_NAME = "GPX Library"
EXPORT_PROJECT_PATH = os.getcwd() # Exported project will be created in the current working directory
EXPORT_PROJECT_NAME = "Project_for_exported_assets"
# Combined the above to create the full initial project file path
INITIAL_PROJECT_FILE_NAME = os.path.join(INITIAL_PROJECT_PATH, INITIAL_PROJECT_NAME + ".gpproject")
ASSET_TYPE_TO_BE_EXPORTED = gp.AssetType.Compound
ASSETS_TO_BE_EXPORTED = ["Atenolol", "Ranitidine"]
Export specified assets
Based on the variables assigned in the previous code cell, following cell will export assets to an intermediate project, which will be created.
#Load the project
gastroplus.open_project(INITIAL_PROJECT_FILE_NAME)
# check to see the assets in the project
assets = gastroplus.get_assets([gp.AssetType.Compound])
assets_df = pd.json_normalize(assets.to_dict(), record_path='project_assets')
# create ProjectAssets object of assets to be exported
exported_assets = gp.ProjectAssets(project_assets=[gp.ProjectAsset(asset_type=ASSET_TYPE_TO_BE_EXPORTED, assets=[gp.ProjectAssetAssetsInner(name) for name in ASSETS_TO_BE_EXPORTED]) ])
# export the assets
gastroplus.export_assets(EXPORT_PROJECT_PATH, EXPORT_PROJECT_NAME, exported_assets)
assets_df
asset_type | assets | |
|---|---|---|
0 | Compound | [Atenolol, Propranolol HCl, Ranitidine, Brick ... |
Setup Input Information: Import
Make modification to the variables in this chunk to customize workflow.
INTERMEDIATE_PROJECT_FILE_NAME: Location of the intermediate project, which was created in the previous cell
IMPORTING_PROJECT_PATH: Location of the project that the assets will be imported to
IMPORTING_PROJECT_NAME: The name of the project that the assets will be imported to
ASSET_TYPE_TO_BE_IMPORTED & ASSETS_TO_BE_IMPORTED: List of assets which will be imported. Details can be retrieved by get_project_assets()
INTERMEDIATE_PROJECT_FILE_NAME = os.path.join(EXPORT_PROJECT_PATH, EXPORT_PROJECT_NAME + ".gpproject")
IMPORTING_PROJECT_PATH = os.path.abspath("../../ProjectFiles")
IMPORTING_PROJECT_NAME = "Metoprolol"
IMPORTING_PROJECT_FILE_NAME = os.path.join(IMPORTING_PROJECT_PATH, IMPORTING_PROJECT_NAME + ".gpproject")
ASSET_TYPE_TO_BE_IMPORTED = "Compound"
ASSETS_TO_BE_IMPORTED = ["Atenolol", "Ranitidine"]
Import specified assets
Based on the variables assigned in the previous code cell, following cell will import assets from the intermediate project, which was created in previous cell.
Imported assets can be listed by get_assets()
Please save project in order to save imported assets (see save_project() and save_project_as()).
#Load the project
gastroplus.open_project(IMPORTING_PROJECT_FILE_NAME)
# create object of assets to import
imported_assets = gp.ProjectAssets(project_assets=[gp.ProjectAsset(asset_type=ASSET_TYPE_TO_BE_IMPORTED, assets=[gp.ProjectAssetAssetsInner(name) for name in ASSETS_TO_BE_IMPORTED]) ])
# import the assets
gastroplus.import_assets(INTERMEDIATE_PROJECT_FILE_NAME, imported_assets)
Check to see if the compounds were imported
assets = gastroplus.get_assets()
pd.json_normalize(assets.to_dict(), record_path='project_assets')
asset_type | assets | |
|---|---|---|
0 | Compound | [Metoprolol, Atenolol, Ranitidine] |
1 | Physiology | [Human 30YO 66kg, 70kg HumanFasted, 78kg Human... |
2 | Formulation | [Fast CR Tablet, Slow CR Tablet, Moderate CR T... |
3 | Dosing Schedule | [Fast CR Tablet 100mg, Moderate CR Tablet 100m... |
4 | Physiology Schedule | [Human 66kg] |
5 | Simulation | [Fast CR oral tablet 100mg-2Comps, Moderate CR... |
6 | Run | [Run, Exploratory Simulation] |
7 | Pharmacokinetic Parameters | [] |
8 | Profiles | [{'data_type': 'InVitroDissolutionRelease', 'g... |