99matplotlib .use ('Agg' )
1010matplotlib .rcParams ['pdf.fonttype' ] = 42
1111matplotlib .rcParams ['svg.fonttype' ] = 'none'
12- from deeptools import cm # noqa: F401
1312import matplotlib .pyplot as plt
1413
15- import plotly .offline as py
16- import plotly .graph_objs as go
17-
1814# own tools
1915from deeptools .parserCommon import writableFile
2016from deeptools .getFragmentAndReadSize import get_read_and_fragment_length
2117from importlib .metadata import version
2218
23-
2419def parse_arguments ():
2520 parser = argparse .ArgumentParser (
2621 description = 'This tool calculates the fragment sizes for read pairs given a BAM file from paired-end sequencing.'
@@ -51,8 +46,11 @@ def parse_arguments():
5146 'ending. The available options are: png, '
5247 'eps, pdf, svg and plotly.' ,
5348 default = None ,
54- choices = ['png' , 'pdf' , 'svg' , 'eps' , 'plotly' ])
55-
49+ choices = ['png' , 'pdf' , 'svg' , 'eps' ])
50+ parser .add_argument ('--ggplot' ,
51+ help = 'Use ggplot theme for figures' ,
52+ action = 'store_true' )
53+
5654 parser .add_argument ('--numberOfProcessors' , '-p' ,
5755 help = 'Number of processors to use. The default is '
5856 'to use 1. (Default: %(default)s)' ,
@@ -311,6 +309,9 @@ def main(args=None):
311309 if args .table is not None :
312310 printTable (args , fraglengths , readlengths )
313311
312+ if args .ggplot :
313+ plt .style .use ('ggplot' )
314+
314315 if args .histogram :
315316 if args .samplesLabel :
316317 if len (args .bamfiles ) != len (args .samplesLabel ):
@@ -331,38 +332,18 @@ def main(args=None):
331332 else :
332333 maxVal = d ['mean' ] * 2
333334
334- if args .plotFileFormat == 'plotly' :
335- trace = go .Histogram (x = d ['lengths' ],
336- histnorm = 'probability' ,
337- opacity = 0.5 ,
338- name = labels [i ],
339- nbinsx = 100 ,
340- xbins = dict (start = d ['min' ], end = maxVal ))
341- data .append (trace )
342- else :
343- plt .bar (d ['lengths' ][1 ][:- 1 ], height = d ['lengths' ][0 ],
344- width = d ['lengths' ][1 ][1 :] - d ['lengths' ][1 ][:- 1 ],
345- align = 'edge' , log = args .logScale ,
346- alpha = 0.5 , label = labels [i ])
335+ plt .bar (d ['lengths' ][1 ][:- 1 ], height = d ['lengths' ][0 ],
336+ width = d ['lengths' ][1 ][1 :] - d ['lengths' ][1 ][:- 1 ],
337+ align = 'edge' , log = args .logScale ,
338+ alpha = 0.5 , label = labels [i ])
347339 i += 1
348340
349- if args .plotFileFormat == 'plotly' :
350- fig = go .Figure ()
351- fig .add_traces (data )
352- fig ['layout' ]['yaxis1' ].update (title = 'Frequency' )
353- fig ['layout' ]['xaxis1' ].update (title = 'Fragment Length' )
354- fig ['layout' ].update (title = args .plotTitle )
355- fig ['layout' ].update (showlegend = True )
356- if args .logScale :
357- fig ['layout' ]['yaxis1' ].update (type = 'log' )
358- py .plot (fig , filename = args .histogram , auto_open = False )
359- else :
360- plt .xlabel ('Fragment Length' )
361- plt .ylabel ('Frequency' )
362- plt .legend (loc = 'upper right' )
363- plt .title (args .plotTitle )
364- plt .savefig (args .histogram , bbox_inches = 0 , format = args .plotFileFormat )
365- plt .close ()
341+ plt .xlabel ('Fragment Length' )
342+ plt .ylabel ('Frequency' )
343+ plt .legend (loc = 'upper right' )
344+ plt .title (args .plotTitle )
345+ plt .savefig (args .histogram , bbox_inches = 0 , format = args .plotFileFormat )
346+ plt .close ()
366347
367348
368349if __name__ == "__main__" :
0 commit comments