11container : "docker://mfansler/scutr-quant:0.1.5"
22configfile : "config.yaml"
33
4- from snakemake .io import load_configfile
5- import pandas as pd
64import os
5+ import pandas as pd
6+ from snakemake .io import load_configfile
7+ from snakemake .utils import min_version
78from sys import stderr
89
10+ # set minimum Snakemake version
11+ min_version ("6.0" )
12+
913# print to stderr
1014def message (* args , ** kwargs ):
1115 print (* args , file = stderr , ** kwargs )
@@ -66,6 +70,66 @@ def get_outputs():
6670rule 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+
69133def 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-
180224def 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
235270rule 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+
0 commit comments