Package: thera-py
Therapy NormalizationServices and guidelines for normalizing drug (and non-drug therapy) termsDeveloper instructionsThe following sections include instructions specifically for developers.InstallationFor a development install, we recommend using Pipenv. See thepipenv docsfor direction on installing pipenv in your compute environment.Once installed, from the project root dir, just run:pipenv syncDeploying DynamoDB LocallyWe use Amazon DynamoDB for data storage. To deploy locally, followthese instructions.Initialize development environmentCode style is managed byflake8and checked prior to commit.We usepre-committo run conformance tests.This ensures:Style correctnessNo large filesAWS credentials are presentPrivate key is presentPre-commitmustbe installed before your first commit. Use the following command:pre-commit installRunning testsUnit tests are provided via pytest.pipenv run pytestBy default, tests will employ an existing DynamoDB database. For test environments where this is unavailable (e.g. in CI), theTHERAPY_TESTenvironment variable can be set to initialize a local DynamoDB instance with miniature versions of input data files before tests are executed.export THERAPY_TEST=trueSometimes, sources will update their data, and our test fixtures and data will become incorrect. Thetests/scripts/subdirectory includes scripts to rebuild data files, although most fixtures will need to be updated manually.Updating the databaseBefore you use the CLI to update the database, run the following in a separate terminal to start DynamoDB onport 8000:java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDbTo change the port, simply add-port value.Setting Environment VariablesRxNorm requires a UMLS license, which you can register for onehere.
You must set theRxNORM_API_KEYenvironment variable to your API key. This can be found in theUTS 'My Profile' areaafter singing in.exportRXNORM_API_KEY={rxnorm_api_key}HemOnc.org data requires a Harvard Dataverse API key. After creating a user account on the Harvard Dataverse website, you can followthese instructionsto generate a key. Once you have a key, set the following environment variable:exportDATAVERSE_API_KEY={yourapikey}Update source(s)The Therapy Normalizer currently aggregates therapy data from:ChEMBLChemIDPlusDrugBank(using CC0 data only)Drugs@FDAThe IUPHAR/BPS Guide to PHARMACOLOGYHemOnc.org(using CC-BY data only).The National Cancer Institute ThesaurusRxNormWikidataTo update source(s), simply set--normalizerto the source(s) you wish to update separated by spaces. For example, the following command updates ChEMBL and Wikidata:python3 -m therapy.cli --normalizer="chembl wikidata"You can update all sources at once with the--update_allflag:python3 -m therapy.cli --update_allThedata/subdirectory within the package source should house all desired input data. Files for all sources should follow the naming convention demonstrated below (with version numbers/dates changed where applicable).therapy/data
├── chembl
│   └── chembl_27.db
├── chemidplus
│   └── chemidplus_20200327.xml
├── drugbank
│   └── drugbank_5.1.8.csv
├── guidetopharmacology
│   ├── guidetopharmacology_ligand_id_mapping_2021.3.tsv
│   └── guidetopharmacology_ligands_2021.3.tsv
├── hemonc
│   ├── hemonc_concepts_20210225.csv
│   ├── hemonc_rels_20210225.csv
│   └── hemonc_synonyms_20210225.csv
├── ncit
│   └── ncit_20.09d.owl
├── rxnorm
│   ├── drug_forms.yaml
│   └── rxnorm_20210104.RRF
└── wikidata
    └── wikidata_20210425.jsonUpdates to the HemOnc source depend on theDisease Normalizerservice. If the Disease Normalizer database appears to be empty or incomplete, updates to HemOnc will also trigger a refresh of the Disease Normalizer database. See its README for additional data requirements.Create Merged Concept GroupsThe/normalizeendpoint relies on merged concept groups.  The--update_mergedflag generates these groups:python3 -m therapy.cli --update_mergedSpecifying the database URL endpointThe default URL endpoint ishttp://localhost:8000.
There are two different ways to specify the database URL endpoint.The first way is to set the--db_urlflag to the URL endpoint.python3 -m therapy.cli --update_all --db_url="http://localhost:8001"The second way is to set the environment variableTHERAPY_NORM_DB_URLto the URL endpoint.export THERAPY_NORM_DB_URL="http://localhost:8001"
python3 -m therapy.cli --update_allStarting the therapy normalization serviceFrom the project root, run the following:uvicorn therapy.main:app --reloadNext, view the OpenAPI docs on your local machine:http://127.0.0.1:8000/therapyFAQA data import method raised a SourceFormatException instance. How do I proceed?TheraPy will automatically try to acquire the latest version of data for each source, but sometimes, sources alter the structure of their data (e.g. adding or removing CSV columns). If you encounter a SourceFormatException while importing data, please notify us by creating a newissueif one doesn't already exist, and we will attempt to resolve it.In the meantime, you can force TheraPy to use an older data release by removing the incompatible version from the source data folder, manually downloading and replacing it with an older version of the data per the structure described above, and calling the CLI with the--use_existingargument.