Skip to content

Commit

Permalink
feat: Add seqkit subseq (#1318)
Browse files Browse the repository at this point in the history
### Description
Adds the seqkit subseq command with support for optional bed and gtf
inputs as well as the CLI --region flag.


### QC

* [X] 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
sallustfire and fgvieira committed May 1, 2023
1 parent 96a2cbb commit 262d9bb
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bio/seqkit/subseq/environment.yaml
@@ -0,0 +1,6 @@
channels:
- conda-forge
- bioconda
- nodefaults
dependencies:
- seqkit =2.4.0
13 changes: 13 additions & 0 deletions bio/seqkit/subseq/meta.yaml
@@ -0,0 +1,13 @@
name: SeqKit subseq
url: https://bioinf.shenwei.me/seqkit/usage/#subseq
description: |
Run SeqKit grep to get subsequences by region/gtf/bed, including flanking sequences.
authors:
- Connor McEntee
input:
- fasta: Input FASTA file
- gtf: GTF (version 2.2) file
output:
- fasta: Output FASTA file
params:
- extra: Optional parameters
40 changes: 40 additions & 0 deletions bio/seqkit/subseq/test/Snakefile
@@ -0,0 +1,40 @@
rule seqkit_subseq_bed:
input:
fasta="sequences/t.fa",
bed="sequences/t.bed",
output:
fasta="out/subseq_bed/t_bed.fa.gz",
log:
"logs/subseq_bed/bed.log",
threads: 2
wrapper:
"master/bio/seqkit/subseq"


rule seqkit_subseq_gtf:
input:
fasta="sequences/t.fa",
gtf="sequences/t.gtf",
output:
fasta="out/subseq_gtf/t_gtf.fa.gz",
log:
"logs/subseq_gtf/gtf.log",
params:
extra="--feature CDS",
threads: 2
wrapper:
"master/bio/seqkit/subseq"


rule seqkit_subseq_region:
input:
fasta="sequences/t.fa",
output:
fasta="out/subseq_region/t_region.fa.gz",
log:
"logs/subseq_region/region.log",
params:
extra="--region 1:12",
threads: 2
wrapper:
"master/bio/seqkit/subseq"
1 change: 1 addition & 0 deletions bio/seqkit/subseq/test/sequences/t.bed
@@ -0,0 +1 @@
seq 4 8
3 changes: 3 additions & 0 deletions bio/seqkit/subseq/test/sequences/t.fa
@@ -0,0 +1,3 @@
>seq
actgACTGactgn

2 changes: 2 additions & 0 deletions bio/seqkit/subseq/test/sequences/t.gtf
@@ -0,0 +1,2 @@
seq test CDS 5 8 . . . gene_id "A"; transcript_id "";
seq test CDS 5 8 . - . gene_id "B"; transcript_id "";
27 changes: 27 additions & 0 deletions bio/seqkit/subseq/wrapper.py
@@ -0,0 +1,27 @@
__author__ = "Connor McEntee"
__license__ = "MIT"

from snakemake.shell import shell

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

bed = snakemake.input.get("bed", "")
if bed:
bed = f"--bed {bed}"

gtf = snakemake.input.get("gtf", "")
if gtf:
gtf = f"--gtf {gtf}"


shell(
"seqkit subseq"
" --threads {snakemake.threads}"
" {bed}"
" {gtf}"
" {extra}"
" --out-file {snakemake.output.fasta}"
" {snakemake.input.fasta}"
" {log}"
)
36 changes: 36 additions & 0 deletions test.py
Expand Up @@ -287,6 +287,42 @@ def test_seqkit_grep():
],
)

@skip_if_not_modified
def test_seqkit_subseq():
run(
"bio/seqkit/subseq",
[
"snakemake",
"--cores",
"2",
"--use-conda",
"-F",
"out/subseq_bed/t_bed.fa.gz",
],
)
run(
"bio/seqkit/subseq",
[
"snakemake",
"--cores",
"2",
"--use-conda",
"-F",
"out/subseq_gtf/t_gtf.fa.gz",
],
)
run(
"bio/seqkit/subseq",
[
"snakemake",
"--cores",
"2",
"--use-conda",
"-F",
"out/subseq_region/t_region.fa.gz",
],
)

@skip_if_not_modified
def test_sickle_pe():
run(
Expand Down

0 comments on commit 262d9bb

Please sign in to comment.