Homework02Task2 / app.py
Zach-Of-All-Trades's picture
Create app.py
4dad5f5
raw
history blame
2.3 kB
import gradio as gr
def find_complimentary_dna(dna_to_compliemnt):
_complement_seq = ''
for pos in range(0,len(dna_to_compliemnt)):
_last_char = dna_to_compliemnt[len(dna_to_compliemnt)-pos-1]
if _last_char == 'A':
_complement_seq = _complement_seq + 'A'
elif _last_char == 'T':
_complement_seq = _complement_seq + 'U'
elif _last_char == 'G':
_complement_seq = _complement_seq + 'G'
elif _last_char == 'C':
_complement_seq = _complement_seq + 'C'
return _complement_seq
def get_protein_from_DNA(DNA):
reading_frames =transcribe(DNA)
orf_list = []
for i in range(len(reading_frames)):
mRNA = reading_frames[i]
one_letter=''
found_start = False
for codon in mRNA:
if codon =='AUG' and not found_start:
one_letter += '<'
found_start = True
if codon =='UAA' or codon=='UGA'or codon =='UAG':
if found_start:
one_letter += '>'
found_start = False
continue
one_letter += AA_mapping[translate[codon]]
# mark the valid orf found
if one_letter.find('M') != -1:
one_letter = '*' + one_letter + '>'
orf_list.append(one_letter)
r = " * means the ORF sequence exists and highlighted in as <>; \n5'to 3' Frame 1:"+ orf_list[0] +"\n5'to 3' Frame 2:" + orf_list[1] + "\n5'to 3' Frame 3:" + orf_list[2] + "\n3'to 5' Frame 1:" + orf_list[3] + "\n3'to 5' Frame 2:" + orf_list[4] + "\n3'to 5' Frame 3:"+orf_list[5]
return DNA, find_complimentary_dna(DNA), r
input1 = gr.inputs.Textbox(label = 'DNA sequence')
output1 = gr.outputs.Textbox(label = 'Primary Sequence')
output2 = gr.outputs.Textbox(label = 'Complimentary Sequence')
output3 = gr.outputs.Textbox(label = 'Open Reading Frames')
interface = gr.Interface(fn=get_protein_from_DNA,
inputs=input1,
outputs=[output1,output2,output3],
title="CSCI1020: Web Application for Transcription/Translation",
description= "A quick tool for translating a DNA sequence into a protein sequence",
theme = 'huggingface',
layout = 'vertical'
)
interface.launch()