Skip to content

Commit

Permalink
updating plotting (removed plotly and code clean-up)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Caballero committed Jan 22, 2025
1 parent d59f85f commit 61d1f30
Showing 1 changed file with 14 additions and 42 deletions.
56 changes: 14 additions & 42 deletions pydeeptools/deeptools/plotFingerprint.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
import argparse
import sys
import matplotlib
matplotlib.use('Agg')
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['svg.fonttype'] = 'none'
from deeptools import cm # noqa: F401
import argparse
import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
from scipy.stats import poisson

import plotly.offline as py
import plotly.graph_objs as go

import deeptools.countReadsPerBin as countR
import deeptools.sumCoveragePerBin as sumR
from deeptools import parserCommon
from deeptools.utilities import smartLabels

old_settings = np.seterr(all='ignore')
MAXLEN = 10000000


Expand Down Expand Up @@ -122,8 +113,9 @@ def get_optional_args():
'overrides the image format based on the ending '
'given via --plotFile '
'ending. The available options are: "png", '
'"eps", "pdf", "plotly" and "svg"',
choices=['png', 'pdf', 'svg', 'eps', 'plotly'])
'"eps", "pdf", "jpeg", and "svg"',
choices=['png', 'pdf', 'svg', 'jpeg', 'eps'],
default=None)

optional.add_argument('--plotTitle', '-T',
help='Title of the plot, to be printed on top of '
Expand Down Expand Up @@ -409,38 +401,18 @@ def main(args=None):
i = 0
# matplotlib won't iterate through line styles by itself
pyplot_line_styles = sum([7 * ["-"], 7 * ["--"], 7 * ["-."], 7 * [":"]], [])
plotly_colors = ["#d73027", "#fc8d59", "#f33090", "#e0f3f8", "#91bfdb", "#4575b4"]
plotly_line_styles = sum([6 * ["solid"], 6 * ["dot"], 6 * ["dash"], 6 * ["longdash"], 6 * ["dashdot"], 6 * ["longdashdot"]], [])
data = []
for i, reads in enumerate(num_reads_per_bin.T):
count = np.cumsum(np.sort(reads))
count = count / count[-1] # to normalize y from 0 to 1
if args.plotFileFormat == 'plotly':
trace = go.Scatter(x=x, y=count, mode='lines', name=args.labels[i])
trace['line'].update(dash=plotly_line_styles[i % 36], color=plotly_colors[i % 6])
data.append(trace)
else:
j = i % len(pyplot_line_styles)
plt.plot(x, count, label=args.labels[i], linestyle=pyplot_line_styles[j])
plt.xlabel('rank')
plt.ylabel('fraction w.r.t. bin with highest coverage')
# set the plotFileFormat explicitly to None to trigger the
# format from the file-extension
if not args.plotFileFormat:
args.plotFileFormat = None

if args.plotFileFormat == 'plotly':
fig = go.Figure()
fig.add_traces(data)
fig['layout'].update(title=args.plotTitle)
fig['layout']['xaxis1'].update(title="rank")
fig['layout']['yaxis1'].update(title="fraction w.r.t bin with highest coverage")
py.plot(fig, filename=args.plotFile, auto_open=False)
else:
plt.legend(loc='upper left')
plt.suptitle(args.plotTitle)
plt.savefig(args.plotFile, bbox_inches=0, format=args.plotFileFormat)
plt.close()
j = i % len(pyplot_line_styles)
plt.plot(x, count, label=args.labels[i], linestyle=pyplot_line_styles[j])

plt.xlabel('rank')
plt.ylabel('fraction w.r.t. bin with highest coverage')
plt.legend(loc='upper left')
plt.suptitle(args.plotTitle)
plt.savefig(args.plotFile, bbox_inches=0, format=args.plotFileFormat)
plt.close()

if args.outRawCounts is not None:
of = open(args.outRawCounts, "w")
Expand Down

0 comments on commit 61d1f30

Please sign in to comment.