Skip to content

Commit

Permalink
feat: Bustools count (#511)
Browse files Browse the repository at this point in the history
* [fix] (template): Missing code in wrappers' doc. Error #187

* New tested wrapper

* Remove automatic addition from my IDE

* Removed automatic IDE addition

* Update bio/bustools/count/environment.yaml

Co-authored-by: tdayris <tdayris@gustaveroussy.fr>
Co-authored-by: tdayris <thibault.dayris@gustaveroussy.fr>
Co-authored-by: Johannes Köster <johannes.koester@uni-due.de>
  • Loading branch information
4 people committed Aug 16, 2022
1 parent 00f60b7 commit bb050e4
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bio/bustools/count/environment.yaml
@@ -0,0 +1,6 @@
channels:
- conda-forge
- bioconda
- nodefaults
dependencies:
- bustools =0.41
20 changes: 20 additions & 0 deletions bio/bustools/count/meta.yaml
@@ -0,0 +1,20 @@
name: bustools count
description: BUS files can be converted into a barcode-feature matrix
url: https://github.com/BUStools/bustools#count
author:
- Thibault Dayris
input:
- bus: Single bus-file, or List of bus-files
- genemap: Transcript to gene mapping
- txnames: List of transcripts
- ecmap: Equivalence classes for transcripts
output:
- barcodes, equivalence classes, and count matrix
params:
- extra: Optional parameters, besides `--output`, `--ecmap`, and `--genemap`
notes: |
When multiple bus files are provided, only one count matrix is returned.
When an output endswith: ".hist.txt", then `--hist` parameter is automatically used.
When an output endswith: ".genes.txt", then `--genemap` parameter is automatically used.
23 changes: 23 additions & 0 deletions bio/bustools/count/test/Snakefile
@@ -0,0 +1,23 @@
rule test_bustools_count:
input:
bus="file.bus",
ecmap="matrix.ec",
txnames="transcripts.txt",
genemap="t2g.txt",
output:
multiext(
"buscount",
".barcodes.txt",
".CUPerCell.txt",
".cu.txt",
".genes.txt",
".hist.txt",
".mtx",
),
threads: 1
params:
extra="",
log:
"bustools.log",
wrapper:
"master/bio/bustools/count"
Binary file added bio/bustools/count/test/file.bus
Binary file not shown.
20 changes: 20 additions & 0 deletions bio/bustools/count/test/matrix.ec
@@ -0,0 +1,20 @@
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 6,12
15 0,1,2
16 0,1
17 6,11
18 3,12
19 1,2
27 changes: 27 additions & 0 deletions bio/bustools/count/test/t2g.txt
@@ -0,0 +1,27 @@
ENST00000282507.7 ENSG00000168671.9
ENST00000513300.5 ENSG00000168671.9
ENST00000504685.5 ENSG00000168671.9
ENST00000504954.1 ENSG00000168671.9
ENST00000515131.1 ENSG00000168671.9
ENST00000512916.2 ENSG00000249641.2
ENST00000243056.4 ENSG00000123364.4
ENST00000243103.3 ENSG00000123407.3
ENST00000546378.1 ENSG00000123388.4
ENST00000243082.4 ENSG00000123388.4
ENST00000515593.1 ENSG00000180818.4
ENST00000303460.4 ENSG00000180818.4
ENST00000511575.1 ENSG00000180818.4
ENST00000514415.1 ENSG00000180818.4
ENST00000513413.2 ENSG00000180818.4
ENST00000504315.1 ENSG00000197757.7
ENST00000509328.1 ENSG00000197757.7
ENST00000394331.3 ENSG00000197757.7
ENST00000243108.4 ENSG00000197757.7
ENST00000504557.1 ENSG00000180806.4
ENST00000508190.1 ENSG00000180806.4
ENST00000303450.4 ENSG00000180806.4
ENST00000040584.5 ENSG00000037965.5
ENST00000303406.4 ENSG00000198353.7
ENST00000507650.1 ENSG00000198353.7
ENST00000430889.2 ENSG00000198353.7
ENST00000312492.2 ENSG00000172789.3
14 changes: 14 additions & 0 deletions bio/bustools/count/test/transcripts.txt
@@ -0,0 +1,14 @@
ENST00000513300.5
ENST00000282507.7
ENST00000504685.5
ENST00000243108.4
ENST00000303450.4
ENST00000243082.4
ENST00000303406.4
ENST00000303460.4
ENST00000243056.4
ENST00000312492.2
ENST00000040584.5
ENST00000430889.2
ENST00000394331.3
ENST00000243103.3
41 changes: 41 additions & 0 deletions bio/bustools/count/wrapper.py
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
# coding: utf-8

"""Snakemake wrapper for bustools count"""

__author__ = "Thibault Dayris"
__copyright__ = "Copyright 2022, Thibault Dayris"
__email__ = "thibault.dayris@gustaveroussy.fr"
__license__ = "MIT"

from snakemake.shell import shell
from os.path import commonprefix

log = snakemake.log_fmt_shell(stdout=True, stderr=True)

# Get IO files and prefixes
bus_files = snakemake.input["bus"]
if isinstance(bus_files, list):
bus_files = " ".join(bus_files)

out_prefix = commonprefix(snakemake.output)[:-1]

# Fill extra parameters if needed
extra = snakemake.params.get("extra", "")
if any(outfile.endswith(".hist.txt") for outfile in snakemake.output):
if "--hist" not in extra:
extra += " --hist"

if any(outfile.endswith(".genes.txt") for outfile in snakemake.output):
if "--genecounts" not in extra:
extra += " --genecounts"

shell(
"bustools count {extra} "
"--output {out_prefix} "
"--genemap {snakemake.input.genemap} "
"--ecmap {snakemake.input.ecmap} "
"--txnames {snakemake.input.txnames} "
"{bus_files} "
"{log}"
)
6 changes: 6 additions & 0 deletions test.py
Expand Up @@ -258,6 +258,12 @@ def test_open_cravat_run():
["snakemake", "--cores", "1", "--use-conda"],
)

@skip_if_not_modified
def test_bustools_count():
run(
"bio/bustools/count",
["snakemake", "--cores", "1", "--use-conda", "-F", "buscount.mtx"]
)

@skip_if_not_modified
def test_open_cravat_module():
Expand Down

0 comments on commit bb050e4

Please sign in to comment.