March 18, 2021
Have you ever wanted to publish your code as a web server to share it with friends and colleagues? In this example, we write an algorithm for transcribing DNA to RNA in Python and use the BioLib platform to turn it into a web-application.
Create a simple Python based web server for transcribing DNA to RNA.
Create a web server that takes a DNA sequence as a text input and converts it to RNA. The Python program we will write
for this task should: Read input sequence with
argparse, then replace all T's with U's in the input string and then
output the modified string using
If you do not already have a BioLib account you can create one at biolib.com/sign-up/. To create a new application, sign in to your account and click "Create Application" in the top right-hand corner. For this tutorial we will use the Python template.
In the application editor scroll down to "Input Arguments". Here you can customize what input the user is asked provide. For this task you might want to something similar to the screenshot below.
The entry point to our Python application is the file
src/__main__.py. Using the Python library
argparse we can read
the user input. The code snippet below shows how you can get the value from the sequence input we created in the
# src/__main__.py import argparse # read inputs provided by user parser = argparse.ArgumentParser() parser.add_argument('--sequence') # inputs can now be accessed using args.[input_key] print(args.sequence)
If you click "Save" and then "Test App" you should now have you should now have an simple application that asks for a sequence input.
Now write some Python code that transcribes the DNA sequence to RNA, and outputs the results with
We now wish to expand the functionality of our application to allow for calculation of the reverse-complement if a toggle is set to "On".
Similar to the
--sequence input in task A you should now be able to handle the reverse-complement logic
if args.rc == "yes". Now if the toggle is true, first map A -> T, T -> A, C -> G and G-> C, then replace all T’s
with U’s and
To further advance the application we can extend it to support a file input. In this case we wish to read from a FASTA file. For an example of FASTA sequence input see: www.cbs.dtu.dk/services/NetGene2/fasta.php
--sequence input from task A, we simply change the render type to
Text File Input, which allows the
user to either paste text or select a file on their computer.
Now modify the Python code to use
biopython to read the FASTA file (hint:
from Bio import SeqIO)
The tool we have just built looks like a traditional web server, and feels like a traditional web server. However, unlike a traditional web server, when a user runs the tool we have just built, the algorithm is actually computed locally on their machine! This means a) no hosting costs; and b) the tool can be used for analyzing even the most sensitive data as no input data ever leaves the machine 🙌