Skip to content

Commit a3ab273

Browse files
committed
merging develop
2 parents 05d5733 + 2b9fa35 commit a3ab273

File tree

50 files changed

+3467
-350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3467
-350
lines changed

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ dist
66
.ipynb_checkpoints
77
*.DS_Store
88
.vscode
9-
*.py.save
9+
*.py.save
10+
11+
cellimages
12+
example_json/
13+
*.png
14+
*.ipynb
15+
psf

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM fcollman/render-python:latest
1+
FROM fcollman/render-modules:master
22
MAINTAINER Forrest Collman ([email protected])
33
RUN mkdir -p /usr/local/render-python-apps
44
WORKDIR /usr/local/render-python-apps
@@ -8,6 +8,7 @@ RUN pip install setuptools --upgrade --disable-pip-version-check
88
RUN pip install argschema --upgrade --disable-pip-version-check
99
RUN pip install jupyter
1010
RUN apt-get install libspatialindex-dev -y
11+
RUN conda install nomkl
1112
COPY . /usr/local/render-python-apps
1213

1314
#RUN git clone https://github.com/fcollman/render-python-apps

allen_utils/docker_setup.sh

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
docker pull atbigdawg:5000/fcollman/render-python:latest
2-
docker tag atbigdawg:5000/fcollman/render-python:latest fcollman/render-python:latest
1+
#docker pull atbigdawg:5000/fcollman/render-python:latest
2+
#docker tag atbigdawg:5000/fcollman/render-python:latest fcollman/render-python:latest
33
docker build -t fcollman/render-python-apps .
44
docker tag fcollman/render-python-apps atbigdawg:5000/fcollman/render-python-apps
55
docker push atbigdawg:5000/fcollman/render-python-apps
@@ -10,14 +10,11 @@ docker run -t --name renderapps \
1010
-v /nas2:/nas2 \
1111
-v /nas3:/nas3 \
1212
-v /nas4:/nas4 \
13+
-v /nas5:/nas5 \
1314
-v /data:/data \
1415
-v /pipeline:/pipeline \
1516
-v /pipeline/render-python-apps:/usr/local/render-python-apps \
1617
-v /etc/hosts:/etc/hosts \
17-
--dns 10.128.104.10 \
18-
-p 8888:8888 \
18+
-p 7777:7777 \
1919
-e "PASSWORD=$JUPYTERPASSWORD" \
20-
-i -t fcollman/render-python-apps \
21-
/bin/bash -c "/opt/conda/bin/jupyter notebook --config=/root/.jupyter/jupyter_notebook_config.py --notebook-dir=/pipeline/render-python-apps --no-browser --allow-root"
22-
23-
20+
-i -t fcollman/render-python-apps

allen_utils/reorg_setup.sh

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
docker pull atbigdawg:5000/fcollman/render-python:master
2-
docker tag atbigdawg:5000/fcollman/render-python:master fcollman/render-python
3-
docker build -t fcollman/render-python-apps:reorg .
4-
docker tag fcollman/render-python-apps:reorg fcollman/render-python-apps:reorg_testsharmi
5-
docker push atbigdawg:5000/fcollman/render-python-apps
6-
docker kill renderapps_testsharmi
7-
docker rm renderapps_testsharmi
8-
docker run -d --name renderapps_testsharmi \
1+
docker pull localhost:5000/fcollman/render-python:master
2+
docker tag localhost:5000/fcollman/render-python:master fcollman/render-python
3+
docker build -t sharmi/render-python-apps:reorg .
4+
#docker tag fcollman/render-python-apps:reorg fcollman/render-python-apps:reorg_testsharmi
5+
#docker push atbigdawg:5000/fcollman/render-python-apps
6+
docker kill renderapps_develop
7+
docker rm renderapps_develop
8+
docker run -d --name renderapps_develop \
99
-v /nas2:/nas2 \
1010
-v /nas:/nas \
1111
-v /nas3:/nas3 \
1212
-v /nas4:/nas4 \
1313
-v /data:/data \
1414
-v /pipeline:/pipeline \
15-
-v /pipeline/sharmi/Sharmi_tools/render-python-apps:/usr/local/render-python-apps \
15+
-v /pipeline/sharmi/Sharmi_tools/render-python-apps-branches/DEVELOP/render-python-apps:/usr/local/share/render-python-apps \
1616
-v /etc/hosts:/etc/hosts \
17-
-p 9999:9999 \
17+
-p 7777:7777 \
1818
-e "PASSWORD=$JUPYTERPASSWORD" \
19-
-i -t fcollman/render-python-apps:reorg_testsharmi
20-
21-
19+
-i -t sharmi/render-python-apps:reorg \
20+
/bin/bash -c "jupyter notebook --config=/root/.jupyter/jupyter_notebook_config.py --no-browser --allow-root --notebook-dir=/pipeline/sharmi/Sharmi_tools/render-python-apps-branches/DEVELOP/render-python-apps"

jupyter_notebook_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from IPython.lib import passwd
1717

1818
c.NotebookApp.ip = '*'
19-
c.NotebookApp.port = 8888
19+
c.NotebookApp.port = 7777
2020
c.NotebookApp.open_browser = False
2121
c.MultiKernelManager.default_kernel_name = 'python2'
2222

renderapps/TrakEM2/AnnotationJsonSchema.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Area(argschema.schemas.mm.Schema):
1919
description='Nx2 numpy array of local points')
2020
global_path = NumpyArray(argschema.fields.List(argschema.fields.Float),
2121
description='Nx2 numpy array of global coordinates')
22+
z = argschema.fields.Float(required=False,description="z value of tileId")
2223

2324
class AreaList(argschema.schemas.mm.Schema):
2425
oid = argschema.fields.Str()

renderapps/TrakEM2/ImportTrakEM2Annotations.py

+24-10
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
"project": "M247514_Rorb_1",
1919
"client_scripts": "/pipeline/render/render-ws-java-client/src/main/scripts"
2020
},
21-
"EMstack": "ALIGNEM_reg2",
22-
"trakem2project": "/nas4/data/EM_annotation/annotationFilesForJHU/annotationTrakEMprojects_M247514_Rorb_1/m247514_Site3Annotation_RD.xml",
23-
"output_annotation_file": "/nas4/data/EM_annotation/annotationFilesForJHU/m247514_Site3Annotation_RD_local.json",
24-
"output_bounding_box_file": "/nas4/data/EM_annotation/annotationFilesForJHU/m247514_Site3Annotation_RD_bb_local.json",
21+
"EMstack": "BIGALIGN_LENS_EMclahe_all",
22+
"trakem2project": "/nas4/data/EM_annotation/M247514_Rorb_1/m247514_Site3Annotation_MN.xml",
23+
"output_annotation_file": "/nas3/data/M247514_Rorb_1/annotation/m247514_Site3Annotation_MN_local.json",
24+
"output_bounding_box_file":"/nas3/data/M247514_Rorb_1/annotation/m247514_Site3Annotation_MN_bb_local.json",
2525
"renderHome": "/pipeline/render"
2626
}
2727

2828

29+
2930
class AnnotationConversionError(Exception):
3031
pass
3132

@@ -98,8 +99,10 @@ def convert_path_to_area(path_numpy, layer_tilespecs):
9899
local_path_numpy[convert_point_mask_ind, :] = local_points
99100
point_missing[convert_point_mask_ind] = 0
100101
local_tileIds[convert_point_mask_ind] = rts.tileId
101-
102-
assert(np.sum(point_missing) == 0)
102+
103+
if np.sum(point_missing)>0:
104+
raise AnnotationConversionError("unable to find all points {} on the tiles given {}".format(path_numpy,[ts.tileId for poly,ts,rts in layer_tilespecs]))
105+
103106

104107
d = {}
105108
d['tileIds'] = local_tileIds
@@ -134,7 +137,10 @@ def parse_area_lists(render_tilespecs, tem2_tilespecs, tem2_polygons, root, area
134137
for path in paths:
135138
# initialize the path's polygon with the entire path
136139
path_numpy = convert_path(path, tform)
137-
d = convert_path_to_area(path_numpy, layer_tilespecs)
140+
try:
141+
d = convert_path_to_area(path_numpy, layer_tilespecs)
142+
except AnnotationConversionError as e:
143+
raise AnnotationConversionError("error in converting synapse oid:{} id:{} on layer:{}, {}".format(al.attrib['oid'],thisid,layerid,e.args))
138144
area_list_d['areas'].append(d)
139145

140146
json_output['area_lists'].append(area_list_d)
@@ -168,8 +174,13 @@ def run(self):
168174
pot_render_tilespecs = self.render.run(renderapi.tilespec.get_tile_specs_from_z,
169175
self.args['EMstack'],
170176
ts.z)
171-
filepath = (os.path.split(ts.ip.get(0)['imageUrl'])[
172-
1]).split('_flip')[0]
177+
try:
178+
mml=ts.ip.get(0)
179+
except KeyError:
180+
mml = ts.channels[0].ip.get(0)
181+
182+
183+
filepath = (os.path.split(mml['imageUrl'])[1]).split('_flip')[0]
173184
pot_filepaths = [(os.path.split(t.ip.get(0)['imageUrl'])[1]).split(
174185
'_flip')[0] for t in pot_render_tilespecs]
175186
render_tilespecs.append(next(t for t, fp in zip(
@@ -204,7 +215,10 @@ def run(self):
204215
layer_tilespecs = [(poly, ts, t) for poly, ts, t
205216
in zip(tem2_polygons, tem2_tilespecs, render_tilespecs)
206217
if ts.tileId in patchids]
207-
d = convert_path_to_area(corners,layer_tilespecs)
218+
try:
219+
d = convert_path_to_area(corners,layer_tilespecs)
220+
except AnnotationConversionError as e:
221+
raise AnnotationConversionError("unable to find bounding box of layer {} z={}, due to corners not being on layers with patches {} ".format(layer.attrib['oid'],layer.attrib['z'],patchids))
208222
area_list_d = {}
209223
area_list_d['oid'] = layer.attrib['oid']
210224
area_list_d['id'] = int(layer_tilespecs[0][2].z)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
import renderapi
2+
import matplotlib as mpl
3+
mpl.use('Agg')
4+
from renderapps.module.render_module import RenderParameters, RenderModule
5+
import argschema
6+
from renderapps.TrakEM2.AnnotationJsonSchema import AnnotationFile
7+
import matplotlib.pyplot as plt
8+
#%matplotlib notebook
9+
import numpy as np
10+
import os
11+
import pandas as pd
12+
from multiprocessing import pool
13+
from functools import partial
14+
import json
15+
16+
17+
############## this is modified from notebook: http://ibs-forrestc-ux1:8888/notebooks/MakeSynaptogramsFromAnnotations.ipynb #####
18+
19+
20+
example_parameters = {
21+
"render":{
22+
"host": "ibs-forrestc-ux1",
23+
"port": 80,
24+
"owner": "Forrest",
25+
"project": "M246930_Scnn1a_4_f1",
26+
"client_scripts": "/pipeline/render/render-ws-java-client/src/main/scripts"
27+
},
28+
29+
"global_annotation_file":"/nas/data/M246930_Scnn1a_4_f1/annotation/m246930_site5_annotation_MN_adjustZ_bb_Take2Site5_EMA_global.json",
30+
"annotation_metadata_json":"/nas/data/M246930_Scnn1a_4_f1/SEMdata/processed/Synaptograms/annotationMetadata/m246930_Take2Site5_synaptogram_metadata.json",
31+
"fig_directory":"/nas/data/M246930_Scnn1a_4_f1/SEMdata/processed/Synaptograms/Take2Site5_TdTeSyn",
32+
"synapses_to_make":['1226','1326','1416','2171','2299','668','2707','2709','2711'],
33+
"channel_stacks":[
34+
{
35+
36+
"stack":"EMSite5_take2_EMA"
37+
},
38+
{
39+
40+
"stack":"EMSite5_take2_EMA"
41+
},
42+
{
43+
"channel":"TdTomato",
44+
"stack":"Take2Site5_EMA_STI_DCV_FF_allSession_2",
45+
"maxIntensity":10000
46+
},
47+
{
48+
"channel":"synapsin",
49+
"stack":"Take2Site5_manReg_EMA_STI_DCV_FF_allSession_3",
50+
"maxIntensity":16000
51+
}
52+
]
53+
}
54+
55+
56+
57+
class ChannelStack(argschema.schemas.DefaultSchema):
58+
channel = argschema.fields.Str(required=False,
59+
description="Channel of stack to render (if needed)")
60+
stack = argschema.fields.Str(required=True,
61+
description="render stack to render")
62+
maxIntensity = argschema.fields.Int(required=False,
63+
description="Max intensity to render this channel")
64+
65+
class MakeAnnotationSynaptogramParameters(RenderParameters):
66+
global_annotation_file = argschema.fields.InputFile(required=True,
67+
description = "global annotation file")
68+
fig_directory = argschema.fields.OutputDir(required=True,
69+
description = "directory to store figures")
70+
annotation_metadata_json = argschema.fields.OutputFile(required=True,
71+
description = "where to save metadata")
72+
channel_stacks = argschema.fields.Nested(ChannelStack,
73+
many=True,
74+
required=True,
75+
description="list of Channel Stacks to render")
76+
synapses_to_make=argschema.fields.List(argschema.fields.Str,
77+
required=False,
78+
description="list of oid's to make synapses from")
79+
80+
81+
82+
def load_annotation_file(annotation_path):
83+
with open(annotation_path,'r') as fp:
84+
annotation_d = json.load(fp)
85+
schema = AnnotationFile()
86+
annotations,errors = schema.load(annotation_d)
87+
assert(len(errors)==0)
88+
return annotations
89+
90+
def make_synaptogram(render,channel_stacks,savedir,al,border=400/3,borderz=2):
91+
oid = al['oid']
92+
zvalues = []
93+
Nareas = len(al['areas'])
94+
mins = np.zeros((Nareas,2))
95+
maxs = np.zeros((Nareas,2))
96+
for i,area in enumerate(al['areas']):
97+
zvalues.append(area['z'])
98+
gp = area['global_path']
99+
mins[i,:] = np.min(gp,axis=0)
100+
maxs[i,:] = np.max(gp,axis=0)
101+
gmins = np.min(mins,axis=0)-border
102+
gmaxs = np.max(maxs,axis=0)+border
103+
minX = gmins[0]
104+
minY = gmins[1]
105+
maxX = gmaxs[0]
106+
maxY = gmaxs[1]
107+
width = maxX-minX+1
108+
height = maxY-minY+1
109+
zvalues=sorted(zvalues)
110+
zvals = np.arange(np.min(zvalues)-1,np.max(zvalues)+1+1)
111+
Nz = len(zvals)
112+
Nc = len(channel_stacks)
113+
minZ = int(min(zvals))
114+
ratio = ((Nc)*(height)*1.05)/((Nz)*(width)*1.0)
115+
fig_width=.5*(width*Nz)/100.0
116+
print width,height,Nz
117+
d={
118+
'oid':oid,
119+
'id':al['id'],
120+
'minX':minX,
121+
'maxX':maxX,
122+
'minY':minY,
123+
'maxY':maxY,
124+
'Nz':Nz,
125+
'minZ':minZ,
126+
'maxZ':minZ+Nz,
127+
'width':width,
128+
'height':height
129+
}
130+
if width>1000:
131+
return d
132+
if height>1000:
133+
return d
134+
if len(zvals)>16:
135+
return d
136+
plt.rcParams['axes.facecolor'] = 'black'
137+
f,ax=plt.subplots(Nc,Nz,
138+
figsize=(fig_width,int(fig_width*ratio)),
139+
gridspec_kw = {'wspace':0, 'hspace':0},
140+
facecolor='black')
141+
plt.subplots_adjust(left=0.0, right=1.0, top=1.0, bottom=0.0)
142+
for c,chstack in enumerate(channel_stacks):
143+
for zi,z in enumerate(zvals):
144+
a=ax[c,zi]
145+
a.set_xlim([minX,maxX])
146+
a.set_ylim([minY,maxY])
147+
a.set_xticks([])
148+
a.set_yticks([])
149+
a.set_aspect('equal')
150+
chname = chstack.get('channel',None)
151+
maxIntensity = chstack.get('maxIntensity',None)
152+
img = renderapi.image.get_bb_image(chstack['stack'],
153+
z,
154+
minX,
155+
minY,
156+
width,
157+
height,
158+
channel=chname,
159+
maxIntensity=maxIntensity,
160+
render=render)
161+
a.imshow(img,vmin=0,vmax=255,extent=[minX,maxX,maxY,minY])
162+
for i,area in enumerate(al['areas']):
163+
zi = int(area['z']-minZ)
164+
for c in range(1,len(channel_stacks)):
165+
a = ax[c,zi]
166+
a.plot(area['global_path'][:,0],area['global_path'][:,1],c='Teal',linewidth=2)
167+
for c,chstack in enumerate(channel_stacks):
168+
chname = chstack.get('channel',chstack['stack'])
169+
170+
ax[c,0].text(minX,minY,chname[0:4],fontdict={'color':'SLATEGRAY','weight':'bold'},fontsize=14)
171+
#f.tight_layout(True)
172+
fname = os.path.join(savedir,'{}.png'.format(oid))
173+
f.savefig(fname)
174+
d['figure']=fname
175+
plt.clf()
176+
plt.close()
177+
del(f)
178+
return d
179+
180+
181+
class MakeAnnotationSynaptograms(RenderModule):
182+
default_schema = MakeAnnotationSynaptogramParameters
183+
184+
def run(self):
185+
print self.args
186+
annotations = load_annotation_file(self.args['global_annotation_file'])
187+
188+
if not os.path.isdir(self.args['fig_directory']):
189+
os.makedirs(self.args['fig_directory'])
190+
191+
192+
myp = partial(make_synaptogram,
193+
self.render,
194+
self.args['channel_stacks'],
195+
self.args['fig_directory'])
196+
197+
#print disagree_oids
198+
proc_pool= pool.Pool(6)
199+
good_oids = self.args.get('synapses_to_make',None)
200+
if good_oids is not None:
201+
good_ann =[al for al in annotations['area_lists'] if al['oid'] in good_oids]
202+
ds = proc_pool.map(myp,good_ann)
203+
else:
204+
ds=proc_pool.map(myp,annotations['area_lists'])
205+
print(len(ds))
206+
with open(self.args['annotation_metadata_json'],'w') as fp:
207+
json.dump(ds,fp)
208+
209+
210+
if __name__ == '__main__':
211+
mod = MakeAnnotationSynaptograms(input_data = example_parameters)
212+
mod.run()

0 commit comments

Comments
 (0)