This repository was archived by the owner on May 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnakefile
More file actions
147 lines (135 loc) · 5.18 KB
/
Snakefile
File metadata and controls
147 lines (135 loc) · 5.18 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
##############################################################################
#
# Snakemake pipeline:
# Run FastQC on RNA-Seq samples (quality analysis)
#
# AUTHOR: Maciej_Bak
# AFFILIATION: Swiss_Institute_of_Bioinformatics
# CONTACT: maciej.bak@unibas.ch
# CREATED: 21-11-2019
# LICENSE: Apache_2.0
#
##############################################################################
# imports
import sys
import os
import pandas as pd
# local rules
localrules: all, create_output_dir, extract_adapters,
# get all fastq files
def get_all_fastq():
design_table = pd.read_csv(config["design_file"], sep="\t", index_col=0)
x = list(design_table["fq1"])+list(design_table["fq2"])
x = [i.split("/")[-1].split(".")[0] for i in x if str(i)!="nan"]
return x
# get full path for a given RNA-Seq sample
def get_full_path(sample_name):
design_table = pd.read_csv(config["design_file"], sep="\t", index_col=0)
for i,row in design_table.iterrows():
if str(row["fq1"])!="nan":
if row["fq1"].find(sample_name)>-1:
return row["fq1"]
if str(row["fq2"])!="nan":
if row["fq2"].find(sample_name)>-1:
return row["fq2"]
##############################################################################
### Target rule with final output of the pipeline
##############################################################################
rule all:
input:
HTML_fastqc_report = \
expand(os.path.join("{output_dir}","{sample}_fastqc.html"), \
output_dir=config["output_dir"], \
sample=get_all_fastq())
##############################################################################
### Create directories for the result
##############################################################################
rule create_output_dir:
output:
TMP_output = temp(os.path.join("{output_dir}", "dir_created"))
params:
DIR_results_dir = "{output_dir}",
DIR_cluster_log = os.path.join("{output_dir}", "cluster_log"),
log:
DIR_local_log = os.path.join("{output_dir}", "local_log"),
shell:
"""
mkdir -p {params.DIR_results_dir}; \
mkdir -p {params.DIR_cluster_log}; \
mkdir -p {log.DIR_local_log}; \
touch {output.TMP_output}
"""
##############################################################################
### Extract adapter per fastq file
##############################################################################
rule extract_adapters:
input:
TMP_output = os.path.join("{output_dir}", "dir_created")
output:
DIR_adapter_dir = \
directory(os.path.join("{output_dir}", "adapters"))
log:
LOG_local_log = \
os.path.join("{output_dir}", "local_log", \
"extract_adapters.log"),
run:
# extract adapter sequence per each fastq file
# and save it to a separate text file
os.mkdir(output.DIR_adapter_dir)
design_table = \
pd.read_csv(config["design_file"],sep="\t", index_col=0)
for i,row in design_table.iterrows():
if str(row["fq1"])!="nan" and str(row["adapter1"])!="nan":
fname = row["fq1"].split("/")[-1].split(".")[0]+".txt"
path_adapter = os.path.join(output.DIR_adapter_dir,fname)
with open(path_adapter,"w") as f:
f.write(row["adapter1"]+"\t"+row["adapter1"]+"\n")
if str(row["fq2"])!="nan" and str(row["adapter2"])!="":
fname = row["fq2"].split("/")[-1].split(".")[0]+".txt"
path_adapter = os.path.join(output.DIR_adapter_dir,fname)
with open(path_adapter,"w") as f:
f.write(row["adapter2"]+"\t"+row["adapter2"]+"\n")
##############################################################################
### Reads alignment
##############################################################################
rule run_FastQC:
input:
DIR_adapter_dir = os.path.join("{output_dir}", "adapters"),
STRING_fastq_path = \
lambda wildcards: get_full_path(wildcards.sample)
output:
HTML_fastqc_report = \
os.path.join("{output_dir}", "{sample}_fastqc.html")
params:
DIR_outdir = "{output_dir}",
TXT_sample_adapter = \
os.path.join("{output_dir}", "adapters", "{sample}.txt"),
LOG_cluster_log = \
os.path.join("{output_dir}", "cluster_log", \
"run_FastQC_{sample}.log"),
queue = "30min",
time = "00:30:00"
log:
LOG_local_log = \
os.path.join("{output_dir}", "local_log", \
"run_FastQC_{sample}.log"),
resources:
threads = 4,
mem = 10000
benchmark:
os.path.join("{output_dir}",
"cluster_log", "run_FastQC_{sample}.benchmark.log")
conda:
"packages.yaml"
shell:
"""
fastqc {input.STRING_fastq_path} \
--outdir {params.DIR_outdir} \
--format fastq \
--nogroup \
--extract \
--adapters {params.TXT_sample_adapter} \
--threads {resources.threads} \
--kmers 7 \
&> {log.LOG_local_log}
"""