Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow swc files without a soma to be loaded #62

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions morphapi/morphology/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,30 @@ def load_from_swc(self):
self.neuron_name = self.data_file.name

nrn = nm.load_morphology(self.data_file)

# Get position and radius of some
soma_pos = nrn.soma.points[0, :3]
soma_radius = nrn.soma.points[0, -1]

# Get the rest of the data and store it
self.morphology = nrn
self.points = dict(
soma=component(
soma_pos[0],
soma_pos[1],
soma_pos[2],
soma_pos,
soma_radius,
nrn.soma,
),
)

try:
# Get position and radius of soma
soma_pos = nrn.soma.points[0, :3]
soma_radius = nrn.soma.points[0, -1]

# Get the rest of the data and store it
self.points = dict(
soma=component(
soma_pos[0],
soma_pos[1],
soma_pos[2],
soma_pos,
soma_radius,
nrn.soma,
),
)
except IndexError:
logger.warning(
f"Neuron {self.neuron_name} has no soma, "
"only neurites will be loaded"
)
self.points = dict(soma=None)

for ntype, nclass in self._neurite_types.items():
self.points[ntype] = [
Expand Down Expand Up @@ -207,16 +214,17 @@ def create_mesh(
else:
# Create soma actor
neurites = {}
coords = self.points["soma"].coords
if self.invert_dims:
coords = coords[[2, 1, 0]]

soma = Sphere(
pos=coords,
r=self.points["soma"].radius * soma_radius,
c=soma_color,
).compute_normals()
neurites["soma"] = soma.clone().c(soma_color)
if self.points["soma"] is not None:
coords = self.points["soma"].coords
if self.invert_dims:
coords = coords[[2, 1, 0]]

soma = Sphere(
pos=coords,
r=self.points["soma"].radius * soma_radius,
c=soma_color,
).compute_normals()
neurites["soma"] = soma.clone().c(soma_color)

# Create neurites actors
for ntype in self._neurite_types:
Expand Down
Loading