def write(self, path, config_list): import ast try: f = open(path, 'w') for item in config_list: label = item.get_name() value = item.get_selection() dtype = item.get_datatype() item_type = item.get_type() sample_list = item.get_values() comment = item.get_help() for line in comment.split("\n"): if line: print>>f, "#", line # prints setting names and values (ex. " runAnatomicalProcessing: [1] ") into the # pipeline_config file, using a different set of code depending on the data type # parameters that are strings (ex. " False " or a path) if dtype == 0 or dtype == 1: print >>f, label, ": ", str(value) print >>f,"\n" # parameters that are integers elif dtype == 2: # Add check for ReHo cluster if label == 'clusterSize': print 'Using ReHo cluster size of ', value elif item_type == 0: value = sample_list.index(value) else: if substitution_map.get(value) != None: value = substitution_map.get(value) elif value != 'None': value = ast.literal_eval(str(value)) print >>f, label, ": ", value print >>f,"\n" # parameters that are lists (ex. " [False, False] ") elif dtype == 3: map = ast.literal_eval(str(value)) values = [] for x in range(0, len(map.keys())): values.append(False) for k, v in map.iteritems(): item, idx = k values[idx] = v print>>f, label, ": ", values print>>f,"\n" # parameters that are switches (ex. [0] or [1] ) elif dtype == 4: values=[] if isinstance(value, list): value = ast.literal_eval(str(value)) else: value = str(value).split(",") for val in value: val = val.strip() sval = substitution_map.get(val) if sval != None: values.append(sval) else: values.append(val) if values == [10]: values = [1,0] elif values == [11]: values = ['ANTS','FSL'] elif values == [12]: values = ['3dAutoMask','BET'] print>>f, label, ": ", values print>>f,"\n" # parameters that are bracketed numbers (int or float) elif dtype == 5: ### parse user input ### can't use internal function type() here??? if value.find(',') != -1: lvalue = value.split(',') elif value.find(';') != -1: lvalue = value.split(';') elif value.find(':') != -1: lvalue = value.split(':') else: lvalue = [value] if value.find('.') != -1: lvalue = [float(item) for item in lvalue] elif len(value) > 0: lvalue = [int(item) for item in lvalue] else: lvalue = 0 print>>f, label, ":", lvalue ### print>>f, "\n" # parameters that are ? (bandpass filter specs) elif dtype == 6: values = [] for val in ast.literal_eval(str(value)): try: val=ast.literal_eval(str(val)) except Exception as err: print "Exception trying to translate: %s, %s, %s, %s"%(label,str(value),val,err) print "value type: %s"%(type(val)) values.append(ast.literal_eval(str(val))) print>>f, label, ":", values print>>f, "\n" # parameters that are whole words # ALSO: the Nuisance Corrections lists elif dtype == 8: print>>f, label,":" value = ast.literal_eval(str(value)) for val in value: val = val.split(',') f.write(" - ") flag = 0 for sample in sample_list: if flag == 0: space = "" flag = 1 else: space = " " if sample in val: print>>f, space, sample, ": ", 1 else: print>>f, space, sample, ": ", 0 print >>f, "\n" else: value = ast.literal_eval(str(value)) print>>f, label, ":", value print>>f, "\n" f.close() except Exception, e: print e print "Error Writing the pipeline configuration file %s" % path raise
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() value = item.get_selection() dtype = item.get_datatype() item_type = item.get_type() sample_list = item.get_values() comment = item.get_help() for line in comment.split("\n"): if line: print >> f, "#", line # prints setting names and values (ex. " runAnatomicalProcessing: [1] ") into the # pipeline_config file, using a different set of code depending on the data type # parameters that are strings (ex. " False " or a path) if dtype == 0 or dtype == 1: print >> f, label, ": ", str(value) print >> f, "\n" # parameters that are integers elif dtype == 2: # Add check for ReHo cluster if label == 'clusterSize': #print 'Using ReHo cluster size of ', value pass elif item_type == 0: value = sample_list.index(value) else: if substitution_map.get(value) != None: value = substitution_map.get(value) elif value != 'None': value = ast.literal_eval(str(value)) print >> f, label, ": ", value print >> f, "\n" # parameters that are lists (ex. " [False, False] ") elif dtype == 3: map = ast.literal_eval(str(value)) values = [] for x in range(0, len(map.keys())): values.append(False) for k, v in map.iteritems(): item, idx = k values[idx] = v print >> f, label, ": ", values print >> f, "\n" # parameters that are switches (ex. [0] or [1] ) elif dtype == 4: values = [] if isinstance(value, list): value = ast.literal_eval(str(value)) else: value = str(value).split(",") for val in value: val = val.strip() sval = substitution_map.get(val) if sval != None: values.append(sval) else: values.append(val) if values == [10]: values = [1, 0] elif values == [11]: values = ['ANTS', 'FSL'] elif values == [12]: values = ['3dAutoMask', 'BET'] print >> f, label, ": ", values print >> f, "\n" # parameters that are bracketed numbers (int or float) elif dtype == 5: ### parse user input ### can't use internal function type() here??? if value.find(',') != -1: lvalue = value.split(',') elif value.find(';') != -1: lvalue = value.split(';') elif value.find(':') != -1: lvalue = value.split(':') else: lvalue = [value] if value.find('.') != -1: lvalue = [float(item) for item in lvalue] elif len(value) > 0: lvalue = [int(item) for item in lvalue] else: lvalue = 0 print >> f, label, ":", lvalue ### print >> f, "\n" # parameters that are ? (bandpass filter specs) elif dtype == 6: values = [] for val in ast.literal_eval(str(value)): try: val = ast.literal_eval(str(val)) except Exception as err: print "Exception trying to translate: %s, %s, %s, %s" % ( label, str(value), val, err) print "value type: %s" % (type(val)) values.append(ast.literal_eval(str(val))) print >> f, label, ":", values print >> f, "\n" # parameters that are whole words # ALSO: the Nuisance Corrections lists elif dtype == 8: print >> f, label, ":" value = ast.literal_eval(str(value)) for val in value: val = val.split(',') f.write(" - ") flag = 0 for sample in sample_list: if flag == 0: space = "" flag = 1 else: space = " " if sample in val: print >> f, space, sample, ": ", 1 else: print >> f, space, sample, ": ", 0 print >> f, "\n" elif dtype == 9: # checkbox grid (ROI extraction etc.) string = gen_checkboxgrid_config_string(label, value) print >> f, string print >> f, "\n" else: value = ast.literal_eval(str(value)) print >> f, label, ":", value print >> f, "\n" f.close() except Exception, e: print e print "Error Writing the pipeline configuration file %s" % path raise
def write(self, path, config_list): import ast try: f = open(path, 'w') for item in config_list: label = item.get_name() value = item.get_selection() dtype = item.get_datatype() type = item.get_type() ''' print "LABEL: ", label print "VALUE: ", value print "DTYPE: ", dtype print "TYPE: ", type print "" ''' sample_list = item.get_values() comment = item.get_help() #print "*****label : type : value -->", label, " : ", dtype, " : ", value for line in comment.split("\n"): if line: print >> f, "#", line # prints setting names and values (ex. " runAnatomicalProcessing: [1] ") into the # pipeline_config file, using a different set of code depending on the data type # parameters that are strings (ex. " False " or a path) if dtype == 0 or dtype == 1: print >> f, label, ": ", str(value) print >> f, "\n" # parameters that are integers elif dtype == 2: if type == 0: value = sample_list.index(value) else: if substitution_map.get(value) != None: value = substitution_map.get(value) elif value != 'None': value = ast.literal_eval(str(value)) print >> f, label, ": ", value print >> f, "\n" # parameters that are lists (ex. " [False, False] ") elif dtype == 3: map = ast.literal_eval(str(value)) values = [] for x in range(0, len(map.keys())): values.append(False) for k, v in map.iteritems(): item, idx = k values[idx] = v print >> f, label, ": ", values print >> f, "\n" # parameters that are switches (ex. [0] or [1] ) elif dtype == 4: values = [] if isinstance(value, list): value = ast.literal_eval(str(value)) else: value = str(value).split(",") for val in value: val = val.strip() sval = substitution_map.get(val) if sval != None: values.append(sval) else: values.append(val) if values == [10]: values = [1, 0] elif values == [11]: values = ['ANTS', 'FSL'] print >> f, label, ": ", values print >> f, "\n" # parameters that are bracketed numbers (int or float) elif dtype == 5: ''' print "1: ", ast.literal_eval(value) print "2: ", ast.literal_eval(str(value)) print "3: ", value print "4: ", str(value) print "5: ", [value] print "6: ", list(value) print "7: ", [sample_list.index(val) for val in value] ''' ''' if isinstance(value, list): value = ast.literal_eval(str(value)) else: value = str(value) ''' ''' if isinstance(value, tuple): value = list(value) elif isinstance(value, list): value = [sample_list.index(val) for val in value] else: value = [value] ''' ### parse user input ### can't use internal function type() here??? if value.find(',') != -1: lvalue = value.split(',') elif value.find(';') != -1: lvalue = value.split(';') elif value.find(':') != -1: lvalue = value.split(':') else: lvalue = [value] #print 'split value: ', lvalue if value.find('.') != -1: lvalue = [float(item) for item in lvalue] elif len(value) > 0: lvalue = [int(item) for item in lvalue] else: lvalue = 0 #print 'final value: ', lvalue """ if len(value) > 1: value = float(value) elif len(value) == 1: value = int(value) else: value = 0 valueList = [] valueList.append(value) """ print >> f, label, ":", lvalue ### print >> f, "\n" # parameters that are ? (bandpass filter specs) elif dtype == 6: values = [] for val in ast.literal_eval(str(value)): values.append(ast.literal_eval(val)) print >> f, label, ":", values print >> f, "\n" # parameters that are whole words elif dtype == 8: print >> f, label, ":" value = ast.literal_eval(str(value)) for val in value: val = val.split(',') f.write(" - ") flag = 0 for sample in sample_list: if flag == 0: space = "" flag = 1 else: space = " " if sample in val: print >> f, space, sample, ": ", 1 else: print >> f, space, sample, ": ", 0 print >> f, "\n" else: value = ast.literal_eval(str(value)) print >> f, label, ":", value print >> f, "\n" f.close() except Exception, e: print e print "Error Writing the pipeline configuration file %s" % path raise Exception
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__) print >>f, "# http://fcp-indi.github.io for more info.\n#" print >>f, "# Tip: This file can be edited manually with a " \ "text editor for quick modifications.\n\n" for item in config_list: label = item.get_name() value = item.get_selection() dtype = item.get_datatype() item_type = item.get_type() sample_list = item.get_values() comment = item.get_help() for line in comment.split("\n"): if line: print>>f, "#", line # prints setting names and values (ex. " runAnatomicalProcessing: [1] ") into the # pipeline_config file, using a different set of code depending on the data type # parameters that are strings (ex. " False " or a path) if dtype == 0 or dtype == 1: print >>f, label, ": ", str(value) print >>f,"\n" # parameters that are integers elif dtype == 2: # Add check for ReHo cluster if label == 'clusterSize': #print 'Using ReHo cluster size of ', value pass elif item_type == 0: value = sample_list.index(value) else: if substitution_map.get(value) != None: value = substitution_map.get(value) elif value != 'None': try: value = ast.literal_eval(str(value)) except Exception as e: raise Exception("could not parse value: " "{0}\n\n{1}" "\n".format(str(value), e)) print >>f, label, ": ", value print >>f,"\n" # parameters that are lists (ex. " [False, False] ") elif dtype == 3: map = ast.literal_eval(str(value)) values = [] for x in range(0, len(map.keys())): values.append(False) for k, v in map.iteritems(): item, idx = k values[idx] = v print>>f, label, ": ", values print>>f,"\n" # parameters that are switches (ex. [0] or [1] ) elif dtype == 4: values=[] if isinstance(value, list): value = ast.literal_eval(str(value)) else: value = str(value).split(",") for val in value: val = val.strip() sval = substitution_map.get(val) if sval != None: values.append(sval) else: values.append(val) if values == [10]: values = [1,0] elif values == [11]: values = ['ANTS','FSL'] elif values == [12]: values = ['3dAutoMask','BET'] print>>f, label, ": ", values print>>f, "\n" # parameters that are bracketed numbers (int or float) elif dtype == 5: ### parse user input ### can't use internal function # type() here??? if value.find(',') != -1: lvalue = value.split(',') elif value.find(';') != -1: lvalue = value.split(';') elif value.find(':') != -1: lvalue = value.split(':') else: lvalue = [value] if value.find('.') != -1: lvalue = [float(item) for item in lvalue] elif len(value) > 0: try: new_lvalue = [int(item) for item in lvalue] except ValueError: # this trips only if user inputs a percentage for # de-spiking/scrubbing motion threshold new_lvalue = [str(item) for item in lvalue] lvalue = new_lvalue else: lvalue = 0 print>>f, label, ":", lvalue ### print>>f, "\n" # parameters that are ? (bandpass filter specs) elif dtype == 6: values = [] for val in ast.literal_eval(str(value)): try: val=ast.literal_eval(str(val)) except Exception as err: print "Exception trying to translate: " \ "%s, %s, %s, %s"%(label,str(value),val,err) print "value type: %s"%(type(val)) values.append(ast.literal_eval(str(val))) print>>f, label, ":", values print>>f, "\n" # parameters that are whole words # ALSO: the Nuisance Corrections lists elif dtype == 8: print>>f, label,":" value = ast.literal_eval(str(value)) for val in value: val = val.split(',') f.write(" - ") flag = 0 for sample in sample_list: if flag == 0: space = "" flag = 1 else: space = " " if sample in val: print>>f, space, sample, ": ", 1 else: print>>f, space, sample, ": ", 0 print >>f, "\n" elif dtype == 9: # checkbox grid (ROI extraction etc.) string = gen_checkboxgrid_config_string(label, value) print >>f, string print >>f, "\n" else: value = ast.literal_eval(str(value)) print>>f, label, ":", value print>>f, "\n" f.close() except Exception, e: print e print "Error Writing the pipeline configuration file %s" % path raise
def write(self, path, config_list): import ast try: f = open(path, 'w') for item in config_list: label = item.get_name() value = item.get_selection() dtype = item.get_datatype() type = item.get_type() ''' print "LABEL: ", label print "VALUE: ", value print "DTYPE: ", dtype print "TYPE: ", type print "" ''' sample_list = item.get_values() comment = item.get_help() #print "*****label : type : value -->", label, " : ", dtype, " : ", value for line in comment.split("\n"): if line: print>>f, "#", line # prints setting names and values (ex. " runAnatomicalProcessing: [1] ") into the # pipeline_config file, using a different set of code depending on the data type # parameters that are strings (ex. " False " or a path) if dtype == 0 or dtype == 1: print >>f, label, ": ", str(value) print >>f,"\n" # parameters that are integers elif dtype == 2: if type == 0: value = sample_list.index(value) else: if substitution_map.get(value) != None: value = substitution_map.get(value) elif value != 'None': value = ast.literal_eval(str(value)) print >>f, label, ": ", value print >>f,"\n" # parameters that are lists (ex. " [False, False] ") elif dtype == 3: map = ast.literal_eval(str(value)) values = [] for x in range(0, len(map.keys())): values.append(False) for k, v in map.iteritems(): item, idx = k values[idx] = v print>>f, label, ": ", values print>>f,"\n" # parameters that are switches (ex. [0] or [1] ) elif dtype == 4: values=[] if isinstance(value, list): value = ast.literal_eval(str(value)) else: value = str(value).split(",") for val in value: val = val.strip() sval = substitution_map.get(val) if sval != None: values.append(sval) else: values.append(val) if values == [10]: values = [1,0] elif values == [11]: values = ['ANTS','FSL'] elif values == [12]: values = ['3dAutoMask','BET'] print>>f, label, ": ", values print>>f,"\n" # parameters that are bracketed numbers (int or float) elif dtype == 5: ''' print "1: ", ast.literal_eval(value) print "2: ", ast.literal_eval(str(value)) print "3: ", value print "4: ", str(value) print "5: ", [value] print "6: ", list(value) print "7: ", [sample_list.index(val) for val in value] ''' ''' if isinstance(value, list): value = ast.literal_eval(str(value)) else: value = str(value) ''' ''' if isinstance(value, tuple): value = list(value) elif isinstance(value, list): value = [sample_list.index(val) for val in value] else: value = [value] ''' ### parse user input ### can't use internal function type() here??? if value.find(',') != -1: lvalue = value.split(',') elif value.find(';') != -1: lvalue = value.split(';') elif value.find(':') != -1: lvalue = value.split(':') else: lvalue = [value] #print 'split value: ', lvalue if value.find('.') != -1: lvalue = [float(item) for item in lvalue] elif len(value) > 0: lvalue = [int(item) for item in lvalue] else: lvalue = 0 #print 'final value: ', lvalue """ if len(value) > 1: value = float(value) elif len(value) == 1: value = int(value) else: value = 0 valueList = [] valueList.append(value) """ print>>f, label, ":", lvalue ### print>>f, "\n" # parameters that are ? (bandpass filter specs) elif dtype == 6: values = [] for val in ast.literal_eval(str(value)): values.append(ast.literal_eval(val)) print>>f, label, ":", values print>>f, "\n" # parameters that are whole words elif dtype == 8: print>>f, label,":" value = ast.literal_eval(str(value)) for val in value: val = val.split(',') f.write(" - ") flag = 0 for sample in sample_list: if flag == 0: space = "" flag = 1 else: space = " " if sample in val: print>>f, space, sample, ": ", 1 else: print>>f, space, sample, ": ", 0 print >>f, "\n" else: value = ast.literal_eval(str(value)) print>>f, label, ":", value print>>f, "\n" f.close() except Exception, e: print e print "Error Writing the pipeline configuration file %s" % path raise Exception