Skip to content

Commit

Permalink
feat: added temp dir to featurecounts (#455)
Browse files Browse the repository at this point in the history
* Added handling of tempdir

* Added author

* Fixed output file names and added doc

* Reformat

* Added missing argument
  • Loading branch information
fgvieira committed Feb 21, 2022
1 parent 3bee861 commit d93866e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
12 changes: 8 additions & 4 deletions bio/subread/featurecounts/meta.yaml
@@ -1,15 +1,19 @@
name: subread featureCounts
description: >
FeatureCounts assign mapped reads or fragments (paired-end data) to genomic features such as genes, exons and promoters.
For more information please see `featureCounts tutorial <http://bioinf.wehi.edu.au/featureCounts/>`_, `documentation of subread <https://bioconductor.org/packages/release/bioc/vignettes/Rsubread/inst/doc/SubreadUsersGuide.pdf>`_ and commandline help.
author:
- Antonie Vietor
- Filipe G. Vieira
input:
- a list of .sam or .bam files
- GTF, GFF or SAF annotation file
- optional a tab separating file that determines the sorting order and contains the chromosome names in the first column
- optional a fasta index file
output:
- .featureCounts file including read counts (tab separated)
- .featureCounts.summary file including summary statistics (tab separated)
- .featureCounts.jcounts file including count number of reads supporting each exon-exon junction (tab separated)
- Feature counts file including read counts (tab separated)
- Summary file including summary statistics (tab separated)
- Junction counts file including count number of reads supporting each exon-exon junction (tab separated)
notes: |
* The `extra` param allows for additional program arguments.
* For more information see, http://subread.sourceforge.net/ and https://bioconductor.org/packages/release/bioc/vignettes/Rsubread/inst/doc/SubreadUsersGuide.pdf
* For a tutorial see, http://bioinf.wehi.edu.au/featureCounts/
24 changes: 12 additions & 12 deletions bio/subread/featurecounts/test/Snakefile
@@ -1,22 +1,22 @@
rule feature_counts:
input:
sam="{sample}.bam", # list of sam or bam files
samples="{sample}.bam", # list of sam or bam files
annotation="annotation.gtf",
# optional input
# chr_names="", # implicitly sets the -A flag
# fasta="genome.fasta" # implicitly sets the -G flag
# fasta="genome.fasta" # implicitly sets the -G flag
output:
multiext("results/{sample}",
".featureCounts",
".featureCounts.summary",
".featureCounts.jcounts")
threads:
2
multiext(
"results/{sample}",
".featureCounts",
".featureCounts.summary",
".featureCounts.jcounts",
),
threads: 2
params:
tmp_dir="", # implicitly sets the --tmpDir flag
r_path="", # implicitly sets the --Rpath flag
extra="-O --fracOverlap 0.2"
r_path="", # implicitly sets the --Rpath flag
extra="-O --fracOverlap 0.2 -J",
log:
"logs/{sample}.log"
"logs/{sample}.log",
wrapper:
"master/bio/subread/featurecounts"
25 changes: 12 additions & 13 deletions bio/subread/featurecounts/wrapper.py
Expand Up @@ -3,6 +3,7 @@
__email__ = "antonie.v@gmx.de"
__license__ = "MIT"

import tempfile
from snakemake.shell import shell

log = snakemake.log_fmt_shell(stdout=True, stderr=True)
Expand All @@ -11,25 +12,23 @@
# optional input files and directories
fasta = snakemake.input.get("fasta", "")
chr_names = snakemake.input.get("chr_names", "")
tmp_dir = snakemake.params.get("tmp_dir", "")
r_path = snakemake.params.get("r_path", "")

if fasta:
extra += " -G {}".format(fasta)
if chr_names:
extra += " -A {}".format(chr_names)
if tmp_dir:
extra += " --tmpDir {}".format(tmp_dir)
if r_path:
extra += " --Rpath {}".format(r_path)

shell(
"(featureCounts"
" {extra}"
" -T {snakemake.threads}"
" -J"
" -a {snakemake.input.annotation}"
" -o {snakemake.output[0]}"
" {snakemake.input.sam})"
" {log}"
)
with tempfile.TemporaryDirectory() as tmpdir:
shell(
"featureCounts"
" -T {snakemake.threads}"
" -a {snakemake.input.annotation}"
" {extra}"
" --tmpDir {tmpdir}"
" -o {snakemake.output[0]}"
" {snakemake.input.samples}"
" {log}"
)

0 comments on commit d93866e

Please sign in to comment.