Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from Bio import SeqIO
|
|
| 5 |
from Bio.SeqUtils.ProtParam import ProteinAnalysis
|
| 6 |
from Bio.Graphics import GenomeDiagram
|
| 7 |
from reportlab.lib.colors import Color, lightblue, blue
|
|
|
|
| 8 |
from reportlab.lib.units import cm
|
| 9 |
from io import StringIO
|
| 10 |
from collections import Counter
|
|
@@ -71,19 +72,23 @@ def add_protein_features(cds_info):
|
|
| 71 |
return cds_info
|
| 72 |
|
| 73 |
# Function to generate genome diagram
|
| 74 |
-
def create_genome_diagram(genbank_content, output_file_path):
|
| 75 |
record = SeqIO.read(StringIO(genbank_content), "genbank")
|
| 76 |
gd_diagram = GenomeDiagram.Diagram(record.id)
|
| 77 |
gd_track_for_features = gd_diagram.new_track(1, name="Annotated Features")
|
| 78 |
gd_feature_set = gd_track_for_features.new_set()
|
| 79 |
|
|
|
|
|
|
|
|
|
|
| 80 |
for feature in record.features:
|
| 81 |
-
if feature.type
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
# Change the output format to SVG
|
| 87 |
gd_diagram.draw(format="circular", circular=True, pagesize=(20*cm, 20*cm), start=0, end=len(record), circle_core=0.7)
|
| 88 |
gd_diagram.write(output_file_path, "SVG")
|
| 89 |
|
|
@@ -104,6 +109,13 @@ if uploaded_file is not None:
|
|
| 104 |
window_size = st.number_input('GC content sliding window size', min_value=100, max_value=10000, value=1000)
|
| 105 |
k = st.number_input('k-mer size', min_value=1, max_value=10, value=6)
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
# Main content
|
| 108 |
col1, col2 = st.columns(2)
|
| 109 |
with col1:
|
|
@@ -130,11 +142,11 @@ if uploaded_file is not None:
|
|
| 130 |
kmers = calculate_kmers(sequence, k) # Ensure this function is defined as per previous instructions
|
| 131 |
st.bar_chart(pd.DataFrame.from_dict(kmers, orient='index', columns=['Frequency']).sort_values('Frequency', ascending=False).head(20))
|
| 132 |
|
| 133 |
-
# Generate and display genome diagram
|
| 134 |
output_file_path_svg = os.path.join(temp_dir, "genome_diagram.svg")
|
| 135 |
-
create_genome_diagram(uploaded_file.getvalue().decode("utf-8"), output_file_path_svg)
|
| 136 |
st.image(output_file_path_svg, caption='Genome Diagram')
|
| 137 |
-
|
| 138 |
# Additional Information
|
| 139 |
with st.expander("View All Genes"):
|
| 140 |
st.dataframe(gene_df)
|
|
|
|
| 5 |
from Bio.SeqUtils.ProtParam import ProteinAnalysis
|
| 6 |
from Bio.Graphics import GenomeDiagram
|
| 7 |
from reportlab.lib.colors import Color, lightblue, blue
|
| 8 |
+
from reportlab.lib import colors
|
| 9 |
from reportlab.lib.units import cm
|
| 10 |
from io import StringIO
|
| 11 |
from collections import Counter
|
|
|
|
| 72 |
return cds_info
|
| 73 |
|
| 74 |
# Function to generate genome diagram
|
| 75 |
+
def create_genome_diagram(genbank_content, output_file_path, selected_features, color_1, color_2):
|
| 76 |
record = SeqIO.read(StringIO(genbank_content), "genbank")
|
| 77 |
gd_diagram = GenomeDiagram.Diagram(record.id)
|
| 78 |
gd_track_for_features = gd_diagram.new_track(1, name="Annotated Features")
|
| 79 |
gd_feature_set = gd_track_for_features.new_set()
|
| 80 |
|
| 81 |
+
color_1 = colors.HexColor(color_1)
|
| 82 |
+
color_2 = colors.HexColor(color_2)
|
| 83 |
+
|
| 84 |
for feature in record.features:
|
| 85 |
+
if feature.type in selected_features:
|
| 86 |
+
if len(gd_feature_set) % 2 == 0:
|
| 87 |
+
color = color_1
|
| 88 |
+
else:
|
| 89 |
+
color = color_2
|
| 90 |
+
gd_feature_set.add_feature(feature, color=color, label=True, label_size=10, label_angle=0)
|
| 91 |
|
|
|
|
| 92 |
gd_diagram.draw(format="circular", circular=True, pagesize=(20*cm, 20*cm), start=0, end=len(record), circle_core=0.7)
|
| 93 |
gd_diagram.write(output_file_path, "SVG")
|
| 94 |
|
|
|
|
| 109 |
window_size = st.number_input('GC content sliding window size', min_value=100, max_value=10000, value=1000)
|
| 110 |
k = st.number_input('k-mer size', min_value=1, max_value=10, value=6)
|
| 111 |
|
| 112 |
+
# Sidebar options for diagram customization
|
| 113 |
+
with st.sidebar:
|
| 114 |
+
diagram_color_1 = st.color_picker("Pick a color for features (odd positions)", '#ff9999')
|
| 115 |
+
diagram_color_2 = st.color_picker("Pick a color for features (even positions)", '#66b3ff')
|
| 116 |
+
feature_selection = st.multiselect("Select features to display:", ['gene', 'tRNA', 'CDS', 'rRNA'], default=['gene', 'CDS'])
|
| 117 |
+
|
| 118 |
+
|
| 119 |
# Main content
|
| 120 |
col1, col2 = st.columns(2)
|
| 121 |
with col1:
|
|
|
|
| 142 |
kmers = calculate_kmers(sequence, k) # Ensure this function is defined as per previous instructions
|
| 143 |
st.bar_chart(pd.DataFrame.from_dict(kmers, orient='index', columns=['Frequency']).sort_values('Frequency', ascending=False).head(20))
|
| 144 |
|
| 145 |
+
# Generate and display genome diagram with user-selected options
|
| 146 |
output_file_path_svg = os.path.join(temp_dir, "genome_diagram.svg")
|
| 147 |
+
create_genome_diagram(uploaded_file.getvalue().decode("utf-8"), output_file_path_svg, feature_selection, diagram_color_1, diagram_color_2)
|
| 148 |
st.image(output_file_path_svg, caption='Genome Diagram')
|
| 149 |
+
|
| 150 |
# Additional Information
|
| 151 |
with st.expander("View All Genes"):
|
| 152 |
st.dataframe(gene_df)
|