-
Notifications
You must be signed in to change notification settings - Fork 0
/
rna_distmap_clust.py
61 lines (51 loc) · 1.58 KB
/
rna_distmap_clust.py
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
#!/usr/bin/env python
# The following python script is aimed at recreating interatomic distance plots such
# as the one in Figure 2 of Malathi and Yathindra, Biochemical Journal, 1982,
# 205, 457-460. It also creates a clustering diagram in both axes.
# http://www.ncbi.nlm.nih.gov/pmc/articles/PMC1158502/?page=3
from numpy import *
#import matplotlib.pyplot as plt
import pylab
import scipy
import scipy.cluster.hierarchy as sch
#
# CMmatr is the output of and octave script
# which computes the interatomic distance
# matrix from pdbfiles which have been parsed
# with an awk/bash script called PPdistance
#
inp = open("CMmatr");
#Arrange the data in an array
dist_arr = []
for line in inp.readlines():
dist_arr.append([])
for i in line.split():
dist_arr[-1].append(float(i))
inp.close()
M = array(dist_arr)
# Compute and plot first dendrogram.
fig = pylab.plt.figure(figsize=(8,8))
ax1 = fig.add_axes([0.09,0.1,0.2,0.6])
Y = sch.linkage(M, method='centroid')
Z1 = sch.dendrogram(Y, orientation='right')
ax1.set_xticks([])
ax1.set_yticks([])
# Compute and plot second dendrogram.
ax2 = fig.add_axes([0.3,0.71,0.6,0.2])
Y = sch.linkage(M, method='single')
Z2 = sch.dendrogram(Y)
ax2.set_xticks([])
ax2.set_yticks([])
# Plot distance matrix.
axmatrix = fig.add_axes([0.3,0.1,0.6,0.6])
idx1 = Z1['leaves']
idx2 = Z2['leaves']
M = M[idx1,:]
M = M[:,idx2]
im = axmatrix.matshow(M, aspect='auto', origin='lower', cmap=pylab.cm.YlGnBu)
axmatrix.set_xticks([])
axmatrix.set_yticks([])
# Plot colorbar.
axcolor = fig.add_axes([0.91,0.1,0.02,0.6])
pylab.colorbar(im, cax=axcolor)
fig.show()