Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Add MorphDB API

Choose a tag to compare

@wizmer wizmer released this 29 Jan 13:38
· 67 commits to master since this release
5fe9578
Add an I/O neurondb API (#25)

* ✨ Add an I/O neurondb API #25

It introduces two classes:

## MorphInfo

A class containing all the information that can be found in the neurondb regarding a single morphology.

```python

info = MorphInfo(name='name', mtype='mtype', 'layer'='layer')
info.use_dendrite = False
info.axon_inputs = ['morph1', 'morph2']
```

## MorphDB

A class containing information regarding collections of morphologies.
The class has a single attribute `self.df` to expose this information as a
Pandas dataframe.

### Constructors:

```python
MorphDB()
MorphDB.from_neurondb()
MorphDB.from_folder()
```

### Adding new data

Data can be added through the the `+` and `+=` operators.

Example:

```python
all_morphs = MorphDB.from_neurondb('/gpfs/.../unravelled', label='unravelled')
all_morphs += MorphDB.from_neurondb('/gpfs/.../repaired', label='repaired')

morph_info_list = [MorphInfo(name='name', mtype='mtype', 'layer'='layer', label='extra-morphs'),
                   MorphInfo(name='name', mtype='mtype', 'layer'='layer', label='extra-morphs'),
                   MorphInfo(name='name', mtype='mtype', 'layer'='layer', label='extra-morphs'),
                   MorphInfo(name='name', mtype='mtype', 'layer'='layer', label='extra-morphs')]
morph2 = all_morphs + morph_info_list
```
### Writing neurondb to disk.

The data can be written to disk with both the XML and DAT format.

```python
MorphDB.from_neurondb('path1').write('neurondb.dat')
```

### Analysing morph-stats features

NeuroM morphometrics can be extracted with `self.features(config)` where
`config` is a [morph-stats
configuration](https://neurom.readthedocs.io/en/latest/morph_stats.html).

Labels can be used to compare morphometrics across different datasets.
```python
db = MorphDB.from_neurondb('path1', label='dataset-1')
db += MorphDB.from_neurondb('path2', label='dataset-2')
db += MorphDB.from_neurondb('path3', label='dataset-3')
db += MorphDB.from_neurondb('path4', label='dataset-4')

features = db.features(config)

for dataset, df in features.groupby(('neuron', 'label')):
    print(dataset, df)
```

* Smarter path discovery

* Implement comments

* fix CI

* Fix CI (again)

* Comments

* Fix more comments

* Update doc/source/morphdb.rst

Co-authored-by: Gianluca Ficarelli <26835404+GianlucaFicarelli@users.noreply.github.com>

* more comments

Co-authored-by: Gianluca Ficarelli <26835404+GianlucaFicarelli@users.noreply.github.com>