Package: transcriptb2b
Bioinformatics-102A friendly introduction to the Docker technologies. For more details about this technology, please visitthe official website. In aprevious repositorywe learnt how to dockerize a project. Now, we are about to create a python HTTP API, package it into a container image, upload the container image to Google Cloud services, and then deploy the container image to Google Cloud Services' Cloud Run to publish this project.Pre-requisitesTo follow this guidelines please install in your local environmentDocker Desktop.AbstractThis repository includes a dummy bioinformatics tool written in Python, called dna2rna, which transcripts an input string of DNA into a RNAm string:DNA sequence -> dna2rna -> RNAm sequenceDetailsThe source code is available insidemain.py:BEGIN
  1. Create a string called <RNA SEQ> with the same length as the input one <DNA SEQ>
  2. For each character <CURRENT> inside <DNA SEQ>:
  3.   Assign the matching value for <CURRENT> inside <OPPOSITE> // A <-> T, C <-> G
  4.   Put <OPPOSITE> inside <RNA_SEQ> at the same position that <CURRENT>
  5. Return <RNA SEQ>
ENDExamples:InputA-> OutputTInputaA-> OutputtTInputABCD-> OutputT?G?More information about the biological transcription process is availablehere.Technical aspectsThe goal of this example is to create an API to process the DNA sequences and return the RNA transcript sequence. To accomplish this goal, we are using the Flask library to create a simple endpoint at/to handlePOSTrequests with a JSON input containing a key named "dnaSequence".ExampleThe input must follow this schema:{"dnaSequence":"gatcctccatatacaacggtatctccacctcaggtttagatctcaacaacggaac"}Assuming the API is running on port 8080:$curl--location--requestPOST'https://localhost:8080'\--header'Content-Type: application/json'\--data-raw'{"dnaSequence": "gatcctccatatacaacggtatctccacctcaggtttagatctcaacaacggaac"}'The return will be:{"dnaSequence":"gatcctccatatacaacggtatctccacctcaggtttagatctcaacaacggaac","rnaSequence":"ctaggaggtatatgttgccatagaggtggagtccaaatctagagttgttgccttg"}Running itThe straightforward alternative is to install the dependencies and run it. However, it implies having a python interpreter installed, or using conda environments...$pipinstall-rrequirements.txt$gunicorn--bind:8080--workers1--threads8--timeout0main:appDocker wayThere is aprevious repositorywhere we discussed the main concepts and the advantages of creating both Docker images and containers.ImageIn this case, instead of starting from agccimage, we are starting from the official lightweight python image:FROM-> Basically we define our Docker image frompython:3.9-slimENV->  Setting a environment variable (PYTHONUNBUFFERED=True). More details inside the DockerfileENV->  Setting a environment variable (APP_HOME) pointing to the working dir path. More details inside the DockerfileWORKDIR-> Create theworking folderCOPY-> Copy the code from your computer to the imageRUN-> Install the requirements inside the image by executingpip install ...CMD-> The command to execute when the container is initialized. In this case we start the serverOnce you have theDockerfileit is easy to build the image:$dockerimagebuild.--tagbioinformatics-102Details:docker image build: Build an image.: the path toDockerfile--tag bioinformatics-102: a tag name to make easier using the image laterContainerNow, we are ready to create a container with the server running from inside it:$dockerrun-p127.0.0.1:80:8080--envPORT=8080bioinformatics-102Details:docker run: Create a container-p 127.0.0.1:8080:8080: bind the your computer's localhost to the container's port 8080--env PORT=8080: defines the environment variable with the running port (8080)bioinformatics-102: the image nameExecute the command to start the server inside the container connected to the machine's 8080 port.Deploying the instance on a cloud providerIt's quite easy to deploy a container on a cloud provider allowing the community to use your code effortless. For this example, the Docker instance is running on Google Cloud Services. Guidelines for Python projects are available onthis official document from Google Cloud.After following the process mentioned above, we have a public URL to access the API:https://dna2rna-de2u5yatga-ew.a.run.app.Try itBy writing the following code script you can easily make a POST request to the deployed container:importrequestsimportjsonurl="https://dna2rna-de2u5yatga-ew.a.run.app"payload=json.dumps({"dnaSequence":"gatcctccatatacaacggtatctccacctcaggtttagatctcaacaacggaac"})headers={'Content-Type':'application/json'}response=requests.request("POST",url,headers=headers,data=payload)print(response.text)Final thoughtsIn addition to what was said in the previous repository, this one wanted to show the pros of using docker with cloud providers. With few steps we have a HTTP API service running online with almost nothing to set up.I would like to recommend you to give it a chance, dockerize your project, create a simple HTTP API to open your code to the community and deploy it to the cloud. In my case, I'm using the Google Cloud free period to test this code.Any comment is welcomed here opening an issue or sending me an email toadrian.diaz@vub.be(ordiaz.adrian.g@gmail.com)Thanks for your time and happy coding!!!