Cookies ๐Ÿช

We use cookies to ensure you the best possible experience when using BioLib. To read our privacy policy and configure what cookies are set, click on cookie settings below.


March 18, 2021

Workshop โ€“ Creating a DNA to RNA web server ๐Ÿงฌ

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.

Today's Goal:

Create a simple Python based web server for transcribing DNA to RNA.

Task A - Create the web server

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 print.

Step 0 - Create an application

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.

Step 1 - Ask the user for an input sequence

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.

input sequence

Step 2 - Read the input sequence

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 previous step.

# 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.

app start

Step 3 - Transcribe the DNA to RNA

Now write some Python code that transcribes the DNA sequence to RNA, and outputs the results with print.

Task B - Implement a reverse-complement feature

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".

Step 1 - Add toggle switch input

input rc

Step 2 - Write the Python code

Similar to the --sequence input in task A you should now be able to handle the reverse-complement logic with 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 print the final string.

Task C - Accept FASTA file as input

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

Step 1 - Ask user for text file input

Keeping the --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.

Step 2 - Modify the Python code to support FASTA sequences

Now modify the Python code to use biopython to read the FASTA file (hint: from Bio import SeqIO)


That's it, you've made a Python based web application! ๐Ÿš€

app final


What about server hosting and data security?

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 ๐Ÿ™Œ