{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n\n#  Downloading and converting the Neurosynth database\n\n\nDownload and convert the Neurosynth database for analysis with NiMARE.\n\n..note::\n    This will likely change as we work to shift database querying to a remote\n    database, rather than handling it locally with NiMARE.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Start with the necessary imports\n--------------------------------\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import os.path as op\nfrom os import mkdir\nfrom neurosynth.base.dataset import download\n\nfrom nimare.io import convert_neurosynth_to_dataset\nfrom nimare.dataset import Dataset"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Download Neurosynth\n--------------------------------\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "out_dir = op.abspath('../example_data/')\nif not op.isdir(out_dir):\n    mkdir(out_dir)\n\nif not op.isfile(op.join(out_dir, 'database.txt')):\n    download(out_dir, unpack=True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Convert Neurosynth database to NiMARE dataset file\n--------------------------------------------------\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "dset = convert_neurosynth_to_dataset(op.join(out_dir, 'database.txt'),\n                                     op.join(out_dir, 'features.txt'))\ngz_file = op.join(out_dir, 'neurosynth_dataset.pkl.gz')\ndset.save(gz_file)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}