Skip to content

Commit

Permalink
Merge pull request #7 from beardymcjohnface/dev
Browse files Browse the repository at this point in the history
Move utils to separate package
  • Loading branch information
beardymcjohnface authored Jun 26, 2023
2 parents e580b1e + c38289a commit 0d08a6c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
strategy:
matrix:
os: [macos-12, ubuntu-latest]
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: "actions/checkout@v3"
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Snaketool

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![](https://img.shields.io/static/v1?label=Citation&message=PlosCompBiol&color=blue)](https://doi.org/10.1371/journal.pcbi.1010705)
[![](https://img.shields.io/static/v1?label=Licence&message=MIT&color=black)](https://opensource.org/license/mit/)
![GitHub last commit](https://img.shields.io/github/last-commit/beardymcjohnface/snaketool)
[![CI](https://github.com/beardymcjohnface/Snaketool/actions/workflows/python-app.yml/badge.svg)](https://github.com/beardymcjohnface/Snaketool/actions/workflows/python-app.yml)

---

[Cookiecutter](https://github.com/cookiecutter/cookiecutter) profile for making a Snakemake-based bioinformatics tool.

__See [Nektool](https://github.com/beardymcjohnface/Nektool) for a NextFlow-based template__
Expand Down Expand Up @@ -63,7 +66,6 @@ And here's what you get:
│   ├── my_snaketool.CITATION
│   ├── my_snaketool.LICENSE
│   ├── my_snaketool.VERSION
│   ├── util.py
│   └── workflow
│   └── Snakefile
├── README.md
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"project_version": "0.1.0",
"citation_doi": "",
"license": ["MIT license", "BSD license", "ISC License (ISCL)", "Apache Software License", "GNU General Public License v3 (GPLv3)", "Other/Proprietary License"],
"min_python_version": ">=3.7",
"min_python_version": ">=3.9",
"snakemake_version": ">=7.14.0",
"pyyaml_version": ">=6.0",
"click_version": ">=8.1.3"
Expand Down
5 changes: 3 additions & 2 deletions {{cookiecutter.project_slug}}/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def get_data_files():
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Bio-Informatics",
]

Expand All @@ -52,6 +52,7 @@ def get_data_files():
data_files=get_data_files(),
py_modules=["{{cookiecutter.project_slug}}"],
install_requires=[
"snaketool-utils>=0.0.2",
"snakemake{{cookiecutter.snakemake_version}}",
"pyyaml{{cookiecutter.pyyaml_version}}",
"Click{{cookiecutter.click_version}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,33 @@
import os
import click

from .util import (
snake_base,
get_version,
default_to_output,
copy_config,
run_snakemake,
OrderedCommands,
print_citation,
)
from snaketool_utils.cli_utils import OrderedCommands, run_snakemake, copy_config, echo_click


def snake_base(rel_path):
"""Get the filepath to a Snaketool system file (relative to __main__.py)"""
return os.path.join(os.path.dirname(os.path.realpath(__file__)), rel_path)


def get_version():
"""Read and print the version from the version file"""
with open(snake_base("{{cookiecutter.project_slug}}.VERSION"), "r") as f:
version = f.readline()
return version


def print_citation():
"""Read and print the Citation information from the citation file"""
with open(snake_base("{{cookiecutter.project_slug}}.CITATION"), "r") as f:
for line in f:
echo_click(line)


def default_to_output(ctx, param, value):
"""Callback for click options; places value in output directory unless specified"""
if param.default == value:
return os.path.join(ctx.params["output"], value)
return value


def common_options(func):
Expand Down Expand Up @@ -122,12 +140,17 @@ def cli():
def run(_input, output, log, **kwargs):
"""Run {{cookiecutter.project_name}}"""
# Config to add or update in configfile
merge_config = {"input": _input, "output": output, "log": log}
merge_config = {
"input": _input,
"output": output,
"log": log
}

# run!
run_snakemake(
# Full path to Snakefile
snakefile_path=snake_base(os.path.join("workflow", "Snakefile")),
system_config=snake_base(os.path.join("config", "config.yaml")),
merge_config=merge_config,
log=log,
**kwargs
Expand All @@ -138,7 +161,7 @@ def run(_input, output, log, **kwargs):
@common_options
def config(configfile, **kwargs):
"""Copy the system default config file"""
copy_config(configfile)
copy_config(configfile, system_config=snake_base(os.path.join("config", "config.yaml")))


@click.command()
Expand Down
189 changes: 0 additions & 189 deletions {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/util.py

This file was deleted.

0 comments on commit 0d08a6c

Please sign in to comment.