diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 72364f9..0000000 --- a/.gitignore +++ /dev/null @@ -1,89 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*,cover -.hypothesis/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# IPython Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# dotenv -.env - -# virtualenv -venv/ -ENV/ - -# Spyder project settings -.spyderproject - -# Rope project settings -.ropeproject diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..77fb6ea --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include versioneer.py +include conwhat/_version.py diff --git a/conwhat/__init__.py b/conwhat/__init__.py index 236fa7a..838ca5d 100644 --- a/conwhat/__init__.py +++ b/conwhat/__init__.py @@ -1,10 +1,9 @@ +__all__ = [ 'VolTractAtlas', 'VolConnAtlas', 'StreamTractAtlas', 'StreamConnAtlas' ] - -__version__ = '0.1.dev0' - - -from atlas import (VolTractAtlas,VolConnAtlas, +from .atlas import (VolTractAtlas,VolConnAtlas, StreamTractAtlas,StreamConnAtlas) - +from ._version import get_versions +__version__ = get_versions()['version'] +del get_versions diff --git a/conwhat/__main__.py b/conwhat/__main__.py new file mode 100644 index 0000000..86cee1f --- /dev/null +++ b/conwhat/__main__.py @@ -0,0 +1,15 @@ + + + +def main(): + "Entry point." + + raise NotImplementedError('The command line interface for ConWhAt is not currently supported. ' + 'Please use it via API in a script or jupyter notebook. \n' + 'Example usages : \n' + 'from conwhat import StreamConnAtlas \n' + 'from conwhat import VolConnAtlas \n' + '') + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/conwhat/atlas.py b/conwhat/atlas.py index 76c5ea8..0ba359e 100644 --- a/conwhat/atlas.py +++ b/conwhat/atlas.py @@ -4,6 +4,7 @@ # Author: John Griffiths # License: simplified BSD +from __future__ import print_function import os @@ -14,17 +15,17 @@ from nilearn.plotting import plot_glass_brain -from utils.readers import (load_connectivity,load_vol_file_mappings,load_vol_bboxes, +from .utils.readers import (load_connectivity,load_vol_file_mappings,load_vol_bboxes, load_stream_file_mappings,load_stream_bboxes, make_nx_graph,dpy_to_trk) -from utils.stats import (compute_vol_hit_stats,compute_vol_scalar_stats, +from .utils.stats import (compute_vol_hit_stats,compute_vol_scalar_stats, compute_streams_in_roi,#compute_stream_hit_stats,compute_stream_scalar_stats, hit_stats_to_nx) -#from viz.network import plot_network,plot_matrix -#from viz.volume import plot_vol_cnxn,plot_vol_tract -#from viz.streams import plot_stream_cnxn,plot_stream_tract +from .viz.network import plot_network, plot_matrix +from .viz.volume import plot_vol_cnxn, plot_vol_tract +from .viz.streams import plot_stream_cnxn, plot_stream_tract @@ -38,7 +39,7 @@ class _Atlas(): # object): def __init__(self): - print 'blah' + print('blah') class _VolAtlas(_Atlas): @@ -61,6 +62,7 @@ def __init__(self,atlas_name=None,atlas_dir=None): self.vfms,self.atlas_dir = load_vol_file_mappings(atlas_name=atlas_name,atlas_dir=atlas_dir) self.bbox = load_vol_bboxes(atlas_name=atlas_name,atlas_dir=atlas_dir) + self.scalar_stats = dict() def get_vol_from_vfm(self,idx): """ @@ -79,10 +81,10 @@ def get_vol_from_vfm(self,idx): if os.path.isfile(nii_file): if (np.isnan(volnum) or volnum == 'nan'): - print 'getting atlas entry %s: image file %s' %(idx,nii_file) + print('getting atlas entry {}: image file {} ' % (idx,nii_file)) img = nib.load(nii_file) else: - print 'getting atlas entry %s: volume %s from image file %s' %(idx,volnum,nii_file) + print('getting atlas entry {}: volume %s from image file {}' % (idx,volnum,nii_file)) img = index_img(nii_file,volnum) return img @@ -174,7 +176,8 @@ def compute_hit_stats(self,roi,idxs,n_jobs=1,run_type='simple',joblib_cache_dir= def plot_tract(self,atlas_name): # (uses plotting param defaults tuned to JHU atlas) - plot_tract() + # plot_tract() + raise NotImplementedError @@ -207,6 +210,8 @@ def __init__(self,atlas_dir=None,atlas_name=None): # Compile node and connectivity info into a networkx graph self.Gnx = make_nx_graph(self.vfms,self.bbox,ws,rls,hs,ctx) + self.modcons = dict() + @property def weights(self): @@ -282,13 +287,17 @@ def get_vol_from_rois(self,roi1,roi2): return img + def modify_vol_connectome(self): + + raise NotImplementedError + def modify_connectome(self, name='mc1',function=''): """ Modify canonical connectome using hit or scalar stats, and store in this obj """ - res = modify_vol_connectome() + res = self.modify_vol_connectome() self.modcons[name] = res @@ -398,7 +407,7 @@ def __init__(self,atlas_name=None,atlas_dir=None): def write_subset_to_trk(self,ref_file,outfile,stream_inds='all'): - print 'writing streams to trk file: %s' %outfile + print('writing streams to trk file: {}' % outfile) dpy_to_trk(self.dpy_file,ref_file,outfile,inds=stream_inds) @@ -444,6 +453,8 @@ def __init__(self,atlas_name=None,atlas_dir=None): # Compile node and connectivity info into a networkx graph self.Gnx = make_nx_graph(self.sfms,self.bbox,ws,rls,hs,ctx) + self.modcons = dict() + def get_rois_from_idx(self,idx): @@ -484,7 +495,8 @@ def compute_hit_stats(self,roi,idxs,n_jobs=1,run_type='simple',joblib_cache_dir= - + def modify_stream_connectome(self): + raise NotImplementedError def modify_connectome(self, name='mc1',function=''): """ @@ -492,7 +504,7 @@ def modify_connectome(self, name='mc1',function=''): stats, and store in this obj """ - res = modify_stream_connectome() + res = self.modify_stream_connectome() self.modcons[name] = res @@ -521,7 +533,7 @@ def plot_matrix(self): def plot_cnxns(self): - plot_stream_cnxns() + plot_stream_cnxn() diff --git a/conwhat/utils/stats.py b/conwhat/utils/stats.py index 64faa73..eae5ed8 100644 --- a/conwhat/utils/stats.py +++ b/conwhat/utils/stats.py @@ -388,20 +388,23 @@ def calc_streams_in_roi(dpy_file,roi_dat,stream_idxs): -def compute_vol_scalar_stats(): +def compute_vol_scalar_stats(params): - print 'computing vol scalar stats' + print('computing vol scalar stats') + raise NotImplementedError -def compute_stream_hit_stats(): +def compute_stream_hit_stats(params): - print 'computing stream hit stats' + print('computing stream hit stats') + raise NotImplementedError -def compute_stream_scalar_stats(): +def compute_stream_scalar_stats(params): + print('computing stream scalar stats') + raise NotImplementedError - print 'computing stream scalar stats' diff --git a/conwhat/viz/network.py b/conwhat/viz/network.py index 2cb1b1f..96bb3f0 100644 --- a/conwhat/viz/network.py +++ b/conwhat/viz/network.py @@ -9,13 +9,16 @@ def plot_network(): - print 'plotting network' + print('plotting network') + return def plot_matrix(): - print 'plotting matrix' + print('plotting matrix') + + return diff --git a/conwhat/viz/streams.py b/conwhat/viz/streams.py index ffe3ce8..b5e7bd3 100644 --- a/conwhat/viz/streams.py +++ b/conwhat/viz/streams.py @@ -54,7 +54,7 @@ def get_track_vis_pic(trk_file, length=None,bg_image=None,bz=None, sc='/tmp/movi if tr: cmd += ' -s -r %s' %tr - if tc: + if tc: cmd += ' -c %s ' %tc if aa: cmd+= ' -aa ' @@ -74,11 +74,13 @@ def get_track_vis_pic(trk_file, length=None,bg_image=None,bz=None, sc='/tmp/movi def plot_stream_cnxn(): - print 'plotting streamlinetric connection' + print('plotting streamlinetric connection') + raise NotImplementedError def plot_stream_tract(): - print 'plotting streamlinetric tract' + print('plotting streamlinetric tract') + raise NotImplementedError diff --git a/conwhat/viz/volume.py b/conwhat/viz/volume.py index 02f10e0..445fb23 100644 --- a/conwhat/viz/volume.py +++ b/conwhat/viz/volume.py @@ -157,3 +157,11 @@ def plot_vol_and_rois_nilearn(vol,labels,roi1_img=None,roi2_img=None, return display +def plot_vol_cnxn(): + "" + + raise NotImplementedError + +def plot_vol_tract(): + + raise NotImplementedError \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b366461..e43e825 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,7 @@ nilearn dipy joblib matplotlib +sklearn +pyyaml +networkx +indexed_gzip \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 5485a90..1a08a6f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,6 +2,6 @@ VCS = git style = pep440 versionfile_source = conwhat/_version.py -versionfile_build = _version.py +versionfile_build = conwhat/_version.py tag_prefix = parentdir_prefix = conwhat- diff --git a/setup.py b/setup.py index dd4d70e..a3fc205 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,20 @@ #!/usr/bin/env python from setuptools import setup, find_packages -import versioneer +import versioneer -setup(name='conwhat', #version=versioneer.get_version(), +setup(name='conwhat', + version=versioneer.get_version(), + cmdclass=versioneer.get_cmdclass(), description='python library for connectome-based white matter atlas analyses in neuroimaging', long_description='python library for connectome-based white matter atlas analyses in neuroimaging', keywords='white matter, tractography, MRI, DTI, diffusion, python', author='John David Griffiths', author_email='j.davidgriffiths@gmail.com', url='https://github.com/JohnGriffiths/conwhat', - packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), - install_requires=['numpy', 'setuptools'], + packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), + install_requires=['numpy', 'setuptools', 'pandas', 'nibabel', 'sklearn', 'nilearn', + 'dipy', 'joblib', 'matplotlib', 'pyyaml', 'networkx', 'indexed_gzip'], classifiers=[ 'Intended Audience :: Science/Research', 'Programming Language :: Python', @@ -28,6 +31,5 @@ "console_scripts": [ "conwhat=conwhat.__main__:main", ] - }, - #cmdclass=versioneer.get_cmdclass() + } )