How to use the fitlins.utils.snake_to_camel function in fitlins

To help you get started, we’ve selected a few fitlins examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github poldracklab / fitlins / fitlins / base.py View on Github external
(deriv_dir, ['bids', 'derivatives',
                     pkgr.resource_filename('fitlins', 'data/fitlins.json')]))
    fl_layout.path_patterns[:0] = PATH_PATTERNS
    analyses = []

    fmri_glm = level2.SecondLevelModel()

    for contrasts, idx, ents in block.get_contrasts():
        if contrasts.empty:
            continue

        data = []
        for in_name, sub_ents in zip(contrasts.index, idx.to_dict(orient='record')):
            # The underlying contrast name might have been added to by a transform
            for option in [in_name] + in_name.split('.'):
                files = fl_layout.get(contrast=snake_to_camel(option),
                                      type='effect', space=space, **sub_ents)
                if files:
                    data.append(files[0].filename)
                    break
            else:
                raise ValueError("Unknown input: {}".format(in_name))

        out_ents = reduce(dict_intersection,
                          map(fl_layout.parse_file_entities, data))
        out_ents['type'] = 'stat'

        contrasts_ents = out_ents.copy()
        contrasts_ents['type'] = 'contrasts'
        contrasts_ents.pop('contrast', None)
        contrasts_ents.pop('space', None)
        contrasts_fname = op.join(
github poldracklab / fitlins / fitlins / interfaces / bids.py View on Github external
base_dir = self.inputs.base_directory

        os.makedirs(base_dir, exist_ok=True)

        layout = BIDSLayout(base_dir, validate=False)
        path_patterns = self.inputs.path_patterns
        if not isdefined(path_patterns):
            path_patterns = None

        out_files = []
        for entities, in_file in zip(self.inputs.entities,
                                     self.inputs.in_file):
            ents = {**self.inputs.fixed_entities}
            ents.update(entities)

            ents = {k: snake_to_camel(str(v)) for k, v in ents.items()}

            out_fname = os.path.join(
                base_dir, layout.build_path(
                    ents, path_patterns, validate=False))
            os.makedirs(os.path.dirname(out_fname), exist_ok=True)

            _copy_or_convert(in_file, out_fname)
            out_files.append(out_fname)

        return {'out_file': out_files}
github poldracklab / fitlins / fitlins / base.py View on Github external
# Make parent results directory
        os.makedirs(os.path.dirname(contrasts_fname), exist_ok=True)
        plot_and_save(contrasts_fname, plot_contrast_matrix, contrasts,
                      ornt='horizontal')

        job_desc = {
            'ents': out_ents,
            'subject_id': ents.get('subject'),
            'dataset': analysis.layout.root,
            'model_name': analysis.model['name'],
            'contrasts_svg': contrasts_fname,
            }

        for contrast in contrasts:
            out_ents['contrast'] = snake_to_camel(contrast)

            stat_fname = op.join(deriv_dir,
                                 fl_layout.build_path(out_ents, strict=True))

            ortho_ents = out_ents.copy()
            ortho_ents['type'] = 'ortho'
            ortho_fname = op.join(deriv_dir,
                                  analysis.layout.build_path(ortho_ents,
                                                             strict=True))

            desc = {'name': contrast, 'image_file': ortho_fname}
            job_desc.setdefault('contrasts', []).append(desc)

            if op.exists(stat_fname):
                continue
github poldracklab / fitlins / fitlins / viz / reports.py View on Github external
contrasts = step.get_contrasts(**ents)[0]
            for key in ('datatype', 'desc', 'suffix', 'extension',
                        'RepetitionTime', 'SkullStripped', 'TaskName'):
                ents.pop(key, None)

            analysis = {
                'entities': {
                    key: val
                    for key, val in ents.items()
                    if key in ('subject', 'session', 'task', 'run') and val},
                'contrasts': []
                }

            for contrast in contrasts:
                glassbrain = fl_layout.get(
                    contrast=snake_to_camel(contrast.name),
                    suffix='ortho', extension='png', **ents)
                analysis['contrasts'].append(
                    {'name': displayify(contrast.name),
                     'glassbrain': glassbrain[0].path if glassbrain else None}
                )
            report_step['analyses'].append(analysis)

            # Space doesn't apply to design/contrast matrices
            ents.pop('space', None)
            design_matrix = fl_layout.get(suffix='design', extension='svg', **ents)
            correlation_matrix = fl_layout.get(suffix='corr', extension='svg', **ents)
            contrast_matrix = fl_layout.get(suffix='contrasts', extension='svg', **ents)
            warning = wd_layout.get(extension='.html', suffix='snippet', **ents)
            if design_matrix:
                analysis['design_matrix'] = design_matrix[0].path
            if correlation_matrix:
github poldracklab / fitlins / fitlins / viz / reports.py View on Github external
def write_full_report(report_dict, run_context, deriv_dir):
    fl_layout = BIDSLayout(
        deriv_dir, config=['bids', 'derivatives', 'fitlins'])

    env = jinja2.Environment(
        loader=jinja2.FileSystemLoader(
            searchpath=pkgr.resource_filename('fitlins', '/')))

    tpl = env.get_template('data/full_report.tpl')

    model = snake_to_camel(report_dict['model']['name'])
    target_file = op.join(
        deriv_dir, fl_layout.build_path(
            {'model': model}, PATH_PATTERNS, validate=False))
    html = tpl.render(deroot({**report_dict, **run_context}, op.dirname(target_file)))
    Path(target_file).write_text(html)