1212import os
1313import random
1414import sys
15+ import textwrap
1516import typing
1617from typing import Optional
1718
2324from neuroml .utils import fix_external_morphs_biophys_in_cell
2425
2526from pyneuroml .pynml import read_neuroml2_file
27+ from pyneuroml .swc .ExportNML import convert_swc_to_neuroml
2628from pyneuroml .utils import extract_position_info
2729from pyneuroml .utils .cli import build_namespace
2830from pyneuroml .utils .plot import (
@@ -46,14 +48,25 @@ def process_args():
4648 Parse command-line arguments.
4749 """
4850 parser = argparse .ArgumentParser (
49- description = ("A script which can generate plots of morphologies in NeuroML 2" )
51+ description = (
52+ textwrap .dedent (
53+ """
54+ A script which can generate plots of morphologies in NeuroML 2.
55+ It can generate plots of single cells (either detailed or point
56+ cells), and networks that include these cells.
57+
58+ It can also visualise single cell morphologies from SWC files,
59+ although it will first convert these to NeuroML.
60+ """
61+ )
62+ )
5063 )
5164
5265 parser .add_argument (
5366 "nmlFile" ,
5467 type = str ,
55- metavar = "<NeuroML 2 file>" ,
56- help = "Name of the NeuroML 2 file" ,
68+ metavar = "<NeuroML 2 file/SWC cell file >" ,
69+ help = "Name of the NeuroML 2 file/SWC cell file " ,
5770 )
5871
5972 parser .add_argument (
@@ -215,17 +228,20 @@ def plot_2D(
215228 If a file with a network containing multiple cells is provided, it will
216229 plot all the cells. For detailed neuroml.Cell types, it will plot their
217230 complete morphology. For point neurons, we only plot the points (locations)
218- where they are.
231+ where they are. For single cell SWC files, it will first convert them to
232+ NeuroML and then plot them.
219233
220234 This method uses matplotlib.
221235
222236 .. versionadded:: 1.1.12
223237 The hightlight_spec parameter
224238
225239
226- :param nml_file: path to NeuroML cell file, or a NeuroMLDocument object
227- :type nml_file: str or :py:class:`neuroml.NeuroMLDocument` or
228- :py:class:`neuroml.Cell`
240+ :param nml_file: path to NeuroML cell file or single cell SWC file or
241+ :py:class:`neuroml.NeuroMLDocument` or :py:class:`neuroml.Cell`
242+ or :py:class:`neuroml.Morphology` object
243+ :type nml_file: str or neuroml.NeuroMLDocument or neuroml.Cell or
244+ neuroml.Morphology
229245 :param plane2d: what plane to plot (xy/yx/yz/zy/zx/xz)
230246 :type plane2d: str
231247 :param min_width: minimum width for segments (useful for visualising very
@@ -317,6 +333,14 @@ def plot_2D(
317333 # TODO: check if this is required: must for MultiscaleISN
318334 if nml_file .endswith (".h5" ):
319335 nml_model = read_neuroml2_file (nml_file )
336+ elif nml_file .endswith (".swc" ):
337+ nml_model_doc = convert_swc_to_neuroml (
338+ nml_file ,
339+ neuroml_file = None ,
340+ standalone_morphology = False ,
341+ unbranched_segment_groups = False ,
342+ )
343+ nml_model = nml_model_doc .cells [0 ]
320344 else :
321345 nml_model = read_neuroml2_file (
322346 nml_file ,
0 commit comments