<commit_before>#! /usr/bin/env python
"""
Group fMRI analysis frontend for Lyman ecosystem

"""
import os
import sys
import time
import shutil
import os.path as op

import matplotlib as mpl
mpl.use("Agg")

from nipype import Node, MapNode, DataGrabber, DataSink, IdentityInterface

import lyman
import lyman.workflows as wf
from lyman import tools


def main(arglist):
    """Main function for workflow setup and execution."""
    args = parse_args(arglist)

    # Get and process specific information
    project = lyman.gather_project_info()
    if project["default_exp"] is not None and args.experiment is None:
        args.experiment = project["default_exp"]
    exp = lyman.gather_experiment_info(args.experiment, args.altmodel)

    if args.altmodel:
        exp_name = "-".join([args.experiment, args.altmodel])
    else:
        exp_name = args.experiment

    # Make sure some paths are set properly
    os.environ["SUBJECTS_DIR"] = project["data_dir"]

    # Set roots of output storage
    anal_dir_base = op.join(project["analysis_dir"], exp_name)
    work_dir_base = op.join(project["working_dir"], exp_name)
    crashdump_dir = "/tmp/%d" % time.time()

    # Subject source (no iterables here)
    subject_list = lyman.determine_subjects(args.subjects)
    subj_source = Node(IdentityInterface(fields=["subject_id"]),
                       name="subj_source")
    subj_source.inputs.subject_id = subject_list

    # Set up the regressors and contrasts
    regressors = dict(group_mean=[1] * len(subject_list))
    contrasts = [["group_mean", "T", ["group_mean"], [1]]]

    # Subject level contrast source
    contrast_source = Node(IdentityInterface(fields=["l1_contrast"]),
                           iterables=("l1_contrast", exp["contrast_names"]),
                           name="contrast_source")

    # Mixed effects group workflow
    mfx, mfx_input, mfx_output = wf.create_volume_mixedfx_workflow(
        subject_list=subject_list, regressors=regressors, contrasts=contrasts)

    # Mixed effects inputs
    mfx_template = "%s/ffx/" + args.regspace + "/smoothed/%s/stats/%s1.nii.gz"
    mfx_source = MapNode(DataGrabber(infields=["subject_id",
                                               "l1_contrast"],
                                     outfields=["copes", "varcopes", "dofs"],
                                     base_directory=anal_dir_base,
                                     template=mfx_template,
                                     sort_filelist=True),
                      iterfield=["subject_id"],
                      name="mfx_source")
    mfx_source.inputs.template_args = dict(<commit_msg>Name group workflow object based off -output (closes GH-11)<commit_after>#! /usr/bin/env python
"""
Group fMRI analysis frontend for Lyman ecosystem

"""
import os
import sys
import time
import shutil
import os.path as op

import matplotlib as mpl
mpl.use("Agg")

from nipype import Node, MapNode, DataGrabber, DataSink, IdentityInterface

import lyman
import lyman.workflows as wf
from lyman import tools


def main(arglist):
    """Main function for workflow setup and execution."""
    args = parse_args(arglist)

    # Get and process specific information
    project = lyman.gather_project_info()
    if project["default_exp"] is not None and args.experiment is None:
        args.experiment = project["default_exp"]
    exp = lyman.gather_experiment_info(args.experiment, args.altmodel)

    if args.altmodel:
        exp_name = "-".join([args.experiment, args.altmodel])
    else:
        exp_name = args.experiment

    # Make sure some paths are set properly
    os.environ["SUBJECTS_DIR"] = project["data_dir"]

    # Set roots of output storage
    anal_dir_base = op.join(project["analysis_dir"], exp_name)
    work_dir_base = op.join(project["working_dir"], exp_name)
    crashdump_dir = "/tmp/%d" % time.time()

    # Subject source (no iterables here)
    subject_list = lyman.determine_subjects(args.subjects)
    subj_source = Node(IdentityInterface(fields=["subject_id"]),
                       name="subj_source")
    subj_source.inputs.subject_id = subject_list

    # Set up the regressors and contrasts
    regressors = dict(group_mean=[1] * len(subject_list))
    contrasts = [["group_mean", "T", ["group_mean"], [1]]]

    # Subject level contrast source
    contrast_source = Node(IdentityInterface(fields=["l1_contrast"]),
                           iterables=("l1_contrast", exp["contrast_names"]),
                           name="contrast_source")

    # Mixed effects group workflow
    mfx, mfx_input, mfx_output = wf.create_volume_mixedfx_workflow(
        name=args.output, subject_list=subject_list,
        regressors=regressors, contrasts=contrasts)

    # Mixed effects inputs
    mfx_template = "%s/ffx/" + args.regspace + "/smoothed/%s/stats/%s1.nii.gz"
    mfx_source = MapNode(DataGrabber(infields=["subject_id",
                                               "l1_contrast"],
                                     outfields=["copes", "varcopes", "dofs"],
                                     base_directory=anal_dir_base,
                                     template=mfx_template,
                                     sort_filelist=True),
                      iterfield=["subject_id"],
                      name="mfx_source")
    mfx_source.inputs.template_args = dict(
{'fraction_non_alphanumeric': 0.1040343668285394, 'fraction_numerical': 0.002614867388868136, 'mean_word_length': 2.630508474576271, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5653292', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1556, 'n_words': 356}