From 1b25b5dc5f4488cf67a6bb094f157f394fb6469d Mon Sep 17 00:00:00 2001 From: Eron11 <60444529+ericron@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:47:06 -0600 Subject: [PATCH 1/4] updated mRNA to include clustered mRNA --- .../Data_Interpretation/DataManagement.py | 32 ++++++++++++++----- .../Notebok_Data_Interpretation.ipynb | 4 +-- src/fish_analyses.py | 4 +-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/publications/Ron_2024/Data_Interpretation/DataManagement.py b/publications/Ron_2024/Data_Interpretation/DataManagement.py index 9dc063c..355dc9c 100644 --- a/publications/Ron_2024/Data_Interpretation/DataManagement.py +++ b/publications/Ron_2024/Data_Interpretation/DataManagement.py @@ -17,7 +17,7 @@ class DataManagement: - def __init__(self, file_path, Condition, DexConc, Replica, time_value,time_TPL_value,output_path,minimum_spots_cluster=4,mandatory_substring=None,connect_to_NAS=False,path_to_config_file=None,save_csv=True): + def __init__(self, file_path, Condition, DexConc, Replica, time_value,time_TPL_value,output_path,minimum_spots_cluster=2,mandatory_substring=None,connect_to_NAS=False,path_to_config_file=None,save_csv=True): # This section downloads the zip file from NAS and extracts the dataframe or uses the dataframe from the local folder. if connect_to_NAS == False: self.file_path = file_path @@ -68,7 +68,6 @@ def data_processor(self): RNA_cyto_list = [] ts_size_list = [] - # This code will loop through each cell and store the values in the lists above. for i in range(number_cells): nuc_area = np.asarray(dataframe.loc[ (dataframe['cell_id'] == i) @@ -97,19 +96,35 @@ def data_processor(self): (dataframe['is_cell_fragmented'] != -1) ].pseudo_cyto_int_ch_0.values[0]) - # This is counting the number of spots in the nucleus that meet certain conditions and storing this in the nuc variable. - nuc = np.asarray(len(dataframe.loc[ + # Count the number of RNA in the nucleus + nuc_spots = len(dataframe.loc[ (dataframe['cell_id'] == i) & (dataframe['is_nuc'] == True) & (dataframe['is_cell_fragmented'] != -1) - ].spot_id)) + ].spot_id) - # This is counting the number of spots in the nucleus that meet certain conditions and storing this in the nuc variable. - cyto = np.asarray(len(dataframe.loc[ + nuc_cluster_rna = dataframe.loc[ + (dataframe['cell_id'] == i) & + (dataframe['is_nuc'] == True) & + (dataframe['is_cell_fragmented'] != -1) + ].cluster_size.sum() + + nuc = np.asarray(nuc_spots + nuc_cluster_rna - 1) + + # Count the number of RNA in the cytoplasm + cyto_spots = len(dataframe.loc[ (dataframe['cell_id'] == i) & (dataframe['is_nuc'] == False) & (dataframe['is_cell_fragmented'] != -1) - ].spot_id)) + ].spot_id) + + cyto_cluster_rna = dataframe.loc[ + (dataframe['cell_id'] == i) & + (dataframe['is_nuc'] == False) & + (dataframe['is_cell_fragmented'] != -1) + ].cluster_size.sum() + + cyto = np.asarray(cyto_spots + cyto_cluster_rna - 1) ####### This is counting all transcription sites for DUSP1 that are larger than "minimum_spots_cluster". ts_size = dataframe.loc[ @@ -141,6 +156,7 @@ def data_processor(self): RNA_nuc_list.append(nuc) RNA_cyto_list.append(cyto) ts_size_list.append(ts_size_array) + # Create a pandas DataFrame from the list of ts_int values df_ts_size_per_cell = pd.DataFrame(ts_size_list) diff --git a/publications/Ron_2024/Data_Interpretation/Notebok_Data_Interpretation.ipynb b/publications/Ron_2024/Data_Interpretation/Notebok_Data_Interpretation.ipynb index 50e8c13..84e73e2 100644 --- a/publications/Ron_2024/Data_Interpretation/Notebok_Data_Interpretation.ipynb +++ b/publications/Ron_2024/Data_Interpretation/Notebok_Data_Interpretation.ipynb @@ -103,7 +103,7 @@ "metadata": {}, "outputs": [], "source": [ - "def summarize_dataframes(list_dirs, Condition, time_list, DexConc_list, time_TPL_value_list=None, Replica='A', minimum_spots_cluster=5, mandatory_substring='nuc_100__cyto_200__psfz_350__psfyx_160', connect_to_NAS=True,save_csv=True):\n", + "def summarize_dataframes(list_dirs, Condition, time_list, DexConc_list, time_TPL_value_list=None, Replica='A', minimum_spots_cluster=2, mandatory_substring='nuc_100__cyto_200__psfz_350__psfyx_160', connect_to_NAS=True,save_csv=True):\n", " \"\"\"\n", " Summarizes the dataframes from multiple directories into a single concatenated dataframe.\n", "\n", @@ -114,7 +114,7 @@ " - DexConc_list (list): List of DexConc values.\n", " - time_TPL_value_list (list, optional): List of time_TPL values. Defaults to None.\n", " - Replica (str, optional): Replica value. Defaults to 'A'.\n", - " - minimum_spots_cluster (int, optional): Minimum number of spots in a cluster. Defaults to 5.\n", + " - minimum_spots_cluster (int, optional): Minimum number of spots in a cluster. Defaults to 2.\n", " - mandatory_substring (str, optional): Mandatory substring in the file path. Defaults to 'nuc_100__cyto_200__psfz_350__psfyx_160'.\n", " - connect_to_NAS (bool, optional): Flag to connect to NAS. Defaults to True.\n", " - save_csv (bool, optional): Flag to save the concatenated dataframe as a CSV file. Defaults to True.\n", diff --git a/src/fish_analyses.py b/src/fish_analyses.py index 855f2c9..5b801b7 100644 --- a/src/fish_analyses.py +++ b/src/fish_analyses.py @@ -67,8 +67,8 @@ import shutil from fpdf import FPDF import gc -import pickle -import pycromanager as pycro +#import pickle +#import pycromanager as pycro # Selecting the GPU. This is used in case multiple scripts run in parallel. try: From 489a011c13e9322e4e030054ba29d1d009b8e53b Mon Sep 17 00:00:00 2001 From: Eron11 <60444529+ericron@users.noreply.github.com> Date: Fri, 2 Aug 2024 09:09:04 -0600 Subject: [PATCH 2/4] fixed nuc and cyto rna levels and added colums for clusters per cell --- .../Data_Interpretation/DataManagement.py | 24 +++++++++++++++++-- .../Notebok_Data_Interpretation.ipynb | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/publications/Ron_2024/Data_Interpretation/DataManagement.py b/publications/Ron_2024/Data_Interpretation/DataManagement.py index 355dc9c..e04a5a2 100644 --- a/publications/Ron_2024/Data_Interpretation/DataManagement.py +++ b/publications/Ron_2024/Data_Interpretation/DataManagement.py @@ -67,6 +67,8 @@ def data_processor(self): RNA_nuc_list = [] RNA_cyto_list = [] ts_size_list = [] + nuc_cluster_list = [] + cyto_cluster_list = [] for i in range(number_cells): nuc_area = np.asarray(dataframe.loc[ @@ -110,6 +112,13 @@ def data_processor(self): ].cluster_size.sum() nuc = np.asarray(nuc_spots + nuc_cluster_rna - 1) + + number_nuc_cluster = len(dataframe.loc[ + (dataframe['cell_id'] == i) & + (dataframe['is_cluster'] == True) & + (dataframe['is_nuc'] == True) & + (dataframe['is_cell_fragmented'] != -1) + ].spot_id) # Count the number of RNA in the cytoplasm cyto_spots = len(dataframe.loc[ @@ -125,6 +134,13 @@ def data_processor(self): ].cluster_size.sum() cyto = np.asarray(cyto_spots + cyto_cluster_rna - 1) + + cyto_cluster_number = len(dataframe.loc[ + (dataframe['cell_id'] == i) & + (dataframe['is_cluster'] == True) & + (dataframe['is_nuc'] == False) & + (dataframe['is_cell_fragmented'] != -1) + ].spot_id) ####### This is counting all transcription sites for DUSP1 that are larger than "minimum_spots_cluster". ts_size = dataframe.loc[ @@ -156,6 +172,8 @@ def data_processor(self): RNA_nuc_list.append(nuc) RNA_cyto_list.append(cyto) ts_size_list.append(ts_size_array) + nuc_cluster_list.append(number_nuc_cluster) + cyto_cluster_list.append(cyto_cluster_number) # Create a pandas DataFrame from the list of ts_int values @@ -176,8 +194,10 @@ def data_processor(self): 'Cyto_GR_avg_int': GR_avg_cyto_intensity_list, 'Nuc_DUSP1_avg_int': DUSP1_avg_nuc_intensity_list, # Only relevant for condition == DUSP1_timesweep and DUSP1_TPL. NaNs for GR_timesweep. 'Cyto_DUSP1_avg_int': DUSP1_avg_cyto_intensity_list, # Only relevant for condition == DUSP1_timesweep and DUSP1_TPL. NaNs for GR_timesweep. - 'RNA_DUSP1_nuc': RNA_nuc_list, # RNA_GR_cyto do we need also for DUSP1? - 'RNA_DUSP1_cyto': RNA_cyto_list # RNA_GR_cyto do we need also for DUSP1? + 'RNA_DUSP1_nuc': RNA_nuc_list, + 'RNA_DUSP1_cyto': RNA_cyto_list, + 'Nuc_cluster_number': nuc_cluster_list, + 'Cyto_cluster_number': cyto_cluster_list } # Create a pandas DataFrame from the dictionary df_data = pd.DataFrame(data) diff --git a/publications/Ron_2024/Data_Interpretation/Notebok_Data_Interpretation.ipynb b/publications/Ron_2024/Data_Interpretation/Notebok_Data_Interpretation.ipynb index 84e73e2..c4b1386 100644 --- a/publications/Ron_2024/Data_Interpretation/Notebok_Data_Interpretation.ipynb +++ b/publications/Ron_2024/Data_Interpretation/Notebok_Data_Interpretation.ipynb @@ -738,7 +738,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.12" + "version": "3.8.15" } }, "nbformat": 4, From 24a68c1e1d6a591e5ca6353855bc35e08609fb28 Mon Sep 17 00:00:00 2001 From: Eron11 <60444529+ericron@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:17:57 -0600 Subject: [PATCH 3/4] Fixed spot size and psf mixup --- src/fish_analyses.py | 112 ++++++++++++++++++------------------- src/pipeline_executable.py | 8 +-- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/fish_analyses.py b/src/fish_analyses.py index 5b801b7..0c4acdd 100644 --- a/src/fish_analyses.py +++ b/src/fish_analyses.py @@ -1195,10 +1195,10 @@ class BigFISH(): Height of a voxel, along the z axis, in nanometers. The default is 300. voxel_size_yx : int, optional Size of a voxel on the yx plan in nanometers. The default is 150. - psf_z : int, optional - Theoretical size of the PSF emitted by a spot in the z plan, in nanometers. The default is 350. - psf_yx : int, optional - Theoretical size of the PSF emitted by a spot in the yx plan in nanometers. + mRNA_radius_z : int, optional + Theoretical size of the mRNA_radius emitted by a spot in the z plan, in nanometers. The default is 350. + mRNA_radius_yx : int, optional + Theoretical size of the mRNA_radius emitted by a spot in the yx plan in nanometers. cluster_radius : int, optional Maximum distance between two samples for one to be considered as in the neighborhood of the other. Radius expressed in nanometer. minimum_spots_cluster : int, optional @@ -1216,15 +1216,15 @@ class BigFISH(): threshold_for_spot_detection: scalar or None. Indicates the intensity threshold used for spot detection, the default is None, and indicates that the threshold is calculated automatically. ''' - def __init__(self,image, FISH_channel , voxel_size_z = 300,voxel_size_yx = 103,psf_z = 350, psf_yx = 150, cluster_radius = 350,minimum_spots_cluster = 4, show_plots =False,image_name=None,save_all_images=False,display_spots_on_multiple_z_planes=False,use_log_filter_for_spot_detection=True,threshold_for_spot_detection=None,save_files=True): + def __init__(self,image, FISH_channel , voxel_size_z = 300,voxel_size_yx = 103,mRNA_radius_z = 350, mRNA_radius_yx = 150, cluster_radius = 350,minimum_spots_cluster = 4, show_plots =False,image_name=None,save_all_images=False,display_spots_on_multiple_z_planes=False,use_log_filter_for_spot_detection=True,threshold_for_spot_detection=None,save_files=True): if len(image.shape)<4: image= np.expand_dims(image,axis =0) self.image = image self.FISH_channel = FISH_channel self.voxel_size_z = voxel_size_z self.voxel_size_yx = voxel_size_yx - self.psf_z = psf_z - self.psf_yx = psf_yx + self.mRNA_radius_z = mRNA_radius_z + self.mRNA_radius_yx = mRNA_radius_yx self.cluster_radius = cluster_radius self.minimum_spots_cluster = minimum_spots_cluster self.show_plots = show_plots @@ -1249,10 +1249,10 @@ def detect(self): # Setting the colormap mpl.rc('image', cmap='viridis') rna=self.image[:,:,:,self.FISH_channel] - # Calculating Sigma with the parameters for the PSF. + # Calculating Sigma with the parameters for the mRNA_radius. spot_radius_px = detection.get_object_radius_pixel( voxel_size_nm=(self.voxel_size_z, self.voxel_size_yx, self.voxel_size_yx), - object_radius_nm=(self.psf_z, self.psf_yx, self.psf_yx), ndim=3) + object_radius_nm=(self.mRNA_radius_z, self.mRNA_radius_yx, self.mRNA_radius_yx), ndim=3) sigma = spot_radius_px #print('sigma_value (z,y,x) =', sigma) ## SPOT DETECTION @@ -1260,7 +1260,7 @@ def detect(self): try: rna_filtered = stack.log_filter(rna, sigma) # LoG filter except ValueError: - print('Error during the log filter calculation, try using larger parameters values for the psf') + print('Error during the log filter calculation, try using larger parameters values for the mRNA_radius') rna_filtered = stack.remove_background_gaussian(rna, sigma) else: rna_filtered = stack.remove_background_gaussian(rna, sigma) @@ -1278,7 +1278,7 @@ def detect(self): spots_post_decomposition, _, _ = detection.decompose_dense(image=rna, spots=spots, voxel_size = (self.voxel_size_z, self.voxel_size_yx, self.voxel_size_yx), - spot_radius = (self.psf_z, self.psf_yx, self.psf_yx), + spot_radius = (self.mRNA_radius_z, self.mRNA_radius_yx, self.mRNA_radius_yx), alpha=0.9, # alpha impacts the number of spots per candidate region beta=1, # beta impacts the number of candidate regions to decompose gamma=5) # gamma the filtering step to denoise the image @@ -1306,7 +1306,7 @@ def detect(self): path_output_elbow= str(self.image_name) +'__elbow_'+ '_ch_' + str(self.FISH_channel) + '.png' plot.plot_elbow(rna, voxel_size=(self.voxel_size_z, self.voxel_size_yx,self.voxel_size_yx), - spot_radius= (self.psf_z, self.psf_yx, self.psf_yx), + spot_radius= (self.mRNA_radius_z, self.mRNA_radius_yx, self.mRNA_radius_yx), path_output = path_output_elbow, show=bool(self.show_plots) ) if self.show_plots ==True: plt.show() @@ -1882,10 +1882,10 @@ class SpotDetection(): list with a tuple with two elements (voxel_size_z,voxel_size_yx ) for each FISH channel. voxel_size_z is the height of a voxel, along the z axis, in nanometers. The default is 300. voxel_size_yx is the size of a voxel on the yx plan in nanometers. The default is 150. - list_psfs : List of tuples or None - List with a tuple with two elements (psf_z, psf_yx ) for each FISH channel. - psf_z is the size of the PSF emitted by a spot in the z plan, in nanometers. The default is 350. - psf_yx is the size of the PSF emitted by a spot in the yx plan in nanometers. + list_mRNA_radius : List of tuples or None + List with a tuple with two elements (mRNA_radius_z, mRNA_radius_yx ) for each FISH channel. + mRNA_radius_z is the size of the mRNA_radius emitted by a spot in the z plan, in nanometers. The default is 350. + mRNA_radius_yx is the size of the mRNA_radius emitted by a spot in the yx plan in nanometers. show_plots : bool, optional If True, it shows a 2D maximum projection of the image and the detected spots. The default is False. image_name : str or None. @@ -1900,7 +1900,7 @@ class SpotDetection(): Indicates the intensity threshold used for spot detection, the default is None, and indicates that the threshold is calculated automatically. ''' - def __init__(self,image, FISH_channels ,channels_with_cytosol,channels_with_nucleus, cluster_radius=500, minimum_spots_cluster=4, masks_complete_cells = None, masks_nuclei = None, masks_cytosol_no_nuclei = None, dataframe=None, image_counter=0, list_voxels=[[500,160]], list_psfs=[[350,160]], show_plots=True,image_name=None,save_all_images=True,display_spots_on_multiple_z_planes=False,use_log_filter_for_spot_detection=True,threshold_for_spot_detection=None,save_files=True): + def __init__(self,image, FISH_channels ,channels_with_cytosol,channels_with_nucleus, cluster_radius=500, minimum_spots_cluster=4, masks_complete_cells = None, masks_nuclei = None, masks_cytosol_no_nuclei = None, dataframe=None, image_counter=0, list_voxels=[[500,160]], list_mRNA_radius=[[350,160]], show_plots=True,image_name=None,save_all_images=True,display_spots_on_multiple_z_planes=False,use_log_filter_for_spot_detection=True,threshold_for_spot_detection=None,save_files=True): if len(image.shape)<4: image= np.expand_dims(image,axis =0) self.image = image @@ -1930,10 +1930,10 @@ def __init__(self,image, FISH_channels ,channels_with_cytosol,channels_with_nuc self.list_voxels = [list_voxels] else: self.list_voxels = list_voxels - if type(list_psfs[0]) != list: - self.list_psfs = [list_psfs] + if type(list_mRNA_radius[0]) != list: + self.list_mRNA_radius = [list_mRNA_radius] else: - self.list_psfs = list_psfs + self.list_mRNA_radius = list_mRNA_radius # converting FISH channels to a list if not (type(FISH_channels) is list): self.list_FISH_channels = [FISH_channels] @@ -1957,15 +1957,15 @@ def get_dataframe(self): reset_cell_counter = False voxel_size_z = self.list_voxels[i][0] voxel_size_yx = self.list_voxels[i][1] - psf_z = self.list_psfs[i][0] - psf_yx = self.list_psfs[i][1] - [spotDetectionCSV, clusterDetectionCSV], image_filtered, threshold = BigFISH(self.image, self.list_FISH_channels[i], voxel_size_z = voxel_size_z,voxel_size_yx = voxel_size_yx, psf_z = psf_z, psf_yx = psf_yx, + mRNA_radius_z = self.list_mRNA_radius[i][0] + mRNA_radius_yx = self.list_mRNA_radius[i][1] + [spotDetectionCSV, clusterDetectionCSV], image_filtered, threshold = BigFISH(self.image, self.list_FISH_channels[i], voxel_size_z = voxel_size_z,voxel_size_yx = voxel_size_yx, mRNA_radius_z = mRNA_radius_z, mRNA_radius_yx = mRNA_radius_yx, cluster_radius=self.cluster_radius,minimum_spots_cluster=self.minimum_spots_cluster, show_plots=self.show_plots,image_name=self.image_name, save_all_images=self.save_all_images,display_spots_on_multiple_z_planes=self.display_spots_on_multiple_z_planes,use_log_filter_for_spot_detection =self.use_log_filter_for_spot_detection, threshold_for_spot_detection=self.threshold_for_spot_detection[i],save_files=self.save_files).detect() list_thresholds_spot_detection.append(threshold) - # converting the psf to pixles - yx_spot_size_in_px = np.max((1,int(voxel_size_yx / psf_yx))).astype('int') + # converting the mRNA_radius to pixles + yx_spot_size_in_px = np.max((1,int(voxel_size_yx / mRNA_radius_yx))).astype('int') dataframe_FISH = DataProcessing(spotDetectionCSV, clusterDetectionCSV, self.image, self.list_masks_complete_cells, self.list_masks_nuclei, self.list_masks_cytosol_no_nuclei, self.channels_with_cytosol,self.channels_with_nucleus, yx_spot_size_in_px=yx_spot_size_in_px, dataframe =dataframe_FISH,reset_cell_counter=reset_cell_counter,image_counter = self.image_counter ,spot_type=i,number_color_channels=self.number_color_channels ).get_dataframe() @@ -1998,8 +1998,8 @@ class Metadata(): Number of spots in a neighborhood for a point to be considered as a core point (from which a cluster is expanded). This includes the point itself. list_voxels : List of lists or None List with a tuple with two elements (voxel_size_z,voxel_size_yx ) for each FISH channel. - list_psfs : List of lists or None - List with a tuple with two elements (psf_z, psf_yx ) for each FISH channel. + list_mRNA_radius : List of lists or None + List with a tuple with two elements (mRNA_radius_z, mRNA_radius_yx ) for each FISH channel. file_name_str : str Name used for the metadata file. The final name has the format metadata_<>.txt list_counter_cell_id : str @@ -2007,7 +2007,7 @@ class Metadata(): threshold_for_spot_detection : int Threshold value used to discriminate background noise from mRNA spots in the image. ''' - def __init__(self,data_dir, channels_with_cytosol, channels_with_nucleus, channels_with_FISH, diameter_nucleus, diameter_cytosol, minimum_spots_cluster, list_voxels=None, list_psfs=None, file_name_str=None,list_segmentation_successful=True,list_counter_image_id=[],threshold_for_spot_detection=[],number_of_images_to_process=None,remove_z_slices_borders=False,NUMBER_Z_SLICES_TO_TRIM=0,CLUSTER_RADIUS=0,list_thresholds_spot_detection=[None],list_average_spots_per_cell=[None],list_number_detected_cells=[None],list_is_image_sharp=[None],list_metric_sharpeness_images=[None],remove_out_of_focus_images=False,sharpness_threshold=None): + def __init__(self,data_dir, channels_with_cytosol, channels_with_nucleus, channels_with_FISH, diameter_nucleus, diameter_cytosol, minimum_spots_cluster, list_voxels=None, list_mRNA_radius=None, file_name_str=None,list_segmentation_successful=True,list_counter_image_id=[],threshold_for_spot_detection=[],number_of_images_to_process=None,remove_z_slices_borders=False,NUMBER_Z_SLICES_TO_TRIM=0,CLUSTER_RADIUS=0,list_thresholds_spot_detection=[None],list_average_spots_per_cell=[None],list_number_detected_cells=[None],list_is_image_sharp=[None],list_metric_sharpeness_images=[None],remove_out_of_focus_images=False,sharpness_threshold=None): self.list_images, self.path_files, self.list_files_names, self.number_images = ReadImages(data_dir,number_of_images_to_process).read() self.channels_with_cytosol = channels_with_cytosol @@ -2019,7 +2019,7 @@ def __init__(self,data_dir, channels_with_cytosol, channels_with_nucleus, channe self.diameter_nucleus = diameter_nucleus self.diameter_cytosol = diameter_cytosol self.list_voxels = list_voxels - self.list_psfs = list_psfs + self.list_mRNA_radius = list_mRNA_radius self.file_name_str=file_name_str self.minimum_spots_cluster = minimum_spots_cluster self.threshold_for_spot_detection=threshold_for_spot_detection @@ -2081,8 +2081,8 @@ def write_data_in_file(filename): fd.write('\n For Channel ' + str(self.channels_with_FISH[k]) ) fd.write('\n voxel_size_z: ' + str(self.list_voxels[k][0]) ) fd.write('\n voxel_size_yx: ' + str(self.list_voxels[k][1]) ) - fd.write('\n psf_z: ' + str(self.list_psfs[k][0]) ) - fd.write('\n psf_yx: ' + str(self.list_psfs[k][1]) ) + fd.write('\n mRNA_radius_z: ' + str(self.list_mRNA_radius[k][0]) ) + fd.write('\n mRNA_radius_yx: ' + str(self.list_mRNA_radius[k][1]) ) if not(self.threshold_for_spot_detection in (None, [None]) ): fd.write('\n threshold_spot_detection: ' + str(self.threshold_for_spot_detection[k]) ) else: @@ -2320,10 +2320,10 @@ class PipelineFISH(): Microscope conversion px to nanometers in the z axis. The default is 500. voxel_size_yx : int, optional Microscope conversion px to nanometers in the xy axis. The default is 160. - psf_z : int, optional - Theoretical size of the PSF emitted by a [rna] spot in the z plan, in nanometers. The default is 350. - psf_yx: int, optional - Theoretical size of the PSF emitted by a [rna] spot in the yx plan, in nanometers. The default is 160. + mRNA_radius_z : int, optional + Theoretical size of the mRNA_radius emitted by a [rna] spot in the z plan, in nanometers. The default is 350. + mRNA_radius_yx: int, optional + Theoretical size of the mRNA_radius emitted by a [rna] spot in the yx plan, in nanometers. The default is 160. list_masks : List of Numpy or None. list of Numpy arrays where each array has values from 0 to n where n is the number of masks in the image. save_all_images : Bool, optional. @@ -2341,7 +2341,7 @@ class PipelineFISH(): This flag indicates the removal of the two first and last 2 z-slices from the segmentation and quantification. This needed to avoid processing images out of focus. The default is True. ''' - def __init__(self,data_folder_path=None, channels_with_cytosol=None, channels_with_nucleus=None, channels_with_FISH=None,diameter_nucleus=100, diameter_cytosol=200, minimum_spots_cluster=5, image=None, masks_dir=None, show_plots=True, voxel_size_z=500, voxel_size_yx=160 ,psf_z=350,psf_yx=160,file_name_str =None,optimization_segmentation_method='default',save_all_images=False,display_spots_on_multiple_z_planes=False,use_log_filter_for_spot_detection=True,threshold_for_spot_detection=[None],NUMBER_OF_CORES=1,list_selected_z_slices=None,save_filtered_images=False,number_of_images_to_process=None,remove_z_slices_borders=False,remove_out_of_focus_images = False,sharpness_threshold =1.05,save_pdf_report=False,folder_name='temp',save_files=True,model_nuc_segmentation='nuclei',model_cyto_segmentation='cyto',pretrained_model_nuc_segmentation=None, pretrained_model_cyto_segmentation=None): + def __init__(self,data_folder_path=None, channels_with_cytosol=None, channels_with_nucleus=None, channels_with_FISH=None,diameter_nucleus=100, diameter_cytosol=200, minimum_spots_cluster=5, image=None, masks_dir=None, show_plots=True, voxel_size_z=500, voxel_size_yx=160 ,mRNA_radius_z=350,mRNA_radius_yx=160,file_name_str =None,optimization_segmentation_method='default',save_all_images=False,display_spots_on_multiple_z_planes=False,use_log_filter_for_spot_detection=True,threshold_for_spot_detection=[None],NUMBER_OF_CORES=1,list_selected_z_slices=None,save_filtered_images=False,number_of_images_to_process=None,remove_z_slices_borders=False,remove_out_of_focus_images = False,sharpness_threshold =1.05,save_pdf_report=False,folder_name='temp',save_files=True,model_nuc_segmentation='nuclei',model_cyto_segmentation='cyto',pretrained_model_nuc_segmentation=None, pretrained_model_cyto_segmentation=None): if type(data_folder_path)== pathlib.PosixPath or isinstance(data_folder_path, str) or type(data_folder_path)== pathlib.WindowsPath: list_images, _ , self.list_files_names, self.number_images = ReadImages(data_folder_path,number_of_images_to_process).read() @@ -2390,19 +2390,19 @@ def __init__(self,data_folder_path=None, channels_with_cytosol=None, channels_wi self.channels_with_FISH = channels_with_FISH self.diameter_nucleus = diameter_nucleus self.diameter_cytosol = diameter_cytosol - self.psf_z = psf_z - self.psf_yx = psf_yx - # Lists for voxels and psfs + self.mRNA_radius_z = mRNA_radius_z + self.mRNA_radius_yx = mRNA_radius_yx + # Lists for voxels and mRNA_radius list_voxels = [] - list_psfs = [] + list_mRNA_radius = [] for i in range (len(channels_with_FISH)): list_voxels.append([voxel_size_z,voxel_size_yx]) - list_psfs.append([psf_z, psf_yx]) + list_mRNA_radius.append([mRNA_radius_z, mRNA_radius_yx]) self.list_voxels = list_voxels - self.list_psfs = list_psfs + self.list_mRNA_radius = list_mRNA_radius self.minimum_spots_cluster = minimum_spots_cluster self.show_plots = show_plots - CLUSTER_RADIUS = 600 #int(psf_yx*1.5) + CLUSTER_RADIUS = mRNA_radius_yx * 2 self.CLUSTER_RADIUS = CLUSTER_RADIUS if not(data_folder_path is None): @@ -2455,15 +2455,15 @@ def __init__(self,data_folder_path=None, channels_with_cytosol=None, channels_wi list_thresholds=[] voxel_size_z = list_voxels[i][0] voxel_size_yx = list_voxels[i][1] - psf_z = list_psfs[i][0] - psf_yx = list_psfs[i][1] + mRNA_radius_z = list_mRNA_radius[i][0] + mRNA_radius_yx = list_mRNA_radius[i][1] for _, image_selected in enumerate(sub_section_images_to_test): threshold = BigFISH(image_selected, channels_with_FISH[i], voxel_size_z = voxel_size_z, voxel_size_yx = voxel_size_yx, - psf_z = psf_z, - psf_yx = psf_yx, + mRNA_radius_z = mRNA_radius_z, + mRNA_radius_yx = mRNA_radius_yx, cluster_radius=CLUSTER_RADIUS, minimum_spots_cluster=self.minimum_spots_cluster, use_log_filter_for_spot_detection =self.use_log_filter_for_spot_detection, @@ -2491,7 +2491,7 @@ def __init__(self,data_folder_path=None, channels_with_cytosol=None, channels_wi def run(self): # Creating folder to store outputs. if self.save_files == True: - output_identification_string = Utilities().create_output_folders(self.data_folder_path, self.diameter_nucleus, self.diameter_cytosol, self.psf_z, self.psf_yx, self.threshold_for_spot_detection, self.channels_with_FISH, self.threshold_for_spot_detection) + output_identification_string = Utilities().create_output_folders(self.data_folder_path, self.diameter_nucleus, self.diameter_cytosol, self.mRNA_radius_z, self.mRNA_radius_yx, self.threshold_for_spot_detection, self.channels_with_FISH, self.threshold_for_spot_detection) else: output_identification_string = '' MINIMAL_NUMBER_OF_PIXELS_IN_MASK = 1000 @@ -2644,7 +2644,7 @@ def run(self): dataframe=dataframe, image_counter=counter, list_voxels=self.list_voxels, - list_psfs=self.list_psfs, + list_mRNA_radius=self.list_mRNA_radius, show_plots=self.show_plots, image_name = temp_detection_img_name, save_all_images=self.save_all_images, @@ -2745,7 +2745,7 @@ def run(self): self.diameter_cytosol, self.minimum_spots_cluster, list_voxels=self.list_voxels, - list_psfs=self.list_psfs, + list_mRNA_radius=self.list_mRNA_radius, file_name_str=self.name_for_files, list_segmentation_successful=list_segmentation_successful, list_counter_image_id=list_counter_image_id, @@ -2799,12 +2799,12 @@ class ColocalizationDistance(): If true, it shows a spots on the plane below and above the selected plane. The default is False. voxel_size_z, voxel_size_yx: float, optional. These values indicate the microscope voxel size. These parameters are optional and should be included only if a normalization to the z-axis is needed to calculate distance. - psf_z, psf_yx: float, optional. + mRNA_radius_z, mRNA_radius_yx: float, optional. These values indicate the microscope point spread function value. These parameters are optional and should be included only if a normalization to the z-axis is needed to calculate distance. report_codetected_spots_in_both_channels : bool, optional This option report the number of co-detected spots in channel both channels. Notice that this represents the total number of codetected spots in ch0 and ch1. The default is True. ''' - def __init__(self, df,list_spot_type_to_compare =[0,1], time_point=0,threshold_intensity_0=0,threshold_intensity_1=0,threshold_distance=2,show_plots = False,voxel_size_z=None,psf_z=None,voxel_size_yx=None,psf_yx=None,report_codetected_spots_in_both_channels=False): + def __init__(self, df,list_spot_type_to_compare =[0,1], time_point=0,threshold_intensity_0=0,threshold_intensity_1=0,threshold_distance=2,show_plots = False,voxel_size_z=None,mRNA_radius_z=None,voxel_size_yx=None,mRNA_radius_yx=None,report_codetected_spots_in_both_channels=False): self.df = df self.time_point= time_point self.threshold_intensity_0 = threshold_intensity_0 @@ -2813,7 +2813,7 @@ def __init__(self, df,list_spot_type_to_compare =[0,1], time_point=0,threshold_i self.show_plots = show_plots self.list_spot_type_to_compare = list_spot_type_to_compare if not (voxel_size_z is None): - self.scale = np.array ([ voxel_size_z/psf_z, voxel_size_yx/psf_yx, voxel_size_yx/psf_yx ]) + self.scale = np.array ([ voxel_size_z/mRNA_radius_z, voxel_size_yx/mRNA_radius_yx, voxel_size_yx/mRNA_radius_yx ]) else: self.scale = 1 self.report_codetected_spots_in_both_channels = report_codetected_spots_in_both_channels @@ -3468,7 +3468,7 @@ def convert_to_standard_format(self,data_folder_path,path_to_config_file, number masks_dir = None return destination_folder,masks_dir, list_files_names, list_images_all_fov, list_images_standard_format - def create_output_folders(self,data_folder_path,diameter_nucleus,diameter_cytosol,psf_z,psf_yx,threshold_for_spot_detection,channels_with_FISH,list_threshold_for_spot_detection): + def create_output_folders(self,data_folder_path,diameter_nucleus,diameter_cytosol,mRNA_radius_z,mRNA_radius_yx,threshold_for_spot_detection,channels_with_FISH,list_threshold_for_spot_detection): # testing if the images were merged. if data_folder_path.name == 'merged': data_folder_path = data_folder_path.parents[0] @@ -3479,9 +3479,9 @@ def create_output_folders(self,data_folder_path,diameter_nucleus,diameter_cytoso original_folder_name= data_folder_path.name # Creating the output_identification_string if (threshold_for_spot_detection is None): - output_identification_string = original_folder_name+'___nuc_' + str(diameter_nucleus) +'__cyto_' + str(diameter_cytosol) +'__psfz_' + str(psf_z) +'__psfyx_' + str(psf_yx)+'__ts_auto' + output_identification_string = original_folder_name+'___nuc_' + str(diameter_nucleus) +'__cyto_' + str(diameter_cytosol) +'__mRNA_radius_z_' + str(mRNA_radius_z) +'__mRNA_radius_yx_' + str(mRNA_radius_yx)+'__ts_auto' else: - output_identification_string = original_folder_name +'___nuc_' + str(diameter_nucleus) +'__cyto_' + str(diameter_cytosol) +'__psfz_' + str(psf_z) +'__psfyx_' + str(psf_yx)+'__ts' + output_identification_string = original_folder_name +'___nuc_' + str(diameter_nucleus) +'__cyto_' + str(diameter_cytosol) +'__mRNA_radius_z_' + str(mRNA_radius_z) +'__mRNA_radius_yx_' + str(mRNA_radius_yx)+'__ts' for i in range (len(channels_with_FISH)): output_identification_string+='_'+ str(list_threshold_for_spot_detection[i]) print ('\n Output folder name : ' , output_identification_string) diff --git a/src/pipeline_executable.py b/src/pipeline_executable.py index 9cc9ff2..4d67b5c 100644 --- a/src/pipeline_executable.py +++ b/src/pipeline_executable.py @@ -47,8 +47,8 @@ diameter_cytosol = int(sys.argv[4]) # Approximate cytosol size in pixels voxel_size_z = int(sys.argv[5]) # Microscope conversion px to nanometers in the z axis. voxel_size_yx = int(sys.argv[6]) # Microscope conversion px to nanometers in the xy axis. -psf_z = int(sys.argv[7]) # Theoretical size of the PSF emitted by a [rna] spot in the z plan, in nanometers. -psf_yx = int(sys.argv[8]) # Theoretical size of the PSF emitted by a [rna] spot in the yx plan, in nanometers. +mRNA_radius_z = int(sys.argv[7]) # Theoretical size of the mRNA_radius emitted by a [rna] spot in the z plan, in nanometers. +mRNA_radius_yx = int(sys.argv[8]) # Theoretical size of the mRNA_radius emitted by a [rna] spot in the yx plan, in nanometers. # Segmentation Channels if sys.argv[9] in tuple_none: channels_with_nucleus = None @@ -155,8 +155,8 @@ masks_dir = masks_dir, voxel_size_z = voxel_size_z, voxel_size_yx = voxel_size_yx, - psf_z = psf_z, - psf_yx = psf_yx, + mRNA_radius_z = mRNA_radius_z, + mRNA_radius_yx = mRNA_radius_yx, show_plots = show_plots, file_name_str = data_folder_path.name, optimization_segmentation_method = optimization_segmentation_method, From 7241a100b6033713daf2232ffd2d9a0e8b6d8d95 Mon Sep 17 00:00:00 2001 From: Eron11 <60444529+ericron@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:18:16 -0600 Subject: [PATCH 4/4] added single cell viewer --- notebooks/FISH_pipeline.ipynb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/notebooks/FISH_pipeline.ipynb b/notebooks/FISH_pipeline.ipynb index 3542ff4..a6a2818 100644 --- a/notebooks/FISH_pipeline.ipynb +++ b/notebooks/FISH_pipeline.ipynb @@ -183,6 +183,7 @@ { "cell_type": "code", "execution_count": 5, + "id": "a061b473", "metadata": {}, "outputs": [], "source": [ @@ -211,8 +212,8 @@ "diameter_nucleus=100 # Approximate nucleus size in pixels\n", "diameter_cytosol=200 # Approximate cytosol size in pixels\n", "\n", - "psf_z=350 # Theoretical size of the PSF emitted by a [rna] spot in the z plan, in nanometers\n", - "psf_yx=160 # Theoretical size of the PSF emitted by a [rna] spot in the yx plan, in nanometers\n", + "mRNA_radius_z=350 # Theoretical size of the mRNA_radius emitted by a [rna] spot in the z plan, in nanometers\n", + "mRNA_radius_yx=160 # Theoretical size of the mRNA_radius emitted by a [rna] spot in the yx plan, in nanometers\n", "\n", "voxel_size_z=500 # Microscope conversion px to nanometers in the z axis.\n", "voxel_size_yx=160 # Microscope conversion px to nanometers in the xy axis.\n", @@ -237,6 +238,7 @@ { "cell_type": "code", "execution_count": 7, + "id": "2a2a6ac1", "metadata": {}, "outputs": [], "source": [ @@ -281,6 +283,7 @@ { "cell_type": "code", "execution_count": null, + "id": "72b35ad6", "metadata": {}, "outputs": [], "source": [ @@ -336,7 +339,7 @@ "source": [ "dataframe_FISH,_,_,_,output_identification_string = fa.PipelineFISH(local_data_dir, channels_with_cytosol, channels_with_nucleus, channels_with_FISH,diameter_nucleus, \n", " diameter_cytosol, minimum_spots_cluster, masks_dir=masks_dir, voxel_size_z=voxel_size_z,\n", - " voxel_size_yx=voxel_size_yx ,psf_z=psf_z,psf_yx=psf_yx, show_plots=show_plots, \n", + " voxel_size_yx=voxel_size_yx ,mRNA_radius_z=mRNA_radius_z,mRNA_radius_yx=mRNA_radius_yx, show_plots=show_plots, \n", " file_name_str=data_folder_path.name, \n", " optimization_segmentation_method=optimization_segmentation_method,\n", " save_all_images=save_all_images,\n",