Esempio n. 1
0
def reg_cc(
    path="~/ni_data/ofM.dr/preprocessing/composite",
    template="/usr/share/mouse-brain-atlases/dsurqec_200micron.nii",
    radius=8,
    autofind=False,
    plot=False,
    save_as="f_reg_quality",
    # metrics = ['CC','GC'],
    metrics=['CC', 'GC', 'MI'],
):
    from samri.report.registration import iter_measure_sim
    from samri.utilities import bids_substitution_iterator

    if autofind:
        path_template, substitutions = bids_autofind(path, "func")
    else:
        path_template = "{data_dir}/preprocessing/{preprocessing_dir}/sub-{subject}/ses-{session}/func/sub-{subject}_ses-{session}_acq-{acquisition}_task-{task}_cbv.nii.gz"
        substitutions = bids_substitution_iterator(
            ["ofM", "ofMaF", "ofMcF1", "ofMcF2", "ofMpF"],
            [
                "4001", "4007", "4008", "4011", "5692", "5694", "5699", "5700",
                "5704", "6255", "6262"
            ],
            ["CogB", "JogB"],
            "~/ni_data/ofM.dr/",
            "composite",
            acquisitions=['EPI', 'EPIlowcov'],
            validate_for_template=path_template,
        )
    df = iter_measure_sim(
        path_template,
        template,
        substitutions,
        metric=metrics[0],
        radius_or_number_of_bins=radius,
        sampling_strategy="Regular",
        sampling_percentage=0.95,
        save_as=False,
    )

    df = df.rename(columns={
        'similarity': metrics[0],
    })

    for metric in metrics[1:]:
        _df = iter_measure_sim(
            path_template,
            template,
            substitutions,
            metric=metric,
            radius_or_number_of_bins=radius,
            sampling_strategy="Regular",
            sampling_percentage=0.95,
            save_as=False,
        )
        df[metric] = _df['similarity'].values
    if save_as:
        df.to_csv(save_as + ".csv")

    return df
Esempio n. 2
0
def reg_gc():
    from samri.plotting.aggregate import registration_qc
    from samri.report.registration import iter_measure_sim
    from samri.typesetting import inline_anova

    df = iter_measure_sim(
        "~/ni_data/ofM.dr/preprocessing/composite",
        "~/.samri_files/templates/mouse/DSURQE/DSURQEc_200micron_average.nii",
        #modality="anat",
        metric="GC",
        radius_or_number_of_bins=0,
        sampling_strategy="Regular",
        sampling_percentage=0.5,
        save_as=False,
    )

    anova_summary = registration_qc(
        df,
        value={"similarity": "Similarity"},
        group={"sub": "Subject"},
        repeat={"ses": "Session"},
        show=False,
        save_as="/tmp/f_reg_gc.png",
    )

    subject_effect = inline_anova(anova_summary, "C(Subject)", style="python")
    print("Subject Main Effect: {}".format(subject_effect))
    session_effect = inline_anova(anova_summary, "C(Session)", style="python")
    print("Session Main Effect: {}".format(session_effect))
Esempio n. 3
0
def reg_gc():
	from samri.plotting.aggregate import registration_qc
	from samri.report.registration import iter_measure_sim
	from samri.typesetting import inline_anova

	df = iter_measure_sim(
		"~/ni_data/ofM.dr/preprocessing/composite",
		"~/.samri_files/templates/mouse/DSURQE/DSURQEc_200micron_average.nii",
		#modality="anat",
		metric="GC",
		radius_or_number_of_bins = 0,
		sampling_strategy = "Regular",
		sampling_percentage=0.5,
		save_as=False,
		)

	anova_summary = registration_qc(df,
		value={"similarity":"Similarity"},
		group={"sub":"Subject"},
		repeat={"ses":"Session"},
		show=False,
		save_as='/tmp/f_reg_gc.png',
		)

	subject_effect = inline_anova(anova_summary,"C(Subject)",style="python")
	print("Subject Main Effect: {}".format(subject_effect))
	session_effect = inline_anova(anova_summary,"C(Session)",style="python")
	print("Session Main Effect: {}".format(session_effect))
Esempio n. 4
0
def reg_cc(
    path="~/ni_data/ofM.dr/preprocessing/composite",
    template="/usr/share/mouse-brain-atlases/dsurqec_200micron.nii",
    radius=8,
    autofind=False,
    plot=False,
    save="f_reg_quality",
    metrics=['CC', 'GC', 'MI'],
):
    from samri.utilities import bids_autofind
    from samri.plotting.aggregate import registration_qc
    from samri.report.registration import iter_measure_sim
    from samri.typesetting import inline_anova
    from samri.utilities import bids_substitution_iterator

    if autofind:
        path_template, substitutions = bids_autofind(path, "func")
    else:
        path_template = "{data_dir}/preprocessing/{preprocessing_dir}/sub-{subject}/ses-{session}/func/sub-{subject}_ses-{session}_acq-{acquisition}_task-{task}_cbv.nii.gz"
        substitutions = bids_substitution_iterator(
            ["ofM", "ofMaF", "ofMcF1", "ofMcF2", "ofMpF"],
            [
                "4001", "4007", "4008", "4011", "5692", "5694", "5699", "5700",
                "5704", "6255", "6262"
            ],
            ["CogB", "JogB"],
            "~/ni_data/ofM.dr/",
            "composite",
            acquisitions=['EPI', 'EPIlowcov'],
            validate_for_template=path_template,
        )

    for metric in metrics:
        df = iter_measure_sim(
            path_template,
            substitutions,
            template,
            metric=metric,
            radius_or_number_of_bins=radius,
            sampling_strategy="Regular",
            sampling_percentage=0.33,
            save_as=save + "_" + metric + ".csv",
        )
Esempio n. 5
0
def test_reg_qc(
    radius=5,
    autofind=False,
    plot=False,
):
    """This could be used as a continuous integration test function once we can distribute demo data."""
    from samri.utilities import bids_autofind
    from samri.plotting.aggregate import registration_qc
    from samri.report.registration import iter_measure_sim
    from samri.typesetting import inline_anova
    from samri.utilities import bids_substitution_iterator

    if autofind:
        path_template, substitutions = bids_autofind(
            "~/ni_data/ofM.dr/preprocessing/composite", "func")
    else:
        path_template = "{data_dir}/preprocessing/{preprocessing_dir}/sub-{subject}/ses-{session}/func/sub-{subject}_ses-{session}_acq-{acquisition}_task-{task}_cbv.nii.gz"
        substitutions = bids_substitution_iterator(
            ["ofM", "ofMaF", "ofMcF1", "ofMcF2", "ofMpF"],
            [
                "5689", "5690", "5691", "5694", "5706", "5700", "5704", "6255",
                "6262"
            ],
            ["CogB"],
            "~/ni_data/ofM.dr/",
            "composite",
            acquisitions=['EPI'],
            check_file_format=path_template,
        )

    df = iter_measure_sim(
        path_template,
        substitutions,
        "/usr/share/mouse-brain-atlases/dsurqec_200micron.nii",
        metric="CC",
        radius_or_number_of_bins=radius,
        sampling_strategy="Regular",
        sampling_percentage=0.33,
        save_as="f_reg_quality.csv",
    )
Esempio n. 6
0
def reg_cc(
        path = "~/ni_data/ofM.dr/preprocessing/composite",
        template = "/usr/share/mouse-brain-atlases/dsurqec_200micron.nii",
        radius=8,
        autofind=False,
        plot=False,
        save = "f_reg_quality",
        metrics = ['CC','GC','MI'],
        ):
        from samri.utilities import bids_autofind
        from samri.plotting.aggregate import registration_qc
        from samri.report.registration import iter_measure_sim
        from samri.typesetting import inline_anova
        from samri.utilities import bids_substitution_iterator

        if autofind:
                path_template, substitutions = bids_autofind(path,"func")
        else:
                path_template = "{data_dir}/preprocessing/{preprocessing_dir}/sub-{subject}/ses-{session}/func/sub-{subject}_ses-{session}_acq-{acquisition}_task-{task}_cbv.nii.gz"
                substitutions = bids_substitution_iterator(
                        ["ofM", "ofMaF", "ofMcF1", "ofMcF2", "ofMpF"],
                        ["4001","4007","4008","4011","5692","5694","5699","5700","5704","6255","6262"],
                        ["CogB","JogB"],
                        "~/ni_data/ofM.dr/",
                        "composite",
                        acquisitions=['EPI','EPIlowcov'],
                        validate_for_template=path_template,
                        )


        for metric in metrics:
                df = iter_measure_sim(path_template, substitutions,
                        template,
                        metric=metric,
                        radius_or_number_of_bins=radius,
                        sampling_strategy="Regular",
                        sampling_percentage=0.33,
			save_as= save + "_" + metric +  ".csv",
                        )
Esempio n. 7
0
def test_autofind():
    """We may be able to turn this into a CI function, if we put together a data fetching script for dummy (empty) BIDS-formatted data.
	"""
    from samri.utilities import bids_autofind
    from samri.plotting.aggregate import registration_qc
    from samri.report.registration import iter_measure_sim
    from samri.typesetting import inline_anova
    from samri.utilities import bids_substitution_iterator

    path_template, substitutions = bids_autofind(
        "~/ni_data/ofM.dr/preprocessing/composite", "func")

    df = iter_measure_sim(
        path_template,
        substitutions,
        "/usr/share/mouse-brain-atlases/dsurqec_200micron.nii",
        metric="CC",
        radius_or_number_of_bins=10,
        sampling_strategy="Regular",
        sampling_percentage=0.33,
        save_as=False,
    )

    anova_summary = registration_qc(
        df,
        value={"similarity": "Similarity"},
        group={"sub": "Subject"},
        repeat={"ses": "Session"},
        show=False,
        save_as="/tmp/f_reg_cc10.png",
    )

    subject_effect = inline_anova(anova_summary, "C(Subject)", style="python")
    print("Subject Main Effect: {}".format(subject_effect))
    session_effect = inline_anova(anova_summary, "C(Session)", style="python")
    print("Session Main Effect: {}".format(session_effect))