Spaces:
Running
Running
supercat666
commited on
Commit
•
5befd90
1
Parent(s):
cce495d
fix plot
Browse files
app.py
CHANGED
@@ -180,62 +180,62 @@ if selected_model == 'Cas9':
|
|
180 |
# Optionally print or log the problematic data for debugging:
|
181 |
print(st.session_state['on_target_results'])
|
182 |
|
183 |
-
#
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
#
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
#
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
#
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
#
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
#
|
238 |
-
|
239 |
|
240 |
# if 'gene_sequence' in st.session_state and st.session_state['gene_sequence']:
|
241 |
# gene_symbol = st.session_state['current_gene_symbol']
|
|
|
180 |
# Optionally print or log the problematic data for debugging:
|
181 |
print(st.session_state['on_target_results'])
|
182 |
|
183 |
+
# Initialize Plotly figure
|
184 |
+
fig = go.Figure()
|
185 |
+
|
186 |
+
EXON_BASE = 0 # Base position for exons and CDS on the Y axis
|
187 |
+
EXON_HEIGHT = 0.02 # How 'tall' the exon markers should appear
|
188 |
+
|
189 |
+
# Plot Exons as small markers on the X-axis
|
190 |
+
for exon in st.session_state['exons']:
|
191 |
+
exon_start, exon_end = exon['start'], exon['end']
|
192 |
+
fig.add_trace(go.Bar(
|
193 |
+
x=[(exon_start + exon_end) / 2],
|
194 |
+
y=[EXON_HEIGHT],
|
195 |
+
width=[exon_end - exon_start],
|
196 |
+
base=EXON_BASE,
|
197 |
+
marker_color='rgba(128, 0, 128, 0.5)',
|
198 |
+
name='Exon'
|
199 |
+
))
|
200 |
+
|
201 |
+
VERTICAL_GAP = 0.2 # Gap between different ranks
|
202 |
+
|
203 |
+
# Define max and min Y values based on strand and rank
|
204 |
+
MAX_STRAND_Y = 0.1 # Maximum Y value for positive strand results
|
205 |
+
MIN_STRAND_Y = -0.1 # Minimum Y value for negative strand results
|
206 |
+
|
207 |
+
# Iterate over top 5 sorted predictions to create the plot
|
208 |
+
for i, prediction in enumerate(st.session_state['on_target_results'][:5], start=1): # Only top 5
|
209 |
+
chrom, start, end, strand, transcript, exon, target, gRNA, prediction_score = prediction
|
210 |
+
midpoint = (int(start) + int(end)) / 2
|
211 |
+
|
212 |
+
# Vertical position based on rank, modified by strand
|
213 |
+
y_value = (MAX_STRAND_Y - (i - 1) * VERTICAL_GAP) if strand == '1' or strand == '+' else (
|
214 |
+
MIN_STRAND_Y + (i - 1) * VERTICAL_GAP)
|
215 |
+
|
216 |
+
fig.add_trace(go.Scatter(
|
217 |
+
x=[midpoint],
|
218 |
+
y=[y_value],
|
219 |
+
mode='markers+text',
|
220 |
+
marker=dict(symbol='triangle-up' if strand == '1' or strand == '+' else 'triangle-down',
|
221 |
+
size=12),
|
222 |
+
text=f"Rank: {i}", # Text label
|
223 |
+
hoverinfo='text',
|
224 |
+
hovertext=f"Rank: {i}<br>Chromosome: {chrom}<br>Target Sequence: {target}<br>gRNA: {gRNA}<br>Start: {start}<br>End: {end}<br>Strand: {'+' if strand == '1' or strand == '+' else '-'}<br>Transcript: {transcript}<br>Prediction: {prediction_score:.4f}",
|
225 |
+
))
|
226 |
+
|
227 |
+
# Update layout for clarity and interaction
|
228 |
+
fig.update_layout(
|
229 |
+
title='Top 5 gRNA Sequences by Prediction Score',
|
230 |
+
xaxis_title='Genomic Position',
|
231 |
+
yaxis_title='Strand',
|
232 |
+
yaxis=dict(tickvals=[MAX_STRAND_Y, MIN_STRAND_Y], ticktext=['+', '-']),
|
233 |
+
showlegend=False,
|
234 |
+
hovermode='x unified',
|
235 |
+
)
|
236 |
+
|
237 |
+
# Display the plot
|
238 |
+
st.plotly_chart(fig)
|
239 |
|
240 |
# if 'gene_sequence' in st.session_state and st.session_state['gene_sequence']:
|
241 |
# gene_symbol = st.session_state['current_gene_symbol']
|