def legacy(): """ This is the code that I had originall wrote to do this. This code was really messy, but worked, so I am leaving it here. It has been rewritten in the above functions, but could be useful to look at. """ ## initialize the scope scope=DGLab_Leica2.DGLab_Leica2() ## set up the rows=string.ascii_uppercase[1:7] columns=range(2,12) sites=range(0,225) pos_string=open("PositionList_96well_15x15sites.pos").read() positions=StagePositions.positionList_parser(pos_string) scope.mmc.enableContinuousFocus(True) scope.set_illumination(Illuminations.Cy5) #start_time=time.asctime().replace(" ","_").replace(":","_") start_time="Thu_Aug_13_14_38_51_2015" done_list={} well_counter={} ## if this is a continuation of an old scan, this will add on to the ## existing log file. if os.path.exists("Scan_%s.txt" % start_time): completed_fin=open("Scan_%s.txt" % start_time,"r") for line in completed_fin: site=line.split(";")[0] try: if "No cells of interest" not in line.split(";")[1]: well=site.split("-") if well not in well_counter: well_counter[well]=0 well_counter+=1 except: pass completed_fin.close() status_out=open("Scan_%s.txt" % start_time,"r") status_string=status_out.read() status_out.close() status_out=open("Scan_%s.txt" % start_time,"w") status_out.write(status_string) else: status_out=open("Scan_%s.txt" % start_time,"w") data_dir="Scan_%s" % start_time if os.path.isdir(data_dir) is False: os.mkdir(data_dir) order=-1 for row in rows: ## flip the order that the columns are gone through order=order*-1 for column in columns[::order]: well="%s%s" % (row,column) if well not in well_counter:well_counter[well]=0 if well_counter[well]<15: ## reset the well count for this new well. well_count=well_counter[well] ## iterate through the site in this well. for site in sites: ## Test case if "%s%s-Site_%s" % (row,column,site) not in done_list.keys(): done_list["%s%s-Site_%s" % (row,column,site)]=True print ">Looking at %s%s-Site_%s" % (row,column,site) x,y=positions["%s%s-Site_%s" % (row,column,site)].get_xy() ## take an image to use for a trigger scope.set_illumination(Illuminations.qCy5) scope.mmc.setXYPosition("XYStage",x,y) scope.mmc.snapImage() img=scope.mmc.getImage() ## show image plt.imshow(img) plt.draw() ## analyze this image cois=Threshold.coi_finder(img, threshold=1000, min_area=100, max_area=1000) if cois: do_stack=True progress_line=">%s%s-Site_%s;cois=%s\n" % (row,column,site,cois) else: do_stack=False progress_line=">%s%s-Site_%s;No cells of interest\n" % (row,column,site) status_out.write(progress_line) ## run the stack if there was a COI found if do_stack: print ">Stack at %s%s-Site_%s" % (row,column,site) well_count+=1 well_counter[well]+=1 channels=[Illuminations.DIC, Illuminations.GFP, Illuminations.qCy5, Illuminations.DAPI] scope.mmc.enableContinuousFocus(False) mda,md=scope.multi_channel_acquisition(channels) FileOut.mda_save(out_dir=data_dir, prefix="%s%s-Site_%s" % (row,column,site), mda=mda, md=md, channels=channels) print "Stack taken at %s%s-Site_%s" % (row,column,site) ## turn AFC back on scope.mmc.enableContinuousFocus(True) ## move onto the next well if we have acquired enough if well_count > 15: break ## break out of the well if you can't focus if scope.mmc.isContinuousFocusLocked() is False: time.sleep(5) if scope.mmc.isContinuousFocusLocked() is False: print "Couldnt focus 3" break ## break out of the column if you still cant focus if scope.mmc.isContinuousFocusLocked() is False: time.sleep(5) if scope.mmc.isContinuousFocusLocked() is False: print "Couldnt focus 2" break ## break out of the row if you STILL cant focus. if scope.mmc.isContinuousFocusLocked() is False: time.sleep(5) if scope.mmc.isContinuousFocusLocked() is False: print "Couldnt focus 1" break status_out.close()
def plateScanSite(scope, illumination, mda_channels, x, y, visible=True, name="", stack_height=5, slice_height=.5, minAreaCOI=100, maxAreaCOI=1000, thresholdCOI=1000): """ This is a function to run at each site of a 96well plate scan. This requires: -scope -scan illumination -MDA illuminations -x -y Optional: -visibility of scan image during acquisition -name this is mostly for progress and debugging purposes This returns: -site_imaged: 0 or 1 depending if a MDA was taken -MDA -MDA_md """ scope.set_illumination(illumination) scope.mmc.setXYPosition("XYStage",x,y) scope.mmc.snapImage() img=scope.mmc.getImage() ## show image if visible is True: plt.imshow(img) plt.show() plt.draw() # analyze this image cois=Threshold.coi_finder(img, threshold=thresholdCOI, min_area=minAreaCOI, max_area=maxAreaCOI) if cois: do_stack=True site_imaged=1 print "COIs found in %s, taking a stack" % name else: do_stack=False site_imaged=0 md=None mda=None print "No COIs found in %s" % name if do_stack: scope.mmc.enableContinuousFocus(False) mda,md=scope.multi_channel_acquisition(mda_channels, z_width=stack_height, z_increments=slice_height) scope.mmc.enableContinuousFocus(True) if visible is True: plt.close() del img return site_imaged, mda, md