示例#1
0
def get_bleach_spots(log_pd: pd.DataFrame,
                     label_nucleoli: np.array,
                     analyze_organelle: str,
                     num_dilation=3):
    """
    Generate bleach spots mask and corresponding pd.DataFrame table

    :param log_pd: pd.DataFrame, requires columns 'x', 'y', 'nucleoli'
                'x': x coordinates of all possible bleach spots
                'y': y coordinates of all possible bleach spots
                'nucleoli': pointer corresponding nucleoli label index
                originally imports from .log file
    :param label_nucleoli: np.array, grey scale labeled nucleoli image
    :param analyze_organelle: str, 'sg' or 'nucleoli'
    :param num_dilation: int, optional (default: 3)
                number of dilation applied from the coordinates
                determines the size of the generated mask for each point
                default number was determined for FRAP analysis
    :return: bleach_spots_ft: np.array, 0-and-1
                bleach spots mask
             pointer_pd: pd.DataFrame
                pointer dataframe, add corresponding bleach spots/nucleoli information
                sorted based on bleach spots, ascending

    """
    # link pointer with corresponding detected bleach spots
    bleach_spots = ana.analysis_mask(log_pd['y'], log_pd['x'], label_nucleoli,
                                     num_dilation)
    label_bleach_spots = label(bleach_spots, connectivity=1)
    log_pd['bleach_spots'] = obj.points_in_objects(label_bleach_spots,
                                                   log_pd['x'], log_pd['y'])

    # filter bleach spots
    pointer_pd = filter_bleach_spots(log_pd, analyze_organelle)

    # generate bleach spots mask (after filtering)
    bleach_spots_ft = ana.analysis_mask(pointer_pd['y'], pointer_pd['x'],
                                        label_nucleoli, num_dilation)
    label_bleach_spots_ft = label(bleach_spots_ft, connectivity=1)

    # link pointer with corresponding filtered bleach spots
    pointer_pd['bleach_spots'] = obj.points_in_objects(label_bleach_spots_ft,
                                                       pointer_pd['x'],
                                                       pointer_pd['y'])
    pointer_pd = pointer_pd.sort_values(by='bleach_spots').reset_index(
        drop=True)

    return bleach_spots_ft, pointer_pd
示例#2
0
def get_spots(x_lst: list,
              y_lst: list,
              pixels_same_size: np.array,
              num_dilation=3):
    """
    Generate spots mask and corresponding pd.DataFrame table

    :param x_lst: list, list of x coordinates
    :param y_lst: list, list of y coordinates
    :param pixels_same_size: np.array, any image of the same size
    :param num_dilation: int, number of dilation applied, default: 3
    :return:
    """
    spots = ana.analysis_mask(y_lst, x_lst, pixels_same_size, num_dilation)
    label_spots = label(spots, connectivity=1)
    pd_spots = pd.DataFrame({'x': x_lst, 'y': y_lst})
    pd_spots['spots'] = obj.points_in_objects(label_spots, pd_spots['x'],
                                              pd_spots['y'])

    # filter spots
    pointer_same_spots = [
        item for item, count in collections.Counter(
            pd_spots['spots'].tolist()).items() if count > 1
    ]
    pd_spots = pd_spots[~pd_spots['spots'].isin(pointer_same_spots)]
    del pd_spots['spots']  # delete previous bleach_spots information
    pd_spots = pd_spots.reset_index(drop=True)  # reset index

    spots_ft = ana.analysis_mask(pd_spots['y'], pd_spots['x'],
                                 pixels_same_size, num_dilation)
    label_spots_ft = label(spots_ft, connectivity=1)
    # link pointer with corresponding filtered bleach spots
    pd_spots['spots'] = obj.points_in_objects(label_spots_ft, pd_spots['x'],
                                              pd_spots['y'])
    pd_spots = pd_spots.sort_values(by='spots').reset_index(drop=True)
    return spots_ft, pd_spots
pointer_pd = dat.copy_based_on_index(
    pointer_pd, nucleoli_pd, 'nucleoli', 'nucleoli', [
        'nucleoli_x', 'nucleoli_y', 'nucleoli_size', 'nucleoli_mean_int',
        'nucleoli_circ'
    ], ['x', 'y', 'size', 'raw_int', 'circ'])

# --------------------------------------------------
# FRAP CURVE ANALYSIS from bleach spots
# --------------------------------------------------
print("### Image analysis: FRAP curve calculation ...")

# create control spots mask
ctrl_nucleoli = ~nucleoli_pd.index.isin(log_pd['nucleoli'].tolist())
ctrl_x = nucleoli_pd[ctrl_nucleoli]['x'].astype(int).tolist()
ctrl_y = nucleoli_pd[ctrl_nucleoli]['y'].astype(int).tolist()
ctrl_spots = ana.analysis_mask(ctrl_x, ctrl_y, pix, num_dilation)
num_ctrl_spots = obj.object_count(ctrl_spots)
pointer_pd['num_ctrl_spots'] = [num_ctrl_spots] * len(pointer_pd)

# get raw intensities for bleach spots and control spots
pointer_pd['raw_int'] = ana.get_intensity(bleach_spots, pixels_tseries)
ctrl_spots_int_tseries = ana.get_intensity(ctrl_spots, pixels_tseries)
ctrl_pd = pd.DataFrame({
    'ctrl_spots': np.arange(0, num_ctrl_spots, 1),
    'raw_int': ctrl_spots_int_tseries
})

print("### Image analysis: background correction ...")
# background intensity measurement
bg_int_tseries = ana.get_bg_int(pixels_tseries)
pointer_pd['bg_int'] = [bg_int_tseries] * len(pointer_pd)
示例#4
0
        ]

        aim_spot = (centroid_y[-1], centroid_x[-1])
        close_spot = dat.find_closest_coordinate(aim_spot, centers,
                                                 tracking_dis)
        centroid_x.append(round(close_spot[1]))
        centroid_y.append(round(close_spot[0]))
        bleach_spots_x_temp = round(
            close_spot[1]) + spots['aim_x'][i] - spots['center_x'][i]
        x_list[i].append(bleach_spots_x_temp)
        bleach_spots_y_temp = round(
            close_spot[0]) + spots['aim_y'][i] - spots['center_y'][i]
        y_list[i].append(bleach_spots_y_temp)

        bleach_spots = ana.analysis_mask([bleach_spots_y_temp],
                                         [bleach_spots_x_temp], pix,
                                         num_dilation)
        label_bleach_spots = label(bleach_spots, connectivity=1)
        int_temp = regionprops(label_bleach_spots, pix)[0].mean_intensity
        int_list[i].append(int_temp)

spots['x'] = x_list
spots['y'] = y_list
spots['int'] = int_list

# --------------------------
# OUTPUT
# --------------------------
print("### Export data ...")

storage_path = save_path