Example #1
0
    def generate(self, **kwargs):
        r"""Generate the methods section.

        Parameters
        ----------
        task_converter : :obj:`dict`, optional
            A dictionary with information for converting task names from BIDS
            filename format to human-readable strings.

        Returns
        -------
        counter : :obj:`collections.Counter`
            A dictionary of unique descriptions across subjects in the dataset,
            along with the number of times each pattern occurred. In cases
            where all subjects underwent the same protocol, the most common
            pattern is most likely the most complete. In cases where the
            dataset contains multiple protocols, each pattern will need to be
            inspected manually.

        Examples
        --------
        >>> from os.path import join
        >>> from bids.layout import BIDSLayout
        >>> from bids.reports import BIDSReport
        >>> from bids.tests import get_test_data_path
        >>> layout = BIDSLayout(join(get_test_data_path(), 'synthetic'))
        >>> report = BIDSReport(layout)
        >>> counter = report.generate(session='01')
        Number of patterns detected: 1
        Remember to double-check everything and to replace <deg> with a degree symbol.

        >>> counter.most_common()[0][0]  # doctest: +ELLIPSIS
        'For session 01:\n\tMR data were...'

        """
        descriptions = []

        subjs = self.layout.get_subjects(**kwargs)
        kwargs = {k: v for k, v in kwargs.items() if k != 'subject'}
        for sid in subjs:
            descriptions.append(self._report_subject(subject=sid, **kwargs))
        counter = Counter(descriptions)
        print('Number of patterns detected: {0}'.format(len(counter.keys())))
        print(utils.reminder())
        return counter
Example #2
0
    def generate(self, **kwargs):
        """Generate the methods section.

        Parameters
        ----------
        task_converter : :obj:`dict`, optional
            A dictionary with information for converting task names from BIDS
            filename format to human-readable strings.

        Returns
        -------
        counter : :obj:`collections.Counter`
            A dictionary of unique descriptions across subjects in the dataset,
            along with the number of times each pattern occurred. In cases
            where all subjects underwent the same protocol, the most common
            pattern is most likely the most complete. In cases where the
            dataset contains multiple protocols, each pattern will need to be
            inspected manually.

        Examples
        --------
        >>> from os.path import join
        >>> from bids.layout import BIDSLayout
        >>> from bids.reports import BIDSReport
        >>> from bids.tests import get_test_data_path
        >>> layout = BIDSLayout(join(get_test_data_path(), 'synthetic'))
        >>> report = BIDSReport(layout)
        >>> counter = report.generate(session='01')
        >>> counter.most_common()[0][0]
        """
        descriptions = []

        subjs = self.layout.get_subjects(**kwargs)
        kwargs = {k: v for k, v in kwargs.items() if k != 'subject'}
        for sid in subjs:
            descriptions.append(self._report_subject(subject=sid, **kwargs))
        counter = Counter(descriptions)
        print('Number of patterns detected: {0}'.format(len(counter.keys())))
        print(utils.reminder())
        return counter
Example #3
0
    def generate(self, **kwargs):
        """Generate the methods section.

        Parameters
        ----------
        task_converter : :obj:`dict`, optional
            A dictionary with information for converting task names from BIDS
            filename format to human-readable strings.

        Returns
        -------
        counter : :obj:`collections.Counter`
            A dictionary of unique descriptions across subjects in the dataset,
            along with the number of times each pattern occurred.

        Examples
        --------
        >>> from os.path import join
        >>> from bids.grabbids import BIDSLayout
        >>> from bids.reports import BIDSReport
        >>> from bids.tests import get_test_data_path
        >>> layout = BIDSLayout(join(get_test_data_path(), 'synthetic'))
        >>> report = BIDSReport(layout)
        >>> counter = report.generate(session='01')
        >>> counter.most_common()[0][0]
        """
        descriptions = []

        subjs = self.layout.get_subjects(**kwargs)
        kwargs = {k: v for k, v in kwargs.items() if k != 'subject'}
        for sid in subjs:
            descriptions.append(self._report_subject(subject=sid, **kwargs))
        counter = Counter(descriptions)
        print('Number of patterns detected: {0}'.format(len(counter.keys())))
        print(utils.reminder())
        return counter
Example #4
0
    def generate_from_files(self, files):
        r"""Generate a methods section from a list of files.

        Parameters
        ----------
        files : list of BIDSImageFile objects
            List of files from which to generate methods description.

        Returns
        -------
        counter : :obj:`collections.Counter`
            A dictionary of unique descriptions across subjects in the file list,
            along with the number of times each pattern occurred. In cases
            where all subjects underwent the same protocol, the most common
            pattern is most likely the most complete. In cases where the
            file list contains multiple protocols, each pattern will need to be
            inspected manually.

        Examples
        --------
        >>> from os.path import join
        >>> from bids.layout import BIDSLayout
        >>> from bids.reports import BIDSReport
        >>> from bids.tests import get_test_data_path
        >>> layout = BIDSLayout(join(get_test_data_path(), 'synthetic'))
        >>> report = BIDSReport(layout)
        >>> files = layout.get(session='01', extension=['.nii.gz', '.nii'])
        >>> counter = report.generate_from_files(files)
        Number of patterns detected: 1
        Remember to double-check everything and to replace <deg> with a degree symbol.

        >>> counter.most_common()[0][0]  # doctest: +ELLIPSIS
        'In session 01, MR data were...'
        """
        descriptions = []

        subjects = sorted(
            list(set([f.get_entities().get("subject") for f in files])))
        sessions = sorted(
            list(set([f.get_entities().get("session") for f in files])))
        for sub in subjects:
            subject_files = [
                f for f in files if f.get_entities().get("subject") == sub
            ]
            description_list = []
            for ses in sessions:
                data_files = [
                    f for f in subject_files
                    if f.get_entities().get("session") == ses
                ]

                if data_files:
                    ses_description = parsing.parse_files(
                        self.layout,
                        data_files,
                        sub,
                        self.config,
                    )
                    ses_description[0] = "In session {0}, ".format(
                        ses) + ses_description[0]
                    description_list += ses_description
                    metadata = self.layout.get_metadata(data_files[0].path)
                else:
                    raise Exception(
                        "No imaging files for subject {0}".format(sub))

            # Assume all data were converted the same way and use the last nifti
            # file's json for conversion information.
            if "metadata" not in vars():
                raise Exception(
                    "No valid jsons found. Cannot generate final paragraph.")

            description = "\n\t".join(description_list)
            description += "\n\n{0}".format(parsing.final_paragraph(metadata))
            descriptions.append(description)
        counter = Counter(descriptions)
        print("Number of patterns detected: {0}".format(len(counter.keys())))
        print(utils.reminder())
        return counter