Skip to content

Commit

Permalink
Migrating code from bitbucket
Browse files Browse the repository at this point in the history
  • Loading branch information
lidakanari committed Feb 2, 2018
1 parent 3ce483e commit 01be170
Show file tree
Hide file tree
Showing 80 changed files with 9,079 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
*.pyc
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Makefile for tests
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

VENV := test_venv
VENV_BIN := $(VENV)/bin

# simulate running in headless mode
unexport DISPLAY

# Test coverage pass threshold (percent)
MIN_COV ?= 90

FIND_LINT_PY=`find tmd -name "*.py" -not -path "*/*test*"`
LINT_PYFILES := $(shell find $(FIND_LINT_PY))

$(VENV):
virtualenv --system-site-packages $(VENV)
$(VENV_BIN)/pip install --ignore-installed -r requirements_dev.txt
$(VENV_BIN)/pip install -e .

run_pep8: $(VENV)
$(VENV_BIN)/pep8 --config=pep8rc $(LINT_PYFILES) > pep8.txt

run_pylint: $(VENV)
$(VENV_BIN)/pylint --rcfile=pylintrc --extension-pkg-whitelist=numpy $(LINT_PYFILES) > pylint.txt

run_tests: $(VENV)
$(VENV_BIN)/nosetests -v --with-coverage --cover-min-percentage=$(MIN_COV) --cover-package tmd

lint: run_pep8 run_pylint

test: lint run_tests

clean_test_venv:
@rm -rf $(VENV)
@rm -rf $(ROOT_DIR)/test-reports

clean: clean_test_venv
@rm -f pep8.txt
@rm -f pylint.txt
@rm -rf neurom.egg-info
@rm -f .coverage
@rm -rf test-reports
@rm -rf dist
@pyclean tmd

.PHONY: run_pep8 run_pylint test
32 changes: 32 additions & 0 deletions Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Topological Analysis of Neuronal Morphologies.
Topological Morphology Descriptor.
---------------------------------------------
Author: Lida Kanari
Contributors: Pawel Dlotko

Publication: A Topological Representation of Branching Neuronal Morphologies
DOI: https://doi.org/10.1007/s12021-017-9341-1

Cite this article as:
Kanari, L., Dłotko, P., Scolamiero, M. et al. Neuroinform (2018)
16: 3. https://doi.org/10.1007/s12021-017-9341-1
---------------------------------------------

This Python module includes:

* Toolkit to load morphologies in swc and h5 file format.
* Toolkit to extract the topological descriptors of tree morphologies.

=============
Supported OS
=============

Ubuntu : 12.0, 14.04, 16.04

====================
Required Dependencies
====================

Python : 2.7
Numpy : 1.8.1
Matplotlib : 1.3 (optional)
Empty file added doc/Installation.txt
Empty file.
26 changes: 26 additions & 0 deletions doc/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
----------------------------------------------------------------------------
- -
- Topological Analysis of Neuronal Morphologies. -
- -
----------------------------------------------------------------------------

This Python module includes:

Toolkit to load and extract morphological features from swc files.
Toolkit to extract the topological data from neuronal morphologies.
Toolkit to analyze the topological data from neuronal morphologies.

====================
Supported OS
====================

Ubuntu : 12.0, 14.04

====================
Required Dependencies
====================

Python : 2.7
Numpy : 1.8.1
Matplotlib : 1.3

22 changes: 22 additions & 0 deletions doc/Tutorial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
----------------------------------------------------------------------------
- -
- Topological Analysis of Neuronal Morphologies. -
- -
----------------------------------------------------------------------------

Python toolkit to analyze anatomical properties of neurons.

====================
Quick example
====================

# Import the TANM toolkit in IPython
import neurontopology as nt

# Load a neuron
neuron = tn.io.load('input_path_to_file/input_file.swc')

# Extract a tree of the morphology
basal = nauron.basal[0]


117 changes: 117 additions & 0 deletions examples/diversity_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Example script to compute the diversity index from a set of classes.

def diversity_index(perc, simil, q):
"""Computes the generalized diversity index
as described in http://onlinelibrary.wiley.com/doi/10.1890/10-2402.1/abstract
Inputs:
perc: list of percentages of species distribution
of size S.
simil: confusion matrix indicating the similarity
between species of size SxS.
q: the order of diversity index.
"""
import numpy as np

perc = np.array(perc, dtype=float)/sum(perc)

diq = 0.0

for i in xrange(len(perc)):
zpi = np.dot(simil[i], perc)
diq = diq + np.power(perc[i], q)*np.power(zpi, q-1.)

return np.power(diq, 1./(1.-q))


def diversity_index_inf(perc, simil):
"""Computes the generalized diversity index
as described in http://onlinelibrary.wiley.com/doi/10.1890/10-2402.1/abstract
Inputs:
perc: list of percentages of species distribution
of size S.
simil: confusion matrix indicating the similarity
between species of size SxS.
q: the order of diversity index is set to inf
"""
import numpy as np

diq = np.inf

perc = np.array(perc, dtype=float)/sum(perc)

for i in xrange(len(perc)):
zpi = np.dot(simil[i], perc)
diq = min(diq, zpi)

return np.float(1.)/diq


def diversity_index_one(perc, simil):
"""Computes the generalized diversity index
as described in http://onlinelibrary.wiley.com/doi/10.1890/10-2402.1/abstract
Inputs:
perc: list of percentages of species distribution
of size S.
simil: confusion matrix indicating the similarity
between species of size SxS.
q: the order of diversity index is set to one
"""
import numpy as np

diq = 1.0

perc = np.array(perc, dtype=float)/sum(perc)

for i in xrange(len(perc)):
zpi = np.dot(simil[i], perc)
diq = diq * np.power(zpi, perc[i])

return np.float(1.)/diq


def diversity_index_zero(perc, simil):
"""Computes the generalized diversity index
as described in http://onlinelibrary.wiley.com/doi/10.1890/10-2402.1/abstract
Inputs:
perc: list of percentages of species distribution
of size S.
simil: confusion matrix indicating the similarity
between species of size SxS.
q: the order of diversity index is set to one
"""
import numpy as np

diq = 1.0

perc = np.array(perc, dtype=float)/sum(perc)

for i in xrange(len(perc)):
zpi = np.dot(simil[i], perc)
diq = diq * np.power(zpi, perc[i])

return np.float(1.)/diq

perc = np.array(perc, dtype=float)/sum(perc)

diq = 0.0

for i in xrange(len(perc)):
zpi = np.dot(simil[i], perc)
if not np.close(zpi, 0.0):
diq = diq + perc[i]/zpi

return diq


def diversity_vary_q(perc, simil, dep=np.linspace(0.05, 0.95, 20).tolist() + range(2, 10)):
"""Computes the diversity index
with different q values:
from q=0 to q=infinity
"""
# div_index = [diversity_index_zero(perc, simil), diversity_index_one(perc, simil)]

div_index = [diversity_index(perc, simil, q) for q in dep]

# div_index = div_index + [diversity_index_inf(perc, simil)]

return dep, div_index
43 changes: 43 additions & 0 deletions examples/extract_ph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Example to extract the persistence diagram from a neuronal tree

# Step 1: Import the tmd module

import tmd

# Step 2: Load your morphology
filename = './test_data/valid/C010398B-P2.CNG.swc'
neu = tmd.io.load_neuron(filename)

# Step 3: Extract the ph diagram of a tree
tree = neu.neurites[0]
ph = tmd.methods.get_persistence_diagram(tree)

# Step 4: Extract the ph diagram of a neuron's trees
ph_neu = tmd.methods.get_ph_neuron(neu)

# Step 5: Extract the ph diagram of a neuron's trees,
# depending on the neurite_type
ph_apical = tmd.methods.get_ph_neuron(neu, neurite_type='apical')
ph_axon = tmd.methods.get_ph_neuron(neu, neurite_type='axon')
ph_basal = tmd.methods.get_ph_neuron(neu, neurite_type='basal')

# Step 6: Plot the extracted topological data with three different ways
import view

# Visualize the neuron
view.view.neuron(neu)

# Visualize a selected neurite type or multiple of them
view.view.neuron(neu, neurite_type=['apical'])

# Visualize the persistence diagram
view.plot.ph_diagram(ph_apical)

# Visualize the persistence barcode
view.plot.barcode(ph_apical)

# Visualize the persistence image
view.plot.ph_image(ph_apical)

# Create an overview figure for the topology of a tree

0 comments on commit 01be170

Please sign in to comment.