supercat666 commited on
Commit
3c85094
1 Parent(s): fcd198b

add visualization

Browse files
Files changed (2) hide show
  1. app.py +17 -25
  2. requirements.txt +2 -1
app.py CHANGED
@@ -4,10 +4,10 @@ import cas9on
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
11
 
12
  # title and documentation
13
  st.markdown(Path('crisprTool.md').read_text(), unsafe_allow_html=True)
@@ -103,38 +103,30 @@ if selected_model == 'Cas9':
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(
 
4
  import cas9off
5
  import pandas as pd
6
  import streamlit as st
7
+ from pygenomeviz import GenomeViz
8
  import numpy as np
9
  from pathlib import Path
10
+
11
 
12
  # title and documentation
13
  st.markdown(Path('crisprTool.md').read_text(), unsafe_allow_html=True)
 
103
  # Process predictions
104
  if predict_button and gene_symbol:
105
  predictions = cas9on.process_gene(gene_symbol, cas9on_path)
 
106
  sorted_predictions = sorted(predictions, key=lambda x: x[-1], reverse=True)[:10]
107
  st.session_state['on_target_results'] = sorted_predictions
108
 
 
109
  if 'on_target_results' in st.session_state and st.session_state['on_target_results']:
 
110
  df = pd.DataFrame(st.session_state['on_target_results'],
111
  columns=["Gene ID", "Start Pos", "End Pos", "Strand", "gRNA", "Prediction"])
112
  st.write('Top on-target predictions:')
113
  st.dataframe(df)
114
 
115
+ # Initialize GenomeViz
116
+ gv = GenomeViz()
117
+ genome_size = max(
118
+ df["End Pos"]) # Assuming the max end position approximates the genome size for visualization purposes
119
+ track = gv.add_feature_track("CRISPR Targets", genome_size)
120
+
121
+ for _, row in df.iterrows():
122
+ start, end, strand = row["Start Pos"], row["End Pos"], row["Strand"]
123
+ label = row["gRNA"]
124
+ track.add_feature(start, end, strand, label=label)
125
+
126
+ # Save and display the visualization
127
+ gv_fig_path = "crispr_targets.png"
128
+ gv.savefig(gv_fig_path)
129
+ st.image(gv_fig_path, caption="CRISPR Targets Visualization")
 
 
 
 
 
130
 
131
  elif target_selection == 'off-target':
132
  ENTRY_METHODS = dict(
requirements.txt CHANGED
@@ -3,4 +3,5 @@ biopython==1.80
3
  pandas==1.5.2
4
  tensorflow==2.11.0
5
  tensorflow-probability==0.19.0
6
- plotly==5.18.0
 
 
3
  pandas==1.5.2
4
  tensorflow==2.11.0
5
  tensorflow-probability==0.19.0
6
+ plotly==5.18.0
7
+ pygenomeviz