Update app.py
Browse files
app.py
CHANGED
|
@@ -72,26 +72,21 @@ def add_protein_features(cds_info):
|
|
| 72 |
return cds_info
|
| 73 |
|
| 74 |
# Function to generate genome diagram
|
| 75 |
-
def create_genome_diagram(genbank_content, output_file_path,
|
| 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
|
| 86 |
-
|
| 87 |
-
|
| 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 |
|
|
|
|
| 95 |
# Streamlit UI setup
|
| 96 |
st.set_page_config(page_title="Genomic Data Dashboard", page_icon="🧬", layout="wide")
|
| 97 |
uploaded_file = st.file_uploader("Upload a GenBank file", type=['gb', 'gbk'])
|
|
@@ -111,9 +106,13 @@ if uploaded_file is not None:
|
|
| 111 |
|
| 112 |
# Sidebar options for diagram customization
|
| 113 |
with st.sidebar:
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
|
| 119 |
# Main content
|
|
@@ -142,6 +141,15 @@ if uploaded_file is not None:
|
|
| 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)
|
|
|
|
| 72 |
return cds_info
|
| 73 |
|
| 74 |
# Function to generate genome diagram
|
| 75 |
+
def create_genome_diagram(genbank_content, output_file_path, display_features, colors):
|
| 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 |
for feature in record.features:
|
| 82 |
+
if feature.type in display_features:
|
| 83 |
+
feature_color = colors.get(feature.type, colors['default']) # Get color, default if not found
|
| 84 |
+
gd_feature_set.add_feature(feature, color=feature_color, label=True, label_size=10, label_angle=0)
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
gd_diagram.draw(format="circular", circular=True, pagesize=(20*cm, 20*cm), start=0, end=len(record), circle_core=0.7)
|
| 87 |
gd_diagram.write(output_file_path, "SVG")
|
| 88 |
|
| 89 |
+
|
| 90 |
# Streamlit UI setup
|
| 91 |
st.set_page_config(page_title="Genomic Data Dashboard", page_icon="🧬", layout="wide")
|
| 92 |
uploaded_file = st.file_uploader("Upload a GenBank file", type=['gb', 'gbk'])
|
|
|
|
| 106 |
|
| 107 |
# Sidebar options for diagram customization
|
| 108 |
with st.sidebar:
|
| 109 |
+
# Sidebar options for color customization
|
| 110 |
+
color_gene = st.color_picker("Gene color", '#ff9999')
|
| 111 |
+
color_cds = st.color_picker("CDS color", '#66b3ff')
|
| 112 |
+
color_trna = st.color_picker("tRNA color", '#99ff99')
|
| 113 |
+
color_rrna = st.color_picker("rRNA color", '#f1c40f')
|
| 114 |
+
# Option to select what to display on the diagram
|
| 115 |
+
display_options = st.multiselect("Select features to display:", ['gene', 'tRNA', 'CDS', 'rRNA'], default=['gene', 'CDS'])
|
| 116 |
|
| 117 |
|
| 118 |
# Main content
|
|
|
|
| 141 |
kmers = calculate_kmers(sequence, k) # Ensure this function is defined as per previous instructions
|
| 142 |
st.bar_chart(pd.DataFrame.from_dict(kmers, orient='index', columns=['Frequency']).sort_values('Frequency', ascending=False).head(20))
|
| 143 |
|
| 144 |
+
# Construct the colors dictionary
|
| 145 |
+
feature_colors = {
|
| 146 |
+
'gene': color_gene,
|
| 147 |
+
'CDS': color_cds,
|
| 148 |
+
'tRNA': color_trna,
|
| 149 |
+
'rRNA': color_rrna,
|
| 150 |
+
'default': '#cccccc' # Default color if needed
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
# Generate and display genome diagram with user-selected options
|
| 154 |
output_file_path_svg = os.path.join(temp_dir, "genome_diagram.svg")
|
| 155 |
create_genome_diagram(uploaded_file.getvalue().decode("utf-8"), output_file_path_svg, feature_selection, diagram_color_1, diagram_color_2)
|