Creating a super cool web app in python using streamlit.
It counts the input Nucleotide DNA query and displays it in several ways.
Here is the Web App -
Here is the code ->
import pandas as pdimport streamlit as stfrom PIL import Imageimport numpy as npimport altair as altimport matplotlibmatplotlib.use('TkAgg')import matplotlib.pyplot as plot
#import imageimage1 = Image.open("C:/data/dna3.jpg")st.image(image1, use_column_width=True)
#page titlest.write(""" # DNA Nucleotide Count Web App
This app counts the nucleotide composition of query DNA
*** """)
# input text boxst.header("Enter DNA Sequence")
# text-areasequence_input = "DNA QUERY\nAGCTTTTCATTCTGACTGCAAC\nGGGCAATATGTCTCTGTGTGGATTAA\nAAAAAGAGTGTCTGATAGCAGC"sequence = st.text_area("Sequence Input", sequence_input, height=250)sequence = sequence.splitlines()sequence = sequence[1:] # DNA QUERY text is omitted from sequencesequence = "".join(sequence)
st.write(""" *** """)
st.header("Input (DNA Query)")st.write(sequence)
st.header("Output (DNA Nucleotide Count)")
#print dictionaryst.subheader("Print Dictionary")def count_dna(seq): data = dict([ ("A", seq.count("A")), ("T", seq.count("T")), ("C", seq.count("C")), ("G", seq.count("G")), ]) return data
x= count_dna(sequence)st.write(x)st.write("\n")
#print textst.subheader("Print Text")st.write("\n")st.write("there are " + str(x["A"]) + "adenine(A)")st.write("there are " + str(x["T"]) + "thymine(T)")st.write("there are " + str(x["C"]) + "cytosine(C)")st.write("there are " + str(x["G"]) + "guanine(G)")st.write("\n")# print dataframest.subheader("Print Dataframe")
d = list(x. items())an_array = np. array(d)df = pd.DataFrame(an_array)
df.rename(columns = {0:'Nucleotide', 1: "Count"}, inplace = True)dfst.write("\n")
#Creating bar chart using altair
st.header("Print Bar Chart - Altair")
df["Count"]=df["Count"].astype(float)
chart = alt.Chart(df).mark_bar().encode( alt.X("Nucleotide"), y='Count',).interactive()chart = chart.properties(width = alt.Step(80))st.altair_chart(chart)st.write("\n")
#Creating bar chart using matlpotlib
st.header("Print Bar Chart - Matplotlib")
ax = df.plot.bar(x='Nucleotide', y='Count', rot=0)plot.savefig("C:/data/mygraph.png")image2 = Image.open("C:/data/mygraph.png")st.image(image2, use_column_width=True)
0 Comments