Spaces:
Running
Running
supercat666
commited on
Commit
•
114492c
1
Parent(s):
ba0ca5b
fix
Browse files
cas9on.py
CHANGED
@@ -213,25 +213,31 @@ def create_bigwig(df, bigwig_path):
|
|
213 |
df['End Pos'] = df['End Pos'].astype(int)
|
214 |
df['Prediction'] = df['Prediction'].astype(float)
|
215 |
|
216 |
-
#
|
217 |
-
|
218 |
|
219 |
# Calculate chromosome sizes for the BigWig header
|
220 |
-
chr_sizes =
|
221 |
-
|
|
|
|
|
|
|
222 |
|
223 |
# Create the BigWig file and add the header
|
224 |
bw = pyBigWig.open(bigwig_path, "w")
|
225 |
-
bw.addHeader(
|
226 |
-
|
227 |
-
#
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
|
|
|
|
|
|
235 |
|
236 |
# Close the BigWig file
|
237 |
bw.close()
|
|
|
213 |
df['End Pos'] = df['End Pos'].astype(int)
|
214 |
df['Prediction'] = df['Prediction'].astype(float)
|
215 |
|
216 |
+
# Get the list of all chromosomes present in the DataFrame
|
217 |
+
all_chromosomes = df['Chr'].unique().tolist()
|
218 |
|
219 |
# Calculate chromosome sizes for the BigWig header
|
220 |
+
chr_sizes = []
|
221 |
+
for chr in all_chromosomes:
|
222 |
+
chr_group = df[df['Chr'] == chr]
|
223 |
+
max_end_pos = chr_group['End Pos'].max()
|
224 |
+
chr_sizes.append((chr, max_end_pos))
|
225 |
|
226 |
# Create the BigWig file and add the header
|
227 |
bw = pyBigWig.open(bigwig_path, "w")
|
228 |
+
bw.addHeader(chr_sizes)
|
229 |
+
|
230 |
+
# Add entries for each chromosome
|
231 |
+
for chr in all_chromosomes:
|
232 |
+
chr_group = df[df['Chr'] == chr]
|
233 |
+
if not chr_group.empty:
|
234 |
+
starts = chr_group['Start Pos'].tolist()
|
235 |
+
ends = chr_group['End Pos'].tolist()
|
236 |
+
values = chr_group['Prediction'].astype(float).tolist()
|
237 |
+
bw.addEntries([chr] * len(starts), starts, ends=ends, values=values)
|
238 |
+
else:
|
239 |
+
# Add empty entries for the missing chromosome
|
240 |
+
bw.addEntries([chr], [0], ends=[1], values=[0.0])
|
241 |
|
242 |
# Close the BigWig file
|
243 |
bw.close()
|