Skip to content

Commit

Permalink
STY: Further simplification
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Markiewicz <[email protected]>
  • Loading branch information
DimitriPapadopoulos and effigies committed Oct 6, 2024
1 parent 0fdc45e commit 2685c02
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion nipype/algorithms/modelgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def bids_gen_info(
for bids_event_file in bids_event_files:
with open(bids_event_file) as f:
f_events = csv.DictReader(f, skipinitialspace=True, delimiter="\t")
events = [dict(row.items()) for row in f_events]
events = list(f_events)
if not condition_column:
condition_column = "_trial_type"
for i in events:
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def load_inputs_from_json(self, json_file, overwrite=True):
if not overwrite:
def_inputs = list(self.inputs.get_traitsfree().keys())

new_inputs = list(set(inputs_dict.keys()) - set(def_inputs))
new_inputs = set(inputs_dict) - set(def_inputs)
for key in new_inputs:
if hasattr(self.inputs, key):
setattr(self.inputs, key, inputs_dict[key])
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/diffusion_toolkit/dti.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class DTIRecon(CommandLine):
def _create_gradient_matrix(self, bvecs_file, bvals_file):
_gradient_matrix_file = "gradient_matrix.txt"
with open(bvals_file) as fbvals:
bvals = list(re.split(r"\s+", fbvals.readline().strip()))
bvals = fbvals.readline().strip().split()
with open(bvecs_file) as fbvecs:
bvecs_x = fbvecs.readline().split()
bvecs_y = fbvecs.readline().split()
Expand Down
12 changes: 6 additions & 6 deletions nipype/interfaces/diffusion_toolkit/odf.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ class HARDIMat(CommandLine):

def _create_gradient_matrix(self, bvecs_file, bvals_file):
_gradient_matrix_file = "gradient_matrix.txt"
bvals = list(re.split(r"\s+", open(bvals_file).readline().strip()))
bvecs_f = open(bvecs_file)
bvecs_x = list(re.split(r"\s+", bvecs_f.readline().strip()))
bvecs_y = list(re.split(r"\s+", bvecs_f.readline().strip()))
bvecs_z = list(re.split(r"\s+", bvecs_f.readline().strip()))
bvecs_f.close()
with open(bvals_file) as bvals_f:
bvals = bvals_f.readline().strip().split()
with open(bvecs_file) as bvecs_f:
bvecs_x = bvecs_f.readline().strip().split()
bvecs_y = bvecs_f.readline().strip().split()
bvecs_z = bvecs_f.readline().strip().split()
gradient_matrix_f = open(_gradient_matrix_file, "w")
for i in range(len(bvals)):
if int(bvals[i]) == 0:
Expand Down
10 changes: 5 additions & 5 deletions nipype/interfaces/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ def _list_outputs(self):
if self.inputs.sort_filelist:
outfiles = human_order_sorted(outfiles)
outputs[key].append(simplify_list(outfiles))
if any(val is None for val in outputs[key]):
if None in outputs[key]:
outputs[key] = []
if len(outputs[key]) == 0:
outputs[key] = None
Expand Down Expand Up @@ -1300,7 +1300,7 @@ def _list_outputs(self):
if self.inputs.drop_blank_outputs:
outputs[key] = [x for x in outputs[key] if x is not None]
else:
if any(val is None for val in outputs[key]):
if None in outputs[key]:
outputs[key] = []
if len(outputs[key]) == 0:
outputs[key] = None
Expand Down Expand Up @@ -2305,7 +2305,7 @@ def __init__(self, input_names, **inputs):
super().__init__(**inputs)

self._input_names = ensure_list(input_names)
add_traits(self.inputs, list(self._input_names))
add_traits(self.inputs, self._input_names)

def _list_outputs(self):
"""Execute this module."""
Expand Down Expand Up @@ -2367,7 +2367,7 @@ def __init__(self, input_names, **inputs):
super().__init__(**inputs)

self._input_names = ensure_list(input_names)
add_traits(self.inputs, list(self._input_names))
add_traits(self.inputs, self._input_names)

def _list_outputs(self):
"""Execute this module."""
Expand Down Expand Up @@ -2645,7 +2645,7 @@ def _list_outputs(self):
outputs[key].append(self._get_files_over_ssh(filledtemplate))

# disclude where there was any invalid matches
if any(val is None for val in outputs[key]):
if None in outputs[key]:
outputs[key] = []

# no outputs is None, not empty list
Expand Down
4 changes: 2 additions & 2 deletions nipype/interfaces/spm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _parse_inputs(self):
"""validate spm realign options if set to None ignore"""
einputs = super()._parse_inputs(skip=("mask_threshold", "flags"))
if isdefined(self.inputs.flags):
einputs[0].update(dict(self.inputs.flags.items()))
einputs[0].update(self.inputs.flags)
for sessinfo in einputs[0]["sess"]:
sessinfo["scans"] = scans_for_fnames(
ensure_list(sessinfo["scans"]), keep4d=False
Expand Down Expand Up @@ -309,7 +309,7 @@ def _parse_inputs(self):
"""validate spm realign options if set to None ignore"""
einputs = super()._parse_inputs(skip=("flags"))
if isdefined(self.inputs.flags):
einputs[0].update(dict(self.inputs.flags.items()))
einputs[0].update(self.inputs.flags)
return einputs

def _list_outputs(self):
Expand Down
6 changes: 2 additions & 4 deletions nipype/interfaces/utility/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ def __init__(
self.inputs.on_trait_change(self._set_function_string, "function_str")
self._input_names = ensure_list(input_names)
self._output_names = ensure_list(output_names)
add_traits(self.inputs, list(self._input_names))
add_traits(self.inputs, self._input_names)
self.imports = imports
self._out = {}
for name in self._output_names:
self._out[name] = None
self._out = {name: None for name in self._output_names}

def _set_function_string(self, obj, name, old, new):
if name == "function_str":
Expand Down
4 changes: 1 addition & 3 deletions nipype/pipeline/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,9 +1483,7 @@ def clean_working_directory(
if str2bool(config["execution"]["remove_unnecessary_outputs"]):
for f in walk_files(cwd):
if f not in needed_files:
if not needed_dirs:
files2remove.append(f)
elif not any(f.startswith(dname) for dname in needed_dirs):
if not f.startswith(tuple(needed_dirs)):
files2remove.append(f)
else:
if not str2bool(config["execution"]["keep_inputs"]):
Expand Down
2 changes: 1 addition & 1 deletion nipype/utils/docparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def _parse_doc(doc, style=["--"]):
flag = [
item
for i, item in enumerate(linelist)
if i < 2 and any(item.startswith(s) for s in style) and len(item) > 1
if i < 2 and item.startswith(tuple(style)) and len(item) > 1
]
if flag:
if len(flag) == 1:
Expand Down

0 comments on commit 2685c02

Please sign in to comment.