1
- from itertools import product
2
1
from pathlib import Path
3
2
4
- from niworkflows .reports .core import Report as _Report
5
- from pkg_resources import resource_filename as pkgrf
3
+ from nireports .assembler .report import Report
6
4
7
-
8
- class Report (_Report ):
9
- # niworkflows patch to preserve `out_filename` even if subject_id is present
10
- def __init__ (
11
- self ,
12
- out_dir ,
13
- run_uuid ,
14
- config = None ,
15
- out_filename = None ,
16
- packagename = None ,
17
- reportlets_dir = None ,
18
- subject_id = None ,
19
- ):
20
- self .root = Path (reportlets_dir or out_dir )
21
-
22
- # Initialize structuring elements
23
- self .sections = []
24
- self .errors = []
25
- self .out_dir = Path (out_dir )
26
- self .run_uuid = run_uuid
27
- self .packagename = packagename
28
- self .subject_id = subject_id
29
- if subject_id is not None :
30
- self .subject_id = subject_id [4 :] if subject_id .startswith ("sub-" ) else subject_id
31
- # ensure set output filename is preserved
32
- if not out_filename :
33
- out_filename = f"sub-{ self .subject_id } .html"
34
-
35
- self .out_filename = out_filename or "report.html"
36
-
37
- # Default template from niworkflows
38
- self .template_path = Path (pkgrf ("niworkflows" , "reports/report.tpl" ))
39
- self ._load_config (Path (config or pkgrf ("niworkflows" , "reports/default.yml" )))
40
- assert self .template_path .exists ()
41
-
42
- # TODO: Upstream ``Report._load_config`` to niworkflows
43
- def _load_config (self , config ):
44
- from yaml import safe_load as load
45
-
46
- settings = load (config .read_text ())
47
- self .packagename = self .packagename or settings .get ("package" , None )
48
-
49
- # Removed from here: Appending self.packagename to self.root and self.out_dir
50
- # In this version, pass reportlets_dir and out_dir with nibabies in the path.
51
-
52
- if self .subject_id is not None :
53
- self .root = self .root / "sub-{}" .format (self .subject_id )
54
-
55
- if "template_path" in settings :
56
- self .template_path = config .parent / settings ["template_path" ]
57
-
58
- self .index (settings ["sections" ])
59
-
60
-
61
- #
62
- # The following are the interface used directly by NiBabies
63
- #
5
+ from nibabies .data import load_resource
64
6
65
7
66
8
def run_reports (
67
9
out_dir ,
68
- subject_label ,
10
+ subject ,
69
11
run_uuid ,
70
- config = None ,
71
- out_filename = 'report.html' ,
12
+ session = None ,
13
+ out_filename = None ,
72
14
reportlets_dir = None ,
73
15
packagename = None ,
74
16
):
@@ -78,10 +20,9 @@ def run_reports(
78
20
return Report (
79
21
out_dir ,
80
22
run_uuid ,
81
- config = config ,
82
- out_filename = out_filename ,
83
- subject_id = subject_label ,
84
- packagename = packagename ,
23
+ subject = subject ,
24
+ session = session ,
25
+ bootstrap_file = load_resource ('reports-spec.yml' ),
85
26
reportlets_dir = reportlets_dir ,
86
27
).generate_report ()
87
28
@@ -90,7 +31,6 @@ def generate_reports(
90
31
sub_ses_list ,
91
32
output_dir ,
92
33
run_uuid ,
93
- config = None ,
94
34
work_dir = None ,
95
35
packagename = None ,
96
36
):
@@ -100,17 +40,13 @@ def generate_reports(
100
40
reportlets_dir = Path (work_dir ) / "reportlets"
101
41
102
42
report_errors = []
103
- for subject_label , session in sub_ses_list :
104
- html_report = '' .join (
105
- [f"sub-{ subject_label } " , f"_ses-{ session } " if session else "" , ".html" ]
106
- )
43
+ for subject , session in sub_ses_list :
107
44
report_errors .append (
108
45
run_reports (
109
46
output_dir ,
110
- subject_label ,
47
+ subject ,
111
48
run_uuid ,
112
- config = config ,
113
- out_filename = html_report ,
49
+ session = session ,
114
50
packagename = packagename ,
115
51
reportlets_dir = reportlets_dir ,
116
52
)
0 commit comments