Spaces:
Sleeping
Sleeping
supercat666
commited on
Commit
•
475fe8c
1
Parent(s):
f067f02
fix
Browse files
cas9on.py
CHANGED
@@ -203,28 +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 |
-
df = predictions # Assuming predictions is already a DataFrame
|
213 |
|
214 |
# Calculate chromosome sizes as the maximum end position per chromosome
|
215 |
-
|
|
|
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(
|
221 |
|
222 |
# Add entries for each prediction
|
223 |
-
for
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
|
|
203 |
# df.to_csv(output_path, index=False)
|
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 |
|
213 |
# Calculate chromosome sizes as the maximum end position per chromosome
|
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 |
# Add entries for each prediction
|
223 |
+
for chrom in df['Chr'].unique():
|
224 |
+
chrom_df = df[df['Chr'] == chrom]
|
225 |
+
bw.addEntries(
|
226 |
+
chrom,
|
227 |
+
chrom_df['Start Pos'].astype(int).tolist(),
|
228 |
+
ends=chrom_df['End Pos'].astype(int).tolist(),
|
229 |
+
values=chrom_df['Prediction'].astype(float).tolist()
|
230 |
+
)
|