diff --git a/examples/easy_start/nipype_preproc_spm_auditory.py b/examples/easy_start/nipype_preproc_spm_auditory.py index c8b9211c..0fdab3ab 100644 --- a/examples/easy_start/nipype_preproc_spm_auditory.py +++ b/examples/easy_start/nipype_preproc_spm_auditory.py @@ -9,7 +9,6 @@ import nibabel from pypreprocess.nipype_preproc_spm_utils import do_subjects_preproc from pypreprocess.datasets import fetch_spm_auditory -from pypreprocess.reporting.glm_reporter import generate_subject_stats_report import pandas as pd from nilearn.glm.first_level.design_matrix import (make_first_level_design_matrix, check_design_matrix) diff --git a/examples/pipelining/nipype_preproc_spm_multimodal_faces.py b/examples/pipelining/nipype_preproc_spm_multimodal_faces.py index 5c32e421..a764991a 100644 --- a/examples/pipelining/nipype_preproc_spm_multimodal_faces.py +++ b/examples/pipelining/nipype_preproc_spm_multimodal_faces.py @@ -20,8 +20,6 @@ # pypreprocess imports from pypreprocess.datasets import fetch_spm_multimodal_fmri -from pypreprocess.reporting.base_reporter import ProgressReport -from pypreprocess.reporting.glm_reporter import generate_subject_stats_report from pypreprocess.nipype_preproc_spm_utils import do_subject_preproc from pypreprocess.subject_data import SubjectData diff --git a/examples/pipelining/nistats_glm_fsl_feeds_fmri.py b/examples/pipelining/nistats_glm_fsl_feeds_fmri.py index cd1ed509..c588d8b7 100644 --- a/examples/pipelining/nistats_glm_fsl_feeds_fmri.py +++ b/examples/pipelining/nistats_glm_fsl_feeds_fmri.py @@ -14,8 +14,6 @@ import time from pypreprocess.nipype_preproc_spm_utils import (SubjectData, do_subjects_preproc) -from pypreprocess.reporting.glm_reporter import generate_subject_stats_report -from pypreprocess.reporting.base_reporter import ProgressReport from pypreprocess.datasets import fetch_fsl_feeds from pypreprocess.io_utils import compute_mean_3D_image diff --git a/pypreprocess/conf_parser.py b/pypreprocess/conf_parser.py index 2891433f..4a69617c 100644 --- a/pypreprocess/conf_parser.py +++ b/pypreprocess/conf_parser.py @@ -445,9 +445,4 @@ def _ignore_subject(subject_id): return subjects, preproc_params # this pseudo is better -import_data = _generate_preproc_pipeline - - -if __name__ == '__main__': - from pypreprocess.reporting.base_reporter import dict_to_html_ul - print(dict_to_html_ul(_parse_job("job.conf"))) +import_data = _generate_preproc_pipeline \ No newline at end of file diff --git a/pypreprocess/nipype_preproc_spm_utils.py b/pypreprocess/nipype_preproc_spm_utils.py index 48f58b5f..c251c488 100644 --- a/pypreprocess/nipype_preproc_spm_utils.py +++ b/pypreprocess/nipype_preproc_spm_utils.py @@ -34,7 +34,7 @@ _do_subject_smooth as _pp_do_subject_smooth) from nilearn.plotting.html_document import HTMLDocument -from .reporting.preproc_reporter import (_set_templates,embed_in_HTML, +from .reporting.pypreproc_reporter import (_set_templates,embed_in_HTML, initialize_report, add_component, finalize_report, generate_realignment_report, generate_registration_report, generate_corregistration_report, generate_segmentation_report, diff --git a/pypreprocess/purepython_preproc_utils.py b/pypreprocess/purepython_preproc_utils.py index b2f83955..271c01aa 100644 --- a/pypreprocess/purepython_preproc_utils.py +++ b/pypreprocess/purepython_preproc_utils.py @@ -8,7 +8,7 @@ import os import inspect -from .reporting.preproc_reporter import ( +from .reporting.pypreproc_reporter import ( generate_preproc_steps_docstring) from joblib import Memory from .io_utils import get_basenames, save_vols, is_niimg, load_vols diff --git a/pypreprocess/reporting/glm_reporter.py b/pypreprocess/reporting/glm_reporter.py deleted file mode 100644 index 95940eeb..00000000 --- a/pypreprocess/reporting/glm_reporter.py +++ /dev/null @@ -1,485 +0,0 @@ -import os -import sys -import numpy as np -import pylab as pl -import nibabel -from nilearn.plotting import plot_stat_map -from nilearn.image import reorder_img -from pypreprocess.external.nistats.design_matrix import plot_design_matrix -from pypreprocess.external.nistats.glm import FirstLevelGLM -import pandas as pd -from nilearn.masking import intersect_masks -from . import base_reporter -from ..cluster_level_analysis import cluster_stats - - -def generate_level1_stats_table(zmap, mask, - output_html_path, - p_threshold=.001, - z_threshold=None, - height_control='fpr', - cluster_th=15, - null_zmax='bonferroni', - null_smax=None, - null_s=None, - nmaxima=4, - cluster_pval=.05, - title=None): - """Function to generate level 1 stats table for a contrast. - - Parameters - ---------- - zmap: image object - z-map data image - - mask: image object or string - - - brain mask defining ROI - - output_html_path: string, - path where the output html should be written - - p_threshold: float (optional, default .001) - (p-variate) frequentist threshold of the activation image - - z_threshold: float (optional, default None) - Threshold that has been applied to Z map (input z_map) - - height_control: string - false positive control meaning of cluster forming - threshold: 'fpr'|'fdr'|'bonferroni'|'none' - - cluster_th: int (optional, default 15) - cluster size threshold (in # voxels) - - null_zmax: string (optional, default 'bonferroni') - parameter for cluster level statistics (?) - - null_s: strint (optional, default None) - parameter for cluster level statistics (?) - - nmaxima: int (optional, default 4) - number of local maxima reported per supra-threshold cluster - - title: string (optional) - title of generated stats table - - """ - # sanity - if isinstance(zmap, str): - zmap = nibabel.load(zmap) - if isinstance(mask, str): - mask = nibabel.load(mask) - - # Compute cluster statistics - nulls = {'zmax': null_zmax, 'smax': null_smax, 's': null_s} - - # do some sanity checks - if title is None: - title = "Level 1 Statistics" - clusters, _ = cluster_stats(zmap, mask, p_threshold, - nulls=nulls, cluster_th=cluster_th, - height_control=height_control) - if clusters is not None: - clusters = [c for c in clusters if c['cluster_p_value'] < cluster_pval] - else: - clusters = [] - - # Make HTML page - page = open(output_html_path, mode="w") - page.write("
\n") - page.write("%s\n" % title) - page.write("\n") - page.write("\ - \ - \n") - page.write("\ - ") - page.write("\ - \n") - - for cluster in clusters: - maxima = cluster['maxima'] - size = cluster['size'] - for j in range(min(len(maxima), nmaxima)): - temp = ["%.3f" % cluster['fwer_p_value'][j]] - temp.append("%.3f" % cluster['fdr_p_value'][j]) - temp.append("%.2f" % cluster['z_score'][j]) - temp.append("%.3f" % cluster['p_value'][j]) - for it in range(3): - temp.append("%.0f" % maxima[j][it]) - if j == 0: - # Main local maximum - temp.append('%i' % size) - page.write('\ - ') - else: - # Secondary local maxima - page.write('\ - \n') - - nclust = len(clusters) - nvox = sum([clusters[k]['size'] for k in range(nclust)]) - - # finish up - page.write("
Voxel significance Coordinates in MNI referentialCluster Size
p FWE corr
(Bonferroni)
p FDR corrZp uncorr x (mm) y (mm) z (mm) (voxels)
' + ''.join(temp) + '
' + ''.join(temp) + '
\n") - page.write("Threshold Z: %.2f (%s control at %.3f)
\n" - % (z_threshold, height_control, p_threshold)) - page.write("Cluster level p-value threshold: %s
\n" % cluster_pval) - page.write("Cluster size threshold: %i voxels
\n" % cluster_th) - page.write("Number of voxels: %i
\n" % nvox) - page.write("Number of clusters: %i
\n" % nclust) - page.write("
\n") - page.close() - return clusters - - -def generate_subject_stats_report( - stats_report_filename, - contrasts, - z_maps, - mask, - design_matrices=None, - subject_id=None, - anat=None, - display_mode="z", - cut_coords=None, - threshold=2.3, - cluster_th=15, - start_time=None, - title=None, - user_script_name=None, - progress_logger=None, - shutdown_all_reloaders=True, - **glm_kwargs): - """Generates a report summarizing the statistical methods and results - - Parameters - ---------- - stats_report_filename: string: - html file to which output (generated html) will be written - - contrasts: dict of arrays - contrasts we are interested in; same number of contrasts as zmaps; - same keys - - zmaps: dict of image objects or strings (image filenames) - zmaps for contrasts we are interested in; one per contrast id - - mask: 'nifti image object' - brain mask for ROI - - design_matrix: list of 'DesignMatrix', `numpy.ndarray` objects or of - strings (.png, .npz, etc.) for filenames - design matrices for the experimental conditions - - contrasts: dict of arrays - dictionary of contrasts of interest; the keys are the contrast ids, - the values are contrast values (lists) - - z_maps: dict of 3D image objects or strings (image filenames) - dict with same keys as 'contrasts'; the values are paths of z-maps - for the respective contrasts - - anat: 3D array (optional) - brain image to serve bg unto which activation maps will be plotted - - anat_affine: 2D array (optional) - affine data for the anat - - threshold: float (optional) - threshold to be applied to activation maps voxel-wise - - cluster_th: int (optional) - minimal voxel count for clusteres declared as 'activated' - - cmap: cmap object (default viz.cm.cold_hot) - color-map to use in plotting activation maps - - start_time: string (optional) - start time for the stats analysis (useful for the generated - report page) - - user_script_name: string (optional, default None) - existing filename, path to user script used in doing the analysis - - progress_logger: ProgressLogger object (optional) - handle for logging progress - - shutdown_all_reloaders: bool (optional, default True) - if True, all pages connected to the stats report page will - be prevented from reloading after the stats report page - has been completely generated - - **glm_kwargs: - kwargs used to specify the control parameters used to specify the - experimental paradigm and the GLM - - """ - # prepare for stats reporting - if progress_logger is None: - progress_logger = base_reporter.ProgressReport() - - output_dir = os.path.dirname(stats_report_filename) - if not os.path.exists(output_dir): - os.makedirs(output_dir) - - # copy css and js stuff to output dir - base_reporter.copy_web_conf_files(output_dir) - - # initialize gallery of design matrices - design_thumbs = base_reporter.ResultsGallery( - loader_filename=os.path.join(output_dir, - "design.html") - ) - - # initialize gallery of activation maps - activation_thumbs = base_reporter.ResultsGallery( - loader_filename=os.path.join(output_dir, - "activation.html") - ) - - # get caller module handle from stack-frame - if user_script_name is None: - user_script_name = sys.argv[0] - user_source_code = base_reporter.get_module_source_code( - user_script_name) - - methods = """ - GLM and Statistical Inference have been done using the %s script, \ -powered by nistats.""" % (user_script_name, - base_reporter.NISTATS_URL) - - # report the control parameters used in the paradigm and analysis - design_params = "" - glm_kwargs["contrasts"] = contrasts - if len(glm_kwargs): - design_params += ("The following control parameters were used for " - " specifying the experimental paradigm and fitting the " - "GLM: