|
42 | 42 | "\n", |
43 | 43 | "\"\"\"\n", |
44 | 44 | "\n", |
45 | | - "analysis_folder = r\"S:\\ASAP_Imaging_Data\\Main_Survey\\20241105_oligomers_in_cells\\caudate\\neurons\\PD_analysis\"\n", |
| 45 | + "analysis_folder = \"/scratch/sycamore-asap/ASAP_Imaging_Data/Main_Survey/20241105_oligomers_in_cells/caudate/neurons/PD_analysis\"\n", |
46 | 46 | "analysis_file = os.path.abspath(\n", |
47 | | - " r\"S:\\ASAP_Imaging_Data\\Main_Survey\\20241105_oligomers_in_cells\\caudate\\neurons\\PD_analysis\\spot_analysis_0_abovephotonthreshold.csv\"\n", |
| 47 | + " os.path.join(analysis_folder, \"20250304\", \"spot_analysis_0_abovephotonthreshold.csv\")\n", |
48 | 48 | ") # example file, replace as you wish. Always input as the absolute path of a raw string\n", |
49 | 49 | "threshold = 0.0\n", |
50 | 50 | "protein_string = \"C1\"\n", |
|
54 | 54 | "analysis_data = pl.read_csv(analysis_file)\n", |
55 | 55 | "z_project_first = [True, True]\n", |
56 | 56 | "\n", |
57 | | - "cell_punctum_analysis_file = r\"S:\\ASAP_Imaging_Data\\Main_Survey\\20241105_oligomers_in_cells\\caudate\\neurons\\PD_analysis\\single_cell_coincidence_mincellsize_2000_photonthreshold_0p0_photons_combined_threshold_percentile_0_k_4_outliersremoved_abovethreshold.csv\"\n", |
| 57 | + "cell_punctum_analysis_file = os.path.join(\n", |
| 58 | + " analysis_folder,\n", |
| 59 | + " \"single_cell_coincidence_mincellsize_2000_photonthreshold_0p0_photons_combined_threshold_percentile_0_k_4_outliersremoved_abovethreshold.csv\",\n", |
| 60 | + ")\n", |
58 | 61 | "cell_punctum_analysis = pl.read_csv(cell_punctum_analysis_file)\n", |
59 | 62 | "cell_punctum_analysis = cell_punctum_analysis.filter(pl.col(\"puncta_cell_likelihood\") != np.NAN)" |
60 | 63 | ] |
|
977 | 980 | "A_F = AnalysisFunctions.Analysis_Functions()\n", |
978 | 981 | "import os\n", |
979 | 982 | "\n", |
| 983 | + "def _to_linux_path(windows_path):\n", |
| 984 | + " \"\"\"Converts a stored Windows-style S:\\\\... path (baked into older analysis\n", |
| 985 | + " CSVs from when this data was analysed on Windows) to the equivalent Linux\n", |
| 986 | + " path used everywhere now.\"\"\"\n", |
| 987 | + " posix_path = windows_path.replace(\"\\\\\", \"/\")\n", |
| 988 | + " if posix_path.startswith(\"S:/\"):\n", |
| 989 | + " posix_path = \"/scratch/sycamore-asap\" + posix_path[2:]\n", |
| 990 | + " return posix_path\n", |
| 991 | + "\n", |
| 992 | + "\n", |
980 | 993 | "for i in np.arange(len(n_cells_per_image)):\n", |
981 | 994 | " cell_file = np.argsort(n_cells_per_image)[i]\n", |
982 | | - " file = image_filenames[cell_file] # we take a file we're interested in\n", |
| 995 | + " file = image_filenames[cell_file] # we take a file we're interested in (as stored in the CSV -- keep as-is for filtering below)\n", |
| 996 | + " file_linux = _to_linux_path(file) # the same file, as an actual path on this machine\n", |
983 | 997 | " # now find the corresponding cell mask\n", |
984 | 998 | " mask_file = os.path.join(\n", |
985 | 999 | " analysis_folder,\n", |
986 | 1000 | " str(\n", |
987 | | - " os.path.split(file)[-1].split(imtype)[0].split(protein_string)[0]\n", |
| 1001 | + " os.path.split(file_linux)[-1].split(imtype)[0].split(protein_string)[0]\n", |
988 | 1002 | " + cell_string\n", |
989 | 1003 | " + \"_cellMask.tiff\"\n", |
990 | 1004 | " ),\n", |
991 | 1005 | " )\n", |
992 | 1006 | " \n", |
993 | 1007 | " # and the corresponding raw cell data\n", |
994 | | - " raw_cell_file = str(file.split(imtype)[0].split(protein_string)[0]+cell_string+imtype)\n", |
| 1008 | + " raw_cell_file = str(file_linux.split(imtype)[0].split(protein_string)[0]+cell_string+imtype)\n", |
995 | 1009 | " cell_mask = IO.read_tiff(mask_file)\n", |
996 | 1010 | " cell_image = IO.read_tiff_tophotons(raw_cell_file)\n", |
997 | | - " puncta_image = IO.read_tiff_tophotons(file)\n", |
| 1011 | + " puncta_image = IO.read_tiff_tophotons(file_linux)\n", |
998 | 1012 | " puncta_values = analysis_data.filter(pl.col('image_filename') == file)\n", |
999 | | - " oned_cell_mask, pil, centroids, areas = A_F.threshold_cell_areas(\n", |
| 1013 | + " # threshold_cell_areas() no longer exists -- threshold_cell_areas_3d is now\n", |
| 1014 | + " # the default cell-size filter (operates on the full 3D mask; note the real\n", |
| 1015 | + " # return order is cell_mask, pil, areas, centroids -- areas before centroids).\n", |
| 1016 | + " cell_mask_new, pil, areas, centroids = A_F.threshold_cell_areas_3d(\n", |
1000 | 1017 | " cell_mask,\n", |
1001 | 1018 | " lower_cell_size_threshold=lower_cell_size_threshold,\n", |
1002 | | - " z_project=[True, True],\n", |
1003 | 1019 | " )\n", |
| 1020 | + " oned_cell_mask = cell_mask_new.sum(axis=0).clip(0, 1)\n", |
1004 | 1021 | " oned_puncta_image = np.sum(puncta_image, axis=-1)\n", |
1005 | 1022 | " oned_cell_image = np.sum(cell_image, axis=-1)\n", |
1006 | 1023 | " print(i)\n", |
|
1016 | 1033 | "outputs": [], |
1017 | 1034 | "source": [ |
1018 | 1035 | " cell_file = np.argsort(n_cells_per_image)[14]\n", |
1019 | | - " file = image_filenames[cell_file] # we take a file we're interested in\n", |
| 1036 | + " file = image_filenames[cell_file] # we take a file we're interested in (as stored in the CSV -- keep as-is for filtering below)\n", |
| 1037 | + " file_linux = _to_linux_path(file) # the same file, as an actual path on this machine\n", |
1020 | 1038 | " # now find the corresponding cell mask\n", |
1021 | 1039 | " mask_file = os.path.join(\n", |
1022 | 1040 | " analysis_folder,\n", |
1023 | 1041 | " str(\n", |
1024 | | - " os.path.split(file)[-1].split(imtype)[0].split(protein_string)[0]\n", |
| 1042 | + " os.path.split(file_linux)[-1].split(imtype)[0].split(protein_string)[0]\n", |
1025 | 1043 | " + cell_string\n", |
1026 | 1044 | " + \"_cellMask.tiff\"\n", |
1027 | 1045 | " ),\n", |
1028 | 1046 | " )\n", |
1029 | 1047 | " \n", |
1030 | 1048 | " # and the corresponding raw cell data\n", |
1031 | | - " raw_cell_file = str(file.split(imtype)[0].split(protein_string)[0]+cell_string+imtype)\n", |
| 1049 | + " raw_cell_file = str(file_linux.split(imtype)[0].split(protein_string)[0]+cell_string+imtype)\n", |
1032 | 1050 | " cell_mask = IO.read_tiff(mask_file)\n", |
1033 | 1051 | " cell_image = IO.read_tiff_tophotons(raw_cell_file)\n", |
1034 | | - " puncta_image = IO.read_tiff_tophotons(file)\n", |
| 1052 | + " puncta_image = IO.read_tiff_tophotons(file_linux)\n", |
1035 | 1053 | " puncta_values = analysis_data.filter(pl.col('image_filename') == file)\n", |
1036 | | - " oned_cell_mask, pil, centroids, areas = A_F.threshold_cell_areas(\n", |
| 1054 | + " # threshold_cell_areas() no longer exists -- threshold_cell_areas_3d is now\n", |
| 1055 | + " # the default cell-size filter (operates on the full 3D mask; note the real\n", |
| 1056 | + " # return order is cell_mask, pil, areas, centroids -- areas before centroids).\n", |
| 1057 | + " cell_mask_new, pil, areas, centroids = A_F.threshold_cell_areas_3d(\n", |
1037 | 1058 | " cell_mask,\n", |
1038 | 1059 | " lower_cell_size_threshold=lower_cell_size_threshold,\n", |
1039 | | - " z_project=[True, True],\n", |
1040 | 1060 | " )\n", |
| 1061 | + " oned_cell_mask = cell_mask_new.sum(axis=0).clip(0, 1)\n", |
1041 | 1062 | " oned_puncta_image = np.sum(puncta_image, axis=-1)\n", |
1042 | 1063 | " oned_cell_image = np.sum(cell_image, axis=-1)" |
1043 | 1064 | ] |
|
0 commit comments