Skip to content

Commit f2fecec

Browse files
author
Jan Ludwiczak
committed
Update plotting procedure to fit webserver requirements, add plot DPI to output options
1 parent cd35528 commit f2fecec

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

bin/deepcoil

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ parser.add_argument('--gpu',
2626
parser.add_argument('--plot',
2727
help='Plot predictions. Images will be stored in the path defined by the -out_path',
2828
action='store_true')
29+
parser.add_argument('--dpi',
30+
help='DPI of the produced images',
31+
default=300,
32+
type=int,
33+
metavar='DPI')
2934
args = parser.parse_args()
3035

3136
# Check if input file exists
@@ -74,5 +79,5 @@ for entry in out_keys:
7479
f.close()
7580
if args.plot:
7681
for entry in out_keys:
77-
plot_preds(preds[entry], out_file=f'{args.out_path}/{entry}.png')
82+
plot_preds(preds[entry], out_file=f'{args.out_path}/{entry}.png', dpi=args.dpi)
7883
print("Done!")

deepcoil/utils/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,25 @@ def sharpen_preds(probs):
5858
return sharp_probs
5959

6060

61-
def plot_preds(results, beg=0, end=-1, out_file=None):
61+
def plot_preds(results, beg=0, end=-1, out_file=None, dpi=300):
6262
"""
6363
Helper function for plotting DeepCoil results
6464
:param results: results for given entry returned by DeepCoil
6565
:param beg: (optional) beginning aa of the range to use for plotting (useful for long sequences to see only subset of results)
6666
:param end: (optional) end aa of the range to use for plotting (useful for long sequences to see only subset of results)
6767
:param out_file: (optional) if specified results will also be dumped to file
68+
:param dpi: (optional) DPI of the resulting image
6869
:return:
6970
"""
7071

7172
sharp_probs = sharpen_preds(results['cc'])[beg:end]
7273
probs, hept = results['cc'][beg:end], results['hept'][beg:end, :]
7374

74-
fig, (ax2, ax1) = plt.subplots(2, gridspec_kw={'height_ratios': [1, 9]}, figsize=(9, 7))
75+
fig, (ax2, ax1) = plt.subplots(2, gridspec_kw={'height_ratios': [1, 9]}, figsize=(9, 5))
7576

7677
# Plot probs and sharpened probs
7778
ax1.plot(probs, linewidth=1, c='gray', linestyle='dashed')
78-
ax1.plot(sharp_probs, linewidth=3, c='black')
79+
ax1.plot(sharp_probs, linewidth=2, c='black')
7980

8081
# Set axis limits
8182
ax1.set_ylim(0.01, 1)
@@ -89,12 +90,12 @@ def plot_preds(results, beg=0, end=-1, out_file=None):
8990
spacing = spacings[np.argmin([abs(10 - len([i for i in range(0, len(probs), spacing)])) for spacing in spacings])]
9091
ticks = [i for i in range(0, len(probs), spacing)]
9192
labels = [i + beg for i in range(0, len(probs), spacing)]
92-
labels[0] = ''
9393
ax1.set_xticks(ticks)
9494
ax1.set_xticklabels(labels)
9595
ax1.set_yticks([i / 10 for i in range(1, 10, 1)])
9696
ax1.xaxis.set_ticks_position('none')
97-
ax1.set_xlabel('Sequence position', fontsize=16)
97+
ax1.set_xlabel('Position in Sequence')
98+
ax1.set_ylabel('Coiled Coil Probablity')
9899

99100
# Parse a, d heptad annotations and plot
100101
a, d = [], []
@@ -120,13 +121,12 @@ def plot_preds(results, beg=0, end=-1, out_file=None):
120121
# Show the ticks corresponding to the bottom panel
121122
ax2.xaxis.grid(linestyle="dashed", color='gray', linewidth=0.5)
122123
ax2.set_xticks([i for i in range(0, len(probs), 50)])
123-
ax2.set_yticklabels(['a', 'd'], rotation=0, fontsize=12)
124+
ax2.set_yticks([0.5, 1.5])
125+
ax2.set_yticklabels(['\'a\' core pos.', '\'d\' core pos.'], rotation=0)
124126
ax2.set_xticks(ticks)
125-
ax2.set_xticklabels(labels)
126127
ax2.xaxis.set_ticks_position('none')
127128

128-
plt.tight_layout()
129129
plt.subplots_adjust(hspace=0)
130130
if out_file:
131-
plt.savefig(out_file, dpi=300)
131+
plt.savefig(out_file, dpi=dpi)
132132
plt.close()

0 commit comments

Comments
 (0)