Spaces:
Sleeping
Sleeping
Commit
•
544275a
1
Parent(s):
475fe8c
fix
Browse files- app.py +12 -18
- cas9on.py +1 -5
- requirements.txt +1 -1
app.py
CHANGED
@@ -6,14 +6,12 @@ import cas12
|
|
6 |
import pandas as pd
|
7 |
import streamlit as st
|
8 |
import plotly.graph_objs as go
|
9 |
-
import coolbox
|
10 |
-
from coolbox.api import *
|
11 |
import numpy as np
|
12 |
from pathlib import Path
|
13 |
import zipfile
|
14 |
import io
|
15 |
-
import
|
16 |
-
|
17 |
|
18 |
|
19 |
# title and documentation
|
@@ -302,24 +300,20 @@ if selected_model == 'Cas9':
|
|
302 |
# Important: move the cursor to the beginning of the BytesIO buffer before reading it
|
303 |
zip_buffer.seek(0)
|
304 |
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
# Path for the temporary plot image
|
309 |
-
plot_image_path = "coolbox_plot.png"
|
310 |
-
|
311 |
-
# Generate the CoolBox plot
|
312 |
-
generate_coolbox_plot(bigwig_file_path, region_to_visualize, plot_image_path)
|
313 |
|
314 |
-
#
|
315 |
-
|
|
|
|
|
|
|
316 |
|
317 |
# Generate the pyGenomeTracks plot
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
# Display the pyGenomeTracks plot image in Streamlit
|
322 |
-
st.image(
|
323 |
|
324 |
# Display the download button for the ZIP file
|
325 |
st.download_button(
|
|
|
6 |
import pandas as pd
|
7 |
import streamlit as st
|
8 |
import plotly.graph_objs as go
|
|
|
|
|
9 |
import numpy as np
|
10 |
from pathlib import Path
|
11 |
import zipfile
|
12 |
import io
|
13 |
+
import gtracks
|
14 |
+
|
15 |
|
16 |
|
17 |
# title and documentation
|
|
|
300 |
# Important: move the cursor to the beginning of the BytesIO buffer before reading it
|
301 |
zip_buffer.seek(0)
|
302 |
|
303 |
+
track = gtracks.Track(bigwig_file_path)
|
304 |
+
plot = gtracks.Plot(tracks=[track])
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
|
306 |
+
# Specify the region you want to visualize
|
307 |
+
min_start = df['Start Pos'].min()
|
308 |
+
max_end = df['End Pos'].max()
|
309 |
+
chromosome = df['Chr'].mode()[0] # Assumes most common chromosome is the target
|
310 |
+
region = f"{chromosome}:{min_start}-{max_end}"
|
311 |
|
312 |
# Generate the pyGenomeTracks plot
|
313 |
+
plot_image_path = f"{gene_symbol}_gtracks_plot.png"
|
314 |
+
plot.plot(region=region, output_file=plot_image_path)
|
|
|
315 |
# Display the pyGenomeTracks plot image in Streamlit
|
316 |
+
st.image(plot_image_path)
|
317 |
|
318 |
# Display the download button for the ZIP file
|
319 |
st.download_button(
|
cas9on.py
CHANGED
@@ -204,9 +204,6 @@ def process_gene(gene_symbol, model_path):
|
|
204 |
|
205 |
|
206 |
def create_bigwig(df, bigwig_path):
|
207 |
-
import pandas as pd
|
208 |
-
import pyBigWig
|
209 |
-
|
210 |
if isinstance(df, list):
|
211 |
df = pd.DataFrame(df, columns=["Chr", "Start Pos", "End Pos", "Strand", "Transcript", "Exon", "Target", "gRNA", "Prediction"])
|
212 |
|
@@ -214,12 +211,11 @@ def create_bigwig(df, bigwig_path):
|
|
214 |
# Ensure the sizes are integers
|
215 |
chrom_sizes = df.groupby('Chr')['End Pos'].max().astype(int).to_dict()
|
216 |
|
217 |
-
# Create a BigWig file
|
218 |
with pyBigWig.open(bigwig_path, "w") as bw:
|
219 |
# Add chromosome sizes to the header, ensuring sizes are integers
|
220 |
bw.addHeader([(chr, size) for chr, size in chrom_sizes.items()])
|
221 |
|
222 |
-
#
|
223 |
for chrom in df['Chr'].unique():
|
224 |
chrom_df = df[df['Chr'] == chrom]
|
225 |
bw.addEntries(
|
|
|
204 |
|
205 |
|
206 |
def create_bigwig(df, bigwig_path):
|
|
|
|
|
|
|
207 |
if isinstance(df, list):
|
208 |
df = pd.DataFrame(df, columns=["Chr", "Start Pos", "End Pos", "Strand", "Transcript", "Exon", "Target", "gRNA", "Prediction"])
|
209 |
|
|
|
211 |
# Ensure the sizes are integers
|
212 |
chrom_sizes = df.groupby('Chr')['End Pos'].max().astype(int).to_dict()
|
213 |
|
|
|
214 |
with pyBigWig.open(bigwig_path, "w") as bw:
|
215 |
# Add chromosome sizes to the header, ensuring sizes are integers
|
216 |
bw.addHeader([(chr, size) for chr, size in chrom_sizes.items()])
|
217 |
|
218 |
+
# Iterate over unique chromosomes and add entries for each
|
219 |
for chrom in df['Chr'].unique():
|
220 |
chrom_df = df[df['Chr'] == chrom]
|
221 |
bw.addEntries(
|
requirements.txt
CHANGED
@@ -4,6 +4,6 @@ pandas==1.5.2
|
|
4 |
tensorflow==2.11.0
|
5 |
tensorflow-probability==0.19.0
|
6 |
plotly==5.18.0
|
7 |
-
|
8 |
pyBigWig
|
9 |
pyGenomeTracks
|
|
|
4 |
tensorflow==2.11.0
|
5 |
tensorflow-probability==0.19.0
|
6 |
plotly==5.18.0
|
7 |
+
gtracks
|
8 |
pyBigWig
|
9 |
pyGenomeTracks
|