Skip to content

Commit 1cc839c

Browse files
Add files via upload
1 parent 48b3f46 commit 1cc839c

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

‎streamlit/dna-app.py‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
######################
2+
# Import libraries
3+
######################
4+
5+
import pandas as pd
6+
import streamlit as st
7+
import altair as alt
8+
from PIL import Image
9+
10+
######################
11+
# Page Title
12+
######################
13+
14+
image = Image.open('dna-logo.jpg')
15+
16+
st.image(image, use_column_width=True)
17+
18+
st.write("""
19+
# DNA Nucleotide Count Web App
20+
21+
This app counts the nucleotide composition of query DNA!
22+
23+
***
24+
""")
25+
26+
27+
######################
28+
# Input Text Box
29+
######################
30+
31+
#st.sidebar.header('Enter DNA sequence')
32+
st.header('Enter DNA sequence')
33+
34+
sequence_input = ">DNA Query 2\nGAACACGTGGAGGCAAACAGGAAGGTGAAGAAGAACTTATCCTATCAGGACGGAAGGTCCTGTGCTCGGG\nATCTTCCAGACGTCGCGACTCTAAATTGCCCCCTCTGAGGTCAAGGAACACAAGATGGTTTTGGAAATGC\nTGAACCCGATACATTATAACATCACCAGCATCGTGCCTGAAGCCATGCCTGCTGCCACCATGCCAGTCCT"
35+
36+
#sequence = st.sidebar.text_area("Sequence input", sequence_input, height=250)
37+
sequence = st.text_area("Sequence input", sequence_input, height=250)
38+
sequence = sequence.splitlines()
39+
sequence = sequence[1:] # Skips the sequence name (first line)
40+
sequence = ''.join(sequence) # Concatenates list to string
41+
42+
st.write("""
43+
***
44+
""")
45+
46+
## Prints the input DNA sequence
47+
st.header('INPUT (DNA Query)')
48+
sequence
49+
50+
## DNA nucleotide count
51+
st.header('OUTPUT (DNA Nucleotide Count)')
52+
53+
### 1. Print dictionary
54+
st.subheader('1. Print dictionary')
55+
def DNA_nucleotide_count(seq):
56+
d = dict([
57+
('A',seq.count('A')),
58+
('T',seq.count('T')),
59+
('G',seq.count('G')),
60+
('C',seq.count('C'))
61+
])
62+
return d
63+
64+
X = DNA_nucleotide_count(sequence)
65+
66+
#X_label = list(X)
67+
#X_values = list(X.values())
68+
69+
X
70+
71+
### 2. Print text
72+
st.subheader('2. Print text')
73+
st.write('There are ' + str(X['A']) + ' adenine (A)')
74+
st.write('There are ' + str(X['T']) + ' thymine (T)')
75+
st.write('There are ' + str(X['G']) + ' guanine (G)')
76+
st.write('There are ' + str(X['C']) + ' cytosine (C)')
77+
78+
### 3. Display DataFrame
79+
st.subheader('3. Display DataFrame')
80+
df = pd.DataFrame.from_dict(X, orient='index')
81+
df = df.rename({0: 'count'}, axis='columns')
82+
df.reset_index(inplace=True)
83+
df = df.rename(columns = {'index':'nucleotide'})
84+
st.write(df)
85+
86+
### 4. Display Bar Chart using Altair
87+
st.subheader('4. Display Bar chart')
88+
p = alt.Chart(df).mark_bar().encode(
89+
x='nucleotide',
90+
y='count'
91+
)
92+
p = p.properties(
93+
width=alt.Step(80) # controls width of bar.
94+
)
95+
st.write(p)

0 commit comments

Comments
 (0)