1
1
"""Internal function for checking the validity of parcel_approach."""
2
- import copy , os , re , warnings
2
+ import copy , os , re , textwrap , warnings
3
3
from nilearn import datasets
4
4
5
5
def _check_parcel_approach (parcel_approach , call = "TimeseriesExtractor" ):
@@ -15,22 +15,22 @@ def _check_parcel_approach(parcel_approach, call = "TimeseriesExtractor"):
15
15
"rh" : [5 ]}}}}
16
16
17
17
if not isinstance (parcel_approach ,dict ) or isinstance (parcel_approach ,dict ) and len (parcel_approach ) > 0 and not isinstance (parcel_approach [list (parcel_approach )[0 ]],dict ):
18
- raise ValueError (f"""
18
+ raise ValueError (textwrap . dedent ( f"""
19
19
Please include a valid `parcel_approach` in one of the following dictionary
20
20
formats for 'Schaefer' or 'AAL' { valid_parcel_dict }
21
- """ )
21
+ """ ))
22
22
23
23
if len (parcel_approach ) > 1 :
24
- raise ValueError (f"""
24
+ raise ValueError (textwrap . dedent ( f"""
25
25
Only one parcellation approach can be selected.
26
26
Example format of `parcel_approach`: { valid_parcel_dict }
27
- """ )
27
+ """ ))
28
28
29
29
if "Schaefer" not in parcel_approach and "AAL" not in parcel_approach and "Custom" not in parcel_approach :
30
- raise ValueError (f"""
30
+ raise ValueError (textwrap . dedent ( f"""
31
31
Please include a valid `parcel_approach` in one of the following formats for
32
32
'Schaefer', 'AAL', or 'Custom': { valid_parcel_dict }
33
- """ )
33
+ """ ))
34
34
35
35
if "Schaefer" in parcel_approach :
36
36
if "n_rois" not in parcel_approach ["Schaefer" ]:
@@ -72,30 +72,30 @@ def _check_parcel_approach(parcel_approach, call = "TimeseriesExtractor"):
72
72
73
73
if "Custom" in parcel_approach :
74
74
if call == "TimeseriesExtractor" and "maps" not in parcel_approach ["Custom" ]:
75
- raise ValueError (f"""
75
+ raise ValueError (textwrap . dedent ( f"""
76
76
For `Custom` parcel_approach, a nested key-value pair containing the key 'maps' with the
77
77
value being a string specifying the location of the parcellation is needed.
78
78
Example: { valid_parcel_dict ['Custom' ]}
79
- """ )
79
+ """ ))
80
80
check_subkeys = ["nodes" in parcel_approach ["Custom" ], "regions" in parcel_approach ["Custom" ]]
81
81
if not all (check_subkeys ):
82
82
missing_subkeys = [["nodes" , "regions" ][x ] for x ,y in enumerate (check_subkeys ) if y is False ]
83
83
error_message = f"The following sub-keys haven't been detected { missing_subkeys } "
84
84
if call == "TimeseriesExtractor" :
85
- warnings .warn (f"""
85
+ warnings .warn (textwrap . dedent ( f"""
86
86
{ error_message } .
87
87
These labels are not needed for timeseries extraction but are needed for future
88
- timeseries or CAPs plotting.""" )
88
+ timeseries or CAPs plotting.""" ))
89
89
else :
90
90
custom_example = {"Custom" : {"nodes" : ["LH_Vis1" , "LH_Vis2" , "LH_Hippocampus" ,
91
91
"RH_Vis1" , "RH_Vis2" , "RH_Hippocampus" ],
92
92
"regions" : {"Vis" : {"lh" : [0 ,1 ],
93
93
"rh" : [3 ,4 ]}},
94
94
"Hippocampus" : {"lh" : [2 ],"rh" : [5 ]}}}
95
- raise ValueError (f"""
95
+ raise ValueError (textwrap . dedent ( f"""
96
96
{ error_message } .
97
97
These subkeys are needed for plotting. Please reassign `parcel_approach` using
98
- `self.parcel_approach` amd refer to the example structure: { custom_example } """ )
98
+ `self.parcel_approach` amd refer to the example structure: { custom_example } """ ))
99
99
if call == "TimeseriesExtractor" and not os .path .isfile (parcel_approach ["Custom" ]["maps" ]):
100
100
raise ValueError ("Please specify the location to the custom parcellation to be used." )
101
101
0 commit comments