A python package for DSM utilities, which make seuences out of neuron SWC and use deep learning models to encode neurons and predict their types.
Project description
DSM-tools
DSM-tools is a Python module that converts neuron morphology into sequences by binary tree traversals and implements deep learning models for encoding the sequences and predicting cell types.
This project was started by Feng Xiong in 2020, SEU-ALLEN, Nanjing. The package was developed by Zuo-Han Zhao.
Installation
Depedencies
- Python (>=3.9)
- tensorflow (>=2.5.0)
- scikit-learn
- SimpleITK
- gensim (>=4.2.0)
- matplotlib
- pandas
- importlib_resources
Install by PyPI
pip install DSM-tools
Install by GitHub
pip install git+https://github.com/xiongfengNJ/DSM-tools
User Guide
Here's some simple usage that get you a quick start.
Transform SWC files to sequence dataframes
from dsmtools.preprocessing import NeuronSequenceDataset
# dataset generation tool, with computation settings
ds = NeuronSequenceDataset(swc_file_paths, jobs=10)
# processing
ds.read_parallel()
ds.qc_parallel(qc_len_thr=10)
ds.make_sequences_parallel()
# save the result (OrderedDict) as pickle
ds.pickle_sequences('output.pickle')
By default, it gives you a set of features for each neuron by the order of preorder traversals.
Predict cell types with HAN model
from dsmtools.modeling import DSMDataConverter, DSMHierarchicalAttentionNetwork
# further convert the dataframes to dataset fed to tensorflow
converter = DSMDataConverter(ds)
han_x = converter.convert_for_han()
# models trained with our data ready for use
han = DSMHierarchicalAttentionNetwork.load_1282_seu()
le = DSMHierarchicalAttentionNetwork.label_encoder_1282_seu()
# decode the one-hot matrix back to labels
le.inverse_transform(np.argmax(han.predict(han_x), axis=1))
The prediction for autoencoder is similar.
Train an autoencoder
from dsmtools.modeling import DSMAutoencoder
ae_x = converter.convert_for_ae()
# build model
ae = DSMAutoencoder(result_dir='output')
ae.compile(input_dim=6, seq_max_len=2000)
# training
ae.fit(train_x, test_x, model_save_path='ae_checkpoint.h5', epochs=300, batch_size=32)
ae.plot_learning_curve('ae_learning.png')
The training for HAN is similar.
Please see the examples directory for details.
Fine tune the data processing
You can inherit classes like NeuronSequenceDataset
to change the data processing behaviours, which should be quite easy.
The tree manipulating class NeuronTree
offers you the freedom of Exploring your own definition of subtree nodes to generate traversal sequences.
Documentation
Comming soon..
Citation
Our paper is still under review, please check the link for preprint. For now, you can cite it as:
Hanchuan Peng, Feng Xiong, Peng Xie et al. DSM: Deep Sequential Model for Complete Neuronal Morphology Representation and Feature Extraction, 29 June 2022, PREPRINT (Version 1) available at Research Square [[https://doi.org/10.21203/rs.3.rs-1627621/v1] ](https://www.researchsquare.com/article/rs-1627621/v1)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file DSM-tools-1.0.0.tar.gz
.
File metadata
- Download URL: DSM-tools-1.0.0.tar.gz
- Upload date:
- Size: 11.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2acb44c3a6e2f229714122a5c984b9281507209aa6bc10b6dd390edfd2f2d2a3 |
|
MD5 | 6f71478c2c9951be6fc5779ad3634e6f |
|
BLAKE2b-256 | 64475bc8a31c55aa6a5ed389d1b7659b89bfb44283aee237f2cc9cec9d3d35fa |
File details
Details for the file DSM_tools-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: DSM_tools-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99e11a65df816a3d83a96a5cf6f0ee49d2eb58fc8d30dc26686753bec5661bc8 |
|
MD5 | 946e4aa878ed0d4348aa1832f924b48b |
|
BLAKE2b-256 | 1f445770b6a59c8529dfd9455aba877550a49817ebf922b946e1dc10e72dded4 |