-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqc.smk
More file actions
190 lines (160 loc) · 5.13 KB
/
Copy pathqc.smk
File metadata and controls
190 lines (160 loc) · 5.13 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# vim: set syntax=snakemake:
from os.path import exists
# ================================================
# FASTQC
# ================================================
def get_fastq(wildcards):
if wildcards.step == "raw":
ext = "fastq.gz"
else:
ext = "fq.gz"
path = "results/reads/{step}/{dataset}/{file}.{ext}".format(
step = wildcards.step,
dataset = wildcards.dataset,
file = wildcards.file,
ext = ext
)
return path
rule fastqc:
""" FastQC on the raw reads and on trimmed reads. """
input:
get_fastq
output:
"results/qc/{step}/{dataset}/{file}_fastqc.html",
"results/qc/{step}/{dataset}/{file}_fastqc.zip"
params:
outdir = lambda wildcards, output: dirname(output[0])
threads: 4
log:
run = "logs/fastqc/{step}/{dataset}/{file}.log",
version = "logs/fastqc/{step}/{dataset}/{file}_versions.yaml"
conda:
"../envs/qc.yaml"
shadow: "shallow"
shell:
fmt("""
fastqc --outdir {params.outdir} \\
--threads {threads} \\
--dir . \\
{input} \\
> {log.run} 2>&1
cat <<-END_VERSION > {log.version}
{rule}:
fastqc: "$(fastqc --version | grep -oE [0-9.]+)"
date: "$(date -Iseconds)"
condaenv: "$CONDA_PREFIX"
END_VERSION
""")
# ================================================
# MULTIQC
# ================================================
def get_dataset_runs(wildcards):
"""
Input function for MultiQC. Includes all logs, reports etc. that multiqc
can read for each step.
That includes in raw reads the fastqc reports , and in trimmed reads the
fastqc reports and salmon quant logs.
"""
# Trimmed reads have a different naming scheme for paired-end fastq files.
if wildcards.step == "raw":
pairs = ["1", "2"]
else:
pairs = ["1_paired", "2_paired"]
# Get run accession numbers of the dataset
run_accessions = runs \
.query(f"DatasetReadable == '{wildcards.dataset}'") \
.RunAccession \
.to_list()
# Single-end and Paired-end reads have different file names.
if is_paired_end(wildcards.dataset):
file = expand(
"{accession}_{pair}_fastqc",
accession = run_accessions,
pair = pairs
)
else:
file = expand(
"{accession}_fastqc",
accession = run_accessions
)
paths = expand(
"results/qc/{step}/{dataset}/{file}.{ext}",
step = wildcards.step,
dataset = wildcards.dataset,
file = file,
ext = ["html", "zip"]
)
# Include STAR alignment logs, if they exist...
quant_logs = f"results/alignment/{wildcards.dataset}"
if wildcards.step == "trimmed" and exists(quant_logs):
paths.append(quant_logs)
# Include featureCounts quantification summary, if it exists...
count_summary = f"results/counts/{wildcards.dataset}"
if wildcards.step == "trimmed" and exists(count_summary):
paths.append(count_summary)
return paths
rule multiqc:
""" MultiQC for raw data before trimming """
input:
get_dataset_runs
output:
"results/qc/{step}/{dataset}/multiqc_report.html",
directory("results/qc/{step}/{dataset}/multiqc_data")
params:
indir = lambda wildcards, input: dirname(input[0]),
outdir = lambda wildcards, output: dirname(output[0])
log:
run = "logs/multiqc/{dataset}_{step}.log",
version = "logs/multiqc/{dataset}_{step}_versions.yaml"
conda:
"../envs/qc.yaml"
shell:
fmt("""
multiqc \\
-o {params.outdir} \\
{input} \\
> {log.run} 2>&1
cat <<-END_VERSION > {log.version}
{rule}:
multiqc: "$(multiqc --version | grep -oE [0-9.]+)"
date: "$(date -Iseconds)"
condaenv: "$CONDA_PREFIX"
END_VERSION
""")
rule test_multiqc:
input:
expand("results/qc/trimmed/{dataset}/multiqc_report.html",
dataset = [
"ERP122753",
"SRP066848",
"SRP069883",
"SRP111368",
"SRP159459",
"SRP234382",
"SRP246348",
"SRP324587",
"INH01_Papez",
"INH02_NovakProducers",
"INH03_WeingunySubclones",
"INH04_WeingunySubclonability",
"INH05_Novak2019Clones",
"INH06_Ruckerbauer",
"INH07_NovakTempShift"
]
)
rule raw_multiqc:
input:
expand(
"results/qc/raw/{dataset}/multiqc_report.html",
dataset = runs.DatasetReadable
)
rule trimmed_multiqc:
input:
expand(
"results/qc/trimmed/{dataset}/multiqc_report.html",
dataset = runs.DatasetReadable.unique().tolist()
)
rule run_multiqc:
input:
rules.raw_multiqc.input,
rules.trimmed_multiqc.input