@@ -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 ,
0 commit comments