def update_styles_for_annotations_in_folder(gc, folderid, workflow_kwargs, recursive=True, catch_exceptions=True, monitor='', verbose=True): """Update styles for all annotations in a folder recursively. Parameters ---------- gc : girder_client.GirderClient authenticated girder client folderid : str girder id of folder workflow_kwargs : dict kwargs to pass to Update styles for all annotations in a slide() recursive : bool do this recursively for subfolders? catch_exceptions : bool passed as-is to histomicstk.workflows.workflow_runner.Workflow_runner monitor : str text to prepend to printed statements verbose : bool print statements to screen? Returns ------- None """ # update annotation styles workflow_kwargs.update({'gc': gc}) workflow_runner = Workflow_runner( slide_iterator=Slide_iterator( gc, source_folder_id=folderid, keep_slides=None, ), workflow=update_styles_for_annotations_in_slide, workflow_kwargs=workflow_kwargs, recursive=recursive, catch_exceptions=catch_exceptions, monitorPrefix=monitor, verbose=verbose, ) workflow_runner.run()
def get_all_rois_from_folder_v2( gc, folderid, get_all_rois_kwargs, monitor=''): """Get all rois in a girder folder using get_all_rois_from_slide_v2(). Parameters ---------- gc : girder_client.Girder_Client authenticated girder client folderid : str girder id of folder get_all_rois_kwargs : dict kwargs to pass to get_all_rois_from_slide_v2() monitor : str monitor prefix Returns ------- None """ def _get_all_rois(slide_id, monitorPrefix, **kwargs): sld = gc.get('/item/%s' % slide_id) if "." not in sld['name']: sld['name'] += "." sldname = sld['name'][:sld['name'].find('.')].replace('/', '_#_') return get_all_rois_from_slide_v2( slide_id=slide_id, monitorprefix=monitorPrefix, # encoding slide id makes things easier later slide_name="%s_id-%s" % (sldname, slide_id), **kwargs) # update with params get_all_rois_kwargs['gc'] = gc # pull annotations for each slide in folder workflow_runner = Workflow_runner( slide_iterator=Slide_iterator( gc, source_folder_id=folderid, keep_slides=None, ), workflow=_get_all_rois, workflow_kwargs=get_all_rois_kwargs, monitorPrefix=monitor ) workflow_runner.run()
def revert_annotations_in_folder(gc, folderid, workflow_kwargs, recursive=True, monitor='', verbose=True): """Revert all annotations in a folder recursively. Parameters ---------- gc : girder_client.GirderClient authenticated girder client folderid : str girder id of folder workflow_kwargs : dict kwargs to pass to revert_annotations_in_slide recursive : bool do this recursively for subfolders? monitor : str text to prepend to printed statements verbose : bool print statements to screen? Returns ------- None """ # update annotation styles workflow_kwargs.update({'gc': gc}) workflow_runner = Workflow_runner( slide_iterator=Slide_iterator( gc, source_folder_id=folderid, keep_slides=None, ), workflow=revert_annotations_in_slide, workflow_kwargs=workflow_kwargs, recursive=recursive, monitorPrefix=monitor, verbose=verbose, ) workflow_runner.run()
def test_runner_using_Cellularity_detector_thresholding(self): """Test workflow runner for cellularity detection.""" # Init Cellularity_detector_thresholding cdt = Cellularity_detector_thresholding(**cdt_params) # Init workflow runner workflow_runner = Workflow_runner( slide_iterator=Slide_iterator( gc, source_folder_id=SAMPLE_SOURCE_FOLDER_ID, keep_slides=['TCGA-A1-A0SK-01Z-00-DX1_POST.svs', ], # keep_slides=None, ), workflow=cellularity_detection_workflow, workflow_kwargs={ 'gc': gc, 'cdo': cdt, 'destination_folder_id': SAMPLE_DESTINATION_FOLDER_ID, 'keep_existing_annotations': False, }, logging_savepath=cdt.logging_savepath, monitorPrefix='test') # Now run workflow_runner.run()
def dump_annotations_locally(gc, folderid, local, save_json=True, save_sqlite=False, dbcon=None, callback=None, callback_kwargs=None): """Dump annotations of folder and subfolders locally recursively. This reproduces this tiered structure locally and (possibly) dumps annotations there. Adapted from Lee A.D. Cooper Parameters ----------- gc : girder_client.GirderClient authenticated girder client instance folderid : str girder id of source (base) folder local : str local path to dump annotations save_json : bool whether to dump annotations as json file save_sqlite : bool whether to save the backup into an sqlite database dbcon : sqlalchemy.create_engine.connect() object IGNORE THIS PARAMETER!! This is used internally. callback : function function to call that CAN accept AT LEAST the following params - item: girder response with item information - annotations: loaded annotations - local: local directory - monitorPrefix: string - dbcon: sqlalchemy.create_engine.connect() object You can just add kwargs at the end of your callback definition for simplicity. callback_kwargs : dict kwargs to pass along to callback. DO NOT pass any of the parameters item, annotations, local, monitorPrefix, or dbcon as these will be internally passed. Just include any specific paremeters for the callback. See parse_annotations_to_local_tables() above for an example of a callback and the unir test of this function. """ callback_kwargs = callback_kwargs or {} assert (save_json or save_sqlite), "must save results somehow!" monitor = os.path.basename(local) # get folder info folder_info = gc.get("folder/%s" % folderid) folder_info['folder_path'] = get_absolute_girder_folderpath( gc=gc, folder_info=folder_info) # connect to sqlite database -- only first stack does this if save_sqlite and (dbcon is None): db_path = os.path.join(local, folder_info['name'] + ".sqlite") sql_engine = create_engine('sqlite:///' + db_path, echo=False) dbcon = sql_engine.connect() # save folder information json if save_json: print("%s: save folder info" % monitor) savepath = os.path.join(local, folder_info['name'] + '.json') with open(savepath, 'w') as fout: json.dump(folder_info, fout) # save folder info to sqlite if save_sqlite: _add_folder_to_sqlite(dbcon, folder_info) # pull annotations for each slide in folder workflow_runner = Workflow_runner(slide_iterator=Slide_iterator( gc, source_folder_id=folderid, keep_slides=None, ), workflow=dump_annotations_workflow, workflow_kwargs={ 'gc': gc, 'local': local, 'save_json': save_json, 'save_sqlite': save_sqlite, 'dbcon': dbcon, 'callback': callback, 'callback_kwargs': callback_kwargs, }, monitorPrefix=monitor) workflow_runner.run() # for each subfolder, create a new folder locally and call self for folder in gc.listFolder(parentId=folderid): # create folder in local new_folder = os.path.join(local, folder['name']) os.mkdir(new_folder) # call self with same prameters dump_annotations_locally(gc=gc, folderid=folder['_id'], local=new_folder, save_json=save_json, save_sqlite=save_sqlite, dbcon=dbcon, callback=callback, callback_kwargs=callback_kwargs)