Spaces:
Running
Running
supercat666
commited on
Commit
•
743d44b
1
Parent(s):
4e09368
fix
Browse files
app.py
CHANGED
@@ -190,77 +190,66 @@ if selected_model == 'Cas9':
|
|
190 |
# Initialize Plotly figure
|
191 |
fig = go.Figure()
|
192 |
|
193 |
-
#
|
194 |
-
|
195 |
-
|
196 |
-
Y_POS = -0.1 # Position on the Y axis to place these markers
|
197 |
|
198 |
-
#
|
|
|
|
|
|
|
199 |
for exon in st.session_state['exons']:
|
200 |
exon_start, exon_end = exon['start'], exon['end']
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
width=
|
206 |
-
base=[Y_POS],
|
207 |
-
marker_color='purple',
|
208 |
name='Exon'
|
209 |
))
|
210 |
|
211 |
-
#
|
212 |
for cds in st.session_state['cds']:
|
213 |
cds_start, cds_end = cds['start'], cds['end']
|
214 |
-
fig.add_trace(go.
|
215 |
-
x=[
|
216 |
-
y=[
|
217 |
-
|
218 |
-
|
219 |
-
marker_color='blue',
|
220 |
name='CDS'
|
221 |
))
|
222 |
|
223 |
-
|
224 |
-
#
|
225 |
-
|
226 |
-
negative_strand_y = -0.1
|
227 |
-
offset = 0.05 # Use an offset to spread gRNA sequences vertically
|
228 |
|
229 |
-
# Iterate over
|
230 |
for i, prediction in enumerate(st.session_state['on_target_results'], start=1):
|
231 |
chrom, start, end, strand, target, gRNA, pred_score = prediction
|
232 |
-
|
233 |
midpoint = (int(start) + int(end)) / 2
|
234 |
-
|
|
|
|
|
235 |
|
236 |
fig.add_trace(go.Scatter(
|
237 |
x=[midpoint],
|
238 |
y=[y_value],
|
239 |
mode='markers+text',
|
240 |
marker=dict(symbol='triangle-up' if strand == '1' else 'triangle-down', size=12),
|
241 |
-
text=f"Rank: {i}", #
|
242 |
hoverinfo='text',
|
243 |
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' else '-'}<br>Prediction Score: {pred_score:.4f}",
|
244 |
))
|
245 |
|
246 |
-
# Update
|
247 |
fig.update_layout(
|
248 |
title='Top 10 gRNA Sequences by Prediction Score',
|
249 |
xaxis_title='Genomic Position',
|
250 |
yaxis_title='Strand',
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
spikesnap='cursor',
|
256 |
-
spikethickness=1,
|
257 |
-
spikecolor='grey',
|
258 |
-
showline=True,
|
259 |
-
showgrid=True,
|
260 |
-
tickformat='.2f', # Adjust based on the precision you need
|
261 |
-
),
|
262 |
-
hovermode='x',
|
263 |
-
hoverdistance=100, # Adjust for best hover interaction
|
264 |
)
|
265 |
|
266 |
# Display the plot
|
|
|
190 |
# Initialize Plotly figure
|
191 |
fig = go.Figure()
|
192 |
|
193 |
+
# Adjust these constants for appearance
|
194 |
+
LINE_WIDTH = 2 # Width of EXON and CDS lines
|
195 |
+
EXON_OPACITY = 0.5 # Make exon lines semi-transparent
|
|
|
196 |
|
197 |
+
# Ensure EXON and CDS are drawn at the same Y position on the X-axis
|
198 |
+
EXON_CDS_Y_POS = 0 # Directly on the X-axis
|
199 |
+
|
200 |
+
# Draw EXONs
|
201 |
for exon in st.session_state['exons']:
|
202 |
exon_start, exon_end = exon['start'], exon['end']
|
203 |
+
fig.add_trace(go.Scatter(
|
204 |
+
x=[exon_start, exon_end],
|
205 |
+
y=[EXON_CDS_Y_POS, EXON_CDS_Y_POS],
|
206 |
+
mode='lines',
|
207 |
+
line=dict(color='purple', width=LINE_WIDTH, opacity=EXON_OPACITY),
|
|
|
|
|
208 |
name='Exon'
|
209 |
))
|
210 |
|
211 |
+
# Draw CDSs
|
212 |
for cds in st.session_state['cds']:
|
213 |
cds_start, cds_end = cds['start'], cds['end']
|
214 |
+
fig.add_trace(go.Scatter(
|
215 |
+
x=[cds_start, cds_end],
|
216 |
+
y=[EXON_CDS_Y_POS, EXON_CDS_Y_POS],
|
217 |
+
mode='lines',
|
218 |
+
line=dict(color='blue', width=LINE_WIDTH + 1), # Slightly thicker than EXON
|
|
|
219 |
name='CDS'
|
220 |
))
|
221 |
|
222 |
+
# Adjust hover interaction and strand plotting
|
223 |
+
MAX_STRAND_Y = 0.5 # Maximum Y value for positive strand
|
224 |
+
MIN_STRAND_Y = -0.5 # Minimum Y value for negative strand
|
|
|
|
|
225 |
|
226 |
+
# Iterate over sorted predictions to create the plot
|
227 |
for i, prediction in enumerate(st.session_state['on_target_results'], start=1):
|
228 |
chrom, start, end, strand, target, gRNA, pred_score = prediction
|
|
|
229 |
midpoint = (int(start) + int(end)) / 2
|
230 |
+
|
231 |
+
# Position based on strand, but within a fixed range
|
232 |
+
y_value = MAX_STRAND_Y if strand == '1' else MIN_STRAND_Y
|
233 |
|
234 |
fig.add_trace(go.Scatter(
|
235 |
x=[midpoint],
|
236 |
y=[y_value],
|
237 |
mode='markers+text',
|
238 |
marker=dict(symbol='triangle-up' if strand == '1' else 'triangle-down', size=12),
|
239 |
+
text=f"Rank: {i}", # Text label
|
240 |
hoverinfo='text',
|
241 |
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' else '-'}<br>Prediction Score: {pred_score:.4f}",
|
242 |
))
|
243 |
|
244 |
+
# Update layout for clarity and interaction
|
245 |
fig.update_layout(
|
246 |
title='Top 10 gRNA Sequences by Prediction Score',
|
247 |
xaxis_title='Genomic Position',
|
248 |
yaxis_title='Strand',
|
249 |
+
yaxis=dict(range=[MIN_STRAND_Y - 0.1, MAX_STRAND_Y + 0.1]), # Fix y-axis range
|
250 |
+
showlegend=False,
|
251 |
+
hovermode='closest', # Adjust hover mode
|
252 |
+
hoverdistance=20, # Reduce hover distance to improve accuracy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
)
|
254 |
|
255 |
# Display the plot
|