{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# FreeSurfer pre-processing use case\n\nCredit: A Grigis\n\nExample on how to run the FreeSurfer pre-processing using the brainprep\nSingularity container.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# sphinx_gallery_thumbnail_path = '_static/carousel/freesurfer.png'\n\nimport os\nimport subprocess\nfrom brainrise.datasets import MRIToyDataset"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Please tune these parameters: not that you need a valid FreeSurfer license.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "DATADIR = \"/tmp/brainprep-data\"\nOUTDIR = \"/tmp/brainprep-out\"\nHOMEDIR = \"/tmp/brainprep-home\"\nSCRIPT = \"fsreconall\"\nSIMG = \"/volatile/nsap/brainprep/anat/brainprep-anat-latest.simg\"\nFS_LICENSE = \"/out/license.txt\"\n\nfor path in (DATADIR, OUTDIR, HOMEDIR):\n    if not os.path.isdir(path):\n        os.mkdir(path)\ndataset = MRIToyDataset(root=DATADIR)\nt1w_file = os.path.join(DATADIR, os.path.basename(MRIToyDataset.t1w_url))\nmask_file = os.path.join(DATADIR, os.path.basename(MRIToyDataset.mask_url))\ncmd = [\"SINGULARITYENV_FS_LICENSE={0}\".format(FS_LICENSE),\n       \"singularity\", \"run\", \"--bind\", \"{0}:/data\".format(DATADIR),\n       \"--bind\", \"{0}:/out\".format(OUTDIR), \"--home\", HOMEDIR, \"--cleanenv\",\n       SIMG,\n       \"brainprep\", SCRIPT,\n       \"sub-test\",\n       t1w_file.replace(DATADIR, \"/data\"),\n       \"/out\"]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "You can now execute this command.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(\" \".join(cmd))"
      ]
    }
  ],
  "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.6.12"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}