Skip to content

Commit

Permalink
Merge pull request #621 from FCP-INDI/101_to_master
Browse files Browse the repository at this point in the history
101 to master
  • Loading branch information
sgiavasis authored Dec 9, 2016
2 parents dc5383c + 1034360 commit 603beb7
Show file tree
Hide file tree
Showing 23 changed files with 2,298 additions and 1,431 deletions.
448 changes: 0 additions & 448 deletions CPAC/AWS/aws_utils.py

This file was deleted.

6 changes: 3 additions & 3 deletions CPAC/GUI/interface/pages/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, parent, counter=0):

self.page.add(label="Maximum Memory Per Participant (GB) ",
control=control.INT_CTRL,
name='memoryAllocatedPerSubject',
name='maximumMemoryPerParticipant',
type=dtype.NUM,
comment="The maximum amount of memory each " \
"participant's workflow can allocate. Use " \
Expand All @@ -104,7 +104,7 @@ def __init__(self, parent, counter=0):

self.page.add(label="Maximum Number of Cores Per Participant ",
control=control.INT_CTRL,
name='numCoresPerSubject',
name='maxCoresPerParticipant',
type=dtype.NUM,
comment="The maximum amount of cores (on a single " \
"machine) or slots on a node (on a " \
Expand All @@ -125,7 +125,7 @@ def __init__(self, parent, counter=0):

self.page.add(label="Number of Participants to Run Simultaneously ",
control=control.INT_CTRL,
name='numSubjectsAtOnce',
name='numParticipantsAtOnce',
type=dtype.NUM,
comment="The number of participant workflows to run " \
"at the same time. The maximum number of " \
Expand Down
62 changes: 50 additions & 12 deletions CPAC/GUI/interface/windows/config_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ def test_sublist(self, sublist):
wx.OK | wx.ICON_ERROR)
errDlg4.ShowModal()
errDlg4.Destroy()

# Raise Exception
raise Exception

Expand All @@ -399,20 +398,41 @@ def test_sublist(self, sublist):
wx.OK | wx.ICON_ERROR)
errDlg3.ShowModal()
errDlg3.Destroy()

# Raise Exception
raise Exception

# Iterate and test each subject's files
for sub in sublist:
anat_file = sub['anat']
func_files = sub['rest']
try:
func_files = sub['func']
except KeyError:
func_files = sub['rest']
checked_anat_s3 = False

if not anat_file:
err = "\n\n[!] Could not read in at least one of your anatom"\
"ical input files. Please double-check the formatting "\
"of your participant list YAML file.\n\n"
raise Exception(err)

if not func_files:
err = "\n\n[!] Could not read in at least one of your functi"\
"onal input files. Please double-check the formatting "\
"of your participant list YAML file.\n\n"
raise Exception(err)

if anat_file.lower().startswith(s3_str):
if checked_s3:
break
dl_dir = tempfile.mkdtemp()
creds_path = sub['creds_path']
try:
creds_path = sub['creds_path']
except KeyError:
# if no creds path is provided, it could be that the user
# is downloading public data - leave it to downstream to
# handle creds issues
creds_path = None
anat_file = check_for_s3(anat_file, creds_path, dl_dir=dl_dir)
checked_anat_s3 = True
# Check if anatomical file exists
if os.path.exists(anat_file):
img = nb.load(anat_file)
Expand All @@ -429,11 +449,25 @@ def test_sublist(self, sublist):
not_found_flg = True
err_str_suffix = 'File not found: %s\n' % anat_file
err_str = err_str + err_str_suffix
# If we're just checking s3 files, remove the temporarily
# downloaded
if checked_anat_s3:
try:
os.remove(anat_file)
except:
pass
# For each functional file
for func_file in func_files.values():
checked_s3 = False
if func_file.lower().startswith(s3_str):
dl_dir = tempfile.mkdtemp()
creds_path = sub['creds_path']
try:
creds_path = sub['creds_path']
except KeyError:
# if no creds path is provided, it could be that the
# user is downloading public data - leave it to down-
# stream to handle creds issues
creds_path = None
func_file = check_for_s3(func_file, creds_path, dl_dir=dl_dir,img_type='func')
checked_s3 = True
# Check if functional file exists
Expand All @@ -452,14 +486,13 @@ def test_sublist(self, sublist):
not_found_flg = True
err_str_suffix = 'File not found: %s\n' % func_file
err_str = err_str + err_str_suffix
# If we're just checking s3 files, remove the temporarily downloaded
# If we're just checking s3 files, remove the temporarily
# downloaded
if checked_s3:
try:
os.remove(anat_file)
os.remove(func_file)
except:
pass
break
# Check flags for error message
if not_found_flg:
err_msg = 'One or more of your input files are missing.\n'
Expand Down Expand Up @@ -754,15 +787,16 @@ def testFile(filepath, paramName, switch):
except Exception as xxx:

print xxx
print "an exception occured"
print "an exception occurred"

testDlg1.Destroy()

errDlg1 = wx.MessageDialog(
self, 'There are issues with the current configuration ' \
'which need to be resolved - please check to make ' \
'sure the options you are running have the proper ' \
'pre-requisites selected.\n\nIssue Info:\n%s' % xxx,
'pre-requisites selected.\n\nIssue Info:\n%s' \
% str(xxx),
'Pipeline Not Ready',
wx.OK | wx.ICON_ERROR)
errDlg1.ShowModal()
Expand Down Expand Up @@ -990,11 +1024,15 @@ def update_listbox(self, value):
def write(self, path, config_list):

import ast
import CPAC

try:

f = open(path, 'w')

print >>f, "# CPAC Pipeline Configuration YAML file"
print >>f, "# version %s\n" % str(CPAC.__version__)

for item in config_list:

label = item.get_name()
Expand Down
89 changes: 79 additions & 10 deletions CPAC/GUI/interface/windows/dataconfig_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ def run(self, config):
CPAC.utils.extract_data.generate_supplementary_files(sublist_outdir, sublist_name)

# Prompt user with naming subject list for main GUI
dlg2 = wx.TextEntryDialog(self, 'Please enter a name for the Subject List',
'Sublist Name', '%s' % sublist_name)
while True:
dlg2 = wx.TextEntryDialog(self, 'Please enter a name for the Subject List',
'Sublist Name', '%s' % sublist_name)
if dlg2.ShowModal() == wx.ID_OK:
if len(dlg2.GetValue()) >0:
parent = self.Parent
Expand All @@ -272,14 +272,19 @@ def run(self, config):
map[dlg2.GetValue()]= out_location
parent.listbox2.Append(dlg2.GetValue())
dlg2.Destroy()
ret = 1
break
else:
dlg3 = wx.MessageDialog(self, 'Subject List with this name already exist','Error!',
wx.OK | wx.ICON_ERROR)
dlg3.ShowModal()
dlg3.Destroy()
elif dlg2.ShowModal() == wx.ID_CANCEL:
dlg2.Destroy()
ret = -1
break
# Return value
return 1
return ret

# Import error if CPAC not available
except ImportError as exc:
Expand All @@ -304,6 +309,7 @@ def run(self, config):
def save(self, event, flag):

config_list =[]
config_dict = {}
def display(win, msg):
wx.MessageBox(msg, "Error")
win.SetBackgroundColour("pink")
Expand Down Expand Up @@ -338,6 +344,67 @@ def display(win, msg):
display(win,"%s field contains incorrect path. Please update the path!"%ctrl.get_name())

config_list.append((name, value, dtype))
config_dict[name] = (value, dtype)

# some final checks
if "BIDS" in config_dict["dataFormat"][0]:
if len(config_dict["anatomicalTemplate"][0]) > 0 or \
len(config_dict["functionalTemplate"][0]) > 0:
err = wx.MessageDialog(self, "Custom filepath template " \
"provided, but data format "\
"is set to BIDS instead of "\
"Custom.",
'Error!',
wx.OK | wx.ICON_ERROR)
err.ShowModal()
err.Destroy()
return

elif not os.path.exists(config_dict["bidsBaseDir"][0]):
err = wx.MessageDialog(self, "Data format is set to " \
"BIDS, but no BIDS base " \
"directory is set, or the " \
"BIDS directory does not " \
"exist.",
'Error!',
wx.OK | wx.ICON_ERROR)
err.ShowModal()
err.Destroy()
return

elif "Custom" in config_dict["dataFormat"][0]:
if len(config_dict["bidsBaseDir"][0]) > 0:
err = wx.MessageDialog(self, "BIDS base directory " \
"provided, but data format "\
"is set to Custom instead " \
"of BIDS.",
'Error!',
wx.OK | wx.ICON_ERROR)
err.ShowModal()
err.Destroy()
return

if len(config_dict["anatomicalTemplate"][0]) == 0:
err = wx.MessageDialog(self, "Custom data format " \
"selected, but no custom " \
"anatomical filepath " \
"template provided.",
'Error!',
wx.OK | wx.ICON_ERROR)
err.ShowModal()
err.Destroy()
return

if len(config_dict["functionalTemplate"][0]) == 0:
err = wx.MessageDialog(self, "Custom data format " \
"selected, but no custom " \
"functional filepath " \
"template provided.",
'Error!',
wx.OK | wx.ICON_ERROR)
err.ShowModal()
err.Destroy()
return

except Exception, e:

Expand All @@ -352,7 +419,7 @@ def display(win, msg):
return

else:

dlg = wx.FileDialog(
self, message="Save file as ...",
defaultDir=os.getcwd(),
Expand All @@ -364,15 +431,17 @@ def display(win, msg):
path = dlg.GetPath()
dlg.Destroy()
f = open(path, 'w')
for ctrl in config_list:
for ctrl_name in config_dict.keys():

if "/" in ctrl[1] or "%s" in ctrl[1] \
or 'None' in ctrl[1] or ctrl[0] =='subjectListName':
value = ctrl[1]
val = config_dict[ctrl_name][0]

if "/" in val or "%s" in val or 'None' in val or \
ctrl_name =='subjectListName':
value = val
else:
value =[val.strip() for val in ctrl[1].split(',')]
value =[item.strip() for item in val.split(',')]

print >>f, ctrl[0], " : ", value, "\n"
print >>f, ctrl_name, " : ", value, "\n"

f.close()
print "saving %s"%path
Expand Down
26 changes: 18 additions & 8 deletions CPAC/GUI/interface/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def runAnalysis1(self,pipeline, sublist, p):
from CPAC.utils import Configuration
from nipype.pipeline.plugins.callback_log import log_nodes_cb
c = Configuration(yaml.load(open(os.path.realpath(pipeline), 'r')))
plugin_args = {'n_procs': c.numCoresPerSubject,
'memory_gb': c.memoryAllocatedPerSubject,
plugin_args = {'n_procs': c.maxCoresPerParticipant,
'memory_gb': c.maximumMemoryPerParticipant,
'callback_log' : log_nodes_cb}

CPAC.pipeline.cpac_runner.run(pipeline, sublist, p,
Expand Down Expand Up @@ -676,12 +676,22 @@ def AddConfig(self, event):
try:
c = Configuration(f_cfg)
except Exception as e:
print '\n\nERROR: Configuration file could not be '\
'loaded properly - the file might be '\
'access-protected or you might have chosen the '\
'wrong file.\n'
print 'Error name: main_window_0001\n\n'
print 'Exception: %s' % e
if "object has no attribute" in e:
err = "%s\n\nIs this attribute linked (using " \
"'${}') in any of your configuration " \
"parameters? (Standard template paths, " \
"for example). If this is a pipeline " \
"configuration file from an older version "\
"of CPAC, this parameter may be obsolete. "\
"Double-check your selections.\n\n" % e
print err
else:
print '\n\nERROR: Configuration file could not ' \
'be loaded properly - the file might be '\
'access-protected or you might have ' \
'chosen the wrong file.\n'
print 'Error name: main_window_0001\n\n'
print 'Exception: %s' % e
# Valid pipeline name
if c.pipelineName != None:
if self.pipeline_map.get(c.pipelineName) == None:
Expand Down
6 changes: 3 additions & 3 deletions CPAC/GUI/resources/config_parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ FSLDIR,FSL Path,Computer Settings
resourceManager,Job Scheduler / Resource Manager,Computer Settings
parallelEnvironment,SGE Parallel Environment,Computer Settings
queue,SGE Queue,Computer Settings
numCoresPerSubject,Maximum Number of Cores Per Participant,Computer Settings
numSubjectsAtOnce,Number of Participants to Run Simultaneously,Computer Settings
maxCoresPerParticipant,Maximum Number of Cores Per Participant,Computer Settings
numParticipantsAtOnce,Number of Participants to Run Simultaneously,Computer Settings
num_ants_threads,Number of Cores for Anatomical Registration (ANTS only),Computer Settings
memoryAllocatedPerSubject,Maximum Memory Per Participant (GB),Computer Settings
maximumMemoryPerParticipant,Maximum Memory Per Participant (GB),Computer Settings
pipelineName,Pipeline Name,Output Settings
workingDirectory,Working Directory,Output Settings
crashLogDirectory,Crash Log Directory,Output Settings
Expand Down
2 changes: 1 addition & 1 deletion CPAC/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test(self, label='fast', verbose=1, extra_argv=['--exe'], doctests = False,
#__version__ = '0.1-git'

try:
version = '1.0.0'
version = '1.0.1'


# gitproc = Popen(['git', 'log', '--oneline'], stdout = PIPE)
Expand Down
Loading

0 comments on commit 603beb7

Please sign in to comment.