supercat666 commited on
Commit
7fa8fbf
1 Parent(s): 45a0b21
Files changed (1) hide show
  1. cas9on.py +6 -8
cas9on.py CHANGED
@@ -208,28 +208,26 @@ def create_bigwig(df, bigwig_path):
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
- # Convert positions to integers
212
  df['Start Pos'] = df['Start Pos'].astype(int)
213
  df['End Pos'] = df['End Pos'].astype(int)
214
-
215
- # Sort the DataFrame by chromosome and start position
216
  df = df.sort_values(by=['Chr', 'Start Pos'])
217
 
218
  # Prepare the BigWig header
219
  chr_sizes = df.groupby('Chr')['End Pos'].max().to_dict()
220
- header = [(chr, int(size)) for chr, size in chr_sizes.items()]
221
 
222
- # Create a BigWig file
223
  bw = pyBigWig.open(bigwig_path, "w")
224
  bw.addHeader(header)
225
 
226
- # Add entries to the BigWig file
227
  for chr, group in df.groupby('Chr'):
228
  starts = group['Start Pos'].tolist()
229
  ends = group['End Pos'].tolist()
230
  values = group['Prediction'].astype(float).tolist()
231
- bw.addEntries(chr, starts, ends=ends, values=values)
232
 
233
- # Close the BigWig file
234
  bw.close()
235
 
 
 
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
+ # Convert positions to integers and sort the DataFrame
212
  df['Start Pos'] = df['Start Pos'].astype(int)
213
  df['End Pos'] = df['End Pos'].astype(int)
 
 
214
  df = df.sort_values(by=['Chr', 'Start Pos'])
215
 
216
  # Prepare the BigWig header
217
  chr_sizes = df.groupby('Chr')['End Pos'].max().to_dict()
218
+ header = [(str(chr), size) for chr, size in chr_sizes.items()]
219
 
220
+ # Create and write to the BigWig file
221
  bw = pyBigWig.open(bigwig_path, "w")
222
  bw.addHeader(header)
223
 
224
+ # Group by chromosome and add entries
225
  for chr, group in df.groupby('Chr'):
226
  starts = group['Start Pos'].tolist()
227
  ends = group['End Pos'].tolist()
228
  values = group['Prediction'].astype(float).tolist()
229
+ bw.addEntries([str(chr)] * len(starts), starts, ends=ends, values=values)
230
 
 
231
  bw.close()
232
 
233
+