Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
input:
outdir1 = expand(
os.path.join(
config['output_dir'],
"{seqmode}",
"{sample}",
"mate1_fastqc"),
zip,
sample=[i for i in list(samples_table.index.values)],
seqmode=[samples_table.loc[i, 'seqmode']
for i in list(samples_table.index.values)]),
pseudoalignment = expand(
os.path.join(
config['output_dir'],
"{seqmode}",
"{sample}",
"quant_kallisto",
"{sample}.kallisto.pseudo.sam"),
zip,
sample=[i for i in list(samples_table.index.values)],
seqmode=[samples_table.loc[i, 'seqmode']
for i in list(samples_table.index.values)]),
TIN_boxplot_PNG = os.path.join(
config['output_dir'],
"TIN_scores_boxplot.png"),
TIN_boxplot_PDF = os.path.join(
config['output_dir'],
"TIN_scores_boxplot.pdf"),
salmon_merge_genes = expand(
os.path.join(
config["output_dir"],
"summary_salmon",
"quantmerge",
"genes_{salmon_merge_on}.tsv"),
salmon_merge_on=["tpm", "numreads"]),
salmon_merge_transcripts = expand(
os.path.join(
config["output_dir"],
"summary_salmon",
"quantmerge",
"transcripts_{salmon_merge_on}.tsv"),
salmon_merge_on=["tpm", "numreads"]),
star_rpm = expand(
os.path.join(
config["output_dir"],
"{seqmode}",
"{sample}",
"STAR_coverage",
"{sample}_Signal.UniqueMultiple.str1.out.bg"),
zip,
sample=[i for i in list(samples_table.index.values)],
seqmode=[samples_table.loc[i, 'seqmode']
for i in list(samples_table.index.values)]),
samples_dir_result = directory(os.path.join(
config["output_dir"],
"samples")),
samples_dir_log = directory(os.path.join(
config["log_dir"],
"samples"))
params:
results_dir = config["output_dir"],
log_dir = config["log_dir"],
log:
stderr = os.path.join(
config["log_dir"],
"prepare_files_for_report.stderr.log"),
stdout = os.path.join(
config["log_dir"],
"prepare_files_for_report.stdout.log")
run:
# remove "single/paired end" from the results directories
os.mkdir(output.samples_dir_result)
# copy paired end results
paired_end_dir = glob.glob(
os.path.join(
params.results_dir,
"paired_end",
"*"))
for s in paired_end_dir:
sample_name = s.split("/")[-1]
shutil.copytree(
s, \
os.path.join(
params.results_dir,
"samples",
sample_name))
single_end_dir = glob.glob(
os.path.join(
params.results_dir,
"single_end",
"*"))
for s in single_end_dir:
sample_name = s.split("/")[-1]
shutil.copytree(
s, \
os.path.join(
params.results_dir,
"samples",
sample_name))
# remove "single/paired end" from the logs directories
os.mkdir(output.samples_dir_log)
# copy paired end results
paired_end_dir = glob.glob(
os.path.join(
params.log_dir,
"paired_end",
"*"))
for s in paired_end_dir:
sample_name = s.split("/")[-1]
shutil.copytree(
s, \
os.path.join(
params.log_dir,
"samples",
sample_name))
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
single_end_dir = glob.glob(
os.path.join(
params.log_dir,
"single_end",
"*"))
for s in single_end_dir:
sample_name = s.split("/")[-1]
shutil.copytree(
s, \
os.path.join(
params.log_dir,
"samples",
sample_name))
# encapsulate salmon quantification results
all_samples_dirs = glob.glob(
os.path.join(
params.results_dir,
"samples",
"*"))
for s in all_samples_dirs:
sample_name = s.split("/")[-1]
shutil.move(
os.path.join(
s,
"salmon_quant"),
os.path.join(
s,
sample_name)
)
os.mkdir(os.path.join(
s,
"salmon_quant"))
shutil.move(
os.path.join(
s,
sample_name),
os.path.join(
s,
"salmon_quant",
sample_name)
)
# adjust FastQC results 'Filename' field:
fastq_zip_list = glob.glob(
os.path.join(
params.results_dir,
"samples",
"*",
"*_fastqc",
"*_fastqc.zip"))
for zipfile in fastq_zip_list:
sample_name = zipfile.split("/")[-3]
absolute_path_zipfile = os.path.abspath(zipfile)
zipfile_path_chunks = absolute_path_zipfile.split(os.path.sep)
dir_path_to_zipfile = os.path.sep + os.path.join(
(*zipfile_path_chunks[:-1]))
zip_f.extractall(dir_path_to_zipfile)
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
fastqc_data_f = os.path.join(
zipfile[:-4],
"fastqc_data.txt")
with open(fastqc_data_f) as f:
log_lines = f.read().splitlines()
log_lines[3] = "Filename\t" + sample_name+"|"+log_lines[3].split("\t")[1]
with open(fastqc_data_f, "w") as f:
for i in log_lines: f.write(i+"\n")
os.remove(zipfile)
# adjust Kallisto quantification logs
kallisto_logs = glob.glob(
os.path.join(
params.log_dir,
"samples",
"*",
"genome_quantification_kallisto.stderr.log"))
for kallisto_log in kallisto_logs:
with open(kallisto_log) as f:
log_lines = f.read().splitlines()
temp = log_lines[8].split(".")
log_lines[8] = temp[0] + "." + temp[2] + "." + temp[3]
with open(kallisto_log+".MODIFIED", "w") as f:
for i in log_lines: f.write(i+"\n")
# add #-comment to all cutadapt logs:
cutadapt_logs = glob.glob(
os.path.join(
params.log_dir,
"samples",
"*",
"remove_*_cutadapt.stdout.log"))
for cutadapt_log in cutadapt_logs:
sample_name = cutadapt_log.split("/")[-2]
with open(cutadapt_log) as f:
log_lines = f.read().splitlines()
log_lines[1] = log_lines[1] + " # " + sample_name
with open(cutadapt_log, "w") as f:
for i in log_lines: f.write(i+"\n")
# adjust TIN boxplots filenames for MutliQC recognition
os.rename(
input.TIN_boxplot_PNG,
os.path.join(
params.results_dir,
"TIN scores_mqc.png"))
os.rename(
input.TIN_boxplot_PDF,
os.path.join(
params.results_dir,
"TIN scores_mqc.pdf"))
# adjust alfa plot filename for MutliQC recognition
os.rename(
input.alfa_concat_out,
os.path.join(
params.results_dir,
"ALFA",
"ALFA_plots.concat_mqc.png"))
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
# remove old result directories
shutil.rmtree(
os.path.join(
params.results_dir,
"paired_end"),
ignore_errors=False,
onerror=None)
shutil.rmtree(
os.path.join(
params.results_dir,
"single_end"),
ignore_errors=False,
onerror=None)
shutil.rmtree(
os.path.join(
params.log_dir,
"paired_end"),
ignore_errors=False,
onerror=None)
shutil.rmtree(
os.path.join(
params.log_dir,
"single_end"),
ignore_errors=False,
onerror=None)
rule prepare_MultiQC_config:
'''
Prepare config for the MultiQC
'''
input:
samples_dir_result = os.path.join(
config["output_dir"],
"samples"),
samples_dir_log = os.path.join(
config["log_dir"],
config["output_dir"],
"MultiQC_config.yaml")
params:
logo_path = os.path.join(
"..",
"..",
"images",
"logo.128px.png"),
results_dir = config["output_dir"]
log:
stderr = os.path.join(
config["log_dir"],
"prepare_MultiQC_config.stderr.log"),
stdout = os.path.join(
config["log_dir"],
"prepare_MultiQC_config.stdout.log")
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
run:
with open(output.multiqc_config, "w") as YAML:
YAML.write("---\n\n")
YAML.write("title: \"Rhea\"\n")
YAML.write("subtitle: \"RNA-Seq processing pipeline developed by the members of Zavolan Lab\"\n")
YAML.write("intro_text: \"Short analysis title from config[analysis_title]\"\n")
YAML.write("custom_logo: \""+params.logo_path+"\"\n")
YAML.write("custom_logo_url: \"https://www.biozentrum.unibas.ch/research/researchgroups/overview/unit/zavolan/research-group-mihaela-zavolan/\"\n")
YAML.write("custom_logo_title: \"ZavoLab\"\n\n")
YAML.write("report_header_info:\n")
YAML.write(" - Project Type: \"Snakemake workflow\"\n")
YAML.write(" - Analysis Type: \"RNA-seq\"\n")
YAML.write(" - Analysis Author: \"config[author_name]\"\n")
YAML.write(" - Contact E-mail: \"config[author_email]\"\n\n")
YAML.write("top_modules:\n\n")
YAML.write(" - fastqc:\n")
YAML.write(" path_filters:\n")
YAML.write(" - \"*/mate1_fastqc/*\"\n")
YAML.write(" - \"*/mate2_fastqc/*\"\n")
YAML.write("\n")
YAML.write(" - cutadapt:\n")
YAML.write(" name: \"Cutadapt: adapter removal\"\n")
YAML.write(" path_filters:\n")
YAML.write(" - \"*/remove_adapters_cutadapt.stdout.log\"\n")
YAML.write("\n")
YAML.write(" - cutadapt:\n")
YAML.write(" name: \"Cutadapt: polyA tails removal\"\n")
YAML.write(" path_filters:\n")
YAML.write(" - \"*/remove_polya_cutadapt.stdout.log\"\n")
YAML.write("\n")
YAML.write(" - star:\n")
YAML.write(" path_filters:\n")
YAML.write(" - \"*/map_genome/*\"\n")
YAML.write("\n")
YAML.write(" - alfa:\n")
YAML.write(" path_filters:\n")
YAML.write(" - \"*/ALFA_plots.concat_mqc.png\"\n")
YAML.write("\n")
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
YAML.write(" - TIN_scores:\n")
YAML.write(" path_filters:\n")
YAML.write(" - \"*/TIN scores_mqc.png\"\n")
YAML.write("\n")
YAML.write(" - salmon:\n")
YAML.write(" path_filters:\n")
YAML.write(" - \"*/salmon_quant/*\"\n")
YAML.write("\n")
YAML.write(" - kallisto:\n")
YAML.write(" path_filters:\n")
YAML.write(" - \"*/genome_quantification_kallisto.stderr.log.MODIFIED\"\n")
YAML.write("\n")
YAML.write("...")
rule MULTIQC_report:
'''
Create report with MultiQC
'''
input:
multiqc_config = os.path.join(
config["output_dir"],
"MultiQC_config.yaml")
output:
MultiQC_report = directory(os.path.join(
config["output_dir"],
"multiqc_summary"))
params:
results_dir = config["output_dir"],
log_dir = config["log_dir"]
log:
stderr = os.path.join(
config["log_dir"],
"MULTIQC_report.stderr.log"),
stdout = os.path.join(
config["log_dir"],
"MULTIQC_report.stdout.log")
singularity:
"docker://ewels/multiqc:1.7"
shell:
"""
multiqc \
--outdir {output.MultiQC_report} \
--config {input.multiqc_config} \
{params.results_dir} \
{params.log_dir} \
1> {log.stdout} 2> {log.stderr}