Skip to content

Commit

Permalink
Merge pull request #3 from akhanf/dev-0.2.0
Browse files Browse the repository at this point in the history
updates for 0.2.0
  • Loading branch information
akhanf authored Dec 14, 2020
2 parents 4451d87 + 710ca0e commit 0ce4a2f
Show file tree
Hide file tree
Showing 20 changed files with 298 additions and 32 deletions.
43 changes: 43 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
amply==0.1.4
appdirs==1.4.4
attrs==20.3.0
bids-validator==1.5.8
certifi==2020.12.5
chardet==3.0.4
click==7.1.2
ConfigArgParse==1.2.3
datrie==0.8.2
docopt==0.6.2
docutils==0.16
gitdb==4.0.5
GitPython==3.1.11
idna==2.10
ipython-genutils==0.2.0
jsonschema==3.2.0
jupyter-core==4.7.0
nbformat==5.0.8
nibabel==3.2.1
num2words==0.5.10
numpy==1.19.4
packaging==20.8
pandas==1.1.5
patsy==0.5.1
psutil==5.7.3
PuLP==2.3.1
pybids==0.12.3
pyparsing==2.4.7
pyrsistent==0.17.3
python-dateutil==2.8.1
pytz==2020.4
PyYAML==5.3.1
ratelimiter==1.2.0.post0
requests==2.25.0
scipy==1.5.4
six==1.15.0
smmap==3.0.4
snakemake==5.30.1
SQLAlchemy==1.3.20
toposort==1.5
traitlets==5.0.5
urllib3==1.26.2
wrapt==1.12.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="snakebids",
version="0.1.5",
version="0.2.0",
author="Ali Khan",
author_email="[email protected]",
description="BIDS integration into snakemake workflows",
Expand Down
38 changes: 25 additions & 13 deletions snakebids/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def run(command, env={}):

class SnakeBidsApp:

def __init__(self, snakemake_dir):
def __init__(self, snakemake_dir, skip_parse_args=False):

#input argument is the dir where snakemake would be run
# we use this to locate the config file, and snakefile adding them to generated_config
Expand Down Expand Up @@ -95,27 +95,32 @@ def __init__(self, snakemake_dir):




self.parse_args()
self.__load_config()

#add path to snakefile to the config -- so workflows can grab files relative to the snakefile folder
self.config['snakemake_dir'] = snakemake_dir

self.write_updated_config()
self.parser = self.__create_parser()

if not skip_parse_args:
self.__parse_args()




def parse_args(self):

#replace with proper name of pipeline here
parser = argparse.ArgumentParser(description='snakebids-app')
def __load_config(self):

#load up workflow config file
with open(self.snakebids_config, 'r') as infile:
self.config = yaml.load(infile, Loader=yaml.FullLoader)




def __create_parser(self):

#replace with proper name of pipeline here
parser = argparse.ArgumentParser(description='snakebids-app')

#update the parser with config options
for name, parse_args in self.config['parse_args'].items():
parser.add_argument(name, **parse_args)
Expand All @@ -133,14 +138,17 @@ def parse_args(self):
help=f'Filters (PyBIDS) for {input_type}, where {arginstance} is '
f'key=value pair(s) (default: {arglist_default_string})')

return parser


def __parse_args(self):


all_args = parser.parse_known_args()
all_args = self.parser.parse_known_args()

args = all_args[0]
snakemake_args = all_args[1]




#add arguments to config
self.config.update(args.__dict__)
Expand All @@ -160,7 +168,8 @@ def parse_args(self):
self.config['output_dir'] = os.path.realpath(self.config['output_dir'])


def write_updated_config(self):

def __write_updated_config(self):
#create an updated snakebids config file
self.updated_config = os.path.join(self.config['output_dir'],'config','snakebids.yml')

Expand All @@ -176,6 +185,9 @@ def write_updated_config(self):
#workflow snakefile will read snakebids config, create inputs_config, read that in
def run_snakemake(self):

#write updated config
self.__write_updated_config()

# running the chosen participant level

analysis_level = self.config['analysis_level']
Expand Down
Empty file added snakebids/tests/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions snakebids/tests/test_bids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .. import bids

def test_bids_subj():
assert bids(root='bids',subject='001',suffix='T1w.nii.gz') == 'bids/sub-001/sub-001_T1w.nii.gz'


3 changes: 0 additions & 3 deletions template_app/README.md

This file was deleted.

4 changes: 4 additions & 0 deletions template_app/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Template App
============

Description of app goes here
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"DatasetType": "derivative",
"GeneratedBy": [
{
"Name": "appname",
"Name": "app_name",
"Version": "0.1.0",
"CodeURL": "http://github.com/org/name"
"CodeURL": "http://github.com/org/name",
"Author": "Author name here",
"AuthorEmail": "Author email"

}
]
}
7 changes: 6 additions & 1 deletion template_app/run.py → template_app/app_name/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
from snakebids.app import SnakeBidsApp


def main():
def get_parser():
"""Exposes parser for sphinx doc generation, cwd is the docs dir"""
app = SnakeBidsApp('../app_name',skip_parse_args=True)
return app.parser


def main():
app = SnakeBidsApp(os.path.abspath(os.path.dirname(__file__)))
app.run_snakemake()

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions template_app/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_build
20 changes: 20 additions & 0 deletions template_app/docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
63 changes: 63 additions & 0 deletions template_app/docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import sphinx_rtd_theme


# -- Project information -----------------------------------------------------


project = 'app_name'
copyright = '2020, Authors here'
author = 'Authors here'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx_rtd_theme",
"sphinxarg.ext",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


master_doc = 'index'


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']




56 changes: 56 additions & 0 deletions template_app/docs/getting_started/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Installation
============

Template snakebids BIDS App


Requirements
------------

Docker (Mac/Windows/Linux) or Singularity (Linux)

Docker:
^^^^^^^

Pull the container:

.. code-block::
docker pull khanlab/app_name:latest
do a dry run, printing the command at each step:

.. code-block::
docker run -it --rm -v PATH_TO_BIDS_DIR:/bids:ro -v PATH_TO_OUTPUT_DIR:/output khanlab/app_name:latest /bids /output participant -np
run it with maximum number of cores:

.. code-block::
docker run -it --rm -v PATH_TO_BIDS_DIR:/bids:ro -v PATH_TO_OUTPUT_DIR:/output khanlab/app_name:latest /bids /output participant -p --cores all
Singularity:
^^^^^^^^^^^^

Pull the container:

.. code-block::
singularity pull khanlab_app_name_latest.sif docker://khanlab/app_name:latest
do a dry run, printing the command at each step:

.. code-block::
singularity run -e khanlab_app_name_latest.sif khanlab/app_name:latest PATH_TO_BIDS_DIR PATH_TO_OUTPUT_DIR participant -np
run it with maximum number of cores:

.. code-block::
singularity run -e khanlab_app_name_latest.sif khanlab/app_name:latest PATH_TO_BIDS_DIR PATH_TO_OUTPUT_DIR participant -p --cores all
32 changes: 32 additions & 0 deletions template_app/docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.. hippunfold documentation master file, created by
sphinx-quickstart on Thu Jul 30 10:15:34 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
.. include:: ../README.rst

.. toctree::
:maxdepth: 1
:caption: Contents:


.. toctree::
:caption: Getting started
:name: getting_started
:hidden:
:maxdepth: 1

getting_started/installation

.. toctree::
:caption: Usage
:name: usage
:hidden:
:maxdepth: 1

usage/app_cli
usage/snakemake_cli




3 changes: 3 additions & 0 deletions template_app/docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sphinx-argparse
sphinx_rtd_theme
snakebids==0.2.0
9 changes: 9 additions & 0 deletions template_app/docs/usage/app_cli.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Command line interface
--------------------

.. argparse::
:filename: ../app_name/run.py
:func: get_parser
:prog: hippunfold


9 changes: 9 additions & 0 deletions template_app/docs/usage/snakemake_cli.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Snakemake Command line interface
________________________________

.. argparse::
:module: snakemake
:func: get_argument_parser
:prog: snakemake


Loading

0 comments on commit 0ce4a2f

Please sign in to comment.