Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move shared functions to ccbr_tools and import them here #32

Merged
merged 10 commits into from
Sep 13, 2024
79 changes: 79 additions & 0 deletions .github/workflows/build-nextflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: build
# TODO replace tool_name with the name of your tool

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
workflow_dispatch:
inputs:
test_run:
type: boolean
default: false
required: true

env:
test_run: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.test_run }}

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 2
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install nextflow
uses: nf-core/setup-nextflow@v1
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install .[dev,test]
- name: Check CLI basics
run: |
which tool_name
tool_name --help
tool_name --version
tool_name --citation
- name: Stub run
run: |
mkdir -p tmp && pushd tmp
tool_name init
tool_name run -c conf/ci_stub.config -stub
popd
- name: Test run
if: ${{ env.test_run == 'true' }}
run: |
mkdir -p tmp && pushd tmp
tool_name init
tool_name run -c conf/ci_stub.config -profile docker
popd
- name: "Upload Artifact"
uses: actions/upload-artifact@v3
if: always() # run even if previous steps fail
with:
name: nextflow-log
path: .nextflow.log

build-status: # https://github.com/orgs/community/discussions/4324#discussioncomment-3477871
runs-on: ubuntu-latest
needs: [build]
if: always()
steps:
- name: Successful build
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0
- name: Failing build
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
44 changes: 0 additions & 44 deletions .github/workflows/build.yml

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/docs-mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: docs
on:
workflow_dispatch:
release:
types:
- published
push:
branches:
- main
paths:
- "docs/**"
- "**.md"
- .github/workflows/docs-mkdocs.yml
- mkdocs.yml

jobs:
mkdocs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: CCBR/actions/[email protected]
with:
github-token: ${{ github.token }}
29 changes: 0 additions & 29 deletions .github/workflows/docs.yml

This file was deleted.

22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

CCBR template for creating Nextflow pipelines <!-- TODO: replace this line with the description of TOOL_NAME -->

[![build](https://github.com/CCBR/CCBR_NextflowTemplate/actions/workflows/build.yml/badge.svg)](https://github.com/CCBR/CCBR_NextflowTemplate/actions/workflows/build.yml) <!-- TODO: replace CCBR/CCBR_NextflowTemplate with your OWNER/TOOL_NAME -->
<!-- TODO: replace CCBR/CCBR_NextflowTemplate in these badge links with your OWNER/TOOL_NAME -->

[![build](https://github.com/CCBR/CCBR_NextflowTemplate/actions/workflows/build-nextflow.yml/badge.svg)](https://github.com/CCBR/CCBR_NextflowTemplate/actions/workflows/build-nextflow.yml)
[![docs](https://github.com/CCBR/CCBR_NextflowTemplate/actions/workflows/docs-mkdocs.yml/badge.svg)](https://github.com/CCBR/CCBR_NextflowTemplate/actions/workflows/docs-mkdocs.yml)

See the website for detailed information, documentation, and examples:
<https://ccbr.github.io/TOOL_NAME/>

## Using this template

Expand Down Expand Up @@ -77,10 +83,22 @@ Install the tool in edit mode:
pip3 install -e .
```

View CLI options:

```sh
tool_name --help
```

Navigate to your project directory and initialize required config files:

```sh
tool_name init
```

Run the example

```sh
TOOL_NAME run --input "Hello world"
tool_name run --input "Hello world"
```

![dag](assets/dag.png)
Expand Down
6 changes: 0 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,3 @@
--8<-- "README.md"

<!--- write additional info that you only want to appear in the docs index here -->

Information on who the pipeline was developed for, and a statement if it's only been tested on Biowulf. For example:

It has been developed and tested solely on NIH [HPC Biowulf](https://hpc.nih.gov/).

Also include a workflow image to summarize the pipeline.
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Topic :: Scientific/Engineering :: Bio-Informatics",
]
requires-python = ">=3.8"
requires-python = ">=3.10"
dependencies = [
"pyyaml >= 6.0",
"ccbr_tools@git+https://github.com/CCBR/Tools",
"cffconvert >= 2.0.0",
"Click >= 8.1.3",
"cffconvert >= 2.0.0"
"pyyaml >= 6.0"
]

[project.optional-dependencies]
Expand Down
81 changes: 62 additions & 19 deletions src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@
Check out the wiki for a detailed look at customizing this file:
https://github.com/beardymcjohnface/Snaketool/wiki/Customising-your-Snaketool
"""

import os
import cffconvert.cli.cli
import click
from .util import (
nek_base,
get_version,
copy_config,
OrderedCommands,
run_nextflow,
print_citation,
)
import os
import pathlib

import ccbr_tools.pkg_util
import ccbr_tools.pipeline.util
import ccbr_tools.pipeline.nextflow


def repo_base(*paths):
basedir = pathlib.Path(__file__).absolute().parent.parent
return basedir.joinpath(*paths)


def print_citation_flag(ctx, param, value):
if not value or ctx.resilient_parsing:
return
ccbr_tools.pkg_util.print_citation(
citation_file=repo_base("CITATION.cff"), output_format="bibtex"
)
ctx.exit()


def common_options(func):
Expand All @@ -28,15 +39,22 @@ def common_options(func):


@click.group(
cls=OrderedCommands, context_settings=dict(help_option_names=["-h", "--help"])
cls=ccbr_tools.pkg_util.CustomClickGroup,
context_settings=dict(help_option_names=["-h", "--help"]),
)
@click.version_option(
ccbr_tools.pkg_util.get_version(repo_base=repo_base),
"-v",
"--version",
is_flag=True,
)
@click.version_option(get_version(), "-v", "--version", is_flag=True)
@click.option(
"-c",
"--citation",
callback=print_citation_flag,
is_eager=True,
is_flag=True,
callback=print_citation,
expose_value=False,
is_eager=True,
help="Print the citation in bibtex format and exit.",
)
def cli():
Expand Down Expand Up @@ -74,7 +92,7 @@ def cli():
"main_path",
help="Path to the tool_name main.nf file or the GitHub repo (CCBR/TOOL_NAME). Defaults to the version installed in the $PATH.",
type=str,
default=nek_base(os.path.join("main.nf")),
default=repo_base("main.nf"),
show_default=True,
)
@click.option(
Expand All @@ -97,7 +115,7 @@ def run(main_path, _mode, **kwargs):
f"Path to the tool_name main.nf file not found: {main_path}"
)

run_nextflow(
ccbr_tools.pipeline.nextflow.run_nextflow(
nextfile_path=main_path,
mode=_mode,
**kwargs,
Expand All @@ -108,13 +126,38 @@ def run(main_path, _mode, **kwargs):
def init(**kwargs):
"""Initialize the working directory by copying the system default config files"""
paths = ("nextflow.config", "conf/", "assets/")
copy_config(paths)
if not os.path.exists("log/"):
os.mkdir("log/")
ccbr_tools.pipeline.util.copy_config(paths, repo_base=repo_base)
os.makedirs("log", exist_ok=True)


@click.command()
@click.argument(
"citation_file",
type=click.Path(exists=True),
required=True,
default=repo_base("CITATION.cff"),
)
@click.option(
"--output-format",
"-f",
default="bibtex",
help="Output format for the citation",
type=cffconvert.cli.cli.options["outputformat"]["type"],
)
def cite(citation_file, output_format):
"""
Print the citation in the desired format

citation_file : Path to a file in Citation File Format (CFF) [default: the CFF for ccbr_tools]
"""
ccbr_tools.pkg_util.print_citation(
citation_file=citation_file, output_format=output_format
)


cli.add_command(run)
cli.add_command(init)
cli.add_command(cite)


def main():
Expand Down
Loading
Loading