29
29
30
30
FONTSIZE = 24
31
31
COLOURMAP = "rainbow" # "Set1", "Paired", "Set2", "Spectral"
32
- BLACK , GREY , BGGREY , WHITE , DGREY = unicode ('#262626' ), unicode ('#d3d3d3' ), unicode ('#F0F0F5' ), unicode ('#ffffff' ), unicode ('#3B3B3B ' )
32
+ BLACK , GREY , BGGREY , WHITE , DGREY = unicode ('#262626' ), unicode ('#d3d3d3' ), unicode ('#F0F0F5' ), unicode ('#ffffff' ), unicode ('#4d4d4d ' )
33
33
nullfmt = NullFormatter ()
34
34
35
35
def n50 (list_of_lengths ):
@@ -47,6 +47,20 @@ def n50(list_of_lengths):
47
47
break
48
48
return N50
49
49
50
+ def parseRefCov (refcov_f ):
51
+ refcov_dict = {}
52
+ with open (refcov_f ) as fh :
53
+ for l in fh :
54
+ try :
55
+ cov_lib , reads_mapped_ref , reads_unmapped_ref = l .split ("," )
56
+ refcov_dict [cov_lib ] = {
57
+ 'reads_mapped' : int (reads_mapped_ref ),
58
+ 'reads_unmapped' : int (reads_unmapped_ref )
59
+ }
60
+ except :
61
+ BtLog .error ('21' )
62
+ return refcov_dict
63
+
50
64
def getSortedGroups (data_dict , sort_order ):
51
65
""" Returns list of sorted groups based on span or count. """
52
66
sorted_groups = []
@@ -285,24 +299,14 @@ def relabel_and_colour(self, colour_f, user_labels):
285
299
if 'other' in self .labels :
286
300
self .plot_order .append ('other' )
287
301
288
- def plotReadCov (self ):
289
- FONTSIZE = 12
290
-
291
- # plot ReadCov by tax for each cov_lib
292
- #plot_data = {'by_group' : {} }
302
+ def plotReadCov (self , refcov_dict ):
303
+ mat .rcParams .update ({'font.size' : 14 })
304
+ plot_data = {}
293
305
294
- # plot ReadCov by cov_lib for each tax
295
- #if len(self.cov_libs) > 1:
296
- reference_read_cov = {}
297
-
298
306
main_columns = 2
299
- if (reference_read_cov ):
307
+ if (refcov_dict ):
300
308
main_columns += 2
301
309
group_columns = len (self .plot_order )
302
-
303
- plot_data = {}
304
-
305
- # plot cov_per_tax
306
310
307
311
for cov_lib in self .cov_libs :
308
312
if not self .cov_libs_total_reads_dict [cov_lib ] == 0 :
@@ -311,100 +315,61 @@ def plotReadCov(self):
311
315
# unmapped (assembly)
312
316
reads_total = self .cov_libs_total_reads_dict [cov_lib ]
313
317
reads_unmapped = reads_total - self .stats ['all' ]['reads_mapped' ][cov_lib ]
314
- main_plot .labels .append ('Unmapped' )
318
+ if cov_lib in refcov_dict :
319
+ reads_mapped_ref = refcov_dict [cov_lib ]['reads_mapped' ]
320
+ reads_unmapped_ref = refcov_dict [cov_lib ]['reads_unmapped' ]
321
+ reads_total_ref = reads_mapped_ref + reads_unmapped_ref
322
+ main_plot .labels .append ('Unmapped (ref)' )
323
+ main_plot .values .append (reads_unmapped_ref / reads_total_ref )
324
+ main_plot .colours .append (DGREY )
325
+ main_plot .labels .append ('Mapped (ref)' )
326
+ main_plot .values .append (reads_mapped_ref / reads_total_ref )
327
+ main_plot .colours .append (DGREY )
328
+
329
+ main_plot .labels .append ('Unmapped (assembly)' )
315
330
main_plot .values .append (reads_unmapped / reads_total )
316
- main_plot .colours .append (GREY )
331
+ main_plot .colours .append (DGREY )
317
332
# mapped (assembly)
318
- main_plot .labels .append ('Mapped' )
333
+ main_plot .labels .append ('Mapped (assembly) ' )
319
334
main_plot .values .append (self .stats ['all' ]['reads_mapped_perc' ][cov_lib ])
320
- main_plot .colours .append (BLACK )
335
+ main_plot .colours .append (DGREY )
321
336
# mapped plotted groups
322
337
for group in self .plot_order :
323
338
group_plot .labels .append (group )
324
339
group_plot .values .append (self .stats [group ]['reads_mapped_perc' ][cov_lib ])
325
340
group_plot .colours .append (self .colours [group ])
341
+
326
342
plot_data [cov_lib ] = {'main' : main_plot , 'group' : group_plot }
327
343
328
- x_pos_main = arange (main_columns )
329
- x_pos_group = arange (len (self .plot_order ))
344
+ x_pos_main = arange (main_columns )
345
+ x_pos_group = arange (len (self .plot_order ))
330
346
331
- for cov_lib in sorted (self .cov_libs ):
332
- if not self .cov_libs_total_reads_dict [cov_lib ] == 0 :
333
- print cov_lib
334
- print plot_data [cov_lib ]['main' ].values
335
- print plot_data [cov_lib ]['main' ].labels
336
- print plot_data [cov_lib ]['group' ].values
337
- print plot_data [cov_lib ]['group' ].labels
338
347
fig = plt .figure (1 , figsize = (30 , 10 ), dpi = 200 )
339
348
gs = mat .gridspec .GridSpec (1 , 2 , width_ratios = [main_columns , len (self .plot_order )])
340
349
ax_main = plt .subplot (gs [0 ])
341
350
ax_main .set_axis_bgcolor (BGGREY )
342
351
ax_group = plt .subplot (gs [1 ])
343
352
ax_group .set_axis_bgcolor (BGGREY )
344
- ax_main .grid (True , axis = 'y' , which = "major" , lw = 2. , color = WHITE , linestyle = '-' )
345
- ax_group .grid (True , axis = 'y' , which = "major" , lw = 2. , color = WHITE , linestyle = '-' )
346
- rect_main = ax_main .bar (x_pos_main , plot_data [cov_lib ]['main' ].values , tick_label = plot_data [cov_lib ]['main' ].labels , align = 'center' , color = plot_data [cov_lib ]['main' ].colours )
347
- for rect_m in rect_main :
348
- height_m = rect_m .get_height ()
349
- ax_main .text (rect_m .get_x () + rect_m .get_width ()/ 2. , 1.05 * height_m , '{:.1f}%' .format (int (height_m )* 100 ), ha = 'center' , va = 'bottom' )
350
- rect_group = ax_group .bar (x_pos_group , plot_data [cov_lib ]['group' ].values , tick_label = plot_data [cov_lib ]['group' ].labels , align = 'center' , color = plot_data [cov_lib ]['group' ].colours )
353
+ rect_group = ax_group .bar (x_pos_group , plot_data [cov_lib ]['group' ].values , width = 0.5 , tick_label = plot_data [cov_lib ]['group' ].labels , align = 'center' , color = plot_data [cov_lib ]['group' ].colours )
351
354
for rect_g in rect_group :
352
- height_g = rect_g .get_height ()
353
- ax_main .text (rect_g .get_x () + rect_g .get_width ()/ 2. , 1.05 * height_g , '{:.1f}%' .format (int (height_g )* 100 ), ha = 'center' , va = 'bottom' )
354
- ax_main = label_barchart (rect_main , ax_main )
355
- ax_group = label_barchart (rect_group , ax_group )
356
- ax_main_y_values = ax_main .get_yticks ()
357
- ax_group_y_values = ax_group .get_yticks ()
358
- ax_main .set_yticklabels (['{:.1f}%' .format (x * 100 ) for x in ax_main_y_values ])
359
- ax_main .set_yticklabels (['{:.1f}%' .format (x * 100 ) for x in ax_group_y_values ])
355
+ height_g = float (rect_g .get_height ())
356
+ ax_group .text (rect_g .get_x () + rect_g .get_width ()/ 2. , 0.005 + height_g , '{:.1f}%' .format (height_g * 100 ), ha = 'center' , va = 'bottom' )
357
+ rect_main = ax_main .bar (x_pos_main , plot_data [cov_lib ]['main' ].values , width = 0.5 , tick_label = plot_data [cov_lib ]['main' ].labels , align = 'center' , color = plot_data [cov_lib ]['main' ].colours )
358
+ for rect_m in rect_main :
359
+ height_m = float (rect_m .get_height ())
360
+ ax_main .text (rect_m .get_x () + rect_m .get_width ()/ 2. , 0.005 + height_m , '{:.1f}%' .format (height_m * 100 ), ha = 'center' , va = 'bottom' )
361
+ ax_main .set_ylim (0 , 1.1 )
362
+ ax_group .set_ylim (0 , 1.1 )
363
+ ax_main .set_yticklabels (['{:.0f}%' .format (x * 100 ) for x in ax_main .get_yticks ()])
364
+ ax_main .set_xticklabels (plot_data [cov_lib ]['main' ].labels , rotation = 45 )
365
+ ax_group .set_yticklabels (['{:.0f}%' .format (x * 100 ) for x in ax_group .get_yticks ()])
366
+ ax_group .set_xticklabels (plot_data [cov_lib ]['group' ].labels , rotation = 45 )
367
+ ax_main .grid (True , axis = 'y' , which = "major" , lw = 2. , color = WHITE , linestyle = '--' )
368
+ ax_group .grid (True , axis = 'y' , which = "major" , lw = 2. , color = WHITE , linestyle = '--' )
360
369
out_f = "%s.%s.read_cov.%s" % (self .out_f , cov_lib , self .format )
361
370
print BtLog .status_d ['8' ] % out_f
362
- plt .xticks (fontsize = FONTSIZE )
363
- plt .yticks (fontsize = FONTSIZE )
364
371
plt .tight_layout ()
365
- plt .savefig (out_f , format = self .format )
366
-
367
- #top_y_pos = arange(len(top_labels))
368
- #bottom_y_pos = arange(len(bottom_labels))
369
- #fig = plt.figure(1, figsize=(30,10), dpi=200)
370
- #gs = mat.gridspec.GridSpec(2, 1, height_ratios=[len(top_labels), len(bottom_labels)])
371
- #axarr[0] = plt.subplot(gs[0], sharex=True)
372
- #axarr = []
373
- #axarr.append(plt.subplot(gs[0]))
374
- #axarr.append(plt.subplot(gs[1]))
375
- #axarr[0].set_axis_bgcolor(BGGREY)
376
- #axarr[1].set_axis_bgcolor(BGGREY)
377
- #
378
- #axarr[0].grid(True, axis='x', which="major", lw=2., color=WHITE, linestyle='-')
379
- #axarr[1].grid(True, axis='x', which="major", lw=2., color=WHITE, linestyle='-')
380
-
381
- #rects_0 = axarr[0].barh(top_y_pos, top_perc_mapped, tick_label=top_labels, align='center', height = 0.75, color = top_colours)
382
- #rects_1 = axarr[1].barh(bottom_y_pos, bottom_perc_mapped, tick_label=bottom_labels, align='center', height = 0.75, color = bottom_colours)
383
- #
384
- # #axarr[1].set_xlabel("Percent of reads")
385
- #axarr[0].set_title(self.title)
386
- #ax_right_0 = axarr[0].twinx()
387
- #ax_right_1 = axarr[1].twinx()
388
- #ax_right_0.set_yticks(top_y_pos)
389
- #ax_right_1.set_yticks(bottom_y_pos)
390
- #axarr[0].set_xticklabels([])
391
- #axarr[1].set_xticklabels([])
392
- #ax_right_0.set_xlim(0, 1)
393
- #ax_right_1.set_xlim(0, 1)
394
- #ax_right_0_labels = ['{0:.2%}'.format(value) for value in top_perc_mapped]
395
- #ax_right_1_labels = ['{0:.2%}'.format(value) for value in bottom_perc_mapped]
396
- #
397
- #ax_right_0.set_yticklabels(ax_right_0_labels)
398
- #ax_right_1.set_yticklabels(ax_right_1_labels)
399
- #
400
- #ax_right_0.set_ylim(axarr[0].get_ylim())
401
- #ax_right_1.set_ylim(axarr[1].get_ylim())
402
- #
403
- #out_f = "%s.%s.read_cov.%s" % (self.out_f, cov_lib, self.format)
404
- #print BtLog.status_d['8'] % out_f
405
- #plt.tight_layout()
406
- #plt.savefig(out_f, format=self.format)
407
-
372
+ plt .savefig (out_f , format = self .format )
408
373
409
374
def plotBlobs (self , cov_lib , info_flag ):
410
375
rect_scatter , rect_histx , rect_histy , rect_legend = set_canvas ()
0 commit comments