Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 25469f1

Browse files
Merge pull request #3680 from DimitriPapadopoulos/C4
STY: Apply ruff/flake8-comprehensions rules (C4)
2 parents 6ac81ca + 1747356 commit 25469f1

File tree

22 files changed

+46
-55
lines changed

22 files changed

+46
-55
lines changed

‎nipype/algorithms/modelgen.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def bids_gen_info(
161161
for bids_event_file in bids_event_files:
162162
with open(bids_event_file) as f:
163163
f_events = csv.DictReader(f, skipinitialspace=True, delimiter="\t")
164-
events = [{k: vfork, vinrow.items()} forrowinf_events]
164+
events = list(f_events)
165165
if not condition_column:
166166
condition_column = "_trial_type"
167167
for i in events:

‎nipype/algorithms/tests/test_CompCor.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ def run_cc(
287287
components_metadata = [
288288
line.rstrip().split("\t") for line in metadata_file
289289
]
290-
components_metadata = {
291-
i: jfori, jinzip(components_metadata[0], components_metadata[1])
292-
}
290+
components_metadata = dict(
291+
zip(components_metadata[0], components_metadata[1])
292+
)
293293
assert components_metadata == expected_metadata
294294

295295
return ccresult

‎nipype/interfaces/ants/segmentation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def _format_arg(self, opt, spec, val):
194194
priors_paths[0] % i for i in range(1, n_classes + 1)
195195
]
196196

197-
if not all([os.path.exists(p) for p in priors_paths]):
197+
if not all(os.path.exists(p) for p in priors_paths):
198198
raise FileNotFoundError(
199199
"One or more prior images do not exist: "
200200
"%s." % ", ".join(priors_paths)

‎nipype/interfaces/base/core.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def load_inputs_from_json(self, json_file, overwrite=True):
486486
if not overwrite:
487487
def_inputs = list(self.inputs.get_traitsfree().keys())
488488

489-
new_inputs = list(set(list(inputs_dict.keys())) - set(def_inputs))
489+
new_inputs = set(inputs_dict) - set(def_inputs)
490490
for key in new_inputs:
491491
if hasattr(self.inputs, key):
492492
setattr(self.inputs, key, inputs_dict[key])

‎nipype/interfaces/cmtk/cmtk.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def cmat(
248248
axis=1,
249249
)
250250
)
251-
G.nodes[int(u)]["dn_position"] = tuple([xyz[0], xyz[2], -xyz[1]])
251+
G.nodes[int(u)]["dn_position"] = (xyz[0], xyz[2], -xyz[1])
252252

253253
if intersections:
254254
iflogger.info("Filtering tractography from intersections")
@@ -1070,7 +1070,7 @@ def create_nodes(roi_file, resolution_network_file, out_filename):
10701070
np.where(np.flipud(roiData) == int(d["dn_correspondence_id"])), axis=1
10711071
)
10721072
)
1073-
G.nodes[int(u)]["dn_position"] = tuple([xyz[0], xyz[2], -xyz[1]])
1073+
G.nodes[int(u)]["dn_position"] = (xyz[0], xyz[2], -xyz[1])
10741074
with open(out_filename, 'wb') as f:
10751075
pickle.dump(G, f, pickle.HIGHEST_PROTOCOL)
10761076
return out_filename

‎nipype/interfaces/diffusion_toolkit/dti.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class DTIRecon(CommandLine):
9797
def _create_gradient_matrix(self, bvecs_file, bvals_file):
9898
_gradient_matrix_file = "gradient_matrix.txt"
9999
with open(bvals_file) as fbvals:
100-
bvals = [valforvalinre.split(r"\s+", fbvals.readline().strip())]
100+
bvals = fbvals.readline().strip().split()
101101
with open(bvecs_file) as fbvecs:
102102
bvecs_x = fbvecs.readline().split()
103103
bvecs_y = fbvecs.readline().split()

‎nipype/interfaces/diffusion_toolkit/odf.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ class HARDIMat(CommandLine):
9898

9999
def _create_gradient_matrix(self, bvecs_file, bvals_file):
100100
_gradient_matrix_file = "gradient_matrix.txt"
101-
bvals= [valforvalinre.split(r"\s+", open(bvals_file).readline().strip())]
102-
bvecs_f=open(bvecs_file)
103-
bvecs_x= [valforvalinre.split(r"\s+", bvecs_f.readline().strip())]
104-
bvecs_y= [valforvalinre.split(r"\s+", bvecs_f.readline().strip())]
105-
bvecs_z= [valforvalinre.split(r"\s+", bvecs_f.readline().strip())]
106-
bvecs_f.close()
101+
withopen(bvals_file)asbvals_f:
102+
bvals=bvals_f.readline().strip().split()
103+
withopen(bvecs_file) asbvecs_f:
104+
bvecs_x=bvecs_f.readline().strip().split()
105+
bvecs_y=bvecs_f.readline().strip().split()
106+
bvecs_z=bvecs_f.readline().strip().split()
107107
gradient_matrix_f = open(_gradient_matrix_file, "w")
108108
for i in range(len(bvals)):
109109
if int(bvals[i]) == 0:

‎nipype/interfaces/freesurfer/preprocess.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,11 @@ def _get_runs(self):
692692
if self.inputs.seq_list:
693693
if self.inputs.ignore_single_slice:
694694
if (int(s[8]) > 1) and any(
695-
[s[12].startswith(sn) for sn in self.inputs.seq_list]
695+
s[12].startswith(sn) for sn in self.inputs.seq_list
696696
):
697697
runs.append(int(s[2]))
698698
else:
699-
if any([s[12].startswith(sn) for sn in self.inputs.seq_list]):
699+
if any(s[12].startswith(sn) for sn in self.inputs.seq_list):
700700
runs.append(int(s[2]))
701701
else:
702702
runs.append(int(s[2]))

‎nipype/interfaces/fsl/model.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,8 +1503,8 @@ def _run_interface(self, runtime):
15031503
regs = sorted(self.inputs.regressors.keys())
15041504
nwaves = len(regs)
15051505
npoints = len(self.inputs.regressors[regs[0]])
1506-
ntcons = sum([1 for con in self.inputs.contrasts if con[1] == "T"])
1507-
nfcons = sum([1 for con in self.inputs.contrasts if con[1] == "F"])
1506+
ntcons = sum(1 for con in self.inputs.contrasts if con[1] == "T")
1507+
nfcons = sum(1 for con in self.inputs.contrasts if con[1] == "F")
15081508
# write mat file
15091509
mat_txt = ["/NumWaves %d" % nwaves, "/NumPoints %d" % npoints]
15101510
ppheights = []
@@ -1591,7 +1591,7 @@ def _run_interface(self, runtime):
15911591

15921592
def _list_outputs(self):
15931593
outputs = self._outputs().get()
1594-
nfcons = sum([1 for con in self.inputs.contrasts if con[1] == "F"])
1594+
nfcons = sum(1 for con in self.inputs.contrasts if con[1] == "F")
15951595
for field in list(outputs.keys()):
15961596
if ("fts" in field) and (nfcons == 0):
15971597
continue

‎nipype/interfaces/io.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ def _list_outputs(self):
942942
# get list of all files in s3 bucket
943943
conn = boto.connect_s3(anon=self.inputs.anon)
944944
bkt = conn.get_bucket(self.inputs.bucket)
945-
bkt_files = list(k.key for k in bkt.list(prefix=self.inputs.bucket_path))
945+
bkt_files = [k.key for k in bkt.list(prefix=self.inputs.bucket_path)]
946946

947947
# keys are outfields, args are template args for the outfield
948948
for key, args in list(self.inputs.template_args.items()):
@@ -1022,7 +1022,7 @@ def _list_outputs(self):
10221022
if self.inputs.sort_filelist:
10231023
outfiles = human_order_sorted(outfiles)
10241024
outputs[key].append(simplify_list(outfiles))
1025-
if any([valisNone forvalin outputs[key]]):
1025+
if None in outputs[key]:
10261026
outputs[key] = []
10271027
if len(outputs[key]) == 0:
10281028
outputs[key] = None
@@ -1297,7 +1297,7 @@ def _list_outputs(self):
12971297
if self.inputs.drop_blank_outputs:
12981298
outputs[key] = [x for x in outputs[key] if x is not None]
12991299
else:
1300-
if any([valisNone forvalin outputs[key]]):
1300+
if None in outputs[key]:
13011301
outputs[key] = []
13021302
if len(outputs[key]) == 0:
13031303
outputs[key] = None
@@ -2302,7 +2302,7 @@ def __init__(self, input_names, **inputs):
23022302
super().__init__(**inputs)
23032303

23042304
self._input_names = ensure_list(input_names)
2305-
add_traits(self.inputs, [namefornameinself._input_names])
2305+
add_traits(self.inputs, self._input_names)
23062306

23072307
def _list_outputs(self):
23082308
"""Execute this module."""
@@ -2364,7 +2364,7 @@ def __init__(self, input_names, **inputs):
23642364
super().__init__(**inputs)
23652365

23662366
self._input_names = ensure_list(input_names)
2367-
add_traits(self.inputs, [namefornameinself._input_names])
2367+
add_traits(self.inputs, self._input_names)
23682368

23692369
def _list_outputs(self):
23702370
"""Execute this module."""
@@ -2642,7 +2642,7 @@ def _list_outputs(self):
26422642
outputs[key].append(self._get_files_over_ssh(filledtemplate))
26432643

26442644
# disclude where there was any invalid matches
2645-
if any([valisNone forvalin outputs[key]]):
2645+
if None in outputs[key]:
26462646
outputs[key] = []
26472647

26482648
# no outputs is None, not empty list

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /