morph-tool


Namemorph-tool JSON
Version 2.11.2 PyPI version JSON
download
home_pagehttps://github.com/bluebrain/morph-tool
SummaryA collection of CLIs and python function related to morphology handling
upload_time2024-09-10 07:09:56
maintainerNone
docs_urlNone
authorBlue Brain Project, EPFL
requires_python>=3.8
licenseLGPLv3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: doc/source/logo/BBP-Morph-Tool.jpg

|docs|

MorphTool
=========

A toolbox for morphology editing. It aims to provide small helper programs that perform simple tasks.

Currently MorphTool provides:

- A morphology diffing tool (via CLI or python)
- A file converter: to convert morphology files from/to the following formats: SWC, ASC, H5
- A soma area calculator (as computed by NEURON, requires the NEURON python module)

MorphIO v2 and NeuroM v1
------------------------
If you want to work with old NeuroM v1 and MorphIO v2, use the version 2.4.7 of morph-tool.

Documentation
-------------

morph-tool documentation is built and hosted on `readthedocs <https://morph-tool.readthedocs.org/>`__.

* `latest snapshot <https://morph-tool.readthedocs.org/en/latest/>`_
* `latest release <https://morph-tool.readthedocs.org/en/stable/>`_

Installation
------------
It is recommended to install in a fresh virtualenv.

Base installation:

.. code:: bash

    pip install morph-tool

If plan to use `dendrogram` module:

.. code:: bash

    pip install morph-tool[plot]

If plan to use `nrnhines` module:

.. code:: bash

    pip install morph-tool[nrn]

If plan to convert folders of morphologies:

.. code:: bash

    pip install morph-tool[parallel]

If plan to use all available functionality:

.. code:: bash

    pip install morph-tool[all]



Usage
-----

In a shell, do:

.. code:: bash

    morph-tool --help

Currently the three sub-command are:

.. code:: bash

    morph-tool convert file input_file output_file
    morph-tool diff morph1 morph2
    morph-tool soma-surface input_file

Morphology diffing
------------------
One can compare two morphologies with the CLI

.. code:: bash

   morph-tool diff morph1 morph2

whose error code is 0 if morphologies are the same, else 1.

Morphologies with different formats can be compared.

Morphologies are considered different if one or more of the following properties differ:

- number of root sections
- sections type
- sections point array
- sections diameter array
- sections perimeter array
- sections number of children

The soma are *not* taken into consideration

The same functionality is also available through the python API:

.. code:: python

   from morph_tool import diff

   # The result can be used as a boolean:
   if diff(filename1, filename2):
       print('morphologies differ')

   # And also contains information about how morphologies differ
   result = diff(filename1, filename2)
   print(result.info)


Converter
---------

What is supported ?
~~~~~~~~~~~~~~~~~~~

The converter can be used to write morphology in different formats.
Currently, supported formats are ASC, SWC and H5.

As each format has its own specificities, data specific to a given
format will be discarded. This means the following will be lost during
conversion:

* spines (present in the ASC format)

* all H5 metadata

* the perimeter and mitochondrial data of the `H5 format <https://bbpteam.epfl.ch/documentation/Morphology%20Documentation-0.0.2/h5v1.html>`__

Soma intricacies
~~~~~~~~~~~~~~~~

Multiple formats are being used to represent somas (mainly) depending on
the file format. For more information about file format, see the `neuromorpho.org specification <http://neuromorpho.org/SomaFormat.html>`__ or `MorphIO
specification <https://github.com/BlueBrain/MorphIO/blob/master/doc/specification.md#soma-formats>`__

Because different soma format represent soma in different planes, soma
format conversion is not a bijective transformation. For example, it is
not possible to have an accurate conversion from a soma contour in the
XY plane from a H5 file to a SWC soma which is represented as a cylinder
along Y.

As a result, it has been chosen to take the soma surface as an
invariant. This means soma surfaces of the input and output morphologies, as computed by NEURON, should be preserved.

Here are the possible cases for the soma conversion:

- SWC input file:

  - SWC output file -> no conversion
  - H5 or ASC output file:

    Depending on the original soma type:

    - Soma stack of cylinders:
      The soma is converted to a contour in the XY plane.
      The points of the new contour are the outline of the soma stack projected in the XY plane.
    - Soma three point cylinder:
      The soma becomes a sphere of same surface. The contour made by the circle of biggest section in the XY plane is sampled in 20 points written to disk.
    - Soma sphere (soma represented by a single point representing the center of a sphere and its radius): the contour made by the circle of biggest section in the XY plane is sampled in 20 points written to disk.
    - other:
      Not in SWC spec -> not supported

- H5 or ASC input file:

  - H5 output file -> no conversion needed
  - ASC output file.

    Depending on soma type:

    - Soma single point sphere (soma represented by a single point representing the center of a sphere and its radius): the contour made by the circle of biggest section in the XY plane is sampled in 20 points written to disk.
    - Soma contour: no conversion needed
    - other: not in H5/ASC specs -> not supported

  - SWC:

    Depending on soma format:

    - Soma single point sphere: no conversion needed
    - Soma contour: A soma stack of cylinder is generated.
      Each cylinder of the stack has its center and its axis along the principal direction of the contour.
      The radius of each stack is chosen such that it minimises the distance between the cylinder and the contour.
    - other: not in H5/ASC specs -> not supported

Example:

.. code:: python

   from morph_tool import convert
   convert(inputfile, outputfile)

   # Additionally the morphology can be recentered or written according to the NEURON neurite order during the conversion
   convert(inputfile, outputfile, recenter=True, nrn_order=True)

The same for bash

.. code:: bash

   morph-tool convert file ./inputfile ./outputfile
   # with additional options
   morph-tool convert file --recenter --nrn-order ./inputfile ./outputfile
   # or an entire folder
   morph-tool convert folder -ext SWC ./h5_input_folder ./swc_output_folder
   # for more info use
   morph-tool convert folder --help

NRN simulator compartment coordinates
-------------------------------------

The NRN simulator splits each section into chunks of equal length (equal only among a given section).
These compartments do not really exist in the physical world but we can remap them to paths
along the section. Each compartment can be associated to a path (a list of 3D points) such
that the path and the compartment have the same path-length.

The following function can be used to access the mapping NeuroM section ID -> list of paths for the section:

.. code:: python

          morph_tool.nrnhines.NeuroM_section_to_NRN_compartment_paths


Example (in 2D) for one section:

.. code::

                   (1, 2) ------ (2, 2)
                      |
                      |
                      |
                      |
                      |
                      |
                      |
                      |
                      |
    (0, 0) ------- (1, 0)


Splitting this section into 3 compartments would results in the following paths:

1.

.. code::

    [[0.        , 0.        ],
     [1.        , 0.        ],
     [1.        , 0.33333333]]

2.

.. code::

   [[1.        , 0.33333333],
    [1.        , 1.66666667]]

3.

.. code::

   [[1.        , 1.66666667],
    [1.        , 2.        ],
    [2.        , 2.        ]]


Plot morphologies with synapses
-------------------------------

This functionality is available only when the package is installed with **plot** extras:

.. code:: bash

    pip install morph-tool[plot]

Dendrogram
~~~~~~~~~~

Draw NeuroM dendrogram with synapses on it. Synapses must be represented as a DataFrame. See
`dendrogram <https://morph-tool.readthedocs.io/en/latest/morph_tool.plot.dendrogram.html>`__.

Morphology
~~~~~~~~~~

Draw NeuroM morphology with synapses on it. Synapses must be represented as a DataFrame. See
`morphology <https://morph-tool.readthedocs.io/en/latest/morph_tool.plot.morphology.html>`__.

Simplification
~~~~~~~~~~~~~~

MorphTool can also be use to "simplify" morphologies.
See `morphology <https://morph-tool.readthedocs.io/en/latest/simplify.html>`__.


Contributing
------------

If you want to improve the project or you see any issue, every contribution is welcome.
Please check the `contribution guidelines <CONTRIBUTING.md>`__ for more information.

Acknowledgements
----------------

The development of this software was supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de Lausanne (EPFL), from the Swiss government’s ETH Board of the Swiss Federal Institutes of Technology.

This research was supported by the EBRAINS research infrastructure, funded from the European Union’s Horizon 2020 Framework Programme for Research and Innovation under the Specific Grant Agreement No. 945539 (Human Brain Project SGA3).

License
-------

morph-tool is licensed under the terms of the GNU Lesser General Public License version 3.
Refer to COPYING.LESSER and COPYING for details.

Copyright (c) 2018-2024 Blue Brain Project/EPFL

.. |docs| image:: https://readthedocs.org/projects/morph-tool/badge/?version=latest
             :target: https://morph-tool.readthedocs.io/
             :alt: documentation status

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bluebrain/morph-tool",
    "name": "morph-tool",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Blue Brain Project, EPFL",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/11/a5/7855ee82afcb112fb1d4184360957225eec4c7595985fe4e64e520af5061/morph-tool-2.11.2.tar.gz",
    "platform": null,
    "description": ".. image:: doc/source/logo/BBP-Morph-Tool.jpg\n\n|docs|\n\nMorphTool\n=========\n\nA toolbox for morphology editing. It aims to provide small helper programs that perform simple tasks.\n\nCurrently MorphTool provides:\n\n- A morphology diffing tool (via CLI or python)\n- A file converter: to convert morphology files from/to the following formats: SWC, ASC, H5\n- A soma area calculator (as computed by NEURON, requires the NEURON python module)\n\nMorphIO v2 and NeuroM v1\n------------------------\nIf you want to work with old NeuroM v1 and MorphIO v2, use the version 2.4.7 of morph-tool.\n\nDocumentation\n-------------\n\nmorph-tool documentation is built and hosted on `readthedocs <https://morph-tool.readthedocs.org/>`__.\n\n* `latest snapshot <https://morph-tool.readthedocs.org/en/latest/>`_\n* `latest release <https://morph-tool.readthedocs.org/en/stable/>`_\n\nInstallation\n------------\nIt is recommended to install in a fresh virtualenv.\n\nBase installation:\n\n.. code:: bash\n\n    pip install morph-tool\n\nIf plan to use `dendrogram` module:\n\n.. code:: bash\n\n    pip install morph-tool[plot]\n\nIf plan to use `nrnhines` module:\n\n.. code:: bash\n\n    pip install morph-tool[nrn]\n\nIf plan to convert folders of morphologies:\n\n.. code:: bash\n\n    pip install morph-tool[parallel]\n\nIf plan to use all available functionality:\n\n.. code:: bash\n\n    pip install morph-tool[all]\n\n\n\nUsage\n-----\n\nIn a shell, do:\n\n.. code:: bash\n\n    morph-tool --help\n\nCurrently the three sub-command are:\n\n.. code:: bash\n\n    morph-tool convert file input_file output_file\n    morph-tool diff morph1 morph2\n    morph-tool soma-surface input_file\n\nMorphology diffing\n------------------\nOne can compare two morphologies with the CLI\n\n.. code:: bash\n\n   morph-tool diff morph1 morph2\n\nwhose error code is 0 if morphologies are the same, else 1.\n\nMorphologies with different formats can be compared.\n\nMorphologies are considered different if one or more of the following properties differ:\n\n- number of root sections\n- sections type\n- sections point array\n- sections diameter array\n- sections perimeter array\n- sections number of children\n\nThe soma are *not* taken into consideration\n\nThe same functionality is also available through the python API:\n\n.. code:: python\n\n   from morph_tool import diff\n\n   # The result can be used as a boolean:\n   if diff(filename1, filename2):\n       print('morphologies differ')\n\n   # And also contains information about how morphologies differ\n   result = diff(filename1, filename2)\n   print(result.info)\n\n\nConverter\n---------\n\nWhat is supported ?\n~~~~~~~~~~~~~~~~~~~\n\nThe converter can be used to write morphology in different formats.\nCurrently, supported formats are ASC, SWC and H5.\n\nAs each format has its own specificities, data specific to a given\nformat will be discarded. This means the following will be lost during\nconversion:\n\n* spines (present in the ASC format)\n\n* all H5 metadata\n\n* the perimeter and mitochondrial data of the `H5 format <https://bbpteam.epfl.ch/documentation/Morphology%20Documentation-0.0.2/h5v1.html>`__\n\nSoma intricacies\n~~~~~~~~~~~~~~~~\n\nMultiple formats are being used to represent somas (mainly) depending on\nthe file format. For more information about file format, see the `neuromorpho.org specification <http://neuromorpho.org/SomaFormat.html>`__ or `MorphIO\nspecification <https://github.com/BlueBrain/MorphIO/blob/master/doc/specification.md#soma-formats>`__\n\nBecause different soma format represent soma in different planes, soma\nformat conversion is not a bijective transformation. For example, it is\nnot possible to have an accurate conversion from a soma contour in the\nXY plane from a H5 file to a SWC soma which is represented as a cylinder\nalong Y.\n\nAs a result, it has been chosen to take the soma surface as an\ninvariant. This means soma surfaces of the input and output morphologies, as computed by NEURON, should be preserved.\n\nHere are the possible cases for the soma conversion:\n\n- SWC input file:\n\n  - SWC output file -> no conversion\n  - H5 or ASC output file:\n\n    Depending on the original soma type:\n\n    - Soma stack of cylinders:\n      The soma is converted to a contour in the XY plane.\n      The points of the new contour are the outline of the soma stack projected in the XY plane.\n    - Soma three point cylinder:\n      The soma becomes a sphere of same surface. The contour made by the circle of biggest section in the XY plane is sampled in 20 points written to disk.\n    - Soma sphere (soma represented by a single point representing the center of a sphere and its radius): the contour made by the circle of biggest section in the XY plane is sampled in 20 points written to disk.\n    - other:\n      Not in SWC spec -> not supported\n\n- H5 or ASC input file:\n\n  - H5 output file -> no conversion needed\n  - ASC output file.\n\n    Depending on soma type:\n\n    - Soma single point sphere (soma represented by a single point representing the center of a sphere and its radius): the contour made by the circle of biggest section in the XY plane is sampled in 20 points written to disk.\n    - Soma contour: no conversion needed\n    - other: not in H5/ASC specs -> not supported\n\n  - SWC:\n\n    Depending on soma format:\n\n    - Soma single point sphere: no conversion needed\n    - Soma contour: A soma stack of cylinder is generated.\n      Each cylinder of the stack has its center and its axis along the principal direction of the contour.\n      The radius of each stack is chosen such that it minimises the distance between the cylinder and the contour.\n    - other: not in H5/ASC specs -> not supported\n\nExample:\n\n.. code:: python\n\n   from morph_tool import convert\n   convert(inputfile, outputfile)\n\n   # Additionally the morphology can be recentered or written according to the NEURON neurite order during the conversion\n   convert(inputfile, outputfile, recenter=True, nrn_order=True)\n\nThe same for bash\n\n.. code:: bash\n\n   morph-tool convert file ./inputfile ./outputfile\n   # with additional options\n   morph-tool convert file --recenter --nrn-order ./inputfile ./outputfile\n   # or an entire folder\n   morph-tool convert folder -ext SWC ./h5_input_folder ./swc_output_folder\n   # for more info use\n   morph-tool convert folder --help\n\nNRN simulator compartment coordinates\n-------------------------------------\n\nThe NRN simulator splits each section into chunks of equal length (equal only among a given section).\nThese compartments do not really exist in the physical world but we can remap them to paths\nalong the section. Each compartment can be associated to a path (a list of 3D points) such\nthat the path and the compartment have the same path-length.\n\nThe following function can be used to access the mapping NeuroM section ID -> list of paths for the section:\n\n.. code:: python\n\n          morph_tool.nrnhines.NeuroM_section_to_NRN_compartment_paths\n\n\nExample (in 2D) for one section:\n\n.. code::\n\n                   (1, 2) ------ (2, 2)\n                      |\n                      |\n                      |\n                      |\n                      |\n                      |\n                      |\n                      |\n                      |\n    (0, 0) ------- (1, 0)\n\n\nSplitting this section into 3 compartments would results in the following paths:\n\n1.\n\n.. code::\n\n    [[0.        , 0.        ],\n     [1.        , 0.        ],\n     [1.        , 0.33333333]]\n\n2.\n\n.. code::\n\n   [[1.        , 0.33333333],\n    [1.        , 1.66666667]]\n\n3.\n\n.. code::\n\n   [[1.        , 1.66666667],\n    [1.        , 2.        ],\n    [2.        , 2.        ]]\n\n\nPlot morphologies with synapses\n-------------------------------\n\nThis functionality is available only when the package is installed with **plot** extras:\n\n.. code:: bash\n\n    pip install morph-tool[plot]\n\nDendrogram\n~~~~~~~~~~\n\nDraw NeuroM dendrogram with synapses on it. Synapses must be represented as a DataFrame. See\n`dendrogram <https://morph-tool.readthedocs.io/en/latest/morph_tool.plot.dendrogram.html>`__.\n\nMorphology\n~~~~~~~~~~\n\nDraw NeuroM morphology with synapses on it. Synapses must be represented as a DataFrame. See\n`morphology <https://morph-tool.readthedocs.io/en/latest/morph_tool.plot.morphology.html>`__.\n\nSimplification\n~~~~~~~~~~~~~~\n\nMorphTool can also be use to \"simplify\" morphologies.\nSee `morphology <https://morph-tool.readthedocs.io/en/latest/simplify.html>`__.\n\n\nContributing\n------------\n\nIf you want to improve the project or you see any issue, every contribution is welcome.\nPlease check the `contribution guidelines <CONTRIBUTING.md>`__ for more information.\n\nAcknowledgements\n----------------\n\nThe development of this software was supported by funding to the Blue Brain Project, a research center of the \u00c9cole polytechnique f\u00e9d\u00e9rale de Lausanne (EPFL), from the Swiss government\u2019s ETH Board of the Swiss Federal Institutes of Technology.\n\nThis research was supported by the EBRAINS research infrastructure, funded from the European Union\u2019s Horizon 2020 Framework Programme for Research and Innovation under the Specific Grant Agreement No. 945539 (Human Brain Project SGA3).\n\nLicense\n-------\n\nmorph-tool is licensed under the terms of the GNU Lesser General Public License version 3.\nRefer to COPYING.LESSER and COPYING for details.\n\nCopyright (c) 2018-2024 Blue Brain Project/EPFL\n\n.. |docs| image:: https://readthedocs.org/projects/morph-tool/badge/?version=latest\n             :target: https://morph-tool.readthedocs.io/\n             :alt: documentation status\n",
    "bugtrack_url": null,
    "license": "LGPLv3",
    "summary": "A collection of CLIs and python function related to morphology handling",
    "version": "2.11.2",
    "project_urls": {
        "Homepage": "https://github.com/bluebrain/morph-tool"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "11a57855ee82afcb112fb1d4184360957225eec4c7595985fe4e64e520af5061",
                "md5": "e85544526c8e81f501c4c018241d89bf",
                "sha256": "5ab943f29eee3c178559ece8d1597d60bf4a03a18b1fbc9fb1f4753854dacb49"
            },
            "downloads": -1,
            "filename": "morph-tool-2.11.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e85544526c8e81f501c4c018241d89bf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 1906296,
            "upload_time": "2024-09-10T07:09:56",
            "upload_time_iso_8601": "2024-09-10T07:09:56.481381Z",
            "url": "https://files.pythonhosted.org/packages/11/a5/7855ee82afcb112fb1d4184360957225eec4c7595985fe4e64e520af5061/morph-tool-2.11.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-10 07:09:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bluebrain",
    "github_project": "morph-tool",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "morph-tool"
}
        
Elapsed time: 0.69269s