@@ -104,7 +104,7 @@ def crispr_surf_sgRNA_summary_table_update(sgRNA_summary_table, gammas2betas, av
104
104
105
105
f .write (',' .join (map (str , row )) + '\n ' )
106
106
107
- def complete_beta_profile (gammas2betas , simulation_n , padj_cutoffs , out_dir ):
107
+ def complete_beta_profile (gammas2betas , simulation_n , padj_cutoffs , estimate_statistical_power , out_dir ):
108
108
"""
109
109
Function to output total beta profile.
110
110
"""
@@ -118,18 +118,32 @@ def complete_beta_profile(gammas2betas, simulation_n, padj_cutoffs, out_dir):
118
118
padj_min = np .min ([float (x ) for x in gammas2betas ['padj' ] if str (x ) != 'nan' and float (x ) > 0 ])
119
119
pvals_new = [float (x ) if float (x ) > 0 else p_min for x in pvals ]
120
120
pvals_adj_new = [float (x ) if float (x ) > 0 else padj_min for x in pvals_adj ]
121
- power = gammas2betas ['power' ]
121
+
122
+ if estimate_statistical_power == 'yes' :
123
+ power = gammas2betas ['power' ]
122
124
123
- df = pd .DataFrame ({
124
- 'Chr' : chrom ,
125
- 'Index' : indices ,
126
- 'Beta' : betas ,
127
- 'Pval.' : pvals_new ,
128
- 'Pval_adj.' : pvals_adj_new ,
129
- 'Statistical_Power' : power
130
- })
125
+ df = pd .DataFrame ({
126
+ 'Chr' : chrom ,
127
+ 'Index' : indices ,
128
+ 'Beta' : betas ,
129
+ 'Pval.' : pvals_new ,
130
+ 'Pval_adj.' : pvals_adj_new ,
131
+ 'Statistical_Power' : power
132
+ })
131
133
132
- df .to_csv (path_or_buf = (out_dir + '/beta_profile.csv' ), index = False , header = True , columns = ['Chr' ,'Index' ,'Beta' ,'Pval.' ,'Pval_adj.' ,'Statistical_Power' ])
134
+ df .to_csv (path_or_buf = (out_dir + '/beta_profile.csv' ), index = False , header = True , columns = ['Chr' ,'Index' ,'Beta' ,'Pval.' ,'Pval_adj.' ,'Statistical_Power' ])
135
+
136
+ else :
137
+
138
+ df = pd .DataFrame ({
139
+ 'Chr' : chrom ,
140
+ 'Index' : indices ,
141
+ 'Beta' : betas ,
142
+ 'Pval.' : pvals_new ,
143
+ 'Pval_adj.' : pvals_adj_new
144
+ })
145
+
146
+ df .to_csv (path_or_buf = (out_dir + '/beta_profile.csv' ), index = False , header = True , columns = ['Chr' ,'Index' ,'Beta' ,'Pval.' ,'Pval_adj.' ])
133
147
134
148
def crispr_surf_significant_regions (sgRNA_summary_table , gammas2betas , padj_cutoffs , scale , guideindices2bin , out_dir ):
135
149
@@ -201,7 +215,7 @@ def crispr_surf_significant_regions(sgRNA_summary_table, gammas2betas, padj_cuto
201
215
if len (associated_sgRNAs ) > 0 :
202
216
f .write (',' .join (map (str , [padj_cutoff , chrom , genomic_boundary_start , genomic_boundary_stop , significance_direction , signal_area , signal_mean , padj_mean , len (associated_sgRNAs ), ',' .join (map (str , associated_sgRNAs ))])) + '\n ' )
203
217
204
- def crispr_surf_IGV (sgRNA_summary_table , gammas2betas , padj_cutoffs , genome , scale , guideindices2bin , out_dir ):
218
+ def crispr_surf_IGV (sgRNA_summary_table , gammas2betas , padj_cutoffs , genome , scale , guideindices2bin , estimate_statistical_power , out_dir ):
205
219
206
220
"""
207
221
Function to output tracks to load on IGV.
@@ -265,27 +279,70 @@ def crispr_surf_IGV(sgRNA_summary_table, gammas2betas, padj_cutoffs, genome, sca
265
279
# Output raw and deconvolved scores IGV track
266
280
dff = df_summary_table [pd .notnull (df_summary_table ['Chr' ]) & pd .notnull (df_summary_table ['Perturbation_Index' ]) & pd .notnull (df_summary_table ['Raw_Signal_Combined' ]) & pd .notnull (df_summary_table ['Deconvolved_Signal_Combined' ])]
267
281
268
- with open (out_dir + '/raw_scores.bedgraph' , 'w' ) as raw_scores , open (out_dir + '/deconvolved_scores.bedgraph' , 'w' ) as deconvolved_scores , open (out_dir + '/neglog10_pvals.bedgraph' , 'w' ) as neglog10_pvals , open (out_dir + '/statistical_power.bedgraph' , 'w' ) as statistical_power :
282
+ # with open(out_dir + '/raw_scores.bedgraph', 'w') as raw_scores, open(out_dir + '/deconvolved_scores.bedgraph', 'w') as deconvolved_scores, open(out_dir + '/neglog10_pvals.bedgraph', 'w') as neglog10_pvals, open(out_dir + '/statistical_power.bedgraph', 'w') as statistical_power:
269
283
270
- for index , row in dff .iterrows ():
284
+ # for index, row in dff.iterrows():
271
285
272
- for r in range (1 , replicates + 1 ):
273
- raw_scores .write ('\t ' .join (map (str , [row ['Chr' ], int (row ['Perturbation_Index' ]), int (row ['Perturbation_Index' ]), float (row ['Log2FC_Replicate%s' % r ]), row ['sgRNA_Sequence' ]])) + '\n ' )
286
+ # for r in range(1, replicates + 1):
287
+ # raw_scores.write('\t'.join(map(str, [row['Chr'], int(row['Perturbation_Index']), int(row['Perturbation_Index']), float(row['Log2FC_Replicate%s' % r]), row['sgRNA_Sequence']])) + '\n')
274
288
275
- for index in range (len (gammas2betas ['indices' ])):
289
+ # for index in range(len(gammas2betas['indices'])):
276
290
277
- if float (gammas2betas ['padj' ][index ]) > 0 :
278
- neglog10_pval = - math .log10 (float (gammas2betas ['padj' ][index ]))
279
- else :
280
- neglog10_pval = - math .log10 (padj_min )
291
+ # if float(gammas2betas['padj'][index]) > 0:
292
+ # neglog10_pval = -math.log10(float(gammas2betas['padj'][index]))
293
+ # else:
294
+ # neglog10_pval = -math.log10(padj_min)
295
+
296
+ # deconvolved_scores.write('\t'.join(map(str, [gammas2betas['chr'][index], int(gammas2betas['indices'][index]), int(gammas2betas['indices'][index]), float(gammas2betas['combined'][index])])) + '\n')
297
+ # neglog10_pvals.write('\t'.join(map(str, [gammas2betas['chr'][index], int(gammas2betas['indices'][index]), int(gammas2betas['indices'][index]), neglog10_pval])) + '\n')
298
+ # statistical_power.write('\t'.join(map(str, [gammas2betas['chr'][index], int(gammas2betas['indices'][index]), int(gammas2betas['indices'][index]), float(gammas2betas['power'][index])])) + '\n')
299
+
300
+ if estimate_statistical_power == 'yes' :
281
301
282
- deconvolved_scores .write ('\t ' .join (map (str , [gammas2betas ['chr' ][index ], int (gammas2betas ['indices' ][index ]), int (gammas2betas ['indices' ][index ]), float (gammas2betas ['combined' ][index ])])) + '\n ' )
283
- neglog10_pvals .write ('\t ' .join (map (str , [gammas2betas ['chr' ][index ], int (gammas2betas ['indices' ][index ]), int (gammas2betas ['indices' ][index ]), neglog10_pval ])) + '\n ' )
284
- statistical_power .write ('\t ' .join (map (str , [gammas2betas ['chr' ][index ], int (gammas2betas ['indices' ][index ]), int (gammas2betas ['indices' ][index ]), float (gammas2betas ['power' ][index ])])) + '\n ' )
302
+ with open (out_dir + '/raw_scores.bedgraph' , 'w' ) as raw_scores , open (out_dir + '/deconvolved_scores.bedgraph' , 'w' ) as deconvolved_scores , open (out_dir + '/neglog10_pvals.bedgraph' , 'w' ) as neglog10_pvals , open (out_dir + '/statistical_power.bedgraph' , 'w' ) as statistical_power :
303
+
304
+ for index , row in dff .iterrows ():
305
+
306
+ for r in range (1 , replicates + 1 ):
307
+ raw_scores .write ('\t ' .join (map (str , [row ['Chr' ], int (row ['Perturbation_Index' ]), int (row ['Perturbation_Index' ]), float (row ['Log2FC_Replicate%s' % r ]), row ['sgRNA_Sequence' ]])) + '\n ' )
308
+
309
+ for index in range (len (gammas2betas ['indices' ])):
310
+
311
+ if float (gammas2betas ['padj' ][index ]) > 0 :
312
+ neglog10_pval = - math .log10 (float (gammas2betas ['padj' ][index ]))
313
+ else :
314
+ neglog10_pval = - math .log10 (padj_min )
285
315
286
- # Create IGV session
287
- with open ('/SURF/igv_session_template.xml' , 'r' ) as f :
288
- igv_template = f .read ()
316
+ deconvolved_scores .write ('\t ' .join (map (str , [gammas2betas ['chr' ][index ], int (gammas2betas ['indices' ][index ]), int (gammas2betas ['indices' ][index ]), float (gammas2betas ['combined' ][index ])])) + '\n ' )
317
+ neglog10_pvals .write ('\t ' .join (map (str , [gammas2betas ['chr' ][index ], int (gammas2betas ['indices' ][index ]), int (gammas2betas ['indices' ][index ]), neglog10_pval ])) + '\n ' )
318
+ statistical_power .write ('\t ' .join (map (str , [gammas2betas ['chr' ][index ], int (gammas2betas ['indices' ][index ]), int (gammas2betas ['indices' ][index ]), float (gammas2betas ['power' ][index ])])) + '\n ' )
319
+
320
+ # Create IGV session
321
+ with open ('/SURF/igv_session_template.xml' , 'r' ) as f :
322
+ igv_template = f .read ()
323
+
324
+ else :
325
+
326
+ with open (out_dir + '/raw_scores.bedgraph' , 'w' ) as raw_scores , open (out_dir + '/deconvolved_scores.bedgraph' , 'w' ) as deconvolved_scores , open (out_dir + '/neglog10_pvals.bedgraph' , 'w' ) as neglog10_pvals :
327
+
328
+ for index , row in dff .iterrows ():
329
+
330
+ for r in range (1 , replicates + 1 ):
331
+ raw_scores .write ('\t ' .join (map (str , [row ['Chr' ], int (row ['Perturbation_Index' ]), int (row ['Perturbation_Index' ]), float (row ['Log2FC_Replicate%s' % r ]), row ['sgRNA_Sequence' ]])) + '\n ' )
332
+
333
+ for index in range (len (gammas2betas ['indices' ])):
334
+
335
+ if float (gammas2betas ['padj' ][index ]) > 0 :
336
+ neglog10_pval = - math .log10 (float (gammas2betas ['padj' ][index ]))
337
+ else :
338
+ neglog10_pval = - math .log10 (padj_min )
339
+
340
+ deconvolved_scores .write ('\t ' .join (map (str , [gammas2betas ['chr' ][index ], int (gammas2betas ['indices' ][index ]), int (gammas2betas ['indices' ][index ]), float (gammas2betas ['combined' ][index ])])) + '\n ' )
341
+ neglog10_pvals .write ('\t ' .join (map (str , [gammas2betas ['chr' ][index ], int (gammas2betas ['indices' ][index ]), int (gammas2betas ['indices' ][index ]), neglog10_pval ])) + '\n ' )
342
+
343
+ # Create IGV session
344
+ with open ('/SURF/igv_session_template_nopower.xml' , 'r' ) as f :
345
+ igv_template = f .read ()
289
346
290
347
igv_template = igv_template .replace ('#genome#' , str (genome ))
291
348
0 commit comments