Purpose of this showcase project is integrate modern NoSQL backend Redis with Async Python Framework as API for chemical compounds extended analyze with RDKit Library.
Data set coming from pub chem database and you can download example from COVID-19 Disease Map here on this link: https://pubchem.ncbi.nlm.nih.gov/#query=covid-19
Pydantic schema was created for PubChem Compounds. You can replace it with your own schema to accept other source of SMILES.
There is many chemical compound sets. Now we all in days when COVID-19 Pandemic is out there We all want to know as much as possible about best cure..., and it is my project background. Show power and robustness of Redis with speed of FastAPI and functionality of RDKit to deliver api which allow quick analyze chem molecules.
For puprose of Redis 2021 Hack-a-toon I added only two cases to load chem molecules to redis cache and to compare all molecules which we already have with new one.
This can be really quickly integrate with other services via REST API and extended to deliver desired chem compound bakery.
Project as whole is build on python asyncio including REST, Redis connection and transactions and unit tests.
To build , run and test and more ... use magic of make help to play with this project.
make help
and you receive below list:
black Apply black in project code
build Build project with compose
clean Reset project containers with compose
down Stop project containers with compose
flake8 Flake8 checks on project code
help Show this help
isort Sort imports in project code
lock Refresh pipfile.lock
mypy Run mypy checks on project code
requirements Refresh requirements.txt from pipfile.lock
test-cov Run project unit tests with coverage
up Run project with compose
-
Download sample JSON form PubChem database i.e. COVID-19 Disease Map here on this link: https://pubchem.ncbi.nlm.nih.gov/#query=covid-19
-
Add SMILES to Redis Hash with
/api/smiles/add-to-hash
endpointcurl --location --request POST 'http://0.0.0.0:8080/api/smiles/add-to-hash?redis_hash=covid-19-canonical' \ --header 'Content-Type: application/json' \ --data-binary '@/fastapi-redis/PubChem_compound_text_covid-19_records.json'
and get response like below with
201 Created
{ "number_of_inserted_keys": 2364, "hash_name": "covid-19-canonical" }
-
Compare SMILES code to list loaded in previous step on Redis Hash with
/api/smiles/compare-to-hash
endpointcurl --location --request GET 'http://0.0.0.0:8080/api/smiles/compare-to-hash?compound=CCC(CC)COC(=O)C(C)NP(=O)(OCC1C(C(C(O1)(C%23N)C2=CC=C3N2N=CN=C3N)O)O)OC4=CC=CC=C4&redis_hash=covid-19-canonical'
and get response like below with
200 OK
{ "number_of_smiles_to_compare": 2364, "similarity": { "CCC(CC)COC(=O)[C@H](C)N[P@](=O)(OC[C@@H]1[C@H]([C@H]([C@](O1)(C#N)C2=CC=C3N2N=CN=C3N)O)O)OC4=CC=CC=C4": 1.0, "CCC(CC)COC(=O)C(C)NP(=O)(OCC1C(C(C(O1)(C#N)C2=CC=C3N2N=CN=C3N)O)O)OC4=CC=CC=C4": 1.0, "C1=C2C(=NC=NN2C(=C1)C3(C(C(C(O3)COP(=O)(O)O)O)O)C#N)N": 0.8964264082374318, "C1=C2C(=NC=NN2C(=C1)[C@]3([C@@H]([C@@H]([C@H](O3)COP(=O)(O)O)O)O)C#N)N": 0.8964264082374318, "C1=C2C(=NC=NN2C(=C1)[C@]3([C@@H]([C@@H]([C@H](O3)CO)O)O)C#N)N": 0.8740109555690809, "C1=C2C(=NC=NN2C(=C1)C3(C(C(C(O3)CO)O)O)C#N)N": 0.8740109555690809 } }
-
For REST API Documentation please use:
http://0.0.0.0:8080/docs
Beside of using latest and greatest version of Redis with it robustness, powerfulness and speed there is FastAPI (modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.) already reviewed on thoughtworks
Hope you enjoy it.