@@ -0,0 +1,2447 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-%0A# vi: set ft=python sts=4 ts=4 sw=4 et:%0A%22%22%22%0AInterfaces to generate reportlets%0A~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%0A%0A%0A%22%22%22%0Afrom __future__ import print_function, division, absolute_import, unicode_literals%0A%0Aimport os%0Afrom niworkflows.nipype.interfaces.base import (%0A    traits, TraitedSpec, BaseInterfaceInputSpec,%0A    File, Directory, InputMultiPath, isdefined)%0Afrom niworkflows.interfaces.base import SimpleInterface%0A%0Afrom niworkflows.nipype.interfaces import freesurfer as fs%0A%0AANATOMICAL_TEMPLATE = %22%22%22%5Ct%5Ct%3Ch3 class=%22elem-title%22%3ESummary%3C/h3%3E%0A%5Ct%5Ct%3Cul class=%22elem-desc%22%3E%0A%5Ct%5Ct%5Ct%3Cli%3EStructural images: %7Bn_t1s:d%7D%3C/li%3E%0A%5Ct%5Ct%5Ct%3Cli%3EFreeSurfer reconstruction: %7Bfreesurfer_status%7D%3C/li%3E%0A%5Ct%5Ct%5Ct%3Cli%3EOutput spaces: %7Boutput_spaces%7D%3C/li%3E%0A%5Ct%5Ct%3C/ul%3E%0A%22%22%22%0A%0A%0Aclass AnatomicalSummaryInputSpec(BaseInterfaceInputSpec):%0A    t1w = InputMultiPath(File(exists=True), desc='T1w structural images')%0A    subjects_dir = Directory(desc='FreeSurfer subjects directory')%0A    subject_id = traits.Str(desc='FreeSurfer subject ID')%0A    output_spaces = traits.List(desc='Target spaces')%0A%0A%0Aclass AnatomicalSummaryOutputSpec(TraitedSpec):%0A    out_report = File(exists=True, desc='HTML segment containing summary')%0A%0A%0Aclass AnatomicalSummary(SimpleInterface):%0A    input_spec = AnatomicalSummaryInputSpec%0A    output_spec = AnatomicalSummaryOutputSpec%0A%0A    def _run_interface(self, runtime):%0A        if not isdefined(self.inputs.subjects_dir):%0A            freesurfer_status = 'Not run'%0A        else:%0A            recon = fs.ReconAll(subjects_dir=self.inputs.subjects_dir,%0A                                subject_id=self.inputs.subject_id,%0A                                T1_files=self.inputs.t1w,%0A                                flags='-noskullstrip')%0A            if recon.cmdline.startswith('echo'):%0A                freesurfer_status = 'Pre-existing directory'%0A            else:%0A                freesurfer_status = 'Run by FMRIPREP'%0A%0A        segment = ANATOMICAL_TEMPLATE.format(n_t1s=len(self.inputs.t1w),%0A                                             freesurfer_status=freesurfer_status,%0A                                             output_spaces=', '.join(self.inputs.output_spaces))%0A%0A        fname = os.path.abspath('report.html')%0A        with open(fname, 'w') as fobj:%0A            fobj.write(segment)%0A%0A        self._results%5B'out_report'%5D = fname%0A%0A        return runtime%0A

Add AnatomicalSummary interface