Skip to content

Commit

Permalink
Merge pull request #444 from dPys/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
dPys authored Sep 25, 2020
2 parents 4c96cc5 + cf47579 commit 3434912
Show file tree
Hide file tree
Showing 23 changed files with 820 additions and 982 deletions.
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Required

:(B): A supported connectivity model specified with the `-mod` flag. If PyNets is executed in multimodal mode (i.e. with both fMRI and dMRI inputs in the same command-line call), multiple modality-applicable connectivity models should be specified (minimally providing at least one for either modality). PyNets will automatically parse which model is appropriate for which data.

:(C): If an atlas is not specified with the `-a` flag must be included, then a parcellation file must be specified with the `-ua` flag. The following curated list of atlases is currently supported:
:(C): If an atlas is not specified with the `-a` flag, then a parcellation file must be specified with the `-ua` flag. The following curated list of atlases is currently supported:

:Atlas Library:
- 'atlas_harvard_oxford'
Expand Down
2 changes: 1 addition & 1 deletion pynets/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# from ._version import get_versions
# __version__ = get_versions()['version']
# del get_versions
__version__ = "1.0.15"
__version__ = "1.0.16"

__packagename__ = "pynets"
__copyright__ = "Copyright 2016, Derek Pisner"
Expand Down
442 changes: 206 additions & 236 deletions pynets/cli/pynets_run.py

Large diffs are not rendered by default.

100 changes: 36 additions & 64 deletions pynets/core/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class FetchNodesLabels(SimpleInterface):
output_spec = _FetchNodesLabelsOutputSpec

def _run_interface(self, runtime):
import sys
from pynets.core import utils, nodemaker
from nipype.utils.filemanip import fname_presuffix, copyfile
from nilearn.image import concat_imgs
Expand Down Expand Up @@ -109,13 +110,9 @@ def _run_interface(self, runtime):
else:
parcel_list = None
else:
try:
raise FileNotFoundError(
f"\nAtlas file for {self.inputs.atlas} not found!"
)
except FileNotFoundError:
import sys
sys.exit(0)
raise FileNotFoundError(
f"\nAtlas file for {self.inputs.atlas} not found!"
)

atlas = self.inputs.atlas
elif (
Expand Down Expand Up @@ -167,12 +164,9 @@ def _run_interface(self, runtime):
else:
parcel_list = None
else:
try:
raise FileNotFoundError(
f"\nAtlas file for {self.inputs.atlas} not found!")
except FileNotFoundError:
import sys
sys.exit(0)
raise FileNotFoundError(
f"\nAtlas file for {self.inputs.atlas} not found!")

par_max = None
atlas = self.inputs.atlas
label_intensities = None
Expand Down Expand Up @@ -205,13 +199,13 @@ def _run_interface(self, runtime):
parcel_list = None
# Describe user atlas coords
print(f"\n{self.inputs.atlas} comes with {par_max} parcels\n")
except ValueError:
import sys
print(
except ValueError as e:
print(e,
"Either you have specified the name of an atlas that does"
" not exist in the nilearn or local repository or you have"
" not supplied a 3d atlas parcellation image!")
sys.exit(0)
import sys
sys.exit(1)
labels = None
networks_list = None
atlas = self.inputs.atlas
Expand Down Expand Up @@ -251,24 +245,21 @@ def _run_interface(self, runtime):

# Describe user atlas coords
print(f"\n{atlas} comes with {par_max} parcels\n")
except ValueError:
import sys
print(
except ValueError as e:
print(e,
"Either you have specified the name of an atlas that does"
" not exist in the nilearn or local repository or you have"
" not supplied a 3d atlas parcellation image!")
sys.exit(0)
import sys
sys.exit(1)
labels = None
networks_list = None
else:
try:
raise ValueError(
"Either you have specified the name of an atlas that does"
" not exist in the nilearn or local repository or you have"
" not supplied a 3d atlas parcellation image!")
except ValueError:
import sys
sys.exit(0)
raise ValueError(
"Either you have specified the name of an atlas that does"
" not exist in the nilearn or local repository or you have"
" not supplied a 3d atlas parcellation image!")

# Labels prep
if atlas and not labels:
if (self.inputs.ref_txt is not None) and (
Expand Down Expand Up @@ -758,15 +749,11 @@ def run_bs_iteration(i, ts_data, work_dir, local_corr,
parcellation.to_filename(out_path)

else:
try:
raise ValueError(
"Clustering method not recognized. See: "
"https://nilearn.github.io/modules/generated/"
"nilearn.regions.Parcellations."
"html#nilearn.regions.Parcellations")
except ValueError:
import sys
sys.exit(0)
raise ValueError(
"Clustering method not recognized. See: "
"https://nilearn.github.io/modules/generated/"
"nilearn.regions.Parcellations."
"html#nilearn.regions.Parcellations")

# Give it a minute
ix = 0
Expand All @@ -776,12 +763,8 @@ def run_bs_iteration(i, ts_data, work_dir, local_corr,
ix += 1

if not os.path.isfile(nip.uatlas):
try:
raise FileNotFoundError(f"Parcellation clustering failed for"
f" {nip.uatlas}")
except FileNotFoundError:
import sys
sys.exit(0)
raise FileNotFoundError(f"Parcellation clustering failed for"
f" {nip.uatlas}")

self._results["atlas"] = atlas
self._results["uatlas"] = nip.uatlas
Expand Down Expand Up @@ -936,12 +919,10 @@ def _run_interface(self, runtime):
== te.ts_within_nodes.shape[1]
)
except AssertionError as e:
import sys
e.args += ('Coords: ', len(self.inputs.coords),
self.inputs.coords, 'Labels:',
len(self.inputs.labels),
self.inputs.labels, te.ts_within_nodes.shape)
raise

self._results["ts_within_nodes"] = te.ts_within_nodes
self._results["node_size"] = te.node_size
Expand Down Expand Up @@ -2311,11 +2292,11 @@ def _run_interface(self, runtime):
aligned_atlas_gm, self.inputs.coords,
self.inputs.labels)

except FileNotFoundError:
except FileNotFoundError as e:
import sys
print('T1w-space parcellation not found. Did you delete '
print(e, 'T1w-space parcellation not found. Did you delete '
'outputs?')
sys.exit(0)
sys.exit(1)
else:
if self.inputs.uatlas is None:
uatlas_tmp_path = None
Expand Down Expand Up @@ -2475,13 +2456,11 @@ def _run_interface(self, runtime):
) if i != 0]
try:
assert len(coords) == len(labels) == len(intensities)
except ValueError as err:
import sys
print('Failed!')
except ValueError as e:
print(e, 'Failed!')
print(f"# Coords: {len(coords)}")
print(f"# Labels: {len(labels)}")
print(f"# Intensities: {len(intensities)}")
sys.exit(1)

self._results["aligned_atlas_gm"] = aligned_atlas_gm
self._results["coords"] = coords
Expand Down Expand Up @@ -2697,6 +2676,7 @@ class Tracking(SimpleInterface):
def _run_interface(self, runtime):
import gc
import os
import sys
import os.path as op
from dipy.io import load_pickle
from colorama import Fore, Style
Expand Down Expand Up @@ -2945,11 +2925,7 @@ def _run_interface(self, runtime):
f" Maximum"
)
else:
try:
raise ValueError("Direction-getting type not recognized!")
except ValueError:
import sys
sys.exit(0)
raise ValueError("Direction-getting type not recognized!")

print(Style.RESET_ALL)

Expand Down Expand Up @@ -3039,12 +3015,8 @@ def _run_interface(self, runtime):
f"streamlines output {namer_dir}/{op.basename(streams)}"
f" is recommended.")
if len(streamlines) < 0.5*orig_count:
try:
raise ValueError('LiFE revealed no plausible streamlines '
'in the tractogram!')
except ValueError:
import sys
sys.exit(0)
raise ValueError('LiFE revealed no plausible streamlines '
'in the tractogram!')
del dwi_data, mask_data

stf = StatefulTractogram(
Expand Down
Loading

0 comments on commit 3434912

Please sign in to comment.