Metadata-Version: 2.4
Name: mgtx-benchling-wrapper
Version: 0.1.0
Summary: Python wrapper for Benchling API with common functions used at MGTX DSC
Author-email: Ana Valinhas <ana.valinhas@meiragtx.com>
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: benchling-sdk>=1.21.2
Requires-Dist: benchling-api-client>=2.0.342
Requires-Dist: pandas>=2.2.2
Requires-Dist: numpy>=1.26.4
Provides-Extra: dev
Requires-Dist: pytest>=9.0.3; extra == "dev"
Requires-Dist: pytest-mock>=3.15.1; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# mgtx-benchling-wrapper
A wrapper of the Benchling API with common functions and workflows used at MGTX DSC.

## Installation 🚀
You can install this package using:
```
pip install mgtx-benchling-wrapper
```

## Quickstart 🚩
After creating an app on your Benchling tenant, create a config.yaml file in your repo.
The following are the contents of the config.yaml
```
BenchlingCredentials:
  benchling_url: 'https://mytenant.benchling.com'
  benchling_access_token: 'https://mytenant.benchling.com/api/v2/token'
  app_client_id: 'your-app-client-id'
  app_client_secret: 'encrypted-client-secret'
AssaySchema:
  schema_id: "schema_api_id"
Project:
  project_id: "project_api_id"
```
The app_client_secret should be encrypted. Create encryption.py Use cryptography as follows:
```
from cryptography.fernet import Fernet

def decrypt(value):
    return f.decrypt(value.encode()).decode()

def encrypt(value):
    return f.encrypt(value.encode()).decode()
    
if __name__ == "__main__":
# Run this to print an encrypted string of "my-value"
print(encrypt('your-app-client-secret))
```
The following is an example of the use of the assay_results_ingestion workflow.
```
import yaml
from encryption import decrypt
from mgtx_benchling_wrapper.context.benchling_context import BenchlingContext
from mgtx_benchling_wrapper.wrapper.facade import BenchlingWrapperFacade
from mgtx_benchling_wrapper.workflows.assays_result_ingestion import (
     AssayResultIngestionWorkflow
)

def config():
    with open("tests/config/test_config.yml") as f:
        return yaml.safe_load(f)

#create the benchling context        
ctx = BenchlingContext(
        base_url=config()['BenchlingCredentials']['benchling_url'],
        client_id=config()['BenchlingCredentials']['app_client_id'],
        client_secret=decrypt(config()['BenchlingCredentials']['app_client_secret']),
        token_url=config()['BenchlingCredentials']['benchling_access_token'],
    )    

#initialize the wrapper
wrapper = BenchlingWrapperFacade(ctx.benchling())

#retrieve assay_schema_id
schema_id = config()['AssaySchema']['schema_id']

#retrieve project_id
project_id = config()['Project']['project_id']

#initiate results ingestion workflow
results_ingestion = AssayResultIngestionWorkflow(wrapper)

#ingest results on benchling
list_missing_entities = results_ingestion.assay_results_ingestion_updated(
        [dataframe_to_ingest],
        schema_id,
        project_id,
        unique_identifiers =['assay_run_id', 'sample_id']
        )       
```


