Spaces:
Running
Running
supercat666
commited on
Commit
•
aea8c18
1
Parent(s):
b31c7ac
fix bigwig
Browse files
cas9on.py
CHANGED
@@ -204,22 +204,21 @@ def process_gene(gene_symbol, model_path):
|
|
204 |
|
205 |
|
206 |
def create_bigwig(df, bigwig_path):
|
207 |
-
|
208 |
-
|
|
|
209 |
|
210 |
-
#
|
211 |
-
|
|
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
starts = chrom_df['Start Pos'].astype(int).tolist()
|
221 |
-
ends = chrom_df['End Pos'].astype(int).tolist()
|
222 |
-
values = chrom_df['Prediction'].astype(float).tolist()
|
223 |
|
224 |
-
|
225 |
-
|
|
|
204 |
|
205 |
|
206 |
def create_bigwig(df, bigwig_path):
|
207 |
+
# Ensure the dataframe has the required columns
|
208 |
+
if not all(column in df.columns for column in ["Chr", "Start Pos", "End Pos", "Prediction"]):
|
209 |
+
raise ValueError("DataFrame must contain 'Chr', 'Start Pos', 'End Pos', and 'Prediction' columns.")
|
210 |
|
211 |
+
# Prepare the BigWig header using unique chromosomes and their max position
|
212 |
+
chr_sizes = df.groupby('Chr')['End Pos'].max().to_dict()
|
213 |
+
header = [(chr, size) for chr, size in chr_sizes.items()]
|
214 |
|
215 |
+
# Create a BigWig file
|
216 |
+
bw = pyBigWig.open(bigwig_path, "w")
|
217 |
+
bw.addHeader(header)
|
218 |
|
219 |
+
# Add entries to the BigWig file
|
220 |
+
for _, row in df.iterrows():
|
221 |
+
bw.addEntries([row['Chr']], [int(row['Start Pos'])], ends=[int(row['End Pos'])], values=[float(row['Prediction'])])
|
|
|
|
|
|
|
222 |
|
223 |
+
# Close the BigWig file
|
224 |
+
bw.close()
|