siibra 1.0a1__1-py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of siibra might be problematic. Click here for more details.
- siibra/VERSION +1 -0
- siibra/__init__.py +164 -0
- siibra/commons.py +823 -0
- siibra/configuration/__init__.py +17 -0
- siibra/configuration/configuration.py +189 -0
- siibra/configuration/factory.py +589 -0
- siibra/core/__init__.py +16 -0
- siibra/core/assignment.py +110 -0
- siibra/core/atlas.py +239 -0
- siibra/core/concept.py +308 -0
- siibra/core/parcellation.py +387 -0
- siibra/core/region.py +1223 -0
- siibra/core/space.py +131 -0
- siibra/core/structure.py +111 -0
- siibra/exceptions.py +63 -0
- siibra/experimental/__init__.py +19 -0
- siibra/experimental/contour.py +61 -0
- siibra/experimental/cortical_profile_sampler.py +57 -0
- siibra/experimental/patch.py +98 -0
- siibra/experimental/plane3d.py +256 -0
- siibra/explorer/__init__.py +17 -0
- siibra/explorer/url.py +222 -0
- siibra/explorer/util.py +87 -0
- siibra/features/__init__.py +117 -0
- siibra/features/anchor.py +224 -0
- siibra/features/connectivity/__init__.py +33 -0
- siibra/features/connectivity/functional_connectivity.py +57 -0
- siibra/features/connectivity/regional_connectivity.py +494 -0
- siibra/features/connectivity/streamline_counts.py +27 -0
- siibra/features/connectivity/streamline_lengths.py +27 -0
- siibra/features/connectivity/tracing_connectivity.py +30 -0
- siibra/features/dataset/__init__.py +17 -0
- siibra/features/dataset/ebrains.py +90 -0
- siibra/features/feature.py +970 -0
- siibra/features/image/__init__.py +27 -0
- siibra/features/image/image.py +115 -0
- siibra/features/image/sections.py +26 -0
- siibra/features/image/volume_of_interest.py +88 -0
- siibra/features/tabular/__init__.py +24 -0
- siibra/features/tabular/bigbrain_intensity_profile.py +77 -0
- siibra/features/tabular/cell_density_profile.py +298 -0
- siibra/features/tabular/cortical_profile.py +322 -0
- siibra/features/tabular/gene_expression.py +257 -0
- siibra/features/tabular/layerwise_bigbrain_intensities.py +62 -0
- siibra/features/tabular/layerwise_cell_density.py +95 -0
- siibra/features/tabular/receptor_density_fingerprint.py +192 -0
- siibra/features/tabular/receptor_density_profile.py +110 -0
- siibra/features/tabular/regional_timeseries_activity.py +294 -0
- siibra/features/tabular/tabular.py +139 -0
- siibra/livequeries/__init__.py +19 -0
- siibra/livequeries/allen.py +352 -0
- siibra/livequeries/bigbrain.py +197 -0
- siibra/livequeries/ebrains.py +145 -0
- siibra/livequeries/query.py +49 -0
- siibra/locations/__init__.py +91 -0
- siibra/locations/boundingbox.py +454 -0
- siibra/locations/location.py +115 -0
- siibra/locations/point.py +344 -0
- siibra/locations/pointcloud.py +349 -0
- siibra/retrieval/__init__.py +27 -0
- siibra/retrieval/cache.py +233 -0
- siibra/retrieval/datasets.py +389 -0
- siibra/retrieval/exceptions/__init__.py +27 -0
- siibra/retrieval/repositories.py +769 -0
- siibra/retrieval/requests.py +659 -0
- siibra/vocabularies/__init__.py +45 -0
- siibra/vocabularies/gene_names.json +29176 -0
- siibra/vocabularies/receptor_symbols.json +210 -0
- siibra/vocabularies/region_aliases.json +460 -0
- siibra/volumes/__init__.py +23 -0
- siibra/volumes/parcellationmap.py +1279 -0
- siibra/volumes/providers/__init__.py +20 -0
- siibra/volumes/providers/freesurfer.py +113 -0
- siibra/volumes/providers/gifti.py +165 -0
- siibra/volumes/providers/neuroglancer.py +736 -0
- siibra/volumes/providers/nifti.py +266 -0
- siibra/volumes/providers/provider.py +107 -0
- siibra/volumes/sparsemap.py +468 -0
- siibra/volumes/volume.py +892 -0
- siibra-1.0.0a1.dist-info/LICENSE +201 -0
- siibra-1.0.0a1.dist-info/METADATA +160 -0
- siibra-1.0.0a1.dist-info/RECORD +84 -0
- siibra-1.0.0a1.dist-info/WHEEL +5 -0
- siibra-1.0.0a1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
# Copyright 2018-2024
|
|
2
|
+
# Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
|
|
3
|
+
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
from ..commons import logger, Species
|
|
17
|
+
from ..features import anchor, connectivity
|
|
18
|
+
from ..features.tabular import (
|
|
19
|
+
receptor_density_profile,
|
|
20
|
+
receptor_density_fingerprint,
|
|
21
|
+
cell_density_profile,
|
|
22
|
+
layerwise_cell_density,
|
|
23
|
+
regional_timeseries_activity,
|
|
24
|
+
)
|
|
25
|
+
from ..features.image import sections, volume_of_interest
|
|
26
|
+
from ..core import atlas, parcellation, space, region
|
|
27
|
+
from ..locations import point, pointcloud, boundingbox
|
|
28
|
+
from ..retrieval import datasets, repositories
|
|
29
|
+
from ..volumes import volume, sparsemap, parcellationmap
|
|
30
|
+
from ..volumes.providers.provider import VolumeProvider
|
|
31
|
+
|
|
32
|
+
from os import path
|
|
33
|
+
import json
|
|
34
|
+
import numpy as np
|
|
35
|
+
from typing import List, Dict, Callable
|
|
36
|
+
import pandas as pd
|
|
37
|
+
from io import BytesIO
|
|
38
|
+
from functools import wraps
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
_registered_build_fns: Dict[str, Callable] = {}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def build_type(type_str: str):
|
|
45
|
+
def outer(fn):
|
|
46
|
+
_registered_build_fns[type_str] = fn
|
|
47
|
+
|
|
48
|
+
@wraps(fn)
|
|
49
|
+
def inner(*args, **kwargs):
|
|
50
|
+
return fn(*args, **kwargs)
|
|
51
|
+
|
|
52
|
+
return inner
|
|
53
|
+
|
|
54
|
+
return outer
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class Factory:
|
|
58
|
+
|
|
59
|
+
_warnings_issued = []
|
|
60
|
+
|
|
61
|
+
@classmethod
|
|
62
|
+
def extract_datasets(cls, spec):
|
|
63
|
+
result = []
|
|
64
|
+
if "minds/core/dataset/v1.0.0" in spec.get("ebrains", {}):
|
|
65
|
+
result.append(
|
|
66
|
+
datasets.EbrainsDataset(id=spec["ebrains"]["minds/core/dataset/v1.0.0"])
|
|
67
|
+
)
|
|
68
|
+
if "openminds/DatasetVersion" in spec.get("ebrains", {}):
|
|
69
|
+
result.append(
|
|
70
|
+
datasets.EbrainsV3DatasetVersion(
|
|
71
|
+
id=spec["ebrains"]["openminds/DatasetVersion"]
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
if "openminds/Dataset" in spec.get("ebrains", {}):
|
|
75
|
+
result.append(
|
|
76
|
+
datasets.EbrainsV3Dataset(id=spec["ebrains"]["openminds/Dataset"])
|
|
77
|
+
)
|
|
78
|
+
if "publications" in spec:
|
|
79
|
+
result.extend(
|
|
80
|
+
datasets.GenericDataset(
|
|
81
|
+
name=pub["name"],
|
|
82
|
+
contributors=pub["authors"],
|
|
83
|
+
url=pub["url"],
|
|
84
|
+
description=pub["description"],
|
|
85
|
+
license=pub.get("license"),
|
|
86
|
+
)
|
|
87
|
+
for pub in spec["publications"]
|
|
88
|
+
if pub.get("name")
|
|
89
|
+
)
|
|
90
|
+
return result
|
|
91
|
+
|
|
92
|
+
@classmethod
|
|
93
|
+
def extract_volumes(
|
|
94
|
+
cls, spec, space_id: str = None, names: List[str] = None, name_prefix: str = ""
|
|
95
|
+
):
|
|
96
|
+
volume_specs = spec.get("volumes", [])
|
|
97
|
+
if names:
|
|
98
|
+
if len(names) != len(volume_specs) and len(names) == 1:
|
|
99
|
+
variants = [vol["variant"] for vol in volume_specs]
|
|
100
|
+
names = [f"{name_prefix}{names[0]} {var} variant" for var in variants]
|
|
101
|
+
else:
|
|
102
|
+
names = [f"{name_prefix} - volume {i}" for i in range(len(volume_specs))]
|
|
103
|
+
for i, vspec in enumerate(volume_specs):
|
|
104
|
+
if space_id:
|
|
105
|
+
if "space" in vspec:
|
|
106
|
+
assert (
|
|
107
|
+
vspec["space"]["@id"] == space_id
|
|
108
|
+
), "Space spec {vspec['space']} in volume field must be the same with space field in the configuration."
|
|
109
|
+
vspec["space"] = {"@id": space_id}
|
|
110
|
+
if (
|
|
111
|
+
names and vspec.get("name") is None
|
|
112
|
+
): # only use provided name if the volume has no specific name
|
|
113
|
+
vspec["name"] = names[i]
|
|
114
|
+
return list(map(cls.build_volume, volume_specs))
|
|
115
|
+
|
|
116
|
+
@classmethod
|
|
117
|
+
def extract_decoder(cls, spec):
|
|
118
|
+
decoder_spec = spec.get("decoder", {})
|
|
119
|
+
if decoder_spec["@type"].endswith("csv"):
|
|
120
|
+
kwargs = {k: v for k, v in decoder_spec.items() if k != "@type"}
|
|
121
|
+
return lambda b: pd.read_csv(BytesIO(b), **kwargs)
|
|
122
|
+
else:
|
|
123
|
+
return None
|
|
124
|
+
|
|
125
|
+
@classmethod
|
|
126
|
+
def extract_anchor(cls, spec):
|
|
127
|
+
if spec.get("region"):
|
|
128
|
+
region = spec["region"]
|
|
129
|
+
elif spec.get("parcellation", {}).get("@id"):
|
|
130
|
+
# a parcellation is a special region,
|
|
131
|
+
# and can be used if no region is found
|
|
132
|
+
region = spec["parcellation"]["@id"]
|
|
133
|
+
elif spec.get("parcellation", {}).get("name"):
|
|
134
|
+
region = spec["parcellation"]["name"]
|
|
135
|
+
else:
|
|
136
|
+
region = None
|
|
137
|
+
|
|
138
|
+
if "location" in spec:
|
|
139
|
+
location = cls.from_json(spec["location"])
|
|
140
|
+
else:
|
|
141
|
+
location = None
|
|
142
|
+
|
|
143
|
+
if (region is None) and (location is None):
|
|
144
|
+
print(spec)
|
|
145
|
+
raise RuntimeError(
|
|
146
|
+
"Spec provides neither region or location - no anchor can be extracted."
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
if "species" in spec:
|
|
150
|
+
species = Species.decode(spec["species"])
|
|
151
|
+
elif "ebrains" in spec:
|
|
152
|
+
species = Species.decode(spec["ebrains"])
|
|
153
|
+
else:
|
|
154
|
+
raise ValueError(f"No species information found in spec {spec}")
|
|
155
|
+
|
|
156
|
+
return anchor.AnatomicalAnchor(
|
|
157
|
+
region=region, location=location, species=species
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
@classmethod
|
|
161
|
+
def extract_connector(cls, spec):
|
|
162
|
+
repospec = spec.get("repository", {})
|
|
163
|
+
spectype = repospec["@type"]
|
|
164
|
+
if spectype == "siibra/repository/zippedfile/v1.0.0":
|
|
165
|
+
return repositories.ZipfileConnector(repospec["url"])
|
|
166
|
+
if spectype == "siibra/repository/localfolder/v1.0.0":
|
|
167
|
+
return repositories.LocalFileRepository(repospec["folder"])
|
|
168
|
+
if spectype == "siibra/repository/gitlab/v1.0.0":
|
|
169
|
+
return repositories.GitlabConnector(
|
|
170
|
+
server=repospec["server"],
|
|
171
|
+
project=repospec["project"],
|
|
172
|
+
reftag=repospec["branch"],
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
logger.warning(
|
|
176
|
+
"Do not know how to create a repository "
|
|
177
|
+
f"connector from specification type {spectype}."
|
|
178
|
+
)
|
|
179
|
+
return None
|
|
180
|
+
|
|
181
|
+
@classmethod
|
|
182
|
+
@build_type("juelich/iav/atlas/v1.0.0")
|
|
183
|
+
def build_atlas(cls, spec):
|
|
184
|
+
a = atlas.Atlas(
|
|
185
|
+
spec["@id"],
|
|
186
|
+
spec["name"],
|
|
187
|
+
species=Species.decode(spec.get("species")),
|
|
188
|
+
prerelease=spec.get("prerelease", False),
|
|
189
|
+
)
|
|
190
|
+
for space_id in spec["spaces"]:
|
|
191
|
+
a._register_space(space_id)
|
|
192
|
+
for parcellation_id in spec["parcellations"]:
|
|
193
|
+
a._register_parcellation(parcellation_id)
|
|
194
|
+
return a
|
|
195
|
+
|
|
196
|
+
@classmethod
|
|
197
|
+
@build_type("siibra/space/v0.0.1")
|
|
198
|
+
def build_space(cls, spec):
|
|
199
|
+
return space.Space(
|
|
200
|
+
identifier=spec["@id"],
|
|
201
|
+
name=spec["name"],
|
|
202
|
+
species=Species.decode(spec.get("species")),
|
|
203
|
+
volumes=cls.extract_volumes(
|
|
204
|
+
spec, space_id=spec.get("@id"), names=[spec.get("name")]
|
|
205
|
+
),
|
|
206
|
+
shortname=spec.get("shortName", ""),
|
|
207
|
+
description=spec.get("description"),
|
|
208
|
+
modality=spec.get("modality"),
|
|
209
|
+
publications=spec.get("publications", []),
|
|
210
|
+
datasets=cls.extract_datasets(spec),
|
|
211
|
+
prerelease=spec.get("prerelease", False),
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
@classmethod
|
|
215
|
+
def build_region(cls, spec):
|
|
216
|
+
return region.Region(
|
|
217
|
+
name=spec["name"],
|
|
218
|
+
children=map(cls.build_region, spec.get("children", [])),
|
|
219
|
+
shortname=spec.get("shortname", ""),
|
|
220
|
+
description=spec.get("description", ""),
|
|
221
|
+
publications=spec.get("publications", []),
|
|
222
|
+
datasets=cls.extract_datasets(spec),
|
|
223
|
+
rgb=spec.get("rgb", None),
|
|
224
|
+
spec=spec,
|
|
225
|
+
prerelease=spec.get("prerelease", False),
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
@classmethod
|
|
229
|
+
@build_type("siibra/parcellation/v0.0.1")
|
|
230
|
+
def build_parcellation(cls, spec):
|
|
231
|
+
regions = []
|
|
232
|
+
for regionspec in spec.get("regions", []):
|
|
233
|
+
try:
|
|
234
|
+
regions.append(cls.build_region(regionspec))
|
|
235
|
+
except Exception as e:
|
|
236
|
+
print(regionspec)
|
|
237
|
+
raise e
|
|
238
|
+
p = parcellation.Parcellation(
|
|
239
|
+
identifier=spec["@id"],
|
|
240
|
+
name=spec["name"],
|
|
241
|
+
species=Species.decode(spec.get("species")),
|
|
242
|
+
regions=regions,
|
|
243
|
+
shortname=spec.get("shortName", ""),
|
|
244
|
+
description=spec.get("description", ""),
|
|
245
|
+
modality=spec.get("modality", ""),
|
|
246
|
+
publications=spec.get("publications", []),
|
|
247
|
+
datasets=cls.extract_datasets(spec),
|
|
248
|
+
prerelease=spec.get("prerelease", False),
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
# add version object, if any is specified
|
|
252
|
+
versionspec = spec.get("@version", None)
|
|
253
|
+
if versionspec is not None:
|
|
254
|
+
version = parcellation.ParcellationVersion(
|
|
255
|
+
name=versionspec.get("name", None),
|
|
256
|
+
parcellation=p,
|
|
257
|
+
collection=versionspec.get("collectionName", None),
|
|
258
|
+
prev_id=versionspec.get("@prev", None),
|
|
259
|
+
next_id=versionspec.get("@next", None),
|
|
260
|
+
deprecated=versionspec.get("deprecated", False),
|
|
261
|
+
)
|
|
262
|
+
p.version = version
|
|
263
|
+
|
|
264
|
+
return p
|
|
265
|
+
|
|
266
|
+
@classmethod
|
|
267
|
+
def build_volumeproviders(cls, provider_specs: Dict) -> List["VolumeProvider"]:
|
|
268
|
+
providers: List[VolumeProvider] = []
|
|
269
|
+
for srctype, provider_spec in provider_specs.items():
|
|
270
|
+
for ProviderType in VolumeProvider._SUBCLASSES:
|
|
271
|
+
if srctype == ProviderType.srctype:
|
|
272
|
+
providers.append(ProviderType(provider_spec))
|
|
273
|
+
break
|
|
274
|
+
else:
|
|
275
|
+
if srctype not in cls._warnings_issued:
|
|
276
|
+
logger.warning(
|
|
277
|
+
f"No provider defined for volume Source type {srctype}"
|
|
278
|
+
)
|
|
279
|
+
cls._warnings_issued.append(srctype)
|
|
280
|
+
assert all([isinstance(p, VolumeProvider) for p in providers])
|
|
281
|
+
return providers
|
|
282
|
+
|
|
283
|
+
@classmethod
|
|
284
|
+
@build_type("siibra/volume/v0.0.1")
|
|
285
|
+
def build_volume(cls, spec):
|
|
286
|
+
result = volume.Volume(
|
|
287
|
+
space_spec=spec.get("space", {}),
|
|
288
|
+
providers=cls.build_volumeproviders(spec.get("providers")),
|
|
289
|
+
name=spec.get("name", ""),
|
|
290
|
+
variant=spec.get("variant"),
|
|
291
|
+
datasets=cls.extract_datasets(spec),
|
|
292
|
+
bbox=cls.build_boundingbox(spec),
|
|
293
|
+
)
|
|
294
|
+
if result._boundingbox is not None:
|
|
295
|
+
assert (
|
|
296
|
+
result._boundingbox._space_spec == result._space_spec
|
|
297
|
+
), "BoundingBox of a volume cannot be in a different space than the volume's space."
|
|
298
|
+
|
|
299
|
+
return result
|
|
300
|
+
|
|
301
|
+
@classmethod
|
|
302
|
+
@build_type("siibra/map/v0.0.1")
|
|
303
|
+
def build_map(cls, spec):
|
|
304
|
+
# maps have no configured identifier - we require the spec filename to build one
|
|
305
|
+
identifier = spec.get("@id")
|
|
306
|
+
volumes = cls.extract_volumes(
|
|
307
|
+
spec, space_id=spec["space"].get("@id"), name_prefix=identifier
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
if spec.get("represented_as_sparsemap", False):
|
|
311
|
+
Maptype = sparsemap.SparseMap
|
|
312
|
+
else:
|
|
313
|
+
Maptype = parcellationmap.Map
|
|
314
|
+
return Maptype(
|
|
315
|
+
identifier=identifier,
|
|
316
|
+
name=spec.get("name"),
|
|
317
|
+
space_spec=spec.get("space", {}),
|
|
318
|
+
parcellation_spec=spec.get("parcellation", {}),
|
|
319
|
+
indices=spec.get("indices", {}),
|
|
320
|
+
volumes=volumes,
|
|
321
|
+
shortname=spec.get("shortName", ""),
|
|
322
|
+
description=spec.get("description"),
|
|
323
|
+
modality=spec.get("modality"),
|
|
324
|
+
publications=spec.get("publications", []),
|
|
325
|
+
datasets=cls.extract_datasets(spec),
|
|
326
|
+
prerelease=spec.get("prerelease", False),
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
@classmethod
|
|
330
|
+
@build_type("siibra/snapshots/ebrainsquery/v1")
|
|
331
|
+
def build_ebrains_dataset(cls, spec):
|
|
332
|
+
return datasets.EbrainsDataset(
|
|
333
|
+
id=spec["id"],
|
|
334
|
+
name=spec["name"],
|
|
335
|
+
embargo_status=spec["embargoStatus"],
|
|
336
|
+
cached_data=spec,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
@classmethod
|
|
340
|
+
@build_type("https://openminds.ebrains.eu/sands/CoordinatePoint")
|
|
341
|
+
@build_type("siibra/location/point/v0.1")
|
|
342
|
+
def build_point(cls, spec):
|
|
343
|
+
if spec.get("@type") == "https://openminds.ebrains.eu/sands/CoordinatePoint":
|
|
344
|
+
space_id = spec["coordinateSpace"]["@id"]
|
|
345
|
+
coord = list(np.float16(c["value"]) for c in spec["coordinates"])
|
|
346
|
+
assert all(c["unit"]["@id"] == "id.link/mm" for c in spec["coordinates"])
|
|
347
|
+
elif spec.get("@type") == "siibra/location/point/v0.1":
|
|
348
|
+
space_id = spec.get("space").get("@id")
|
|
349
|
+
coord = spec.get("coordinate")
|
|
350
|
+
else:
|
|
351
|
+
raise ValueError(f"Unknown point specification: {spec}")
|
|
352
|
+
return point.Point(
|
|
353
|
+
coordinatespec=coord,
|
|
354
|
+
space=space_id,
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
@classmethod
|
|
358
|
+
@build_type("tmp/poly")
|
|
359
|
+
@build_type("siibra/location/pointcloud/v0.1")
|
|
360
|
+
def build_pointcloud(cls, spec):
|
|
361
|
+
if spec.get("@type") == "tmp/poly":
|
|
362
|
+
space_id = spec["coordinateSpace"]["@id"]
|
|
363
|
+
coords = []
|
|
364
|
+
for coord in spec["coordinates"]:
|
|
365
|
+
assert all(c["unit"]["@id"] == "id.link/mm" for c in coord)
|
|
366
|
+
coords.append(list(np.float16(c["value"]) for c in coord))
|
|
367
|
+
elif spec.get("@type") == "siibra/location/pointcloud/v0.1":
|
|
368
|
+
space_id = spec.get("space").get("@id")
|
|
369
|
+
coords = [tuple(c) for c in spec.get("coordinates")]
|
|
370
|
+
return pointcloud.PointCloud(coords, space=space_id)
|
|
371
|
+
|
|
372
|
+
@classmethod
|
|
373
|
+
@build_type("siibra/location/boundingbox/v0.1")
|
|
374
|
+
def build_boundingbox(cls, spec):
|
|
375
|
+
bboxspec = spec.get("boundingbox", None)
|
|
376
|
+
if bboxspec is None:
|
|
377
|
+
return None
|
|
378
|
+
space_spec = bboxspec.get("space")
|
|
379
|
+
coords = [tuple(c) for c in bboxspec.get("coordinates")]
|
|
380
|
+
return boundingbox.BoundingBox(coords[0], coords[1], space=space_spec)
|
|
381
|
+
|
|
382
|
+
@classmethod
|
|
383
|
+
@build_type("siibra/feature/fingerprint/receptor/v0.1")
|
|
384
|
+
def build_receptor_density_fingerprint(cls, spec):
|
|
385
|
+
return receptor_density_fingerprint.ReceptorDensityFingerprint(
|
|
386
|
+
tsvfile=spec["file"],
|
|
387
|
+
anchor=cls.extract_anchor(spec),
|
|
388
|
+
datasets=cls.extract_datasets(spec),
|
|
389
|
+
id=spec.get("@id", None),
|
|
390
|
+
prerelease=spec.get("prerelease", False),
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
@classmethod
|
|
394
|
+
@build_type("siibra/feature/fingerprint/celldensity/v0.1")
|
|
395
|
+
def build_cell_density_fingerprint(cls, spec):
|
|
396
|
+
return layerwise_cell_density.LayerwiseCellDensity(
|
|
397
|
+
segmentfiles=spec["segmentfiles"],
|
|
398
|
+
layerfiles=spec["layerfiles"],
|
|
399
|
+
anchor=cls.extract_anchor(spec),
|
|
400
|
+
datasets=cls.extract_datasets(spec),
|
|
401
|
+
id=spec.get("@id", None),
|
|
402
|
+
prerelease=spec.get("prerelease", False),
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
@classmethod
|
|
406
|
+
@build_type("siibra/feature/profile/receptor/v0.1")
|
|
407
|
+
def build_receptor_density_profile(cls, spec):
|
|
408
|
+
return receptor_density_profile.ReceptorDensityProfile(
|
|
409
|
+
receptor=spec["receptor"],
|
|
410
|
+
tsvfile=spec["file"],
|
|
411
|
+
anchor=cls.extract_anchor(spec),
|
|
412
|
+
datasets=cls.extract_datasets(spec),
|
|
413
|
+
id=spec.get("@id", None),
|
|
414
|
+
prerelease=spec.get("prerelease", False),
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
@classmethod
|
|
418
|
+
@build_type("siibra/feature/profile/celldensity/v0.1")
|
|
419
|
+
def build_cell_density_profile(cls, spec):
|
|
420
|
+
return cell_density_profile.CellDensityProfile(
|
|
421
|
+
section=spec["section"],
|
|
422
|
+
patch=spec["patch"],
|
|
423
|
+
url=spec["file"],
|
|
424
|
+
anchor=cls.extract_anchor(spec),
|
|
425
|
+
datasets=cls.extract_datasets(spec),
|
|
426
|
+
id=spec.get("@id", None),
|
|
427
|
+
prerelease=spec.get("prerelease", False),
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
@classmethod
|
|
431
|
+
@build_type("siibra/feature/section/v0.1")
|
|
432
|
+
def build_section(cls, spec):
|
|
433
|
+
kwargs = {
|
|
434
|
+
"name": spec.get("name"),
|
|
435
|
+
"region": spec.get("region", None),
|
|
436
|
+
"space_spec": spec.get("space"),
|
|
437
|
+
"providers": cls.build_volumeproviders(spec.get("providers")),
|
|
438
|
+
"datasets": cls.extract_datasets(spec),
|
|
439
|
+
"bbox": cls.build_boundingbox(spec),
|
|
440
|
+
"id": spec.get("@id", None),
|
|
441
|
+
"prerelease": spec.get("prerelease", False),
|
|
442
|
+
}
|
|
443
|
+
modality = spec.get("modality", "")
|
|
444
|
+
if modality == "cell body staining":
|
|
445
|
+
return sections.CellbodyStainedSection(**kwargs)
|
|
446
|
+
else:
|
|
447
|
+
raise ValueError(
|
|
448
|
+
f"No method for building image section feature type {modality}."
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
@classmethod
|
|
452
|
+
@build_type("siibra/feature/voi/v0.1")
|
|
453
|
+
def build_volume_of_interest(cls, spec):
|
|
454
|
+
kwargs = {
|
|
455
|
+
"name": spec.get("name"),
|
|
456
|
+
"region": spec.get("region", None),
|
|
457
|
+
"space_spec": spec.get("space"),
|
|
458
|
+
"providers": cls.build_volumeproviders(spec.get("providers")),
|
|
459
|
+
"datasets": cls.extract_datasets(spec),
|
|
460
|
+
"bbox": cls.build_boundingbox(spec),
|
|
461
|
+
"id": spec.get("@id", None),
|
|
462
|
+
"prerelease": spec.get("prerelease", False),
|
|
463
|
+
}
|
|
464
|
+
modality = spec.get("modality", "")
|
|
465
|
+
if modality == "cell body staining":
|
|
466
|
+
return volume_of_interest.CellBodyStainedVolumeOfInterest(**kwargs)
|
|
467
|
+
elif modality == "blockface":
|
|
468
|
+
return volume_of_interest.BlockfaceVolumeOfInterest(**kwargs)
|
|
469
|
+
elif modality == "PLI HSV fibre orientation map":
|
|
470
|
+
return volume_of_interest.PLIVolumeOfInterest(
|
|
471
|
+
modality="HSV fibre orientation map", **kwargs
|
|
472
|
+
)
|
|
473
|
+
elif modality == "transmittance":
|
|
474
|
+
return volume_of_interest.PLIVolumeOfInterest(
|
|
475
|
+
modality="transmittance", **kwargs
|
|
476
|
+
)
|
|
477
|
+
elif modality == "XPCT":
|
|
478
|
+
return volume_of_interest.XPCTVolumeOfInterest(modality="XPCT", **kwargs)
|
|
479
|
+
elif modality == "DTI":
|
|
480
|
+
return volume_of_interest.DTIVolumeOfInterest(modality=modality, **kwargs)
|
|
481
|
+
# elif modality == "segmentation":
|
|
482
|
+
# return volume_of_interest.SegmentedVolumeOfInterest(**kwargs)
|
|
483
|
+
elif "MRI" in modality:
|
|
484
|
+
return volume_of_interest.MRIVolumeOfInterest(modality=modality, **kwargs)
|
|
485
|
+
elif modality == "LSFM":
|
|
486
|
+
return volume_of_interest.LSFMVolumeOfInterest(
|
|
487
|
+
modality="Light Sheet Fluorescence Microscopy", **kwargs
|
|
488
|
+
)
|
|
489
|
+
else:
|
|
490
|
+
raise ValueError(
|
|
491
|
+
f"No method for building image section feature type {modality}."
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
@classmethod
|
|
495
|
+
@build_type("siibra/feature/connectivitymatrix/v0.3")
|
|
496
|
+
def build_connectivity_matrix(cls, spec):
|
|
497
|
+
files = spec.get("files", {})
|
|
498
|
+
modality = spec["modality"]
|
|
499
|
+
try:
|
|
500
|
+
conn_cls = getattr(connectivity, modality)
|
|
501
|
+
except Exception:
|
|
502
|
+
raise ValueError(
|
|
503
|
+
f"No method for building connectivity matrix of type {modality}."
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
decoder_func = cls.extract_decoder(spec)
|
|
507
|
+
repo_connector = (
|
|
508
|
+
cls.extract_connector(spec) if spec.get("repository", None) else None
|
|
509
|
+
)
|
|
510
|
+
if repo_connector is None:
|
|
511
|
+
base_url = spec.get("base_url", "")
|
|
512
|
+
kwargs = {
|
|
513
|
+
"cohort": spec.get("cohort", ""),
|
|
514
|
+
"modality": modality,
|
|
515
|
+
"regions": spec["regions"],
|
|
516
|
+
"connector": repo_connector,
|
|
517
|
+
"decode_func": decoder_func,
|
|
518
|
+
"anchor": cls.extract_anchor(spec),
|
|
519
|
+
"description": spec.get("description", ""),
|
|
520
|
+
"datasets": cls.extract_datasets(spec),
|
|
521
|
+
"prerelease": spec.get("prerelease", False),
|
|
522
|
+
}
|
|
523
|
+
paradigm = spec.get("paradigm")
|
|
524
|
+
if paradigm:
|
|
525
|
+
kwargs["paradigm"] = paradigm
|
|
526
|
+
files_indexed_by = spec.get("files_indexed_by", "subject")
|
|
527
|
+
assert files_indexed_by in ["subject", "feature"]
|
|
528
|
+
conn_by_file = []
|
|
529
|
+
for fkey, filename in files.items():
|
|
530
|
+
kwargs.update(
|
|
531
|
+
{
|
|
532
|
+
"filename": filename,
|
|
533
|
+
"subject": fkey if files_indexed_by == "subject" else "average",
|
|
534
|
+
"feature": fkey if files_indexed_by == "feature" else None,
|
|
535
|
+
"connector": repo_connector or base_url + filename,
|
|
536
|
+
"id": spec.get("@id", None),
|
|
537
|
+
}
|
|
538
|
+
)
|
|
539
|
+
conn_by_file.append(conn_cls(**kwargs))
|
|
540
|
+
return conn_by_file
|
|
541
|
+
|
|
542
|
+
@classmethod
|
|
543
|
+
@build_type("siibra/feature/timeseries/activity/v0.1")
|
|
544
|
+
def build_activity_timeseries(cls, spec):
|
|
545
|
+
files = spec.get("files", {})
|
|
546
|
+
modality = spec["modality"]
|
|
547
|
+
try:
|
|
548
|
+
timeseries_cls = getattr(regional_timeseries_activity, modality)
|
|
549
|
+
except Exception:
|
|
550
|
+
raise ValueError(f"No method for building signal table of type {modality}.")
|
|
551
|
+
|
|
552
|
+
kwargs = {
|
|
553
|
+
"cohort": spec.get("cohort", ""),
|
|
554
|
+
"modality": modality,
|
|
555
|
+
"regions": spec["regions"],
|
|
556
|
+
"connector": cls.extract_connector(spec),
|
|
557
|
+
"decode_func": cls.extract_decoder(spec),
|
|
558
|
+
"anchor": cls.extract_anchor(spec),
|
|
559
|
+
"description": spec.get("description", ""),
|
|
560
|
+
"datasets": cls.extract_datasets(spec),
|
|
561
|
+
"timestep": spec.get("timestep"),
|
|
562
|
+
"prerelease": spec.get("prerelease", False),
|
|
563
|
+
}
|
|
564
|
+
paradigm = spec.get("paradigm")
|
|
565
|
+
if paradigm:
|
|
566
|
+
kwargs["paradigm"] = paradigm
|
|
567
|
+
timeseries_by_file = []
|
|
568
|
+
for fkey, filename in files.items():
|
|
569
|
+
kwargs.update(
|
|
570
|
+
{"filename": filename, "subject": fkey, "id": spec.get("@id", None)}
|
|
571
|
+
)
|
|
572
|
+
timeseries_by_file.append(timeseries_cls(**kwargs))
|
|
573
|
+
return timeseries_by_file
|
|
574
|
+
|
|
575
|
+
@classmethod
|
|
576
|
+
def from_json(cls, spec: dict):
|
|
577
|
+
|
|
578
|
+
if isinstance(spec, str):
|
|
579
|
+
if path.isfile(spec):
|
|
580
|
+
with open(spec, "r") as f:
|
|
581
|
+
spec = json.load(f)
|
|
582
|
+
else:
|
|
583
|
+
spec = json.loads(spec)
|
|
584
|
+
|
|
585
|
+
spectype = spec.get("@type", None)
|
|
586
|
+
if spectype in _registered_build_fns:
|
|
587
|
+
return _registered_build_fns[spectype](cls, spec)
|
|
588
|
+
else:
|
|
589
|
+
raise RuntimeError(f"No factory method for specification type {spectype}.")
|
siibra/core/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright 2018-2024
|
|
2
|
+
# Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
|
|
3
|
+
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
""":ref:`Main siibra concepts<mainconcepts>`"""
|
|
16
|
+
from . import atlas, parcellation, space
|