Spaces:
Sleeping
Sleeping
supercat666
commited on
Commit
•
f067f02
1
Parent(s):
9999544
fix
Browse files
app.py
CHANGED
@@ -287,8 +287,8 @@ if selected_model == 'Cas9':
|
|
287 |
# cas9on.create_bed_file_from_df(df, bed_file_path)
|
288 |
# cas9on.create_csv_from_df(df, csv_file_path)
|
289 |
|
290 |
-
# Assuming
|
291 |
-
cas9on.
|
292 |
|
293 |
# Prepare an in-memory buffer for the ZIP file
|
294 |
zip_buffer = io.BytesIO()
|
|
|
287 |
# cas9on.create_bed_file_from_df(df, bed_file_path)
|
288 |
# cas9on.create_csv_from_df(df, csv_file_path)
|
289 |
|
290 |
+
# Assuming create_bigwig is a function that generates a BigWig file from the DataFrame
|
291 |
+
cas9on.create_bigwig(df, bigwig_file_path)
|
292 |
|
293 |
# Prepare an in-memory buffer for the ZIP file
|
294 |
zip_buffer = io.BytesIO()
|
cas9on.py
CHANGED
@@ -203,24 +203,28 @@ def process_gene(gene_symbol, model_path):
|
|
203 |
# df.to_csv(output_path, index=False)
|
204 |
|
205 |
|
206 |
-
def create_bigwig(
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
bw.
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
|
|
|
|
|
|
|
|
|
203 |
# df.to_csv(output_path, index=False)
|
204 |
|
205 |
|
206 |
+
def create_bigwig(predictions, bigwig_path):
|
207 |
+
# Convert predictions to DataFrame if it's a list of lists
|
208 |
+
if isinstance(predictions, list):
|
209 |
+
import pandas as pd
|
210 |
+
df = pd.DataFrame(predictions, columns=["Chr", "Start Pos", "End Pos", "Strand", "Transcript", "Exon", "Target", "gRNA", "Prediction"])
|
211 |
+
else:
|
212 |
+
df = predictions # Assuming predictions is already a DataFrame
|
213 |
+
|
214 |
+
# Calculate chromosome sizes as the maximum end position per chromosome
|
215 |
+
chrom_sizes = df.groupby('Chr')['End Pos'].max().to_dict()
|
216 |
+
|
217 |
+
# Create a BigWig file
|
218 |
+
with pyBigWig.open(bigwig_path, "w") as bw:
|
219 |
+
# Add chromosome sizes to the header
|
220 |
+
bw.addHeader(list(chrom_sizes.items()))
|
221 |
+
|
222 |
+
# Add entries for each prediction
|
223 |
+
for index, row in df.iterrows():
|
224 |
+
chrom = row['Chr']
|
225 |
+
start = int(row['Start Pos']) - 1 # BigWig positions are 0-based
|
226 |
+
end = int(row['End Pos'])
|
227 |
+
score = float(row['Prediction'])
|
228 |
+
|
229 |
+
# Add the entry to the BigWig file
|
230 |
+
bw.addEntries([chrom], [start], ends=[end], values=[score])
|