-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmk_heatmap.py
More file actions
executable file
·68 lines (54 loc) · 1.83 KB
/
Copy pathmk_heatmap.py
File metadata and controls
executable file
·68 lines (54 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# encoding: utf-8
import pickle
import sys
import numpy as np
from numpy.linalg import norm
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from prettytable import PrettyTable
from collections import defaultdict
from progressbar import ProgressBar
def truncate_colormap(cmap, minval=0.0, maxval=1.0, n=100):
new_cmap = colors.LinearSegmentedColormap.from_list(
'trunc({n},{a:.2f},{b:.2f})'.format(n=cmap.name, a=minval, b=maxval),
cmap(np.linspace(minval, maxval, n)))
return new_cmap
#Get data
data_source = sys.argv[1]
try:
outname = sys.argv[2]
except IndexError:
outname = "heatmap.eps"
heatmap = np.loadtxt(data_source)
# heatmap = heatmap/(10150*8) #<- n16N-8
# heatmap = heatmap/(9861*8) #<- n16NN-8
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.set_ylabel("Residue 1", fontsize=22, labelpad=35)
ax.set_xlabel("Residue 2", fontsize=22, labelpad=35)
plt.gcf().subplots_adjust(bottom=0.15,left=0.25)
#Axes, labels and label sizes
loc = plt.MultipleLocator(base=1.0) # this locator puts ticks at regular intervals
ax.yaxis.set_major_locator(loc)
ax.xaxis.set_major_locator(loc)
ax.xaxis.set_tick_params(width=0,labelsize=13)
ax.yaxis.set_tick_params(width=0,labelsize=11)
ax.get_yaxis().set_major_formatter(plt.FixedFormatter( list('AAYHKKCGRYSYCWIPYDIERDRYDNGDKKC') ))
ax.get_xaxis().set_major_formatter(plt.FixedFormatter( list('AAYHKKCGRYSYCWIPYDIERDRYDNGDKKC') ))
#Colour scheme
cmap=None
base_cmap=plt.get_cmap('jet')
cmap = truncate_colormap(base_cmap, 0.0, 0.92)
norm=None
#Make heatmap
imageplot = ax.imshow(heatmap, cmap=cmap, norm=norm)
cbar=fig.colorbar(imageplot)
cbar.ax.tick_params(labelsize=18)
imageplot.set_interpolation('nearest')
ax.invert_yaxis()
#Bounds of legend
clims = imageplot.get_clim()
imageplot.set_clim(0.0, clims[1])
#Save file
plt.savefig(outname)