Skip to content

Commit

Permalink
Adding base scaffold and boilerplate for pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
skchronicles committed Feb 18, 2022
1 parent 2c823f1 commit 8b8f3a4
Show file tree
Hide file tree
Showing 20 changed files with 818 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4

[*.{yml,yaml}]
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.smk linguist-language=Python
Snakefile linguist-language=Python
161 changes: 161 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site
site/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# DS_Store
.DS_Store
._*
**/.DS_Store
**/._*

.snakemake*
**/.snakemake*
.venv
.venv/*

# Pipeline Results or Output
results/
output/
tmp/
scratch/

# mkdocs documentation
site/

# Pipeline generated files or directories
.tests/*/
.snakemake/

# Cached Java directories
.oracle_jre_usage/
.java/

# GNU Parallel
.parallel/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0-beta] - 2022-02-18
### Added
- Recommended scaffold for building a snakemake pipeline
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 OpenOmics

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0-beta
8 changes: 8 additions & 0 deletions config/cluster.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"__default__": {
"threads": "4",
"mem": "8g",
"partition": "norm",
"time": "0-04:00:00"
}
}
6 changes: 6 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"inputs": {
},
"options": {
}
}
4 changes: 4 additions & 0 deletions config/containers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"images": {
}
}
4 changes: 4 additions & 0 deletions config/genome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"references": {
}
}
4 changes: 4 additions & 0 deletions config/modules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tools": {
}
}
35 changes: 35 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Steps for Building Docker Images

Directly below are instructions for building an image using the provided Dockerfile:

```bash
# See listing of images on computer
docker image ls

# Build from Dockerfile
docker build --no-cache -f example.dockerfile --tag=example:v0.1.0 .

# Testing, take a peek inside
docker run -ti example:v0.1.0 /bin/bash

# Updating Tag before pushing to DockerHub
docker tag example:v0.1.0 skchronicles/example:v0.1.0
docker tag example:v0.1.0 skchronicles/example # latest

# Check out new tag(s)
docker image ls

# Push new tagged image to DockerHub
docker push skchronicles/example:v0.1.0
docker push skchronicles/example:latest
```

### Other Recommended Steps

Scan your image for known vulnerabilities:

```bash
docker scan example:v0.1.0
```

> **Please Note**: Any references to `skchronicles` should be replaced your username if you would also like to push the image to a non-org account.
5 changes: 5 additions & 0 deletions resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Resources

This folder, `resources/`, is meant to contain all resources necessary for running the workflow. This can be small reference files, such as reference sequences or small databases. This directory also contains utility scripts or wrappers to help facilitate running the pipeline.

Whenever feasible, they can also be downloaded programmatically via rules defined in the pipeline.
10 changes: 10 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os, sys
# Makes relative imports to work in Python 3.6
# without the need of '.' before the name of the
# package or py file.
# Allows for consistent syntax of relative imports
# across python2 and python3.
sys.path.append(os.path.dirname(os.path.realpath(__file__)))

# Ground source of truth for version information
version = open('../VERSION', 'r').readlines()[0].strip()
70 changes: 70 additions & 0 deletions src/shells.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

# Python standard library
from __future__ import print_function
from subprocess import CalledProcessError
import os, subprocess

# Local imports
from utils import fatal, err


def set_options(strict):
"""
Changes behavior of default shell and get overrides options
to run bash in a strict mode.
@param strict <bool>:
Overrides default shell options and runs shell in strict or
less permissive mode.
@return prefix <int>:
Returns overrides options to run bash in a strict mode
"""
prefix = '' # permissive shell option
if strict:
# Changes behavior of default shell
# set -e: exit immediately upon error
# set -u: treats unset variables as an error
# set -o pipefail: exits if a error occurs in any point of a pipeline
prefix = 'set -euo pipefail; '

return prefix


def bash(cmd, interpreter='/bin/bash', strict=set_options(True), cwd=os.getcwd(), **kwargs):
"""
Interface to run a process or bash command. Using subprocess.call_check()
due to portability across most python versions. It was introduced in python 2.5
and it is also interoperabie across all python 3 versions.
@param cmd <str>:
Shell command to run
@param interpreter <str>:
Interpreter for command to run [default: bash]
@pararm strict <bool>:
Prefixes any command with 'set -euo pipefail' to ensure process fail with
the expected exit-code
@params kwargs <check_call()>:
Keyword arguments to modify subprocess.check_call() behavior
@return exitcode <int>:
Returns the exit code of the run command, failures return non-zero exit codes
"""
try:
exitcode = subprocess.check_call(strict + cmd,
shell=True,
executable=interpreter,
cwd=cwd,
**kwargs
)
except CalledProcessError as e:
exitcode = e.returncode
err("""WARNING: Failed to run '{}' command!
└── Command returned a non-zero exitcode of '{}'.""".format(strict + cmd, exitcode)
)

return exitcode


if __name__ == '__main__':
# Tests
bash('ls -la /home/')
bash('ls -la /fake/dne/path')
Loading

0 comments on commit 8b8f3a4

Please sign in to comment.