/
drosophila.py
82 lines (62 loc) · 2.51 KB
/
drosophila.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import sys
sys.path.append('./')
import os
import pandas as pd
from vtkplotter import load
from brainrender import DEFAULT_STRUCTURE_COLOR
def get_drosophila_regions_metadata(metadata_fld):
"""
:param metadata_fld:
"""
return pd.read_pickle(os.path.join(metadata_fld,"drosophila_structures.pkl"))
def get_drosophila_mesh_from_region(region, paths, **kwargs):
"""
:param region:
:param paths:
:param **kwargs:
"""
if not isinstance(region, (tuple, list)):
region = [region]
check = False
else: check = True
metadata = get_drosophila_regions_metadata(paths.metadata)
if "color" in list(kwargs.keys()):
color = kwargs.pop("color", DEFAULT_STRUCTURE_COLOR)
elif "c" in list(kwargs.keys()):
color = kwargs.pop("c", DEFAULT_STRUCTURE_COLOR)
if "color" in list(kwargs.keys()): del kwargs["color"]
elif "c" in list(kwargs.keys()): del kwargs["c"]
meshes = []
for reg in region:
if reg.lower() == "root":
meshname = drosophila_root ## UNDEFINED!!??
mesh = load(meshname, c=color, **kwargs)
mesh = mesh.smoothLaplacian().subdivide(2)
meshes.append(mesh)
else:
if isinstance(reg, int):
entry = metadata.loc[metadata.Id == reg]
elif isinstance(reg, str):
entry = metadata.loc[metadata['acronym'] == reg]
else:
raise ValueError("Unrecognized value for region while trying to get mesh for rat: {}".format(reg))
try:
eid = entry.Id.values[0]
if len(eid) == 1:
meshname = os.path.join(paths.drosophila_meshes, "domains/AdultBrainDomain000{}.obj".format(eid))
if len(eid) == 2:
meshname = os.path.join(paths.drosophila_meshes, "domains/AdultBrainDomain00{}.obj".format(eid))
if len(eid) == 3:
meshname = os.path.join(paths.drosophila_meshes, "domains/AdultBrainDomain0{}.obj".format(eid))
if not os.path.isfile(meshname):
raise FileExistsError(meshname)
mesh = load(meshname, c=color, **kwargs)
mesh = mesh.smoothLaplacian().subdivide(2)
meshes.append(mesh)
except:
print("Could not load rat region: {}".format(entry["acronym"].values[0]))
return None
if not check:
return meshes[0]
else:
return meshes