Skip to content
This repository was archived by the owner on Aug 15, 2018. It is now read-only.

Commit a08830a

Browse files
sparkvillariccardomurri
authored andcommitted
added wellX and wellY as params for LocalCC
1 parent 05cdb94 commit a08830a

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

tmlib/workflow/popcon/api.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,6 @@ def delete_previous_job_output(self):
9999
children instances for the processed experiment.
100100
'''
101101
pass
102-
# logger.info('delete existing mapobjects and mapobject types')
103-
# with tm.utils.ExperimentSession(self.experiment_id, False) as session:
104-
# static_types = ['Plates', 'Wells', 'Sites']
105-
# mapobject_types = session.query(tm.MapobjectType.id).\
106-
# filter(~tm.MapobjectType.name.in_(static_types)).\
107-
# all()
108-
# mapobject_type_ids = [t.id for t in mapobject_types]
109-
# session.query(tm.Mapobject).\
110-
# filter(tm.Mapobject.mapobject_type_id.in_(mapobject_type_ids)).\
111-
# delete()
112-
# session.query(tm.MapobjectType).\
113-
# filter(tm.MapobjectType.id.in_(mapobject_type_ids)).\
114-
#delete()
115102

116103
def run_job(self, batch, assume_clean_state):
117104
'''Runs the pipeline, i.e. executes modules sequentially. After
@@ -126,32 +113,51 @@ def run_job(self, batch, assume_clean_state):
126113
for well_id in batch['well_ids']:
127114
logger.info('process well %d', well_id)
128115
with tm.utils.ExperimentSession(self.experiment_id) as session:
129-
# sites = session.query(tm.Site.id, tm.Site.height, tm.Site.width, tm.Site.y, tm.Site.x).\
130-
# filter_by(well_id=well_id).all()
131-
# wellY = sites_per_well[0][1]*len(set([i[3] for i in sites_per_well]))
132-
# wellX = sites_per_well[0][2]*len(set([i[4]for i in sites_per_well]))
116+
sites = session.query(tm.Site.id, tm.Site.height, tm.Site.width, tm.Site.y, tm.Site.x).\
117+
filter_by(well_id=well_id).all()
118+
wellY = sites[0][1]*len(set([i[3] for i in sites]))
119+
wellX = sites[0][2]*len(set([i[4]for i in sites]))
120+
133121

134-
extract_mapobject_type_id = session.query(tm.MapobjectType.id).filter_by(name=batch['extract_object']).one()[0]
135-
extract_seg_layer_id = session.query(tm.SegmentationLayer.id).filter_by(mapobject_type_id=extract_mapobject_type_id).one()[0]
136-
extract_centroids = session.query(tm.MapobjectSegmentation.geom_centroid,tm.MapobjectSegmentation.mapobject_id,tm.MapobjectSegmentation.label,tm.MapobjectSegmentation.partition_key).filter_by(segmentation_layer_id=extract_seg_layer_id).all()
137-
assign_mapobject_type_id = session.query(tm.MapobjectType.id).filter_by(name=batch['assign_object']).one()[0]
138-
assign_seg_layer_id = session.query(tm.SegmentationLayer.id).filter_by(mapobject_type_id=assign_mapobject_type_id).one()[0]
139-
assign_centroids = session.query(tm.MapobjectSegmentation.geom_centroid,tm.MapobjectSegmentation.mapobject_id,tm.MapobjectSegmentation.label,tm.MapobjectSegmentation.partition_key).filter_by(segmentation_layer_id=assign_seg_layer_id).all()
122+
extract_mapobject_type_id = session.query(tm.MapobjectType.id).\
123+
filter_by(name=batch['extract_object']).one()[0]
124+
extract_seg_layer_id = session.query(tm.SegmentationLayer.id).\
125+
filter_by(mapobject_type_id=extract_mapobject_type_id).one()[0]
126+
extract_centroids = session.query(tm.MapobjectSegmentation.geom_centroid,tm.MapobjectSegmentation.mapobject_id,tm.MapobjectSegmentation.label,tm.MapobjectSegmentation.partition_key).\
127+
filter_by(segmentation_layer_id=extract_seg_layer_id).all()
128+
assign_mapobject_type_id = session.query(tm.MapobjectType.id).\
129+
filter_by(name=batch['assign_object']).one()[0]
130+
assign_seg_layer_id = session.query(tm.SegmentationLayer.id).\
131+
filter_by(mapobject_type_id=assign_mapobject_type_id).one()[0]
132+
assign_centroids = session.query(tm.MapobjectSegmentation.geom_centroid,tm.MapobjectSegmentation.mapobject_id,tm.MapobjectSegmentation.label,tm.MapobjectSegmentation.partition_key).\
133+
filter_by(segmentation_layer_id=assign_seg_layer_id).all()
140134

141135
logger.info('Calculating LCC for well_id %s', well_id)
142-
lcc_extract = LocalCC(extract_centroids)
136+
logger.info('Instantiating LCC for extract_object')
137+
lcc_extract = LocalCC(extract_centroids, wellY, wellX)
138+
logger.info('df lcc_extract: %s',lcc_extract.df.head())
139+
logger.info(
140+
'wellX: %s, wellY: %s, diagonal: %s'
141+
, lcc_extract.wellX, lcc_extract.wellY, lcc_extract.well_diagonal)
142+
143143
real_lcc = lcc_extract.real_distances()
144144
random_lcc = lcc_extract.random_distances()
145145
lcc = lcc_extract.get_lcc(real_lcc,random_lcc)
146-
147-
lcc_assign = LocalCC(assign_centroids)
146+
logger.info('Instantiating LCC for assign_object')
147+
lcc_assign = LocalCC(assign_centroids, wellY, wellX)
148148

149149
# remap y,x coordinates of extract object with mapobject_id
150150
# of assign object
151-
lcc_extract.df['mapobject_id'] = lcc_assign.df['mapobject_id']
151+
logger.info(
152+
'assign mapobject_id of %s to %s'
153+
, batch['assign_object'], batch['extract_object'])
152154

155+
#logger.debug(
156+
# 'assign: %s extract: %s', lcc_assign.df['mapobject_id'], lcc_extract.df['mapobject_id'])
157+
158+
lcc_extract.df['mapobject_id'] = lcc_assign.df['mapobject_id']
153159

154-
feature_name = batch['extract_object']+'_{}_lcc'.format(well_id)
160+
feature_name = 'LocalCellCrowding_{}'.format(batch['extract_object'])
155161
feature = session.get_or_create(
156162
tm.Feature, name=feature_name,
157163
mapobject_type_id=assign_mapobject_type_id,

tmlib/workflow/popcon/lcc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _get_df(np_centroids):
2828
df = data_df.sort_values(['site', 'label'])
2929
return df
3030

31-
def __init__(self, centroids):
31+
def __init__(self, centroids, wellY, wellX):
3232
'''
3333
Parameters
3434
----------
@@ -37,12 +37,12 @@ def __init__(self, centroids):
3737
'''
3838
self.centroids = centroids
3939

40-
self.centroids_coordinates = [(self._get_yx(element[0]).y,self._get_yx(element[0]).x, int(element[1]), int(element[2]), int(element[3])) for element in self.centroids]
40+
self.centroids_coordinates = [(abs(self._get_yx(element[0]).y),abs(self._get_yx(element[0]).x), int(element[1]), int(element[2]), int(element[3])) for element in self.centroids]
4141

4242
self.df = self._get_df(self.centroids_coordinates)
4343
self.yx_coordinates = np.asarray((self.df['y'],self.df['x'])).transpose()
44-
self.wellY = np.floor(self.df['y'].min())
45-
self.wellX = np.ceil(self.df['x'].max())
44+
self.wellY = wellY
45+
self.wellX = wellX
4646
self.well_diagonal = np.round(math.sqrt(self.wellX**2+self.wellY**2))
4747

4848

@@ -67,7 +67,7 @@ def random_distances(self):
6767
rand_dists= list()
6868

6969
for yx_real in self.yx_coordinates:
70-
y_rand= np.random.uniform(self.wellY,0,len(self.yx_coordinates)-1)
70+
y_rand= np.random.uniform(0,self.wellY,len(self.yx_coordinates)-1)
7171
x_rand= np.random.uniform(0,self.wellX,len(self.yx_coordinates)-1)
7272
yx_coordinates_random = np.concatenate( (y_rand[:,np.newaxis],x_rand[:,np.newaxis]), axis=1)
7373

0 commit comments

Comments
 (0)