Skip to content

Commit f77872d

Browse files
Merge branch 'chreef-analysis' into create_plots
2 parents 316a9a4 + 4f9917f commit f77872d

File tree

81 files changed

+5059
-446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+5059
-446
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ converted/
44
*.egg-info/
55
checkpoints/
66
logs/
7+
*.csv
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import os
2+
import subprocess
3+
from typing import Tuple
4+
5+
import pandas as pd
6+
7+
from ome_zarr.io import parse_url
8+
from ome_zarr.reader import Reader
9+
10+
import dask.array as da
11+
12+
13+
def _get_dasky_data(url):
14+
reader = Reader(parse_url(url)) # Prepare a reader.
15+
nodes = list(reader()) # Might include multiple stuff
16+
image_node = nodes[0] # First node is expected to be image pixel data.
17+
18+
dask_data = image_node.data # Get the daskified data.
19+
20+
return dask_data
21+
22+
23+
def get_zebrahub_data(timepoint: int = 740, view: bool = False) -> Tuple[da.Array, pd.DataFrame]:
24+
"""Gets the ZebraHub data from https://doi.org/10.1016/j.cell.2024.09.047.
25+
26+
Args:
27+
timepoint: The timepoint where the 3d imaging data will be returned from.
28+
view: Whether to view the dask array via napari.
29+
30+
Returns:
31+
The daskified chunky array.
32+
And the tracking annotations.
33+
"""
34+
# NOTE: There's more single objective samples for zebrafish available with tracking annotations
35+
# https://public.czbiohub.org/royerlab/zebrahub/imaging/single-objective/
36+
url = "https://public.czbiohub.org/royerlab/zebrahub/imaging/single-objective/ZSNS001.ome.zarr"
37+
38+
# Let's get the image data.
39+
dask_data = _get_dasky_data(url)
40+
41+
# Get the lowest resolution (see below on how to access other resolutions)
42+
curr_data = dask_data[-1]
43+
44+
# And strip out the channel dimension (see below for more details)
45+
curr_data = curr_data[timepoint, 0]
46+
47+
# We have tracking annotations here. Let's check them out.
48+
tracks_fpath = "ZSNS001_tracks.csv"
49+
if not os.path.exists(tracks_fpath):
50+
subprocess.run(
51+
["wget", "https://public.czbiohub.org/royerlab/zebrahub/imaging/single-objective/ZSNS001_tracks.csv"]
52+
)
53+
54+
# Load the tracking annotation file.
55+
tracks = pd.read_csv("ZSNS001_tracks.csv") # I think this is on original resolution (?)
56+
57+
# HACK: Filtering ids based on one time-frame (the most plausible setup we might be opting for)
58+
curr_tracks = tracks.loc[tracks["t"] == timepoint]
59+
60+
if view:
61+
import napari
62+
napari.view_image(curr_data)
63+
napari.run()
64+
65+
return curr_data, curr_tracks
66+
67+
68+
def get_czi_zebrafish_data(
69+
neuromast: bool = True, view: bool = False
70+
) -> da.Array:
71+
"""Gets the CZI ZebraFish light-sheet microscopy data.
72+
NOTE: Currently, we support only the raw data.
73+
74+
Args:
75+
view: Whether to view the dask array via napari.
76+
77+
Returns:
78+
The daskified chunky array.
79+
"""
80+
# NOTE: Let's try for one link first, we can generalize it later.
81+
82+
if neuromast:
83+
# Link for nuclear and membrane labeled zebrafish neuromast.
84+
url = "https://public.czbiohub.org/royerlab/ultrack/zebrafish_neuromast.ome.zarr"
85+
else:
86+
# Link for dense nuclear labeled zebrafish embryo.
87+
# NOTE: This data does not have tracking annotations!
88+
url = "https://public.czbiohub.org/royerlab/ultrack/zebrafish_embryo.ome.zarr"
89+
90+
# Let's get the image data
91+
dask_data = _get_dasky_data(url)
92+
93+
# HACK: Try it for one dask array with lowest resolution (there exists four resolutions in this data).
94+
# TODO: Control res below, the highest res starts at the first index, lowest at the last index.
95+
curr_data = dask_data[-1]
96+
97+
# We don't care about the over-time information. Let's get the 3d info for now!
98+
# I am removing the channel dimension here (OG dimension style: (T, C, Z, Y, X))
99+
curr_data = curr_data[:, 0] # TODO: Parse values in the time or z-dimension to access limited slices?
100+
101+
# NOTE: The following line of code brings the entire dask array in memory.
102+
# curr_data = curr_data.compute()
103+
104+
if view:
105+
import napari
106+
napari.view_image(curr_data)
107+
napari.run()
108+
109+
return curr_data
110+
111+
112+
def main():
113+
# image = get_czi_zebrafish_data(neuromast=True, view=False)
114+
115+
# Suggested timepoints I like in the developmental cycle:
116+
# 740/760: kind of at the end of cycle.
117+
# 650: it's a nice development stage which visually surfaces a lot of nucleus.
118+
119+
image, tracks = get_zebrahub_data(timepoint=740, view=False)
120+
print(image.shape)
121+
122+
123+
if __name__ == "__main__":
124+
main()

environment.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
name: flamingo
22

33
channels:
4-
- pytorch
54
- conda-forge
65

76
dependencies:
8-
- cpuonly
97
- cluster_tools
108
- scikit-image
119
- pybdv

0 commit comments

Comments
 (0)