scripts/klf14_b6ntac_exp_0111_paper_figures_v8.py
def table_of_hand_traced_regions(file_svg_list):
    """
    Open SVG files in a list, and count the number of different types of regions (Cells, Other, Background, Windows,
    Windows with cells) and create a table with them for the paper
    :param file_svg_list: list of filenames
    :return: pd.Dataframe
    """

    # init dataframe to aggregate training numbers of each mouse
    table = pd.DataFrame(columns=['Cells', 'Other', 'Background', 'Windows', 'Windows with cells'])

    # loop files with hand traced contours
    for i, file_svg in enumerate(file_svg_list):

        print('file ' + str(i) + '/' + str(len(file_svg_list) - 1) + ': ' + os.path.basename(file_svg))

        # read the ground truth cell contours in the SVG file. This produces a list [contour_0, ..., contour_N-1]
        # where each contour_i = [(X_0, Y_0), ..., (X_P-1, X_P-1)]
        cell_contours = cytometer.data.read_paths_from_svg_file(file_svg, tag='Cell', add_offset_from_filename=False,
                                                                minimum_npoints=3)
        other_contours = cytometer.data.read_paths_from_svg_file(file_svg, tag='Other', add_offset_from_filename=False,
                                                                 minimum_npoints=3)
        brown_contours = cytometer.data.read_paths_from_svg_file(file_svg, tag='Brown', add_offset_from_filename=False,
                                                                 minimum_npoints=3)
        background_contours = cytometer.data.read_paths_from_svg_file(file_svg, tag='Background',
                                                                      add_offset_from_filename=False,
                                                                      minimum_npoints=3)
        contours = cell_contours + other_contours + brown_contours + background_contours

        # make a list with the type of cell each contour is classified as
        contour_type = [np.zeros(shape=(len(cell_contours),), dtype=np.uint8),  # 0: white-adipocyte
                        np.ones(shape=(len(other_contours),), dtype=np.uint8),  # 1: other types of tissue
                        np.ones(shape=(len(brown_contours),), dtype=np.uint8),
                        # 1: brown cells (treated as "other" tissue)
                        np.zeros(shape=(len(background_contours),), dtype=np.uint8)]  # 0: background
        contour_type = np.concatenate(contour_type)

        print('Cells: ' + str(len(cell_contours)) + '. Other: ' + str(len(other_contours))
              + '. Brown: ' + str(len(brown_contours)) + '. Background: ' + str(len(background_contours)))

        # create dataframe for this image
        df_common = cytometer.data.tag_values_with_mouse_info(metainfo=metainfo, s=os.path.basename(file_svg),
                                                              values=[i, ], values_tag='i',
                                                              tags_to_keep=['id', 'ko_parent', 'sex'])

        # mouse ID as a string
        id = df_common['id'].values[0]
        sex = df_common['sex'].values[0]
        ko = df_common['ko_parent'].values[0]

        # row to add to the table
        df = pd.DataFrame(
            [(sex, ko,
              len(cell_contours), len(other_contours) + len(brown_contours), len(background_contours), 1,
              int(len(cell_contours) > 0))],
            columns=['Sex', 'Genotype', 'Cells', 'Other', 'Background', 'Windows', 'Windows with cells'], index=[id])

        if id in table.index:

            num_cols = ['Cells', 'Other', 'Background', 'Windows', 'Windows with cells']
            table.loc[id, num_cols] = (table.loc[id, num_cols] + df.loc[id, num_cols])

        else:

            table = table.append(df, sort=False, ignore_index=False, verify_integrity=True)

    # alphabetical order by mouse IDs
    table = table.sort_index()

    return table

    Open SVG files in a list, and count the number of different types of regions (Cells, Other, Background, Windows,
    Windows with cells) and create a table with them for the paper
    :param file_svg_list: list of filenames
    :return: pd.Dataframe
    
Open SVG files in a list, and count the number of different types of regions (Cells, Other, Background, Windows,
Windows with cells) and create a table with them for the paper
Open SVG files in a list and count the number of different types of regions ( Cells Other Background Windows Windows with cells ) and create a table with them for the paper
def table_of_hand_traced_regions(file_svg_list):
    table = pd.DataFrame(columns=['Cells', 'Other', 'Background', 'Windows', 'Windows with cells'])
    for i, file_svg in enumerate(file_svg_list):
        print('file ' + str(i) + '/' + str(len(file_svg_list) - 1) + ': ' + os.path.basename(file_svg))
        cell_contours = cytometer.data.read_paths_from_svg_file(file_svg, tag='Cell', add_offset_from_filename=False,
                                                                minimum_npoints=3)
        other_contours = cytometer.data.read_paths_from_svg_file(file_svg, tag='Other', add_offset_from_filename=False,
                                                                 minimum_npoints=3)
        brown_contours = cytometer.data.read_paths_from_svg_file(file_svg, tag='Brown', add_offset_from_filename=False,
                                                                 minimum_npoints=3)
        background_contours = cytometer.data.read_paths_from_svg_file(file_svg, tag='Background',
                                                                      add_offset_from_filename=False,
                                                                      minimum_npoints=3)
        contours = cell_contours + other_contours + brown_contours + background_contours
        contour_type = [np.zeros(shape=(len(cell_contours),), dtype=np.uint8),  
                        np.ones(shape=(len(other_contours),), dtype=np.uint8),  
                        np.ones(shape=(len(brown_contours),), dtype=np.uint8),
                        np.zeros(shape=(len(background_contours),), dtype=np.uint8)]  
        contour_type = np.concatenate(contour_type)
        print('Cells: ' + str(len(cell_contours)) + '. Other: ' + str(len(other_contours))
              + '. Brown: ' + str(len(brown_contours)) + '. Background: ' + str(len(background_contours)))
        df_common = cytometer.data.tag_values_with_mouse_info(metainfo=metainfo, s=os.path.basename(file_svg),
                                                              values=[i, ], values_tag='i',
                                                              tags_to_keep=['id', 'ko_parent', 'sex'])
        id = df_common['id'].values[0]
        sex = df_common['sex'].values[0]
        ko = df_common['ko_parent'].values[0]
        df = pd.DataFrame(
            [(sex, ko,
              len(cell_contours), len(other_contours) + len(brown_contours), len(background_contours), 1,
              int(len(cell_contours) > 0))],
            columns=['Sex', 'Genotype', 'Cells', 'Other', 'Background', 'Windows', 'Windows with cells'], index=[id])
        if id in table.index:
            num_cols = ['Cells', 'Other', 'Background', 'Windows', 'Windows with cells']
            table.loc[id, num_cols] = (table.loc[id, num_cols] + df.loc[id, num_cols])
        else:
            table = table.append(df, sort=False, ignore_index=False, verify_integrity=True)
    table = table.sort_index()
    return table
def table_of_hand_traced_regions ( file_svg_list ) : table = pd . DataFrame ( columns = [ 'Cells' , 'Other' , 'Background' , 'Windows' , 'Windows with cells' ] ) for i , file_svg in enumerate ( file_svg_list ) : print ( 'file ' + str ( i ) + '/' + str ( len ( file_svg_list ) - 1 ) + ': ' + os . path . basename ( file_svg ) ) cell_contours = cytometer . data . read_paths_from_svg_file ( file_svg , tag = 'Cell' , add_offset_from_filename = False , minimum_npoints = 3 ) other_contours = cytometer . data . read_paths_from_svg_file ( file_svg , tag = 'Other' , add_offset_from_filename = False , minimum_npoints = 3 ) brown_contours = cytometer . data . read_paths_from_svg_file ( file_svg , tag = 'Brown' , add_offset_from_filename = False , minimum_npoints = 3 ) background_contours = cytometer . data . read_paths_from_svg_file ( file_svg , tag = 'Background' , add_offset_from_filename = False , minimum_npoints = 3 ) contours = cell_contours + other_contours + brown_contours + background_contours contour_type = [ np . zeros ( shape = ( len ( cell_contours ) , ) , dtype = np . uint8 ) , np . ones ( shape = ( len ( other_contours ) , ) , dtype = np . uint8 ) , np . ones ( shape = ( len ( brown_contours ) , ) , dtype = np . uint8 ) , np . zeros ( shape = ( len ( background_contours ) , ) , dtype = np . uint8 ) ] contour_type = np . concatenate ( contour_type ) print ( 'Cells: ' + str ( len ( cell_contours ) ) + '. Other: ' + str ( len ( other_contours ) ) + '. Brown: ' + str ( len ( brown_contours ) ) + '. Background: ' + str ( len ( background_contours ) ) ) df_common = cytometer . data . tag_values_with_mouse_info ( metainfo = metainfo , s = os . path . basename ( file_svg ) , values = [ i , ] , values_tag = 'i' , tags_to_keep = [ 'id' , 'ko_parent' , 'sex' ] ) id = df_common [ 'id' ] . values [ 0 ] sex = df_common [ 'sex' ] . values [ 0 ] ko = df_common [ 'ko_parent' ] . values [ 0 ] df = pd . DataFrame ( [ ( sex , ko , len ( cell_contours ) , len ( other_contours ) + len ( brown_contours ) , len ( background_contours ) , 1 , int ( len ( cell_contours ) > 0 ) ) ] , columns = [ 'Sex' , 'Genotype' , 'Cells' , 'Other' , 'Background' , 'Windows' , 'Windows with cells' ] , index = [ id ] ) if id in table . index : num_cols = [ 'Cells' , 'Other' , 'Background' , 'Windows' , 'Windows with cells' ] table . loc [ id , num_cols ] = ( table . loc [ id , num_cols ] + df . loc [ id , num_cols ] ) else : table = table . append ( df , sort = False , ignore_index = False , verify_integrity = True ) table = table . sort_index ( ) return table
Open SVG files in a list, and count the number of different types of regions (Cells, Other, Background, Windows,
Windows with cells) and create a table with them for the paper
Open SVG files in a list and count the number of different types of regions ( Cells Other Background Windows Windows with cells ) and create a table with them for the paper
"""
    Open SVG files in a list, and count the number of different types of regions (Cells, Other, Background, Windows,
    Windows with cells) and create a table with them for the paper
    :param file_svg_list: list of filenames
    :return: pd.Dataframe
    """ # init dataframe to aggregate training numbers of each mouse # loop files with hand traced contours # read the ground truth cell contours in the SVG file. This produces a list [contour_0, ..., contour_N-1] # where each contour_i = [(X_0, Y_0), ..., (X_P-1, X_P-1)] # make a list with the type of cell each contour is classified as # 0: white-adipocyte # 1: other types of tissue # 1: brown cells (treated as "other" tissue) # 0: background # create dataframe for this image # mouse ID as a string # row to add to the table # alphabetical order by mouse IDs
None
file_svg_list
list of filenames
list of filenames