Skip to content

Remove SWC file repair method #60

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

Merged
merged 1 commit into from
Apr 26, 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
34 changes: 0 additions & 34 deletions morphapi/morphology/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,44 +73,10 @@ def load_from_file(self):
else:
self.load_from_swc()

def repair_swc_file(self):
"""
Fixes this: https://github.com/BlueBrain/NeuroM/issues/835
"""
with open(self.data_file, "r") as read:
content = read.readlines()

clean = []
for line in content:
if not len(line):
clean.append(line)
continue

line = line.replace("\n", "").replace("\t", " ")
vals = line.split(" ")
if len(vals) < 2:
clean.append(line)
continue

if vals[1] != "1" and vals[-1] == "-1":
vals[-1] = "0"
clean.append(" ".join(vals))
else:
clean.append(line)

if len(clean) != len(content):
raise ValueError

with open(self.data_file, "w") as write:
for line in clean:
write.write(f"{line}\n")

def load_from_swc(self):
if self.neuron_name is None:
self.neuron_name = self.data_file.name

self.repair_swc_file()

nrn = nm.load_morphology(self.data_file)

# Get position and radius of some
Expand Down
Loading