-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUsingSSBDapi.py
More file actions
233 lines (132 loc) · 4.31 KB
/
Copy pathUsingSSBDapi.py
File metadata and controls
233 lines (132 loc) · 4.31 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# coding: utf-8
# # Using Python SSBDapi to access SSBD data for visualization and analysis
# In[1]:
get_ipython().magic(u"config InlineBackend.figure_formats=['png']")
# In[2]:
from IPython.display import display
# In[3]:
import matplotlib.pyplot as plt
# In[4]:
import numpy as np
import pandas as pd
# In[5]:
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d import proj3d
# In[6]:
get_ipython().magic(u'matplotlib inline')
# ## Loading ivisual library allows iPython to use VPython to display 3D graphics
#
# * Installing ivisual can be found here https://github.com/mwcraig/ivisual-notebook-info
# In[7]:
from ivisual import *
# ## Loading json library allows iPython to deal with JSON formatted data
# In[8]:
import json
# # Loading SSBDapi Library
# In[9]:
import SSBDapi as ssbdapi
# ## Using ssbdapi function 'meta_data' to search for simulation 'sim' in the field 'basedon'
# In[10]:
q=ssbdapi.ssbd()
q.set_display('on')
resultdata = q.meta_data('basedon', 'sim')
# ## Using ssbdapi function 'meta_data' to search for 'osaka' in the field 'address'
# In[11]:
resultdata = q.meta_data('address', 'osaka')
# ## Using ssbdapi function 'meta_data' to search for 'osaka' in the field 'address'
# In[12]:
resultdata = q.meta_data(field='contributors', search='keller')
# ## Using ssbdapi function 'data' to search for string '505' in the field 'localid'
# In[13]:
resultdata = q.data(field='localid', search='505')
# ## Return data is in JSON format
# In[14]:
print(resultdata)
# ## Retrieve function to get all the coordinates at a specific time point
# In[15]:
def retrieve_coord_tp(bdmlID, timept, display='on'):
q=ssbdapi.ssbd()
q.set_display(display)
tmp_result = q.coordXYZ(bdmlID, timept)
total = tmp_result['meta']['total_count']
#print "total=", total
result=tmp_result
tmp_offset=0
while total>0:
tmp_offset=tmp_offset+100
tmp_result=q.coordXYZ(bdmlID, timept, offset=tmp_offset)
result['objects']=result['objects']+tmp_result['objects']
total=total-100
return(result)
# ## Call retrieve coordinates function to get the coordinates of BDMLID that contains string 'd15115' at time point 15
# In[16]:
resultdata=retrieve_coord_tp('d15115', 15)
# ## Using the ssbdapi function 'scale' and search for bdmlID using field 'bdml__bdml_ID'
# In[17]:
s=q.scale(field='bdml__bdml_ID', search='d15115')
# ## Setup a canvas to display 3D graphics
# In[21]:
canvas(title="Displaying 3D graphics", background=(0.8,0.8,0.8) )
c = color.red
r = 0.1
x = 0
y = 0
Z = 0
# ## Visualization - displaying the coordinates as sphere in 3D
# In[22]:
for j in s['objects']:
sx = j['xScale']
sy = j['yScale']
sz = j['zScale']
sr = j['xScale']
st = j['tScale']
tu = j['tUnit']
# In[23]:
for i in resultdata['objects']:
sphere(pos=(i['x']*sx, i['y']*sy, i['z']*sz), color=c, radius=i['radius'])
# ## Analysis - plotting the proliferation curve
# In[24]:
no_of_nucleus = []
timept = []
tp = 1
resultdata = retrieve_coord_tp('d15115', tp, display='off')
nn =resultdata['meta']['total_count']
while nn > 0:
no_of_nucleus.append(nn)
timept.append(tp)
# print "tp="+str(tp)+" nn="+str(nn)
tp=tp+1
resultdata = retrieve_coord_tp('d15115', tp, display='off')
nn =resultdata['meta']['total_count']
# ## Get the title, organism and contact name of the dataset
# In[25]:
q.set_display('off')
resultmetadata = q.data(field='bdmlUUID', search='d15115')
for i in resultmetadata['objects']:
title= i['meta_data']['title']
name= i['meta_data']['name']
pmid = i['meta_data']['PMID']
organism = i['meta_data']['organism']
# ## Plotting the curve
# In[26]:
fig=plt.figure()
plt.plot(timept, no_of_nucleus, 'r')
ax = fig.add_subplot(1,1,1)
ax.set_ylabel('cellstage')
ax.set_xlabel('timepoint')
plottitle = title+' ['+organism+'] ('+name+') PMID: '+str(pmid)+' Cell divsion over time '
plt.title(plottitle);
# ### Plotting using actual time instead of time point
# In[27]:
tmp=np.array(timept)
time=tmp*st
fig=plt.figure()
plt.plot(time, no_of_nucleus, 'r')
ax = fig.add_subplot(1,1,1)
ax.set_ylabel('cellstage')
xlabel = 'time ( '+tu+' )'
ax.set_xlabel(xlabel)
plottitle = title+' ('+name+') PMID: '+str(pmid)+' Cell divsion over time '
plt.title(plottitle);
# In[ ]:
# In[ ]: