Skip to content

Commit

Permalink
feat: barrnap-wrapper (#1448)
Browse files Browse the repository at this point in the history
### Description
A wrapper for barrnap, a  bacterial ribosomal RNA predictor.

### QC

* [ ] I confirm that:

For all wrappers added by this PR, 

* there is a test case which covers any introduced changes,
* `input:` and `output:` file paths in the resulting rule can be changed
arbitrarily,
* either the wrapper can only use a single core, or the example rule
contains a `threads: x` statement with `x` being a reasonable default,
* rule names in the test case are in
[snake_case](https://en.wikipedia.org/wiki/Snake_case) and somehow tell
what the rule is about or match the tools purpose or name (e.g.,
`map_reads` for a step that maps reads),
* all `environment.yaml` specifications follow [the respective best
practices](https://stackoverflow.com/a/64594513/2352071),
* wherever possible, command line arguments are inferred and set
automatically (e.g. based on file extensions in `input:` or `output:`),
* all fields of the example rules in the `Snakefile`s and their entries
are explained via comments (`input:`/`output:`/`params:` etc.),
* `stderr` and/or `stdout` are logged correctly (`log:`), depending on
the wrapped tool,
* temporary files are either written to a unique hidden folder in the
working directory, or (better) stored where the Python function
`tempfile.gettempdir()` points to (see
[here](https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir);
this also means that using any Python `tempfile` default behavior
works),
* the `meta.yaml` contains a link to the documentation of the respective
tool or command,
* `Snakefile`s pass the linting (`snakemake --lint`),
* `Snakefile`s are formatted with
[snakefmt](https://github.com/snakemake/snakefmt),
* Python wrapper scripts are formatted with
[black](https://black.readthedocs.io).
* Conda environments use a minimal amount of channels, in recommended
ordering. E.g. for bioconda, use (conda-forge, bioconda, nodefaults, as
conda-forge should have highest priority and defaults channels are
usually not needed because most packages are in conda-forge nowadays).

---------

Co-authored-by: Filipe G. Vieira <1151762+fgvieira@users.noreply.github.com>
  • Loading branch information
currocam and fgvieira committed Jun 22, 2023
1 parent 96a3958 commit 34e4e2c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bio/barrnap/environment.yaml
@@ -0,0 +1,5 @@
channels:
- bioconda
- conda-forge
dependencies:
- barrnap =0.9
14 changes: 14 additions & 0 deletions bio/barrnap/meta.yaml
@@ -0,0 +1,14 @@
name: barrnap
description: BAsic Rapid Ribosomal RNA Predictor
url: https://github.com/tseemann/barrnap
authors:
- Curro Campuzano Jiménez
input:
- fasta: query fasta file
output:
- gff: The rRNA locations in GFF3 format.
- fasta: Optional. Fasta file with the hit sequences.
params:
- extra: additional parameters
- kingdom: database to use, either Bacteria:`bac`, Archaea:`arc`, Eukaryota:`euk` or Metazoan Mitochondria:`mito`.
notes: Multiple threads can be used during nhmmer search.
14 changes: 14 additions & 0 deletions bio/barrnap/test/Snakefile
@@ -0,0 +1,14 @@
rule barrnap:
input:
fasta="{sample}.fasta",
output:
gff="{sample}.gff",
fasta="{sample}_hits.fasta",
params:
kingdom="bac",
extra="",
threads: 1
log:
"logs/barrnap/{sample}.log",
wrapper:
"master/bio/barrnap"
22 changes: 22 additions & 0 deletions bio/barrnap/test/mitochondria.fasta
@@ -0,0 +1,22 @@
>gi|13272612|gb|AF346967.1| Homo sapiens mitochondrion, fragment
GATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGGGGG
GTGTGCACGCGATAGCATTGCGAGACGCTGGAGCCGGAGCACCCTATGTCGCAGTATCTGTCTTTGATTC
CTGCCTCATTCTATTATTTATCGCACCTACGTTCAATATTACAGGCGAACATACCTACTAAAGTGTGTTA
ATTAATTAATGCTTGTAGGACATAATAATAACAATTGAATGTCTGCACAGCCGCTTTCCACACAGACATC
ATAACAAAAAATTTCCACCAAACCCCCCCTCCCCCCGCTTCTGGCCACAGCACTTAAACACATCTCTGCC
AAACCCCAAAAACAAAGAACCCTAACACCAGCCTAACCAGATTTCAAATTTTATCTTTTGGCGGTATGCA
CTTTTAACAGTCACCCCCCAACTAACACATTATTTTCCCCTCCCACTCCCATACTACTAATCTCATCAAT
ACAACCCCCGCCCATCCTACCCAGCACACACACCGCTGCTAACCCCATACCCCGAACCAACCAAACCCCA
AAGACACCCCCCACAGTTTATGTAGCTTACCTCCTCAAAGCAATACACTGAAAATGTTTAGACGGGCTCA
CATCACCCCATAAACAAATAGGTTTGGTCCTAGCCTTTCTATTAGCTCTTAGTAAGATTACACATGCAAG
CATCCCCGTTCCAGTGAGTTCACCCTCTAAATCACCACGATCAAAAGGAACAAGCATCAAGCACGCAGCA
ATGCAGCTCAAAACGCTTAGCCTAGCCACACCCCCACGGGAAACAGCAGTGATTAACCTTTAGCAATAAA
CGAAAGTTTAACTAAGCTATACTAACCCCAGGGTTGGTCAATTTCGTGCCAGCCACCGCGGTCACACGAT
TAACCCAAGTCAATAGAAGCCGGCGTAAAGAGTGTTTTAGATCACCCCCTCCCCAATAAAGCTAAAACTC
ACCTGAGTTGTAAAAAACTCCAGTTGACACAAAATAGACTACGAAAGTGGCTTTAACATATCTGAACACA
CAATAGCTAAGACCCAAACTGGGATTAGATACCCCACTATGCTTAGCCCTAAACCTCAACAGTTAAATCA
ACAAAACTGCTCGCCAGAACACTACGAGCCACAGCTTAAAACTCAAAGGACCTGGCGGTGCTTCATATCC
CTCTAGAGGAGCCTGTTCTGTAATCGATAAACCCCGATCAACCTCACCACCTCTTGCTCAGCCTATATAC
CGCCATCTTCAGCAAACCCTGATGAAGGCTACAAAGTAAGCGCAAGTACCCACGTAAAGACGTTAGGTCA
AGGTGTAGCCCATGAGGTGGCAAGAAATGGGCTACATTTTCTACCCCAGAAAACTACGATAGCCCTTATG
AAACTTAAGGGTCGAAGGTGGATTTAGCAGTAAACTGAGAGTAGAGTGCTTAGTTGAACAGGGCCCTGAA
27 changes: 27 additions & 0 deletions bio/barrnap/wrapper.py
@@ -0,0 +1,27 @@
"""Snakemake wrapper for barrnap."""

__author__ = "Curro Campuzano Jiménez"
__copyright__ = "Copyright 2023, Curro Campuzano Jiménez"
__email__ = "campuzanocurro@gmail.com"
__license__ = "MIT"


from snakemake.shell import shell

log = snakemake.log_fmt_shell(stdout=False, stderr=True)
extra = snakemake.params.get("extra", "")
kingdom = snakemake.params.get("kingdom", "bac")

fasta_out = snakemake.output.get("fasta")
if fasta_out:
extra += f" -o {fasta_out}"

shell(
"barrnap"
" --threads {snakemake.threads}"
" -k {kingdom}"
" {extra}"
" < {snakemake.input.fasta}"
" > {snakemake.output.gff}"
" {log}"
)
15 changes: 14 additions & 1 deletion test.py
Expand Up @@ -5606,7 +5606,6 @@ def test_bazam_separated():
],
)


@skip_if_not_modified
def test_ragtag_correction():
run(
Expand Down Expand Up @@ -5665,3 +5664,17 @@ def test_ragtag_merge():
"-F",
],
)

@skip_if_not_modified
def test_barrnap():
run(
"bio/barrnap",
[
"snakemake",
"--cores",
"1",
"mitochondria.gff",
"--use-conda",
"-F",
],
)

0 comments on commit 34e4e2c

Please sign in to comment.