Skip to content

Commit 692bd84

Browse files
committed
updating notebook structure
1 parent ebc0644 commit 692bd84

1 file changed

Lines changed: 36 additions & 15 deletions

File tree

‎example_twocolour_notebooks/Step4b_CountPunctaInCells.ipynb‎

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
"\n",
4343
"\"\"\"\n",
4444
"\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",
4646
"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",
4848
") # example file, replace as you wish. Always input as the absolute path of a raw string\n",
4949
"threshold = 0.0\n",
5050
"protein_string = \"C1\"\n",
@@ -54,7 +54,10 @@
5454
"analysis_data = pl.read_csv(analysis_file)\n",
5555
"z_project_first = [True, True]\n",
5656
"\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",
5861
"cell_punctum_analysis = pl.read_csv(cell_punctum_analysis_file)\n",
5962
"cell_punctum_analysis = cell_punctum_analysis.filter(pl.col(\"puncta_cell_likelihood\") != np.NAN)"
6063
]
@@ -977,30 +980,44 @@
977980
"A_F = AnalysisFunctions.Analysis_Functions()\n",
978981
"import os\n",
979982
"\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",
980993
"for i in np.arange(len(n_cells_per_image)):\n",
981994
" 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",
983997
" # now find the corresponding cell mask\n",
984998
" mask_file = os.path.join(\n",
985999
" analysis_folder,\n",
9861000
" 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",
9881002
" + cell_string\n",
9891003
" + \"_cellMask.tiff\"\n",
9901004
" ),\n",
9911005
" )\n",
9921006
" \n",
9931007
" # 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",
9951009
" cell_mask = IO.read_tiff(mask_file)\n",
9961010
" 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",
9981012
" 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",
10001017
" cell_mask,\n",
10011018
" lower_cell_size_threshold=lower_cell_size_threshold,\n",
1002-
" z_project=[True, True],\n",
10031019
" )\n",
1020+
" oned_cell_mask = cell_mask_new.sum(axis=0).clip(0, 1)\n",
10041021
" oned_puncta_image = np.sum(puncta_image, axis=-1)\n",
10051022
" oned_cell_image = np.sum(cell_image, axis=-1)\n",
10061023
" print(i)\n",
@@ -1016,28 +1033,32 @@
10161033
"outputs": [],
10171034
"source": [
10181035
" 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",
10201038
" # now find the corresponding cell mask\n",
10211039
" mask_file = os.path.join(\n",
10221040
" analysis_folder,\n",
10231041
" 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",
10251043
" + cell_string\n",
10261044
" + \"_cellMask.tiff\"\n",
10271045
" ),\n",
10281046
" )\n",
10291047
" \n",
10301048
" # 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",
10321050
" cell_mask = IO.read_tiff(mask_file)\n",
10331051
" 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",
10351053
" 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",
10371058
" cell_mask,\n",
10381059
" lower_cell_size_threshold=lower_cell_size_threshold,\n",
1039-
" z_project=[True, True],\n",
10401060
" )\n",
1061+
" oned_cell_mask = cell_mask_new.sum(axis=0).clip(0, 1)\n",
10411062
" oned_puncta_image = np.sum(puncta_image, axis=-1)\n",
10421063
" oned_cell_image = np.sum(cell_image, axis=-1)"
10431064
]

0 commit comments

Comments
 (0)