scripts/fus_delta_exp_0002_annotations_postprocessing.py
def process_annotations(annotation_files_list, overwrite_aggregated_annotation_file=False, create_symlink=False):
    """
    Helper function to process a list of JSON files with annotations.
    :param annotation_files_list: list of JSON filenames containing annotations.
    :return:
    """

    for annotation_file in annotation_files_list:

        print('File: ' + os.path.basename(annotation_file))

        # name of the file that we are going to save the aggregated annotations to
        aggregated_annotation_file = annotation_file.replace('.json', '_aggregated.json')

        # name of the original .ndpi file
        ndpi_file = os.path.basename(annotation_file).replace(auto_filename_suffix, '.ndpi')
        ndpi_file = os.path.join(histology_dir, ndpi_file)

        im = openslide.OpenSlide(ndpi_file)
        xres = 1e-2 / float(im.properties['tiff.XResolution'])
        yres = 1e-2 / float(im.properties['tiff.YResolution'])

        # aggregate cells from all blocks and write/overwrite a file with them
        if not os.path.isfile(aggregated_annotation_file) or overwrite_aggregated_annotation_file:

            # load contours from annotation file
            cells = cytometer.data.aida_get_contours(annotation_file, layer_name='White adipocyte.*')

            # create AIDA items to contain contours
            items = cytometer.data.aida_contour_items(cells, f_area2quantile_m, cm='quantiles_aida',
                                                      xres=xres*1e6, yres=yres*1e6)

            # write contours to single layer AIDA file (one to visualise, one to correct manually)
            cytometer.data.aida_write_new_items(aggregated_annotation_file, items, mode='w', indent=0)

        if create_symlink:

            # name expected by AIDA for annotations
            symlink_name = os.path.basename(ndpi_file).replace('.ndpi', '.json')
            symlink_name = os.path.join(annotations_dir, symlink_name)

            # create symlink to the aggregated annotation file from the name expected by AIDA
            if os.path.isfile(symlink_name):
                if os.path.islink(symlink_name):
                    # delete existing symlink
                    os.remove(symlink_name)
                else:
                    raise FileExistsError('File found with the name of the symlink we are trying to create')
            else:
                os.symlink(os.path.basename(aggregated_annotation_file), symlink_name)

    Helper function to process a list of JSON files with annotations.
    :param annotation_files_list: list of JSON filenames containing annotations.
    :return:
    
Helper function to process a list of JSON files with annotations.
Helper function to process a list of JSON files with annotations .
def process_annotations(annotation_files_list, overwrite_aggregated_annotation_file=False, create_symlink=False):
    for annotation_file in annotation_files_list:
        print('File: ' + os.path.basename(annotation_file))
        aggregated_annotation_file = annotation_file.replace('.json', '_aggregated.json')
        ndpi_file = os.path.basename(annotation_file).replace(auto_filename_suffix, '.ndpi')
        ndpi_file = os.path.join(histology_dir, ndpi_file)
        im = openslide.OpenSlide(ndpi_file)
        xres = 1e-2 / float(im.properties['tiff.XResolution'])
        yres = 1e-2 / float(im.properties['tiff.YResolution'])
        if not os.path.isfile(aggregated_annotation_file) or overwrite_aggregated_annotation_file:
            cells = cytometer.data.aida_get_contours(annotation_file, layer_name='White adipocyte.*')
            items = cytometer.data.aida_contour_items(cells, f_area2quantile_m, cm='quantiles_aida',
                                                      xres=xres*1e6, yres=yres*1e6)
            cytometer.data.aida_write_new_items(aggregated_annotation_file, items, mode='w', indent=0)
        if create_symlink:
            symlink_name = os.path.basename(ndpi_file).replace('.ndpi', '.json')
            symlink_name = os.path.join(annotations_dir, symlink_name)
            if os.path.isfile(symlink_name):
                if os.path.islink(symlink_name):
                    os.remove(symlink_name)
                else:
                    raise FileExistsError('File found with the name of the symlink we are trying to create')
            else:
                os.symlink(os.path.basename(aggregated_annotation_file), symlink_name)
def process_annotations ( annotation_files_list , overwrite_aggregated_annotation_file = False , create_symlink = False ) : for annotation_file in annotation_files_list : print ( 'File: ' + os . path . basename ( annotation_file ) ) aggregated_annotation_file = annotation_file . replace ( '.json' , '_aggregated.json' ) ndpi_file = os . path . basename ( annotation_file ) . replace ( auto_filename_suffix , '.ndpi' ) ndpi_file = os . path . join ( histology_dir , ndpi_file ) im = openslide . OpenSlide ( ndpi_file ) xres = 1e-2 / float ( im . properties [ 'tiff.XResolution' ] ) yres = 1e-2 / float ( im . properties [ 'tiff.YResolution' ] ) if not os . path . isfile ( aggregated_annotation_file ) or overwrite_aggregated_annotation_file : cells = cytometer . data . aida_get_contours ( annotation_file , layer_name = 'White adipocyte.*' ) items = cytometer . data . aida_contour_items ( cells , f_area2quantile_m , cm = 'quantiles_aida' , xres = xres * 1e6 , yres = yres * 1e6 ) cytometer . data . aida_write_new_items ( aggregated_annotation_file , items , mode = 'w' , indent = 0 ) if create_symlink : symlink_name = os . path . basename ( ndpi_file ) . replace ( '.ndpi' , '.json' ) symlink_name = os . path . join ( annotations_dir , symlink_name ) if os . path . isfile ( symlink_name ) : if os . path . islink ( symlink_name ) : os . remove ( symlink_name ) else : raise FileExistsError ( 'File found with the name of the symlink we are trying to create' ) else : os . symlink ( os . path . basename ( aggregated_annotation_file ) , symlink_name )
Helper function to process a list of JSON files with annotations.
Helper function to process a list of JSON files with annotations .
"""
    Helper function to process a list of JSON files with annotations.
    :param annotation_files_list: list of JSON filenames containing annotations.
    :return:
    """ # name of the file that we are going to save the aggregated annotations to # name of the original .ndpi file # aggregate cells from all blocks and write/overwrite a file with them # load contours from annotation file # create AIDA items to contain contours # write contours to single layer AIDA file (one to visualise, one to correct manually) # name expected by AIDA for annotations # create symlink to the aggregated annotation file from the name expected by AIDA # delete existing symlink
None
annotation_files_list
list of JSON filenames containing annotations.
list of JSON filenames containing annotations .
overwrite_aggregated_annotation_file
create_symlink