Skip to content

Commit cfed44f

Browse files
authored
Merge pull request #70 from Mayrlab/dev
Version 0.4.0
2 parents 444dad6 + 64e4c38 commit cfed44f

9 files changed

Lines changed: 185 additions & 70 deletions

File tree

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ repository directly tests running examples on the GitHub-hosted runners.
6969
### Conda/Mamba Mode (MacOS or Linux)
7070
Snakemake can use Conda to install the needed software. This configuration requires:
7171

72-
- [Snakemake][ref:snakemake] >= 5.11<sup>ª</sup>
72+
- [Snakemake][ref:snakemake] >= 6.0, < 8.0<sup>ª</sup>
7373
- [Conda](https://docs.conda.io/projects/conda/en/latest/)
7474

7575
If Conda is not already installed, we strongly recommend installing
@@ -84,7 +84,7 @@ conda install -n base -c conda-forge mamba
8484
Snakemake can use the pre-built scUTRsquant Docker image to provide all additional software.
8585
This configuration requires installing:
8686

87-
- [Snakemake][ref:snakemake] >= 5.11<sup>ª</sup>
87+
- [Snakemake][ref:snakemake] >= 6.0, < 8.0<sup>ª</sup>
8888
- [Singularity](https://singularity.lbl.gov/index.html)
8989

9090

@@ -96,7 +96,13 @@ This configuration requires installing:
9696
git clone git@github.com:Mayrlab/scUTRquant.git
9797
```
9898
99-
2. Download the UTRome annotation, kallisto index, and merge file.
99+
As of scUTRquant v0.4.0, that is all!
100+
101+
<details>
102+
103+
> *The following steps of prepopulating the annotations and barcode whitelists are now handled directly in the pipeline.*
104+
105+
2. (**Deprecated**) Download the UTRome annotation, kallisto index, and merge file.
100106
**Human (hg38)**
101107
```
102108
cd scUTRquant/extdata/targets/utrome_hg38_v1
@@ -112,7 +118,7 @@ This configuration requires installing:
112118
`utrome_kdx`, and `utrome_merge` to point to the central location. In that
113119
case, one does not need to redownload the files.
114120
115-
3. (Optional) Download the barcode whitelists.
121+
3. (**Deprecated** and Optional) Download the barcode whitelists.
116122
```
117123
cd scUTRquant/extdata/bxs
118124
sh download_10X_whitelists.sh
@@ -121,6 +127,7 @@ This configuration requires installing:
121127
and referenced by the `bx_whitelist` variable in the `configfile`.
122128
123129
For GitHub runners, it takes ~ 3 mins to clone and download the scUTRquant files.
130+
</details>
124131
125132
# Running Examples
126133
Examples are provided in the `scUTRquant/examples` folder. Each includes a script
@@ -219,6 +226,7 @@ pipeline. The following keys are expected:
219226
- `min_umis`: minimum number of UMIs per cell; cells below this threshold are excluded
220227
- `cell_annots`: (optional) CSV file with a key column that matches the `<sample_id>_<cell_bx>` format
221228
- `cell_annots_key`: specifies the name of the key column in the `cell_annots` file; default is `cell_id`
229+
- `exclude_unannotated_cells`: boolean indicating whether unannotated cells should be excluded from the final output; default is `False`
222230
223231
### Default Values
224232

Snakefile

Lines changed: 92 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
container: "docker://mfansler/scutr-quant:0.1.5"
22
configfile: "config.yaml"
33

4-
from snakemake.io import load_configfile
5-
import pandas as pd
64
import os
5+
import pandas as pd
6+
from snakemake.io import load_configfile
7+
from snakemake.utils import min_version
78
from sys import stderr
89

10+
# set minimum Snakemake version
11+
min_version("6.0")
12+
913
# print to stderr
1014
def message(*args, **kwargs):
1115
print(*args, file=stderr, **kwargs)
@@ -66,6 +70,66 @@ def get_outputs():
6670
rule all:
6771
input: get_outputs()
6872

73+
################################################################################
74+
## Downloading and Preprocessing
75+
################################################################################
76+
77+
## generate downloading rules for target files if a script is provided
78+
## NB: script should generate files *relative* to the script
79+
for target_id, target in targets.items():
80+
if 'download_script' not in target or target['download_script'] is None:
81+
continue
82+
83+
target_path = target['path']
84+
download_script = target_path + target['download_script']
85+
86+
FILE_KEYS = ['gtf', 'kdx', 'merge_tsv', 'tx_annots', 'gene_annots']
87+
target_files = [target_path + target[k] for k in FILE_KEYS]
88+
89+
rule:
90+
name: f"download_{target_id}"
91+
input: f"{download_script}"
92+
output: expand("{target_file}", target_file=target_files)
93+
conda: "envs/downloading.yaml"
94+
shell:
95+
"""
96+
pushd $(dirname {input})
97+
sh $(basename {input})
98+
popd
99+
"""
100+
101+
## Import downloading rules for barcodes
102+
module bxs_workflow:
103+
snakefile: "extdata/bxs/download.smk"
104+
105+
use rule * from bxs_workflow
106+
107+
## Convert merge data for tx output
108+
rule generate_tx_merge:
109+
input:
110+
tsv=get_target_file('merge_tsv')
111+
output:
112+
"data/utrs/{target}/tx_merge.tsv"
113+
shell:
114+
"""
115+
tail -n+2 {input.tsv} | cut -f1,2 > {output}
116+
"""
117+
118+
## Convert merge data for gene output
119+
rule generate_gene_merge:
120+
input:
121+
tsv=get_target_file('merge_tsv')
122+
output:
123+
"data/utrs/{target}/gene_merge.tsv"
124+
shell:
125+
"""
126+
tail -n+2 {input.tsv} | cut -f1,3 > {output}
127+
"""
128+
129+
################################################################################
130+
## kallisto-bustools
131+
################################################################################
132+
69133
def get_file_type(wildcards):
70134
return "--bam" if samples.file_type[wildcards.sample_id] == 'bam' else ""
71135

@@ -157,26 +221,6 @@ rule bustools_correct_sort:
157221
bustools sort -t{threads} -T {params.tmpDir} -o {output} {input}
158222
"""
159223

160-
rule generate_tx_merge:
161-
input:
162-
tsv=get_target_file('merge_tsv')
163-
output:
164-
"data/utrs/{target}/tx_merge.tsv"
165-
shell:
166-
"""
167-
tail -n+2 {input.tsv} | cut -f1,2 > {output}
168-
"""
169-
170-
rule generate_gene_merge:
171-
input:
172-
tsv=get_target_file('merge_tsv')
173-
output:
174-
"data/utrs/{target}/gene_merge.tsv"
175-
shell:
176-
"""
177-
tail -n+2 {input.tsv} | cut -f1,3 > {output}
178-
"""
179-
180224
def get_input_busfile(wildcards):
181225
if config['correct_bus']:
182226
return "data/kallisto/%s/%s/output.corrected.sorted.bus" % (wildcards.target, wildcards.sample_id)
@@ -219,18 +263,9 @@ rule bustools_count_genes:
219263
bustools count -e {input.ec} -t {input.txs} -g {input.merge} -o $prefix --em --genecounts {input.bus}
220264
"""
221265

222-
rule report_umis_per_cell:
223-
input:
224-
bxs="data/kallisto/{target}/{sample_id}/txs.barcodes.txt",
225-
txs="data/kallisto/{target}/{sample_id}/txs.genes.txt",
226-
mtx="data/kallisto/{target}/{sample_id}/txs.mtx"
227-
params:
228-
min_umis=config['min_umis']
229-
output:
230-
"qc/umi_count/{target}/{sample_id}.umi_count.html"
231-
conda: "envs/rmd-reporting.yaml"
232-
script:
233-
"scripts/report_umi_counts_per_cell.Rmd"
266+
################################################################################
267+
## Outputs
268+
################################################################################
234269

235270
rule mtxs_to_sce_txs:
236271
input:
@@ -250,6 +285,7 @@ rule mtxs_to_sce_txs:
250285
sample_ids=samples.index.values,
251286
min_umis=config['min_umis'],
252287
cell_annots_key=config['cell_annots_key'],
288+
exclude_unannotated_cells=config['exclude_unannotated_cells'],
253289
tmp_dir=config['tmp_dir'],
254290
use_hdf5=False
255291
resources:
@@ -276,6 +312,7 @@ rule mtxs_to_sce_genes:
276312
sample_ids=samples.index.values,
277313
min_umis=config['min_umis'],
278314
cell_annots_key=config['cell_annots_key'],
315+
exclude_unannotated_cells=config['exclude_unannotated_cells'],
279316
tmp_dir=config['tmp_dir'],
280317
use_hdf5=False
281318
resources:
@@ -303,6 +340,7 @@ rule mtxs_to_sce_h5_txs:
303340
sample_ids=samples.index.values,
304341
min_umis=config['min_umis'],
305342
cell_annots_key=config['cell_annots_key'],
343+
exclude_unannotated_cells=config['exclude_unannotated_cells'],
306344
tmp_dir=lambda wcs: config['tmp_dir'] + "/sce-txs-" + wcs.target + "-" + config['dataset_name'],
307345
use_hdf5=True
308346
resources:
@@ -331,6 +369,7 @@ rule mtxs_to_sce_h5_genes:
331369
sample_ids=samples.index.values,
332370
min_umis=config['min_umis'],
333371
cell_annots_key=config['cell_annots_key'],
372+
exclude_unannotated_cells=config['exclude_unannotated_cells'],
334373
tmp_dir=lambda wcs: config['tmp_dir'] + "/sce-genes-" + wcs.target + "-" + config['dataset_name'],
335374
use_hdf5=True
336375
resources:
@@ -339,3 +378,22 @@ rule mtxs_to_sce_h5_genes:
339378
conda: "envs/bioconductor-sce.yaml"
340379
script:
341380
"scripts/mtxs_to_sce_genes.R"
381+
382+
383+
################################################################################
384+
## Reports
385+
################################################################################
386+
387+
rule report_umis_per_cell:
388+
input:
389+
bxs="data/kallisto/{target}/{sample_id}/txs.barcodes.txt",
390+
txs="data/kallisto/{target}/{sample_id}/txs.genes.txt",
391+
mtx="data/kallisto/{target}/{sample_id}/txs.mtx"
392+
params:
393+
min_umis=config['min_umis']
394+
output:
395+
"qc/umi_count/{target}/{sample_id}.umi_count.html"
396+
conda: "envs/rmd-reporting.yaml"
397+
script:
398+
"scripts/report_umi_counts_per_cell.Rmd"
399+

config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ dataset_name: "output"
22
sample_regex: ".*"
33
cell_annots: null
44
cell_annots_key: "cell_id"
5+
exclude_unannotated_cells: False
56
target: "utrome_mm10_v2"
67
output_type:
78
- "txs"

envs/downloading.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: downloading
2+
channels:
3+
- conda-forge
4+
- nodefaults
5+
dependencies:
6+
- gzip
7+
- tar
8+
- wget

extdata/bxs/download.smk

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Download Rules
2+
##
3+
## Any rules added here will automatically be imported into the main Snakefile.
4+
## Important notes:
5+
## - all `input`/`output` must be relative to main Snakefile
6+
## - `conda` is relative to this file
7+
## - `shell` will execute relative to main Snakefile
8+
## - `download_10X_whitelists` shows how to run script in-place (see shell)
9+
10+
rule download_10X_whitelists:
11+
input: "extdata/bxs/download_10X_whitelists.sh"
12+
output:
13+
"extdata/bxs/737K-april-2014_rc.txt",
14+
"extdata/bxs/737K-august-2016.txt",
15+
"extdata/bxs/3M-february-2018.txt"
16+
conda: "../../envs/downloading.yaml"
17+
shell:
18+
"""
19+
pushd $(dirname {input})
20+
sh $(basename {input})
21+
popd
22+
"""

extdata/bxs/download_10X_whitelists.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env bash
22

33
# 10xv1
4-
wget https://github.com/10XGenomics/cellranger/raw/3.0.2/lib/python/cellranger/barcodes/737K-april-2014_rc.txt
4+
wget https://teichlab.github.io/scg_lib_structs/data/737K-april-2014_rc.txt.gz \
5+
&& gzip -d 737K-april-2014_rc.txt.gz
56

67
# 10xv2
7-
wget https://github.com/10XGenomics/cellranger/raw/3.0.2/lib/python/cellranger/barcodes/737K-august-2016.txt
8+
wget https://teichlab.github.io/scg_lib_structs/data/737K-august-2016.txt.gz \
9+
&& gzip -d 737K-august-2016.txt.gz
810

911
# 10xv3
10-
wget https://github.com/10XGenomics/cellranger/raw/3.0.2/lib/python/cellranger/barcodes/3M-february-2018.txt.gz \
12+
wget https://teichlab.github.io/scg_lib_structs/data/3M-february-2018.txt.gz \
1113
&& gzip -d 3M-february-2018.txt.gz
12-

extdata/targets/targets.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ utrome_mm10_v1:
66
merge_tsv: "adult.utrome.e3.t200.f0.999.w500.merge.tsv"
77
tx_annots: "utrome_txs_annotation.Rds"
88
gene_annots: "utrome_genes_annotation.Rds"
9+
download_script: "download_utrome.sh"
910

1011
utrome_mm10_v2:
1112
path: "extdata/targets/utrome_mm10_v2/"
@@ -15,6 +16,7 @@ utrome_mm10_v2:
1516
merge_tsv: "utrome.e30.t5.gc25.pas3.f0.9999.w500.m200.tsv"
1617
tx_annots: "utrome_txs_annotation.Rds"
1718
gene_annots: "utrome_genes_annotation.Rds"
19+
download_script: "download_utrome.sh"
1820

1921
utrome_hg38_v1:
2022
path: "extdata/targets/utrome_hg38_v1/"
@@ -24,6 +26,7 @@ utrome_hg38_v1:
2426
merge_tsv: "utrome.e30.t5.gc39.pas3.f0.9999.w500.m200.tsv"
2527
tx_annots: "utrome_txs_annotation.Rds"
2628
gene_annots: "utrome_genes_annotation.Rds"
29+
download_script: "download_utrome.sh"
2730

2831
## example custom target using GENCODE
2932
## see https://github.com/Mayrlab/txcutr-db

0 commit comments

Comments
 (0)