Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Workflow ParcFodToConnectivity #33

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions bin/run_parc_fod_to_connectome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import logging
import sys

from tvb.recon.flow.parc_fod_to_connectome import ParcFodToConnectome
from tvb.recon.cli.runner import SimpleRunner


logging.basicConfig(level=logging.INFO)

parc, fod, track_counts, mean_lengths, gmwmi, ftt = sys.argv[1:]
runner = SimpleRunner()
convtest = ParcFodToConnectome(parc, fod, track_counts, mean_lengths, gmwmi, ftt)

convtest.run(runner)
8 changes: 7 additions & 1 deletion provision/00-system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ else
mkdir $PREFIX
chown -R ubuntu:ubuntu $prefix_base
fi


# Move temp dir
mkdir /work/tmp
chmod 1777 /work/tmp
sudo rm -r /tmp
sudo ln -s /work/tmp /tmp

# setup /work/env/lib as system wide library location
echo /work/env/lib > /etc/ld.so.conf.d/work.conf
ldconfig
Expand Down
6 changes: 2 additions & 4 deletions tvb/recon/cli/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def __new__(cls: type, name: str, bases: Tuple[type],
attrs: Dict[str, object]) -> type:
for key, value in list(attrs.items()):
if not key.startswith('_'):
value:
str
value: str
attrs[key] = Flag(key, value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is valid syntax for local variable type declaration in Python 3.6; I think I wrote that just to convince PyCharm that value was a string. Still, I admit I have no idea why it's on two lines, and deleting these lines is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, on one line it makes sense (this two line syntax is invalid under 3.6, at least according to the interpreter). I'll put it back.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I don't know how the two line thing happened, honestly

return super().__new__(cls, name, bases, attrs)

Expand All @@ -55,8 +54,7 @@ def __new__(cls: type, name: str, bases: Tuple[type],
attrs: Dict[str, object]) -> type:
for key, value in list(attrs.items()):
if not key.startswith('_'):
value:
str
value: str
attrs[key] = EnvVar(key, value)
return super().__new__(cls, name, bases, attrs)

Expand Down
20 changes: 14 additions & 6 deletions tvb/recon/cli/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,18 @@ class Flags(BaseFsCLI.Flags):
all_ = '-all'
parallel = '-parallel'
openmp = '-openmp'
t2 = '-T2'
t2_pial = '-T2pial'
flair = '-FLAIR'
flair_pial = '-FLAIRpial'


def reconstruct(subjid: str,
input_,
all_: bool=True,
parallel: bool=False,
openmp: int=4
openmp_num_threads: int=4,
t2=None,
flair=None,
):
"""
Perform the FreeSurfer reconstruction process.
Expand All @@ -241,13 +246,16 @@ def reconstruct(subjid: str,
args = [
recon_all.exe,
recon_all.Flags.subjid, subjid,
recon_all.Flags.input_, input_
recon_all.Flags.input_, input_,
recon_all.Flags.all_
]
if all_:
args += [recon_all.Flags.all_]
if parallel:
args += [recon_all.Flags.parallel]
args += [recon_all.Flags.openmp, openmp]
args += [recon_all.Flags.openmp, openmp_num_threads]
if t2:
args += [recon_all.Flags.t2, t2, recon_all.Flags.t2_pial]
if flair:
args += [recon_all.Flags.flair, flair, recon_all.Flags.flair_pial]

return args

Expand Down
166 changes: 163 additions & 3 deletions tvb/recon/cli/mrtrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

import enum
import os
import abc
from .core import BaseCLI, BaseEnv, BaseFlags


Expand Down Expand Up @@ -165,11 +167,61 @@ class tck2connectome(BaseMtrixCLI):
"""

class Flags(BaseMtrixCLI.Flags):
assignment_radial_search = "-assignment_radial_search"
assignment_end_voxels = "-assignment_end_voxels"
scale_length = "-scale_length"
out_assignments = "-out_assignments"
stat_edge = "-stat_edge"

class Assignment:
def __init__(self, suffix, *extras):
self.flag = '-assignment_' + suffix
self.extras = extras

def to_args(self):
return [self.flag] + list(self.extras)

@classmethod
def end_voxels(cls):
return cls('end_voxels')

@classmethod
def radial_search(cls, radius):
return cls('radial_search', str(radius))

@classmethod
def reverse_search(cls, max_dist):
return cls('reverse_search', str(max_dist))

@classmethod
def forward_search(cls, max_dist):
return cls('forward_search', str(max_dist))

@classmethod
def all_voxels(cls):
return cls('all_voxels')

class Scale:
def __init__(self, suffix, *extras):
self.flag = '-scale_' + suffix
self.extras = extras

def to_args(self):
return [self.flag] + list(self.extras)

@classmethod
def length(cls):
return cls('length')

@classmethod
def invlength(cls):
return cls('invlength')

@classmethod
def invnodevol(cls):
return cls('invnodevol')

@classmethod
def file(cls, path):
return cls('file', path)

class stat_edge(enum.Enum):
sum = "sum"
mean = "mean"
Expand All @@ -179,6 +231,18 @@ class stat_edge(enum.Enum):
exe = 'tck2connectome'


class tckedit(BaseMtrixCLI):
"""
The tckedit command from the mtrix package.

"""

class Flags(BaseMtrixCLI.Flags):
pass

exe = 'tckedit'


class tckgen(BaseMtrixCLI):
"""
The tckgen command from the mtrix package.
Expand Down Expand Up @@ -225,5 +289,101 @@ class Flags(BaseMtrixCLI.Flags):
exe = 'tcksift'


class tckstats(BaseMtrixCLI):
"""
The tckstats command from the mtrix package.

"""

class Flags(BaseMtrixCLI.Flags):
dump = '-dump'

exe = 'tckstats'


def extract_bzero(in_, out):
return [dwiextract.exe, dwiextract.Flags.bzero, in_, out]


def run_tckgen(source: os.PathLike,
tracks: os.PathLike,
ntracks: int,
seed_gmwmi: os.PathLike=None,
act: os.PathLike=None,
unidirectional: bool=True,
maxlength: float=250.0,
step: float=0.5,
):
args = [
tckgen.exe, source, tracks,
tckgen.Flags.number, ntracks,
tckgen.Flags.maxlength, maxlength,
tckgen.Flags.step, step
]
if unidirectional:
args += [tckgen.Flags.unidirectional]

if act:
args += [tckgen.Flags.act, act]
if seed_gmwmi:
args += [tckgen.Flags.seed_gmwmi, seed_gmwmi]

return args


def run_tcksift(in_tracks: os.PathLike,
in_fod: os.PathLike,
out_tracks: os.PathLike,
term_number: int,
act: os.PathLike=None
):
args = [
tcksift.exe, in_tracks, in_fod, out_tracks,
tcksift.Flags.term_number, term_number
]
if act:
args += [tcksift.Flags.act, act]

return args


def merge_trackfiles(tracks_a: os.PathLike,
tracks_b: os.PathLike,
tracks_merged: os.PathLike):

return [tckedit.exe, tracks_a, tracks_b, tracks_merged]


def dump_streamlines_length(tracks: os.PathLike,
lengths: os.PathLike):
return [tckstats.exe, tracks, tckstats.Flags.dump, lengths]


def run_labelconvert(image_in: os.PathLike,
lut_in: os.PathLike,
lut_out: os.PathLike,
image_out: os.PathLike):

return [labelconvert.exe, image_in, lut_in, lut_out, image_out]


def run_tck2connectome(track_in: os.PathLike,
nodes_in: os.PathLike,
connectome_out: os.PathLike,
assignment: tck2connectome.Assignment=None,
scale: tck2connectome.Scale=None,
stat_edge: tck2connectome.stat_edge=tck2connectome.stat_edge.sum,
out_assignments: os.PathLike=None
):
args = [
tck2connectome.exe, track_in, nodes_in, connectome_out,
tck2connectome.Flags.stat_edge, stat_edge
]
if assignment:
args += assignment.to_args()
if scale:
args += scale.to_args()
if out_assignments:
args += [tck2connectome.Flags.out_assignments, out_assignments]

return args
Loading