deepcinac.utils.cinac_file_utils

Module Contents

Classes

CinacFileReader_open_close

CinacFileWriter

CinacFileReader

Functions

read_cell_type_categories_yaml_file(yaml_file[, ...])

Read cell type categories from a yaml file. If more than 2 type cells are given, then a multi-class

create_tiffs_from_movie(path_for_tiffs, movie_identifier)

Take a Tiff movie or 3d array representing it, and save an unique tiff file for each of its frame.

class deepcinac.utils.cinac_file_utils.CinacFileReader_open_close(file_name, frames_to_keep=None)
_open_file()
close_file()

Close the file Returns:

create_new_cinac_file_for_segment_chunk(dir_path, segment, first_frame, last_frame)
create_cinac_file_for_each_segment(dir_path, return_file_readers)

For each segment in the instance, it created a .cinac file that will contain just that sequence. :param dir_path: Directory in which save the new .cinac files :param return_file_readers: (bool) if True return a list of instances of :param CinacFileReader from the individual .cinac files created:

Returns:

__building_segments_list()
_get_segment_group(segment)

Return the group from cinac_file, it should be open :param segment:

Returns:

get_coords_full_movie()

Returns:

get_invalid_cells()

Return the invalid cells

Returns: 1d array of n cells, as many cells. Binary array, 0 is valid, 1 if invalid Return None if no

with_full_data()

Return True if full data is available, meaning coords of cells in the original movie, invalid cells Returns:

get_ci_movie_file_name()

Returns the name of full calcium imaging movie file_name from which the data are extracted. None if the file_name is unknown. Returns:

get_all_segments()

Return a list of tuple of 3 int (cell, first_frame, last_frame) representing the segments of ground truth available in this file Returns: list

get_n_frames_gt()

Return the number of frames with ground truth Returns:

get_n_active_frames()

Return the number of frames with cells being active Returns:

fill_doubtful_frames_from_segments(doubtful_frames_nums)

Fill the doubtful_frames_nums using the ground truth from the segments. :param doubtful_frames_nums: 2d arrays (n_cells x n_frames)

Returns:

fill_raster_dur_from_segments(raster_dur)

Fill the raster_dur using the ground truth from the segments. :param raster_dur: 2d arrays (n_cells x n_frames)

Returns:

get_segment_ci_movie(segment)

Return the calcium imaging from the ground truth segment. :param segment: segment to use to get ci_movie, tuple of 3 to 4 int

Returns: 3d array

get_segment_ci_movie_frames(segment, frames)

Return frames from the calcium imaging from the ground truth segment. :param segment: segment to use to get ci_movie, tuple of 3 to 4 int

Returns: 3d array

get_segment_cell_type(segment)

Return the name of the cell type from the segment, or None if this information is not known. :param segment: segment

Returns:

get_segment_pixels_around(segment)

Return the pixels_around used to produce the cell profile on the frame (not really used anymore). :param segment: segment

Returns:

get_segment_buffer(segment)

Return the buffer used to produce the cell profile on the frame (not really used anymore). :param segment: segment

Returns:

get_all_cell_types()

Return a dict with as a key the cell index and value a string representing the cell type. Covers all the cells represented by the segments.

Returns:

get_segment_smooth_traces(segment)

Return the smooth fluorescence signal from the ground truth segment. :param segment: segment to use to fill raster_dur, tuple of 3 to 4 int

Returns: 1d array

get_segment_raw_traces(segment)

Return the smooth fluorescence signal from the ground truth segment. :param segment: segment to use to fill raster_dur, tuple of 3 to 4 int

Returns: 1d array

get_segment_cells_contour(segment)

Return the cells contour from the ground truth segment. :param segment: segment to use to fill raster_dur, tuple of 3 to 4 int

Returns: a list of 2d array that encodes x, y coord (len of the 2d array corresponds to the number of point in the contour.

get_segment_raster_dur(segment)

Return the raster_dur from the ground truth segment. :param segment: segment to use to get raster_dur

Returns: 1d array of n frames as specified in segment

get_segment_invalid_cells(segment)

Return the invalid cells from the ground truth segment. :param segment: segment (tuple of 3 int)

Returns: 1d array of n cells, as many cells as in the segment (cell of interest + interesections). Binary, 0 is valid, 1 if invalid

get_segment_doubtful_frames(segment)

Return the doubtful_frames from the ground truth segment. :param segment: segment (tuple of 3 int)

Returns: 1d array of n frames, as many frames as in the segment. Binary, 0 is not doubtful, 1 if doubtful

class deepcinac.utils.cinac_file_utils.CinacFileWriter(file_name)
close_file()

Close the file Returns:

delete_groups(group_names)
get_group_names()
add_segment_group(cell, first_frame, last_frame, raster_dur, ci_movie, cells_contour, pixels_around, buffer, invalid_cells, smooth_traces, raw_traces, cell_type=None, doubtful_frames=None)

Add just a segment (some frames and a given cell) :param cell: :param first_frame: :param last_frame: :param raster_dur: :param ci_movie: :param cells_contour: :param pixels_around: :param buffer: :param invalid_cells: :param smooth_traces: normalized (z-scored) smmoth fluorescence signal of the cell during the give frames :param doubtful_frames: :param raw_traces: normalized (z-scored) raw fluorescence signal of the cell during the give frames :param cell_type: any string describing the cell type, in our case it would be “interneuron” or “pyr” :param (for pyramidal cell). If None: :param means we don’t encode this information: :param the cell type is: :param not known ?:

Returns:

create_full_data_group(save_only_movie_ref, save_ci_movie_info, cells_contour, n_frames, n_cells, smooth_traces=None, raw_traces=None, ci_movie_file_name=None, ci_movie=None, invalid_cells=None)

Create a group that represents all data (full movie, all cells etc…) :param save_only_movie_ref: boolean, if True means we just save the path & file_name of the calcium imaging movie. :param Otherwise the full movie is saved if ci_movie argument is passed.: :param save_ci_movie_info: boolean, if True then either the ci movie ref or the full data is saved in the file :param n_frames: number of frames in the full movie :param n_cells: number of cells segmented (should be the length of cells_contour) :param cells_contour: a list of 2d np.array representing the coordinates of the contour points :param smooth_traces: Smooth fluorescence signals of the cells (z-score) :param raw_traces: Raw fluorescence signals of the cells (z-score) :param ci_movie_file_name: :param ci_movie: np.array should be 3d: n_frames*len_x*len_y, calcium imaging data :param invalid_cells: a binary np.array of the length the number of cells, set to True or 1 is the cell is invalid.

Returns:

get_n_cells()

Returns: the number of cells in the movie that have been segmented. Return None if this information if not available (need the full_data group to exists)

deepcinac.utils.cinac_file_utils.read_cell_type_categories_yaml_file(yaml_file, using_multi_class=2)

Read cell type categories from a yaml file. If more than 2 type cells are given, then a multi-class classifier will be used. If 2 type cells are given, then either it could be multi-class or binary classifier, then this choice should be given in the parameters of CinacModel. If 2 cell-type are given, for binary classifier, it should be precised which cell type should be predicted if we get more than 0.5 probability. :param yaml_file: :param using_multi_class: int, give the default number of classes used, not necessary if already :param put in the yaml file:

Returns: cell_type_from_code_dict, cell_type_to_code_dict, multi_class_arg cell_type_from_code_dict: dict, key is an int, value is the cell_type cell_type_to_code_dict: dict, key is a string, value is the code of the cell_type. A code can have more than one string associated, but all of them represent the same cell_type defined in cell_type_from_code_dict multi_class_arg: is None if no multi_class_arg was given in the yaml_file, True or False, if False means we want to use a binary classifier

class deepcinac.utils.cinac_file_utils.CinacFileReader(file_name, frames_to_keep=None)
close_file()

Close the file Returns:

create_new_cinac_file_for_segment_chunk(dir_path, segment, first_frame, last_frame)
create_cinac_file_for_each_segment(dir_path, return_file_readers)

For each segment in the instance, it created a .cinac file that will contain just that sequence. :param dir_path: Directory in which save the new .cinac files :param return_file_readers: (bool) if True return a list of instances of :param CinacFileReader from the individual .cinac files created:

Returns:

__building_segments_list()
get_coords_full_movie()

Returns:

get_n_cells()

Return the number of cells with contours in this movie (if the information is available, None otherwise) Returns:

get_n_frames()

Return the number of frames in the full movie Returns:

get_invalid_cells()

Return the invalid cells

Returns: 1d array of n cells, as many cells. Binary array, 0 is valid, 1 if invalid Return None if no

with_full_data()

Return True if full data is available, meaning coords of cells in the original movie, invalid cells Returns:

get_ci_movie_file_name()

Returns the name of full calcium imaging movie file_name from which the data are extracted. None if the file_name is unknown. Returns:

get_all_segments()

Return a list of tuple of 3 int (cell, first_frame, last_frame) representing the segments of ground truth available in this file Returns: list

get_n_frames_gt()

Return the number of frames with ground truth Returns:

get_n_active_frames()

Return the number of frames with cells being active Returns:

fill_doubtful_frames_from_segments(doubtful_frames_nums)

Fill the doubtful_frames_nums using the ground truth from the segments. :param doubtful_frames_nums: 2d arrays (n_cells x n_frames)

Returns:

fill_raster_dur_from_segments(raster_dur)

Fill the raster_dur using the ground truth from the segments. :param raster_dur: 2d arrays (n_cells x n_frames)

Returns:

get_segment_ci_movie(segment)

Return the calcium imaging from the ground truth segment. :param segment: segment to use to get ci_movie, tuple of 3 to 4 int

Returns: 3d array

get_segment_ci_movie_frames(segment, frames)

Return frames from the calcium imaging from the ground truth segment. :param segment: segment to use to get ci_movie, tuple of 3 to 4 int

Returns: 3d array

get_segment_cell_type(segment)

Return the name of the cell type from the segment, or None if this information is not known. :param segment: segment

Returns:

get_segment_pixels_around(segment)

Return the pixels_around used to produce the cell profile on the frame (not really used anymore). :param segment: segment

Returns:

get_segment_buffer(segment)

Return the buffer used to produce the cell profile on the frame (not really used anymore). :param segment: segment

Returns:

get_all_cell_types()

Return a dict with as a key the cell index and value a string representing the cell type. Covers all the cells represented by the segments.

Returns:

get_segment_smooth_traces(segment)

Return the smooth fluorescence signal from the ground truth segment. :param segment: segment to use to fill raster_dur, tuple of 3 to 4 int

Returns: 1d array

get_segment_raw_traces(segment)

Return the smooth fluorescence signal from the ground truth segment. :param segment: segment to use to fill raster_dur, tuple of 3 to 4 int

Returns: 1d array

get_segment_cells_contour(segment)

Return the cells contour from the ground truth segment. :param segment: segment to use to fill raster_dur, tuple of 3 to 4 int

Returns: a list of 2d array that encodes x, y coord (len of the 2d array corresponds to the number of point in the contour.

get_segment_raster_dur(segment)

Return the raster_dur from the ground truth segment. :param segment: segment to use to get raster_dur

Returns: 1d array of n frames as specified in segment

get_segment_invalid_cells(segment)

Return the invalid cells from the ground truth segment. :param segment: segment (tuple of 3 int)

Returns: 1d array of n cells, as many cells as in the segment (cell of interest + interesections). Binary, 0 is valid, 1 if invalid

get_segment_doubtful_frames(segment)

Return the doubtful_frames from the ground truth segment. :param segment: segment (tuple of 3 int)

Returns: 1d array of n frames, as many frames as in the segment. Binary, 0 is not doubtful, 1 if doubtful

deepcinac.utils.cinac_file_utils.create_tiffs_from_movie(path_for_tiffs, movie_identifier, movie_file_name=None, movie_data=None)

Take a Tiff movie or 3d array representing it, and save an unique tiff file for each of its frame. Save as well the mean and std as npy file, all in the directory path_for_tiffs, in a directory with the identifier :param path_for_tiffs: str :param movie_identifier: str :param movie_file_name: str :param movie_data: 3d array

Returns: boolean, return False if the directory with this identifier already exists, True if Tiffs have been created