Skip to content

Commit

Permalink
moved the export functio inside SWCGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaPandeyCN committed Jul 11, 2024
1 parent 3a57a1c commit abb001a
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions pyneuroml/swc/LoadSWC.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@ def get_branch_points(
branch_points[type_id] = self.get_nodes_with_multiple_children(type_id)
return branch_points

def export_to_swc_file(self, filename: str) -> None:
"""
Export the SWCGraph to a new SWC file.
:param filename: The path to the output SWC file
:type filename: str
"""
with open(filename, "w") as file:
# Write metadata
for key, value in self.metadata.items():
file.write(f"# {key} {value}\n")

# Write node data
for node in sorted(self.nodes, key=lambda n: n.id):
file.write(
f"{node.id} {node.type} {node.x:.4f} {node.y:.4f} {node.z:.4f} {node.radius:.4f} {node.parent_id}\n"
)


def parse_header(line: str) -> typing.Optional[typing.Tuple[str, str]]:
"""
Expand Down Expand Up @@ -334,22 +352,3 @@ def load_swc(filename: str) -> SWCGraph:
tree.add_node(node)

return tree


def export_swc(graph: SWCGraph, filename: str) -> None:
"""
Export the SWCGraph to a new SWC file.
:param filename: The path to the output SWC file
:type filename: str
"""
with open(filename, "w") as file:
# Write metadata
for key, value in graph.metadata.items():
file.write(f"# {key} {value}\n")

# Write node data
for node in sorted(graph.nodes, key=lambda n: n.id):
file.write(
f"{node.id} {node.type} {node.x:.4f} {node.y:.4f} {node.z:.4f} {node.radius:.4f} {node.parent_id}\n"
)

0 comments on commit abb001a

Please sign in to comment.