-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcell_density_heatmaps.py
175 lines (140 loc) · 4.97 KB
/
cell_density_heatmaps.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""
smFISH data analysis
Perform analysis for single cell analysis data
"""
"""
Import python packages
"""
import HTSeq
import collections
import itertools
import os
import subprocess
import collections
import datetime
import yaml
import fnmatch
import shlex
import numpy
import scipy
import scipy.io as sio
import pyensembl
# import h5py
import pandas as pd
import numpy as np
import scipy.cluster.hierarchy as sch
from seq_functions import smFISH_cell
import rpy2
from rpy2.robjects.packages import importr
import cPickle as pickle
from seq_functions import smFISH_cell_minimal
rpy2.robjects.numpy2ri.activate()
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
matplotlib.rcParams['pdf.fonttype'] = 42
"""
Initialize R instances
"""
R = rpy2.robjects.r
DTW = importr('dtw')
DTWCLUST = importr('dtwclust')
"""
Load excel files
"""
direc = "/scratch/PI/mcovert/dvanva/sequencing/cell_density"
list_of_dfs = []
file_name = os.path.join(direc, "LPS2500_df.csv")
list_of_dfs += [pd.read_csv(file_name)]
file_name = os.path.join(direc, "LPS5000_df.csv")
list_of_dfs += [pd.read_csv(file_name)]
file_name = os.path.join(direc, "LPS10000_df.csv")
list_of_dfs += [pd.read_csv(file_name)]
file_name = os.path.join(direc, "LPS15000_df.csv")
list_of_dfs += [pd.read_csv(file_name)]
file_name = os.path.join(direc, "LPS25000_df.csv")
list_of_dfs += [pd.read_csv(file_name)]
list_of_densities = ["2500", "5000", "10000", "15000", "25000"]
"""
Load cluster averages
"""
direc = "/scratch/PI/mcovert/dvanva/sequencing/smFISH"
file_name = os.path.join(direc,"300_cluster_avg_kshape_c1.npz")
file_load = np.load(file_name)
cluster_dynamics_avg = file_load["cluster_dynamics_avg"]
dense_count = 0
for df in list_of_dfs:
list_of_cells = []
for row in xrange(len(df.index)):
norm_med = df.iloc[row,1:].values
cell = smFISH_cell_minimal(norm_med = norm_med, cluster_dynamics_avg = cluster_dynamics_avg)
list_of_cells += [cell]
"""
Plot heat map using the c1 clustering
"""
"""
Fill up the heat map matrix
"""
longest_time = 0
number_of_cells = 0
for cell in list_of_cells:
number_of_cells += 1
longest_time = np.amax([longest_time, cell.norm_med.shape[0]])
dynamics_matrix = np.zeros((number_of_cells,longest_time))
cluster_len_1 = 0
cluster_len_2 = 0
cluster_len_3 = 0
for cell in list_of_cells:
if cell.clusterID == 0:
cluster_len_1 += 1
if cell.clusterID == 1:
cluster_len_2 += 1
if cell.clusterID == 2:
cluster_len_3 += 1
print cluster_len_1, cluster_len_2, cluster_len_3
frac_1 = np.float(cluster_len_1) / np.float(cluster_len_1 + cluster_len_2 + cluster_len_3)
frac_2 = np.float(cluster_len_2) / np.float(cluster_len_1 + cluster_len_2 + cluster_len_3)
frac_3 = np.float(cluster_len_3) / np.float(cluster_len_1 + cluster_len_2 + cluster_len_3)
print frac_1, frac_2, frac_3
cell_counter = 0
fig = plt.figure()
ax_heatmap_1 = fig.add_axes([0.3, 0.1 +0.005, 0.6, 0.8*frac_1 - 0.005], frame_on = True)
ax_heatmap_2 = fig.add_axes([0.3, 0.1 +0.005+ 0.8*frac_1, 0.6 , 0.8*frac_2 - 0.005], frame_on = True)
ax_heatmap_3 = fig.add_axes([0.3, 0.1 +0.005+ 0.8*frac_1 + 0.8*frac_2, 0.6, 0.8*frac_3 - 0.005], frame_on = True)
for cell in list_of_cells:
if cell.clusterID == 0:
dynam = cell.norm_med
dynamics_matrix[cell_counter,0:dynam.shape[0]] = dynam
cell_counter += 1
for cell in list_of_cells:
if cell.clusterID == 1:
dynam = cell.norm_med
dynamics_matrix[cell_counter,0:dynam.shape[0]] = dynam
cell_counter += 1
for cell in list_of_cells:
if cell.clusterID == 2:
dynam = cell.norm_med
dynamics_matrix[cell_counter,0:dynam.shape[0]] = dynam
cell_counter += 1
# ax_heatmap = fig.add_axes([0.3, 0.1, 0.6, 0.8])
im1 = ax_heatmap_1.matshow(dynamics_matrix[0:cluster_len_1,:], aspect = 'auto', origin = 'lower', cmap = plt.get_cmap('Reds'), interpolation = 'none')
im2 = ax_heatmap_2.matshow(dynamics_matrix[cluster_len_1:cluster_len_1+cluster_len_2,:], aspect = 'auto', origin = 'lower', cmap = plt.get_cmap('Reds'), interpolation = 'none')
im3 = ax_heatmap_3.matshow(dynamics_matrix[cluster_len_1+cluster_len_2:,:], aspect = 'auto', origin = 'lower', cmap = plt.get_cmap('Reds'), interpolation = 'none')
# fig.colorbar(im1, ticks = [0, 1], orientation = 'vertical')
# ax_heatmap.xaxis.set_ticks(np.arange(63))
ax_heatmap_1.xaxis.set_ticklabels([])
ax_heatmap_1.xaxis.set_ticks([])
ax_heatmap_1.yaxis.set_ticklabels([])
ax_heatmap_1.yaxis.set_ticks([])
ax_heatmap_2.yaxis.set_ticklabels([])
ax_heatmap_2.yaxis.set_ticks([])
ax_heatmap_2.xaxis.set_ticklabels([])
ax_heatmap_2.xaxis.set_ticks([])
ax_heatmap_3.yaxis.set_ticklabels([])
ax_heatmap_3.yaxis.set_ticks([])
ax_heatmap_3.xaxis.set_ticklabels([])
ax_heatmap_3.xaxis.set_ticks([])
ax_heatmap_3.set_title("Cell density - " + list_of_densities[dense_count] + " - 300 minutes - " + str(number_of_cells) + ' cells', y = 1.05)
ax_heatmap_1.set_xlabel('Time (minutes)')
plt.savefig("plots/300min_cell_density_dynamics_c1_clustering_"+ list_of_densities[dense_count] +".pdf")
dense_count += 1