Skip to content

Commit

Permalink
Try fixing again.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Aug 19, 2024
1 parent 92e7df4 commit ee3ec0b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 47 deletions.
73 changes: 30 additions & 43 deletions qsirecon/interfaces/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
CommandLineInputSpec,
Directory,
File,
InputMultiObject,
InputMultiPath,
SimpleInterface,
Str,
Expand All @@ -35,12 +36,14 @@

from .qc import createB0_ColorFA_Mask_Sprites, createSprite4D

SUBJECT_TEMPLATE = """\t<ul class="elem-desc">
SUBJECT_TEMPLATE = """\
\t<ul class="elem-desc">
\t\t<li>Subject ID: {subject_id}</li>
\t\t<li>Structural images: {n_t1s:d} T1-weighted {t2w}</li>
\t\t<li>Diffusion-weighted series: inputs {n_dwis:d}, outputs {n_outputs:d}</li>
\t\t<li>FreeSurfer input: {freesurfer}</li>
\t\t<li>Resampling targets: {output_spaces}</li>
\t\t<li>Structural images: {n_t1w:d} T1-weighted {t2w}</li>
\t\t<li>Diffusion-weighted series: {n_dwi:d}</li>
\t\t<li>Standard output spaces: {std_spaces}</li>
\t\t<li>Non-standard output spaces: {nstd_spaces}</li>
\t\t<li>FreeSurfer reconstruction: {freesurfer_status}</li>
\t</ul>
"""

Expand Down Expand Up @@ -121,9 +124,12 @@ class SubjectSummaryInputSpec(BaseInterfaceInputSpec):
t2w = InputMultiPath(File(exists=True), desc="T2w structural images")
subjects_dir = Directory(desc="FreeSurfer subjects directory")
subject_id = Str(desc="Subject ID")
dwi_groupings = traits.Dict(desc="groupings of DWI files and their output names")
output_spaces = traits.List(desc="Target spaces")
template = traits.Enum("MNI152NLin2009cAsym", desc="Template space")
dwi = InputMultiObject(
traits.Either(File(exists=True), traits.List(File(exists=True))),
desc="Preprocessed DWI series",
)
std_spaces = traits.List(Str, desc="list of standard spaces")
nstd_spaces = traits.List(Str, desc="list of non-standard spaces")


class SubjectSummaryOutputSpec(SummaryOutputSpec):
Expand All @@ -139,49 +145,30 @@ class SubjectSummary(SummaryInterface):
def _run_interface(self, runtime):
if isdefined(self.inputs.subject_id):
self._results["subject_id"] = self.inputs.subject_id
return super(SubjectSummary, self)._run_interface(runtime)
return super()._run_interface(runtime)

def _generate_segment(self):
if not isdefined(self.inputs.subjects_dir):
freesurfer_status = "Not run"
else:
freesurfer_status = "Pre-existing directory"

t2w_seg = ""
if self.inputs.t2w:
t2w_seg = "(+ {:d} T2-weighted)".format(len(self.inputs.t2w))

# Add text for how the dwis are grouped
n_dwis = 0
n_outputs = 0
groupings = ""
if isdefined(self.inputs.dwi_groupings):
for output_fname, group_info in self.inputs.dwi_groupings.items():
n_outputs += 1
files_desc = []
files_desc.append(
"\t\t\t<li>Scan group: %s (PE Dir %s)</li><ul>"
% (output_fname, group_info["dwi_series_pedir"])
)
files_desc.append("\t\t\t\t<li>DWI Files: </li>")
for dwi_file in group_info["dwi_series"]:
files_desc.append("\t\t\t\t\t<li> %s </li>" % dwi_file)
n_dwis += 1
fieldmap_type = group_info["fieldmap_info"]["suffix"]
if fieldmap_type is not None:
files_desc.append("\t\t\t\t<li>Fieldmap type: %s </li>" % fieldmap_type)

for key, value in group_info["fieldmap_info"].items():
files_desc.append("\t\t\t\t\t<li> %s: %s </li>" % (key, str(value)))
n_dwis += 1
files_desc.append("</ul>")
groupings += GROUPING_TEMPLATE.format(
output_name=output_fname, input_files="\n".join(files_desc)
)
t2w_seg = f"(+ {len(self.inputs.t2w):d} T2-weighted)"

# Add list of tasks with number of runs
dwi_series = self.inputs.dwi if isdefined(self.inputs.dwi) else []
dwi_series = [s[0] if isinstance(s, list) else s for s in dwi_series]

return SUBJECT_TEMPLATE.format(
subject_id=self.inputs.subject_id,
n_t1s=len(self.inputs.t1w),
n_t1w=len(self.inputs.t1w),
t2w=t2w_seg,
n_dwis=n_dwis,
n_outputs=n_outputs,
groupings=groupings,
output_spaces="T1wACPC",
n_dwi=len(dwi_series),
std_spaces=", ".join(self.inputs.std_spaces),
nstd_spaces=", ".join(self.inputs.nstd_spaces),
freesurfer_status=freesurfer_status,
)


Expand Down
10 changes: 6 additions & 4 deletions qsirecon/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,18 @@ def init_single_subject_recon_wf(subject_id):
]) # fmt:skip

# Preprocessing of anatomical data (includes possible registration template)
dwi_basename = fix_multi_T1w_source_name(dwi_recon_inputs)
about = pe.Node(
AboutSummary(version=config.environment.version, command=" ".join(sys.argv)),
AboutSummary(
version=config.environment.version,
command=" ".join(sys.argv),
),
name="about",
run_without_submitting=True,
)
ds_report_about = pe.Node(
DerivativesDataSink(
source_file=dwi_basename,
base_directory=config.execution.output_dir,
datatype="figures",
suffix="about",
Expand All @@ -254,9 +259,6 @@ def init_single_subject_recon_wf(subject_id):
run_without_submitting=True,
)
workflow.connect([
(file_anat_ingress_node, ds_report_about, [
(('outputnode.t1w_preproc', fix_multi_T1w_source_name), 'source_file'),
]),
(about, ds_report_about, [('out_report', 'in_file')]),
]) # fmt:skip

Expand Down

0 comments on commit ee3ec0b

Please sign in to comment.