-
Notifications
You must be signed in to change notification settings - Fork 10
/
Snakefile
executable file
·81 lines (70 loc) · 3.28 KB
/
Snakefile
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
version="1.2.0"
# Check for required parameters
if "samples" not in config:
print("No samples defined on the configuration file")
elif "workdir" not in config:
print("No working directory defined on the configuration file")
elif "dbdir" not in config:
print("No database directory defined on the configuration file")
else:
include: "scripts/util.py"
# Load default values (when they are not set on the configfile.yaml)
include: "scripts/default.sm"
# Set snakemake main workdir variable
workdir: config["workdir"]
onstart:
import pprint
# create dir for log on cluster mode (script breaks without it)
shell("mkdir -p clusterlog/")
print("")
print("---------------------------------------------------------------------------------------")
print("MetaMeta Pipeline v%s by Vitor C. Piro ([email protected], http://github.com/pirovc)" % version)
print("---------------------------------------------------------------------------------------")
print("Parameters:")
for k,v in sorted(config.items()):
print(" - " + k + ": ", end='')
pprint.pprint(v)
print("---------------------------------------------------------------------------------------")
print("")
def onend(msg, log):
import os
#Remove clusterlog folder (if exists and empty)
shell('if [ -d "clusterlog/" ]; then if [ ! "$(ls -A clusterlog/)" ]; then rm -rf clusterlog/; fi; fi')
from datetime import datetime
dtnow = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
log_file = "metameta_" + dtnow + ".log"
shell("cp {log} {log_file}")
print("")
print("---------------------------------------------------------------------------------------")
print(msg)
print("Please check the main log file for more information:")
print("\t" + os.path.abspath(config["workdir"]) + "/" + log_file)
print("Detailed output and execution time for each rule can be found at:")
print("\t" + os.path.abspath(config["dbdir"]) + "/log/")
print("\t" + os.path.abspath(config["workdir"]) + "/SAMPLE_NAME/log/")
print("---------------------------------------------------------------------------------------")
print("")
onsuccess:
onend("MetaMeta finished successfuly", log)
onerror:
onend("An error has occured.", log)
##############################################################################################
include: "scripts/database_profile.sm"
include: "scripts/clean_files.sm"
include: "scripts/clean_reads.sm"
include: "scripts/krona.sm"
include: "scripts/metametamerge.sm"
include: "scripts/preconfigdb.sm"
include: "scripts/preproc.sm"
include: "scripts/taxonomy.sm"
# Include all selected tools
for tool in config["tools"]:
if has_custom_db(tool):
include: ("tools/"+tool+"_db_custom.sm")
include: ("tools/"+tool+".sm")
##############################################################################################
rule all:
input:
clean_reads = expand("{sample}/clean_reads.done", sample=config["samples"]), #TARGET SAMPLE {sample}/clean_reads.done
krona_html = expand("{sample}/metametamerge/{database}/final.metametamerge.profile.html", sample=config["samples"], database=config["databases"]) # TARGET SAMPLE AND DATABASE {sample}/metametamerge/{database}/final.metametamerge.profile.html
##############################################################################################