.gitignore CHANGED
@@ -1,8 +1,2 @@
1
  .DS_Store
2
- .vscode/
3
-
4
- .python-version
5
- LICENSE.txt
6
- pyproject.toml
7
- requirements-dev.lock
8
- requirements.lock
 
1
  .DS_Store
2
+ .vscode/
 
 
 
 
 
 
ark_example.py CHANGED
@@ -14,27 +14,18 @@
14
 
15
  """
16
  This dataset contains example data for running through the multiplexed imaging data pipeline in
17
- Ark Analysis: https://github.com/angelolab/ark-analysis.
18
-
19
-
20
- Dataset Fov renaming:
21
-
22
- TMA2_R8C3 -> fov0
23
- TMA6_R4C5 -> fov1
24
- TMA7_R5C4 -> fov2
25
- TMA10_R7C3 -> fov3
26
- TMA11_R9C6 -> fov4
27
- TMA13_R8C5 -> fov5
28
- TMA17_R9C2 -> fov6
29
- TMA18_R9C2 -> fov7
30
- TMA21_R2C5 -> fov8
31
- TMA21_R12C6 -> fov9
32
- TMA24_R9C1 -> fov10
33
-
34
  """
35
 
 
 
 
36
  import datasets
37
  import pathlib
 
 
 
 
38
 
39
  # Find for instance the citation on arxiv or on the dataset repo/website
40
  _CITATION = """\
@@ -55,145 +46,84 @@ _HOMEPAGE = "https://github.com/angelolab/ark-analysis"
55
 
56
  _LICENSE = "https://github.com/angelolab/ark-analysis/blob/main/LICENSE"
57
 
 
58
  # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
59
  # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
 
60
 
61
- _URL_DATA = {
62
- "image_data": "data/image_data.zip",
63
- "cell_table": "data/segmentation/cell_table.zip",
64
- "deepcell_output": "data/segmentation/deepcell_output.zip",
65
- "example_pixel_output_dir": "data/pixie/example_pixel_output_dir.zip",
66
- "example_cell_output_dir": "data/pixie/example_cell_output_dir.zip",
67
- "spatial_lda": "data/spatial_analysis/spatial_lda.zip",
68
- "post_clustering": "data/post_clustering.zip",
69
- "ome_tiff": "data/ome_tiff.zip",
70
- "ez_seg_data": "data/ez_seg_data.zip"
71
- }
72
 
73
- _URL_DATASET_CONFIGS = {
74
- "segment_image_data": {"image_data": _URL_DATA["image_data"]},
75
- "cluster_pixels": {
76
- "image_data": _URL_DATA["image_data"],
77
- "cell_table": _URL_DATA["cell_table"],
78
- "deepcell_output": _URL_DATA["deepcell_output"],
79
- },
80
- "cluster_cells": {
81
- "image_data": _URL_DATA["image_data"],
82
- "cell_table": _URL_DATA["cell_table"],
83
- "deepcell_output": _URL_DATA["deepcell_output"],
84
- "example_pixel_output_dir": _URL_DATA["example_pixel_output_dir"],
85
- },
86
- "post_clustering": {
87
- "image_data": _URL_DATA["image_data"],
88
- "cell_table": _URL_DATA["cell_table"],
89
- "deepcell_output": _URL_DATA["deepcell_output"],
90
- "example_cell_output_dir": _URL_DATA["example_cell_output_dir"],
91
- },
92
- "fiber_segmentation": {
93
- "image_data": _URL_DATA["image_data"],
94
- },
95
- "LDA_preprocessing": {
96
- "image_data": _URL_DATA["image_data"],
97
- "cell_table": _URL_DATA["cell_table"],
98
- },
99
- "LDA_training_inference": {
100
- "image_data": _URL_DATA["image_data"],
101
- "cell_table": _URL_DATA["cell_table"],
102
- "spatial_lda": _URL_DATA["spatial_lda"],
103
- },
104
- "neighborhood_analysis": {
105
- "image_data": _URL_DATA["image_data"],
106
- "cell_table": _URL_DATA["cell_table"],
107
- "deepcell_output": _URL_DATA["deepcell_output"],
108
- },
109
- "pairwise_spatial_enrichment": {
110
- "image_data": _URL_DATA["image_data"],
111
- "cell_table": _URL_DATA["cell_table"],
112
- "deepcell_output": _URL_DATA["deepcell_output"],
113
- "post_clustering": _URL_DATA["post_clustering"],
114
- },
115
- "ome_tiff": {
116
- "ome_tiff": _URL_DATA["ome_tiff"],
117
- },
118
- "ez_seg_data": {
119
- "ez_seg_data": _URL_DATA["ez_seg_data"]
120
- }
121
- }
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
- # Note: Name of the dataset usually match the script name with CamelCase instead of snake_case
125
  class ArkExample(datasets.GeneratorBasedBuilder):
126
  """The Dataset consists of 11 FOVs"""
127
 
128
- VERSION = datasets.Version("0.0.5")
 
 
 
 
 
 
 
 
129
 
130
  # You will be able to load one or the other configurations in the following list with
 
 
131
  BUILDER_CONFIGS = [
132
  datasets.BuilderConfig(
133
- name="segment_image_data",
134
- version=VERSION,
135
- description="This configuration contains data used by notebook 1 - Segment Image Data.",
136
- ),
137
- datasets.BuilderConfig(
138
- name="cluster_pixels",
139
- version=VERSION,
140
- description="This configuration contains data used by notebook 2 - Pixel Clustering (Pixie Pipeline #1).",
141
- ),
142
- datasets.BuilderConfig(
143
- name="cluster_cells",
144
  version=VERSION,
145
- description="This configuration contains data used by notebook 3 - Cell Clustering (Pixie Pipeline #2).",
146
  ),
147
  datasets.BuilderConfig(
148
- name="post_clustering",
149
  version=VERSION,
150
- description="This configuration contains data used by notebook 4 - Post Clustering.",
 
151
  ),
152
- datasets.BuilderConfig(
153
- name="fiber_segmentation",
154
- version=VERSION,
155
- description="This configuration contains data used by the Fiber Segmentation Notebook.",
156
- ),
157
- datasets.BuilderConfig(
158
- name="LDA_preprocessing",
159
- version=VERSION,
160
- description="This configuration contains data used by the Spatial LDA - Preprocessing Notebook."
161
- ),
162
- datasets.BuilderConfig(
163
- name="LDA_training_inference",
164
- version=VERSION,
165
- description="This configuration contains data used by the Spatial LDA - Training and Inference Notebook."
166
- ),
167
- datasets.BuilderConfig(
168
- name="neighborhood_analysis",
169
- version=VERSION,
170
- description="This configuration contains data used by the Neighborhood Analysis Notebook."
171
- ),
172
- datasets.BuilderConfig(
173
- name="pairwise_spatial_enrichment",
174
- version=VERSION,
175
- description="This configuration contains data used by the Pairwise Spatial Enrichment Notebook."
176
- ),
177
- datasets.BuilderConfig(
178
- name="ome_tiff",
179
- version=VERSION,
180
- description="This configuration contains an OME-TIFF format of FOV1. Intended to be used with the OME-TIFF Conversion Notebook."
181
- ),
182
- datasets.BuilderConfig(
183
- name="ez_seg_data",
184
- version=VERSION,
185
- description="This configuration contains the data used by the ezSegmenter notebook."
186
- )
187
  ]
188
 
 
 
 
 
189
  def _info(self):
190
  # This is the name of the configuration selected in BUILDER_CONFIGS above
191
- if self.config.name in list(_URL_DATASET_CONFIGS.keys()):
 
 
 
 
 
 
 
 
192
  features = datasets.Features(
193
- {f: datasets.Value("string") for f in _URL_DATASET_CONFIGS[self.config.name].keys()}
 
 
 
 
 
194
  )
195
- else:
196
- ValueError(f"Dataset name is incorrect, options include {list(_URL_DATASET_CONFIGS.keys())}")
197
  return datasets.DatasetInfo(
198
  # This is the description that will appear on the datasets page.
199
  description=_DESCRIPTION,
@@ -211,21 +141,50 @@ class ArkExample(datasets.GeneratorBasedBuilder):
211
  )
212
 
213
  def _split_generators(self, dl_manager):
214
- # This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
215
- urls = _URL_DATASET_CONFIGS[self.config.name]
216
- data_dirs = {}
217
- for data_name, url in urls.items():
218
- dl_path = pathlib.Path(dl_manager.download_and_extract(url))
219
- data_dirs[data_name] = dl_path
 
 
220
 
221
  return [
222
  datasets.SplitGenerator(
223
- name=self.config.name,
224
  # These kwargs will be passed to _generate_examples
225
- gen_kwargs={"dataset_paths": data_dirs},
226
  ),
227
  ]
228
 
229
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
230
- def _generate_examples(self, dataset_paths):
231
- yield self.config.name, dataset_paths
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  """
16
  This dataset contains example data for running through the multiplexed imaging data pipeline in
17
+ Ark Analysis: https://github.com/angelolab/ark-analysis
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  """
19
 
20
+ import json
21
+ import os
22
+
23
  import datasets
24
  import pathlib
25
+ import glob
26
+ import tifffile
27
+ import xarray as xr
28
+ import numpy as np
29
 
30
  # Find for instance the citation on arxiv or on the dataset repo/website
31
  _CITATION = """\
 
46
 
47
  _LICENSE = "https://github.com/angelolab/ark-analysis/blob/main/LICENSE"
48
 
49
+ # TODO: Add link to the official dataset URLs here
50
  # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
51
  # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
52
+ _URL_REPO = "https://huggingface.co/datasets/angelolab/ark_example/resolve/main"
53
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
+ _URLS = {"base_dataset": f"{_URL_REPO}/data/input_data.zip"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
+ """
58
+ Dataset Fov renaming:
59
+
60
+ TMA2_R8C3 -> fov0
61
+ TMA6_R4C5 -> fov1
62
+ TMA7_R5C4 -> fov2
63
+ TMA10_R7C3 -> fov3
64
+ TMA11_R9C6 -> fov4
65
+ TMA13_R8C5 -> fov5
66
+ TMA17_R9C2 -> fov6
67
+ TMA18_R9C2 -> fov7
68
+ TMA21_R2C5 -> fov8
69
+ TMA21_R12C6 -> fov9
70
+ TMA24_R9C1 -> fov10
71
+ """
72
 
73
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
74
  class ArkExample(datasets.GeneratorBasedBuilder):
75
  """The Dataset consists of 11 FOVs"""
76
 
77
+ VERSION = datasets.Version("0.0.1")
78
+
79
+ # This is an example of a dataset with multiple configurations.
80
+ # If you don't want/need to define several sub-sets in your dataset,
81
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
82
+
83
+ # If you need to make complex sub-parts in the datasets with configurable options
84
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
85
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
86
 
87
  # You will be able to load one or the other configurations in the following list with
88
+ # data = datasets.load_dataset('my_dataset', 'base_dataset')
89
+ # data = datasets.load_dataset('my_dataset', 'dev_dataset')
90
  BUILDER_CONFIGS = [
91
  datasets.BuilderConfig(
92
+ name="base_dataset",
 
 
 
 
 
 
 
 
 
 
93
  version=VERSION,
94
+ description="This dataset contains only the 12 FOVs.",
95
  ),
96
  datasets.BuilderConfig(
97
+ name="dev_dataset",
98
  version=VERSION,
99
+ description="This dataset is a superset of the base_dataset, and contains intermediate data for all notebooks. \
100
+ Therefore you can start at any notebook with this dataset.",
101
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  ]
103
 
104
+ DEFAULT_CONFIG_NAME = (
105
+ "base_dataset" # It's not mandatory to have a default configuration. Just use one if it make sense.
106
+ )
107
+
108
  def _info(self):
109
  # This is the name of the configuration selected in BUILDER_CONFIGS above
110
+ if self.config.name == "base_dataset":
111
+ features = datasets.Features(
112
+ {
113
+ "Channel Data": datasets.Sequence(datasets.Image()),
114
+ "Channel Names": datasets.Sequence(datasets.Value("string")),
115
+ "Data Path": datasets.Value("string"),
116
+ }
117
+ )
118
+ else: # This is an example to show how to have different features for "first_domain" and "second_domain"
119
  features = datasets.Features(
120
+ {
121
+ "sentence": datasets.Value("string"),
122
+ "option2": datasets.Value("string"),
123
+ "second_domain_answer": datasets.Value("string")
124
+ # These are the features of your dataset like images, labels ...
125
+ }
126
  )
 
 
127
  return datasets.DatasetInfo(
128
  # This is the description that will appear on the datasets page.
129
  description=_DESCRIPTION,
 
141
  )
142
 
143
  def _split_generators(self, dl_manager):
144
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
145
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
146
+
147
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
148
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
149
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
150
+ urls = _URLS[self.config.name]
151
+ data_dir = dl_manager.download_and_extract(urls)
152
 
153
  return [
154
  datasets.SplitGenerator(
155
+ name="base_dataset",
156
  # These kwargs will be passed to _generate_examples
157
+ gen_kwargs={"filepath": pathlib.Path(data_dir)},
158
  ),
159
  ]
160
 
161
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
162
+ def _generate_examples(self, filepath: pathlib.Path):
163
+
164
+ # Get all TMA paths
165
+ file_paths = list(pathlib.Path(filepath / "input_data").glob("*"))
166
+
167
+ # Loop over all the TMAs
168
+ for fp in file_paths:
169
+
170
+ # Get the TMA FOV Name
171
+ fov_name = fp.stem
172
+
173
+ # Get all channels per TMA FOV
174
+ channel_paths = fp.glob("*.tiff")
175
+
176
+ chan_data = []
177
+ chan_names = []
178
+ for chan in channel_paths:
179
+ chan_name = chan.stem
180
+ chan_image: np.ndarray = tifffile.imread(chan)
181
+
182
+ chan_data.append(chan_image)
183
+ chan_names.append(chan_name)
184
+
185
+ if self.config.name == "base_dataset":
186
+ yield fov_name, {
187
+ "Channel Data": chan_data,
188
+ "Channel Names": chan_names,
189
+ "Data Path": filepath.as_posix(),
190
+ }
data/image_data.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:4d1f29e53a40bb162e795f68906095131d88647f70a6e080ca3bac749a3f6174
3
- size 373529148
 
 
 
 
data/{ez_seg_data.zip → input_data.zip} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:7251a3c98e53ac00858560c1f234208228f14198b915aabd6715cac0c8d5d74c
3
- size 14749038
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37eed9f786570426ee8e7cbd9447ef98c82830b7fee064e56cb79b360887489a
3
+ size 400326580
data/ome_tiff.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:82d3278f7d3e27e128f3ec3607934b933f68e3a3aab1298ce1e6dc5d0cf402e2
3
- size 37043244
 
 
 
 
data/pixie/example_cell_output_dir.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:a76c024385ae04c9f21229a053c3623429d9fa26241265fc304e92716eb5fe3d
3
- size 2888930
 
 
 
 
data/pixie/example_pixel_output_dir.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:1e01263920bb7d98b836204ad3c7e6175487c9d139c7cf504c136391536796ba
3
- size 1384928027
 
 
 
 
data/post_clustering.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:d969d298c2a42130f17955b13f5b1b2c1e8687c180e1e27ce9205bc9ea8d33a1
3
- size 9209730
 
 
 
 
data/segmentation/cell_table.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:4c453a9a6fe6f21d411ecd9e60278e4360d8df4b876f9b382d2d139ae62ade5d
3
- size 16724377
 
 
 
 
data/segmentation/deepcell_output.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:92c1bf023c58187264d31848addb602d8aeb7f7545ef0fa370c73a5f35325a15
3
- size 1571004
 
 
 
 
data/spatial_analysis/spatial_lda.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:eb7bdab9c054d4fff8504c51e9b185e02a8cc13e15287bafdee2fbb7ddcd66b4
3
- size 3296785