-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnakefile
More file actions
160 lines (145 loc) · 5.25 KB
/
Copy pathSnakefile
File metadata and controls
160 lines (145 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import os
import glob
from snakemake.io import glob_wildcards
from snakemake.io import expand
DATA_DIR=config["Data_dir"]
REF_PATH=config["Ref_path"]
META_PATH=config["Meta_path"]
PATTERN = "{batch}/{prefix}_MiSeq-{suffix}/{sample}.fastq.gz"
samples_path = os.path.join(DATA_DIR, PATTERN)
batches, prefixes, suffixes, samples = glob_wildcards(samples_path)
run_map = {
(b, s): f"{p}_MiSeq-{sx}"
for b, p, sx, s in zip(batches, prefixes, suffixes, samples)}
PAIRS = sorted(run_map.keys())
#targets = [f"sports_final/{b}/1_{s}/{s}_result/{s}_output.txt" for b, s in PAIRS]
rule all:
input:
"out_data/01_data_processing.html",
"out_data/02_overview_plots.html",
"out_data/03_de_analysis.html"
def input_path(wc):
run = run_map[(wc.batch, wc.sample)]
return os.path.join(DATA_DIR, wc.batch, run, f"{wc.sample}.fastq.gz")
# For the Adapter-seq see: https://support-docs.illumina.com/SHARE/AdapterSequences/Content/SHARE/AdapterSeq/TruSeq/TruSeqSmallRNA.htm
rule trimming:
input:
input_path
output:
trimmed_fastq="trimmed_final/{batch}/{sample}.fastq"
params:
adapter_seq="TGGAATTCTCGGGTGCCAAGG",
out_dir="trimmed_final"
threads: 1
shell:
"""
mkdir -p {params.out_dir}
cutadapt -a "{params.adapter_seq}" -o "{params.out_dir}/{wildcards.batch}/{wildcards.sample}.fastq" {input} --maximum-length 50 --minimum-length 15
"""
rule reads_cleaning:
input:
trimmed_fastq=rules.trimming.output.trimmed_fastq
output:
filtered_fastq="filtered_final/{batch}/{sample}.fastq"
params:
trimmed_dir=rules.trimming.params.out_dir,
out_dir="filtered_final"
threads: 1
script: "src/readCleaning.R"
rule sports_align:
input:
filtered_fastq=rules.reads_cleaning.output.filtered_fastq
output:
aligned_sample="sports_final/{batch}/1_{sample}/{sample}_result/{sample}_output.txt"
params:
ref_path=REF_PATH,
out_dir="sports_final"
threads: 4
log: "logs/sports_{batch}_{sample}.txt"
shell:
"""
exec 2>>{log}
mkdir -p {params.out_dir}
sports.pl -i {input.filtered_fastq} -p 8 -o {params.out_dir}/{wildcards.batch} -M 2 \
-g {params.ref_path}/UCSC/mm10/Sequence/BowtieIndex/genome \
-m {params.ref_path}/miRBase_21/miRBase_21-mmu \
-r {params.ref_path}/rRNAdb/mouse_rRNA \
-t {params.ref_path}/GtRNAdb/mm10-tRNAs \
-e {params.ref_path}/Ensembl/Mus_musculus.GRCm38.ncrna \
-f {params.ref_path}/Rfam_12.3/Rfam-12.3-mouse \
-w {params.ref_path}/piRBase/piR_mouse \
-L 50
"""
def sports_all_samples(wc):
return [
f"sports_final/{b}/1_{s}/{s}_result/{s}_output.txt"
for (b, s) in PAIRS
]
rule construct_se:
input:
sports_all_samples
output:
output_html="out_data/01_data_processing.html",
se="out_data/01_sports_se.rds"
params:
out_dir="out_data",
meta_path=META_PATH,
sports_dir=rules.sports_align.params.out_dir
threads: 1
log: "logs/construct_se.log"
shell:
"""
exec 2>>{log}
mkdir -p {params.out_dir}
Rscript -e 'rmarkdown::render("src/01_data_processing.Rmd",
"html_document",
output_file="../{output.output_html}",
params=list(sports_dir="../{params.sports_dir}",
out_dir="../{params.out_dir}",
meta_path="../{params.meta_path}"))'
"""
#TODO: check filtering reads stats first!!
rule quality_plots:
input:
se=rules.construct_se.output.se,
ephys_path="ephys.csv"
output:
se="out_data/02_sports_se.rds",
output_html="out_data/02_overview_plots.html"
params:
out_data_dir=rules.construct_se.params.out_dir,
out_plot_dir="plots"
threads: 1
log: "logs/quality_plots.log"
shell:
"""
mkdir -p {params.out_plot_dir}
exec 2>>{log}
Rscript -e 'rmarkdown::render("src/02_overview_plots.Rmd",
"html_document",
output_file="../{output.output_html}",
params=list(se_dir="../{input.se}",
ephys_path="../{input.ephys_path}",
out_data_dir="../{params.out_data_dir}",
out_plots_dir="../{params.out_plot_dir}"))'
"""
rule differential_testing:
input:
se=rules.quality_plots.output.se
output:
output_html="out_data/03_de_analysis.html"
params:
out_data_dir=rules.construct_se.params.out_dir,
out_plot_dir=rules.quality_plots.params.out_plot_dir,
threads: 1
log: "logs/differential_testing.log"
shell:
"""
exec 2>>{log}
Rscript -e 'rmarkdown::render("src/03_de_analysis.Rmd",
"html_document",
output_file="../{output.output_html}",
params=list(se_dir="../{input.se}",
out_data_dir="../{params.out_data_dir}",
out_plots_dir="../{params.out_plot_dir}"))'
"""