# Path: neurosynth/base/imageutils.py
# def get_sphere(coords, r=4, vox_dims=(2, 2, 2), dims=(91, 109, 91)):
# def map_peaks_to_image(peaks, r=4, vox_dims=(2, 2, 2), dims=(91, 109, 91),
#                        header=None):
# def load_imgs(filenames, masker, nan_to_num=True):
# def save_img(data, filename, masker, header=None):
# def threshold_img(data, threshold, mask=None, mask_out='below'):
# def create_grid(image, scale=4, apply_mask=True, save_file=None):
# 
# Path: neurosynth/analysis/stats.py
# def pearson(x, y):
# def two_way(cells):
# def one_way(data, n):
# def fdr(p, q=.05):


import logging
import numpy as np
from scipy.stats import norm
from neurosynth.base import imageutils
from neurosynth.analysis import stats
from os.path import join, exists
from os import makedirs
    if features is None:
        features = dataset.get_feature_names()
    if output_dir is None:
        result = np.zeros((dataset.masker.n_vox_in_mask, len(features)))

    for i, f in enumerate(features):
        ids = dataset.get_studies(features=f, frequency_threshold=threshold)
        ma = MetaAnalysis(dataset, ids, q=q)
        if output_dir is None:
            result[:, i] = ma.images[image_type]
        else:
            pfx = f if prefix is None else prefix + '_' + f
            ma.save_results(output_dir=output_dir, prefix=pfx)

    if output_dir is None:
        return result


class MetaAnalysis(object):

    """ Meta-analysis of a Dataset. Currently contrasts two subsets of
    studies within a Dataset and saves a bunch of statistical images.
    Only one list of study IDs (ids) needs to be passed; the Universe will
    be bisected into studies that are and are not included in the
    list, and the contrast is then performed across these two groups.
    If a second optional second study list is provided (ids2), the Dataset
    is first constrained to the union of ids1 and ids2, and the standard
    contrast is then performed."""

    def __init__(self, dataset, ids, ids2=None, q=0.01, prior=0.5,

# Path: neurosynth/base/imageutils.py
# def get_sphere(coords, r=4, vox_dims=(2, 2, 2), dims=(91, 109, 91)):
# def map_peaks_to_image(peaks, r=4, vox_dims=(2, 2, 2), dims=(91, 109, 91),
#                        header=None):
# def load_imgs(filenames, masker, nan_to_num=True):
# def save_img(data, filename, masker, header=None):
# def threshold_img(data, threshold, mask=None, mask_out='below'):
# def create_grid(image, scale=4, apply_mask=True, save_file=None):
# 
# Path: neurosynth/analysis/stats.py
# def pearson(x, y):
# def two_way(cells):
# def one_way(data, n):
# def fdr(p, q=.05):


# Path: neurosynth/analysis/meta.py
import logging
import numpy as np
from scipy.stats import norm
from neurosynth.base import imageutils
from neurosynth.analysis import stats
from os.path import join, exists
from os import makedirs

    if features is None:
        features = dataset.get_feature_names()
    if output_dir is None:
        result = np.zeros((dataset.masker.n_vox_in_mask, len(features)))

    for i, f in enumerate(features):
        ids = dataset.get_studies(features=f, frequency_threshold=threshold)
        ma = MetaAnalysis(dataset, ids, q=q)
        if output_dir is None:
            result[:, i] = ma.images[image_type]
        else:
            pfx = f if prefix is None else prefix + '_' + f
            ma.save_results(output_dir=output_dir, prefix=pfx)

    if output_dir is None:
        return result


class MetaAnalysis(object):

    """ Meta-analysis of a Dataset. Currently contrasts two subsets of
    studies within a Dataset and saves a bunch of statistical images.
    Only one list of study IDs (ids) needs to be passed; the Universe will
    be bisected into studies that are and are not included in the
    list, and the contrast is then performed across these two groups.
    If a second optional second study list is provided (ids2), the Dataset
    is first constrained to the union of ids1 and ids2, and the standard
    contrast is then performed."""

    def __init__(self, dataset, ids, ids2=None, q=0.01, prior=0.5,

                 min_studies=1):