Skip to content

Commit 92cf826

Browse files
Update DNA sequence analyzer with Plotly visuals
Refactored DNA analysis app with updated input handling and enhanced visualizations.
1 parent 35bb75c commit 92cf826

1 file changed

Lines changed: 46 additions & 23 deletions

File tree

app.py

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,52 @@
1-
import streamlit as str
1+
import streamlit as st
2+
import plotly.express as px
3+
import pandas as pd
24

3-
str.set_page_config(page_title="Bioinformatics Aligner", page_icon="🧬")
5+
st.set_page_config(page_title="Bioinformatics Aligner", page_icon="🧬")
46

5-
str.title("🧬 Advanced DNA Sequence Checker")
6-
str.write("Built by Siddharth-lab-cmd")
7+
st.title("🧬 Advanced DNA Analyzer & Visualizer")
8+
st.write("Built with tactical precision by Siddharth-lab-cmd")
79

8-
seq1 = str.text_input("Enter DNA Sequence 1:", "ATCGATCG").upper()
9-
seq2 = str.text_input("Enter DNA Sequence 2:", "ATGGATCG").upper()
10+
# Input field for DNA
11+
seq = st.text_input("Enter DNA Sequence to Analyze:", "ATCGATCGATGGATCGATCG").upper()
1012

11-
if str.button("Analyze Match"):
12-
if len(seq1) != len(seq2):
13-
str.error("For a simple match check, both sequences must be the same length!")
13+
# Core calculation logic
14+
if st.button("Run Analytics"):
15+
# 1. Calculate length and counts
16+
total_length = len(seq)
17+
a_count = seq.count("A")
18+
t_count = seq.count("T")
19+
c_count = seq.count("C")
20+
g_count = seq.count("G")
21+
22+
# 2. Check for empty or invalid inputs
23+
if total_length == 0:
24+
st.error("Please enter a valid DNA sequence!")
1425
else:
15-
matches = 0
16-
visual_line = ""
17-
for i in range(len(seq1)):
18-
if seq1[i] == seq2[i]:
19-
matches += 1
20-
visual_line += "|"
21-
else:
22-
visual_line += "."
23-
24-
identity = (matches / len(seq1)) * 100
26+
gc_total = g_count + c_count
27+
gc_percentage = (gc_total / total_length) * 100
2528

26-
str.success(f"Analysis Complete! Identity Score: {identity:.2f}%")
27-
str.text(f"Seq 1: {seq1}")
28-
str.text(f"Match: {visual_line}")
29-
str.text(f"Seq 2: {seq2}")
29+
# Display text matrix scores
30+
st.success("Analysis Complete!")
31+
st.write(f"**Total Base Pairs:** {total_length}")
32+
st.write(f"**GC Content Percentage:** {gc_percentage:.2f}%")
33+
34+
# 3. Create the Plotly Data Frame Table
35+
data = {
36+
'Nucleotide': ['Adenine (A)', 'Thymine (T)', 'Cytosine (C)', 'Guanine (G)'],
37+
'Count': [a_count, t_count, c_count, g_count]
38+
}
39+
df = pd.DataFrame(data)
40+
41+
# 4. Generate Interactive Plotly Bar Chart
42+
fig = px.bar(
43+
df,
44+
x='Nucleotide',
45+
y='Count',
46+
title="DNA Base Distribution Frequency",
47+
color='Nucleotide',
48+
labels={'Count': 'Number of Bases'}
49+
)
50+
51+
# Render the interactive chart on our Streamlit site
52+
st.plotly_chart(fig)

0 commit comments

Comments
 (0)