supercat666 commited on
Commit
fcd198b
1 Parent(s): a5f860b

using plotly

Browse files
Files changed (2) hide show
  1. app.py +30 -19
  2. requirements.txt +1 -0
app.py CHANGED
@@ -4,6 +4,7 @@ import cas9on
4
  import cas9off
5
  import pandas as pd
6
  import streamlit as st
 
7
  import numpy as np
8
  from pathlib import Path
9
  from igv_component import igv_component
@@ -93,37 +94,47 @@ if selected_model == 'Cas9':
93
  )
94
 
95
  if target_selection == 'on-target':
 
96
  gene_symbol = st.text_input('Enter a Gene Symbol:', key='gene_symbol')
97
 
98
- # Add genome reference selection
99
- genome_reference = st.selectbox('Select a Genome Reference:', ['hg19', 'hg38'], key='genome_reference')
100
-
101
  predict_button = st.button('Predict on-target')
102
 
 
103
  if predict_button and gene_symbol:
104
  predictions = cas9on.process_gene(gene_symbol, cas9on_path)
105
- st.session_state['on_target_results'] = predictions[:10]
106
- st.session_state['full_on_target_results'] = predictions
 
107
 
 
108
  if 'on_target_results' in st.session_state and st.session_state['on_target_results']:
109
- # Convert non-serializable types (like numpy float32) to Python native types
110
- crispr_results_serializable = [
111
- [item if not isinstance(item, np.floating) else float(item) for item in row]
112
- for row in st.session_state['on_target_results']
113
- ]
114
-
115
- # Pass the serializable results to the IGV component
116
- igv_component(crispr_results=crispr_results_serializable,
117
- genome_reference=genome_reference,
118
- gene_symbol=gene_symbol,
119
- key="igv_viewer")
120
-
 
 
 
 
121
  if 'full_on_target_results' in st.session_state:
122
  full_df = pd.DataFrame(st.session_state['full_on_target_results'],
123
  columns=["Gene ID", "Start Pos", "End Pos", "Strand", "gRNA", "Prediction"])
124
  full_predictions_csv = full_df.to_csv(index=False).encode('utf-8')
125
- st.download_button(label='Download on-target predictions', data=full_predictions_csv,
126
- file_name='on_target_results.csv', mime='text/csv')
 
 
 
 
127
 
128
  elif target_selection == 'off-target':
129
  ENTRY_METHODS = dict(
 
4
  import cas9off
5
  import pandas as pd
6
  import streamlit as st
7
+ import plotly.express as px
8
  import numpy as np
9
  from pathlib import Path
10
  from igv_component import igv_component
 
94
  )
95
 
96
  if target_selection == 'on-target':
97
+ # Gene symbol entry
98
  gene_symbol = st.text_input('Enter a Gene Symbol:', key='gene_symbol')
99
 
100
+ # Prediction button
 
 
101
  predict_button = st.button('Predict on-target')
102
 
103
+ # Process predictions
104
  if predict_button and gene_symbol:
105
  predictions = cas9on.process_gene(gene_symbol, cas9on_path)
106
+ # Sort predictions by the 'Prediction' score in descending order and take the top 10
107
+ sorted_predictions = sorted(predictions, key=lambda x: x[-1], reverse=True)[:10]
108
+ st.session_state['on_target_results'] = sorted_predictions
109
 
110
+ # On-target results display
111
  if 'on_target_results' in st.session_state and st.session_state['on_target_results']:
112
+ # Convert the results to a pandas DataFrame for better display
113
+ df = pd.DataFrame(st.session_state['on_target_results'],
114
+ columns=["Gene ID", "Start Pos", "End Pos", "Strand", "gRNA", "Prediction"])
115
+ st.write('Top on-target predictions:')
116
+ st.dataframe(df)
117
+
118
+ # Plotting with Plotly
119
+ fig = px.bar(df, x='gRNA', y='Prediction', color='Prediction',
120
+ labels={'gRNA': 'Guide RNA', 'Prediction': 'Prediction Score'},
121
+ hover_data=['Start Pos', 'End Pos', 'Strand'])
122
+ fig.update_layout(title='Top 10 CRISPR Targets by Prediction Score',
123
+ xaxis_title='Guide RNA',
124
+ yaxis_title='Prediction Score')
125
+ st.plotly_chart(fig)
126
+
127
+ # Download button for full results
128
  if 'full_on_target_results' in st.session_state:
129
  full_df = pd.DataFrame(st.session_state['full_on_target_results'],
130
  columns=["Gene ID", "Start Pos", "End Pos", "Strand", "gRNA", "Prediction"])
131
  full_predictions_csv = full_df.to_csv(index=False).encode('utf-8')
132
+ st.download_button(
133
+ label='Download all on-target predictions',
134
+ data=full_predictions_csv,
135
+ file_name='on_target_results.csv',
136
+ mime='text/csv'
137
+ )
138
 
139
  elif target_selection == 'off-target':
140
  ENTRY_METHODS = dict(
requirements.txt CHANGED
@@ -3,3 +3,4 @@ biopython==1.80
3
  pandas==1.5.2
4
  tensorflow==2.11.0
5
  tensorflow-probability==0.19.0
 
 
3
  pandas==1.5.2
4
  tensorflow==2.11.0
5
  tensorflow-probability==0.19.0
6
+ plotly==5.18.0