Skip to content

Commit

Permalink
Run ruff fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed May 7, 2024
1 parent 29d61b9 commit b39f054
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 350 deletions.
20 changes: 10 additions & 10 deletions src/fmripost_aroma/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,21 +356,21 @@ def _bids_filter(value, parser):
),
)
g_aroma.add_argument(

Check warning on line 358 in src/fmripost_aroma/cli/parser.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/cli/parser.py#L358

Added line #L358 was not covered by tests
"--denoising-method",
action="store",
nargs="+",
choices=["aggr", "nonaggr", "orthaggr"],
'--denoising-method',
action='store',
nargs='+',
choices=['aggr', 'nonaggr', 'orthaggr'],
default=None,
help="Denoising method to apply, if any.",
help='Denoising method to apply, if any.',
)
g_aroma.add_argument(

Check warning on line 366 in src/fmripost_aroma/cli/parser.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/cli/parser.py#L366

Added line #L366 was not covered by tests
"--orthogonalize",
action="store_true",
'--orthogonalize',
action='store_true',
default=False,
help=(
"If True, the AROMA-flagged noise components will be orthogonalized with respect to "
"the non-noise components in the MELODIC mixing matrix. "
"This can serve as an alternative to non-aggressive denoising."
'If True, the AROMA-flagged noise components will be orthogonalized with respect to '
'the non-noise components in the MELODIC mixing matrix. '
'This can serve as an alternative to non-aggressive denoising.'
),
)

Expand Down
50 changes: 25 additions & 25 deletions src/fmripost_aroma/interfaces/aroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@


class _AROMAClassifierInputSpec(BaseInterfaceInputSpec):
motpars = File(exists=True, desc="motion parameters or general confounds file")
mixing = File(exists=True, desc="mixing matrix")
component_maps = File(exists=True, desc="thresholded z-statistic component maps")
TR = traits.Float(desc="repetition time in seconds")
motpars = File(exists=True, desc='motion parameters or general confounds file')
mixing = File(exists=True, desc='mixing matrix')
component_maps = File(exists=True, desc='thresholded z-statistic component maps')
TR = traits.Float(desc='repetition time in seconds')


class _AROMAClassifierOutputSpec(TraitedSpec):
aroma_features = File(exists=True, desc="output confounds file extracted from ICA-AROMA")
aroma_noise_ics = File(exists=True, desc="ICA-AROMA noise components")
aroma_metadata = traits.Dict(desc="metadata for the ICA-AROMA confounds")
aroma_features = File(exists=True, desc='output confounds file extracted from ICA-AROMA')
aroma_noise_ics = File(exists=True, desc='ICA-AROMA noise components')
aroma_metadata = traits.Dict(desc='metadata for the ICA-AROMA confounds')


class AROMAClassifier(SimpleInterface):
Expand All @@ -38,58 +38,58 @@ class AROMAClassifier(SimpleInterface):

def _run_interface(self, runtime):
TR = self.inputs.TR
motion_params = utils.load_motpars(self.inputs.motpars, source="fmriprep")
motion_params = utils.load_motpars(self.inputs.motpars, source='fmriprep')
mixing = np.loadtxt(self.inputs.mixing) # T x C
component_maps = nb.load(self.inputs.component_maps) # X x Y x Z x C

Check warning on line 43 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L40-L43

Added lines #L40 - L43 were not covered by tests
if mixing.shape[1] != component_maps.shape[3]:
raise ValueError(

Check warning on line 45 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L45

Added line #L45 was not covered by tests
f"Number of columns in mixing matrix ({mixing.shape[1]}) does not match "
f"fourth dimension of component maps file ({component_maps.shape[3]})."
f'Number of columns in mixing matrix ({mixing.shape[1]}) does not match '
f'fourth dimension of component maps file ({component_maps.shape[3]}).'
)

if mixing.shape[0] != motion_params.shape[0]:
raise ValueError(

Check warning on line 51 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L51

Added line #L51 was not covered by tests
f"Number of rows in mixing matrix ({mixing.shape[0]}) does not match "
f"number of rows in motion parameters ({motion_params.shape[0]})."
f'Number of rows in mixing matrix ({mixing.shape[0]}) does not match '
f'number of rows in motion parameters ({motion_params.shape[0]}).'
)

config.loggers.interface.info(" - extracting the CSF & Edge fraction features")
config.loggers.interface.info(' - extracting the CSF & Edge fraction features')
metric_metadata = {}
features_df = pd.DataFrame()
spatial_df, spatial_metadata = features.feature_spatial(component_maps)
features_df = pd.concat([features_df, spatial_df], axis=1)
metric_metadata.update(spatial_metadata)

Check warning on line 61 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L56-L61

Added lines #L56 - L61 were not covered by tests

config.loggers.interface.info(" - extracting the Maximum RP correlation feature")
config.loggers.interface.info(' - extracting the Maximum RP correlation feature')
ts_df, ts_metadata = features.feature_time_series(mixing, motion_params)
features_df = pd.concat([features_df, ts_df], axis=1)
metric_metadata.update(ts_metadata)

Check warning on line 66 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L63-L66

Added lines #L63 - L66 were not covered by tests

config.loggers.interface.info(" - extracting the High-frequency content feature")
config.loggers.interface.info(' - extracting the High-frequency content feature')

Check warning on line 68 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L68

Added line #L68 was not covered by tests
# Should probably check that the frequencies match up with MELODIC's outputs
mixing_fft, _ = utils.get_spectrum(mixing, TR)
freq_df, freq_metadata = features.feature_frequency(mixing_fft, TR, f_hp=0.01)
features_df = pd.concat([features_df, freq_df], axis=1)
metric_metadata.update(freq_metadata)

Check warning on line 73 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L70-L73

Added lines #L70 - L73 were not covered by tests

config.loggers.interface.info(" - classification")
config.loggers.interface.info(' - classification')
clf_df, clf_metadata = utils.classification(features_df)
features_df = pd.concat([features_df, clf_df], axis=1)
metric_metadata.update(clf_metadata)

Check warning on line 78 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L75-L78

Added lines #L75 - L78 were not covered by tests

# Split out the motion components
motion_components = features_df.loc[

Check warning on line 81 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L81

Added line #L81 was not covered by tests
features_df["classification"] == "rejected",
"classification",
features_df['classification'] == 'rejected',
'classification',
].index
motion_components = motion_components.values
motion_components_file = os.path.abspath("aroma_motion_components.txt")
np.savetxt(motion_components_file, motion_components, fmt="%s")
motion_components_file = os.path.abspath('aroma_motion_components.txt')
np.savetxt(motion_components_file, motion_components, fmt='%s')

Check warning on line 87 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L85-L87

Added lines #L85 - L87 were not covered by tests

features_file = os.path.abspath("aroma_features.tsv")
features_df.to_csv(features_file, sep="\t", index=False)
features_file = os.path.abspath('aroma_features.tsv')
features_df.to_csv(features_file, sep='\t', index=False)

Check warning on line 90 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L89-L90

Added lines #L89 - L90 were not covered by tests

self._results["aroma_features"] = features_file
self._results["aroma_metadata"] = metric_metadata
self._results["aroma_noise_ics"] = motion_components_file
self._results['aroma_features'] = features_file
self._results['aroma_metadata'] = metric_metadata
self._results['aroma_noise_ics'] = motion_components_file
return runtime

Check warning on line 95 in src/fmripost_aroma/interfaces/aroma.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/aroma.py#L92-L95

Added lines #L92 - L95 were not covered by tests
22 changes: 11 additions & 11 deletions src/fmripost_aroma/interfaces/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ def _get_ica_confounds(ica_out_dir, skip_vols, newpath=None):


class _ICADenoiseInputSpec(BaseInterfaceInputSpec):
method = traits.Enum("aggr", "nonaggr", "orthaggr", mandatory=True, desc="denoising method")
bold_file = File(exists=True, mandatory=True, desc="input file to denoise")
mask_file = File(exists=True, mandatory=True, desc="mask file")
confounds = File(exists=True, mandatory=True, desc="confounds file")
method = traits.Enum('aggr', 'nonaggr', 'orthaggr', mandatory=True, desc='denoising method')
bold_file = File(exists=True, mandatory=True, desc='input file to denoise')
mask_file = File(exists=True, mandatory=True, desc='mask file')
confounds = File(exists=True, mandatory=True, desc='confounds file')


class _ICADenoiseOutputSpec(TraitedSpec):
denoised_file = File(exists=True, desc="denoised output file")
denoised_file = File(exists=True, desc='denoised output file')


class ICADenoise(SimpleInterface):
Expand All @@ -160,12 +160,12 @@ def _run_interface(self, runtime):

# Split up component time series into accepted and rejected components
metrics_df = pd.read_table(metrics_file)
rejected_columns = metrics_df.loc[metrics_df["classification"] == "rejected", "Component"]
accepted_columns = metrics_df.loc[metrics_df["classification"] == "accepted", "Component"]
rejected_columns = metrics_df.loc[metrics_df['classification'] == 'rejected', 'Component']
accepted_columns = metrics_df.loc[metrics_df['classification'] == 'accepted', 'Component']
rejected_components = confounds_df[rejected_columns].to_numpy()
accepted_components = confounds_df[accepted_columns].to_numpy()

Check warning on line 166 in src/fmripost_aroma/interfaces/confounds.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/confounds.py#L162-L166

Added lines #L162 - L166 were not covered by tests

if method == "aggr":
if method == 'aggr':
# Denoise the data with the motion components
masker = NiftiMasker(

Check warning on line 170 in src/fmripost_aroma/interfaces/confounds.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/confounds.py#L170

Added line #L170 was not covered by tests
mask_img=self.inputs.mask_file,
Expand All @@ -184,7 +184,7 @@ def _run_interface(self, runtime):

# Transform denoised data back into 4D space
denoised_img = masker.inverse_transform(denoised_img_2d)

Check warning on line 186 in src/fmripost_aroma/interfaces/confounds.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/confounds.py#L186

Added line #L186 was not covered by tests
elif method == "orthaggr":
elif method == 'orthaggr':
# Regress the good components out of the bad time series to get "pure evil" regressors
betas = np.linalg.lstsq(accepted_components, rejected_components, rcond=None)[0]
pred_bad_timeseries = np.dot(accepted_components, betas)
Expand Down Expand Up @@ -231,7 +231,7 @@ def _run_interface(self, runtime):
# Save to file
denoised_img = unmask(data_denoised, self.inputs.mask_file)

Check warning on line 232 in src/fmripost_aroma/interfaces/confounds.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/confounds.py#L232

Added line #L232 was not covered by tests

self._results["denoised_file"] = os.path.abspath("denoised.nii.gz")
denoised_img.to_filename(self._results["denoised_file"])
self._results['denoised_file'] = os.path.abspath('denoised.nii.gz')
denoised_img.to_filename(self._results['denoised_file'])

Check warning on line 235 in src/fmripost_aroma/interfaces/confounds.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/confounds.py#L234-L235

Added lines #L234 - L235 were not covered by tests

return runtime

Check warning on line 237 in src/fmripost_aroma/interfaces/confounds.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/confounds.py#L237

Added line #L237 was not covered by tests
8 changes: 4 additions & 4 deletions src/fmripost_aroma/interfaces/reportlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ class _ICAAROMAInputSpecRPT(nrb._SVGReportCapableInputSpec):
in_file = File(
exists=True,
mandatory=True,
desc="BOLD series input to ICA-AROMA",
desc='BOLD series input to ICA-AROMA',
)
melodic_dir = Directory(
exists=True,
mandatory=True,
desc="MELODIC directory containing the ICA outputs",
desc='MELODIC directory containing the ICA outputs',
)
aroma_noise_ics = File(
exists=True,
desc="Noise components estimated by ICA-AROMA, in a comma-separated values file.",
desc='Noise components estimated by ICA-AROMA, in a comma-separated values file.',
)
out_report = File(
'ica_aroma_reportlet.svg',
Expand Down Expand Up @@ -237,7 +237,7 @@ def _generate_report(self):
)

def _post_run_hook(self, runtime):
NIWORKFLOWS_LOG.info("Generating report for ICA AROMA")
NIWORKFLOWS_LOG.info('Generating report for ICA AROMA')

return super()._post_run_hook(runtime)

Expand Down
Loading

0 comments on commit b39f054

Please sign in to comment.