-
Notifications
You must be signed in to change notification settings - Fork 2
/
Snakefile
97 lines (85 loc) · 3.55 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from pipeline_util import *
from pipeline_util import _fastq_paths, _bams_paths, _sample_2_control
# use this file as a basic config file in your working directory
# if you'd like to customise it: fix it directly or override required args
# using --config options or from --configfile file.
configfile: f"{workflow.basedir}/config.yaml"
WORK_DIR = os.getcwd()
FASTQ_DIR = config['fastq_dir']
FASTQ_EXT = config['fastq_ext']
FASTQ_PATHS = _fastq_paths(FASTQ_DIR, FASTQ_EXT)
BAMS_DIR = config['bams_dir']
BAMS_PATHS = _bams_paths(BAMS_DIR)
SAMPLE_2_CONTROL_MAP = _sample_2_control(config, FASTQ_PATHS, BAMS_PATHS)
onstart:
print(f"Working directory: {WORK_DIR}")
print(f"Snakefile directory: {workflow.basedir}")
print(f"Environment: TMPDIR={os.environ.get('TMPDIR', '<n/a>')}")
print(f"Environment: PATH={os.environ.get('PATH', '<n/a>')} ")
print(f"Config: ", *[f'{k}: {v}' for k, v in config.items()], sep = "\n ")
print("TOOLS: ")
os.system('echo " bash: $(which bash)"')
os.system('echo " PYTHON: $(which python)"')
os.system('echo " CONDA: $(which conda)"')
os.system('echo " SNAKEMAKE: $(which snakemake)"')
os.system('echo " PYTHON VERSION: $(python --version)"')
os.system('echo " CONDA VERSION: $(conda --version)"')
os.system('')
# check shell (cond not work properly due to shell detection issues
print("Snakemake shell check")
shell('echo " SNAKEMAKE VERSION: $(snakemake --version)"')
if bool(config['start_with_bams']):
print("Bam directory:", BAMS_DIR)
else:
print("Fastq directory:", FASTQ_DIR)
print("Fastq extension:", FASTQ_EXT)
#---------------------------------------------------------------------
# Let's create symlinks for several pipeline source dirs to simplify
# further paths in pipeline
for pipeline_dir in ['scripts', 'envs', 'schemas']:
if not os.path.exists(pipeline_dir):
src_dir = os.path.join(workflow.basedir , pipeline_dir)
if os.path.exists(src_dir):
print(f"Linking '{pipeline_dir}' directory:")
shell(f"ln -sf {src_dir} {pipeline_dir}")
include: "rules/raw_qc.smk"
include: "rules/trim_fastq.smk"
include: "rules/alignment.smk"
include: "rules/reads_bw.smk"
include: "rules/bam_quality_metrics.smk"
include: "rules/macs2.smk"
include: "rules/sicer.smk"
include: "rules/span.smk"
wildcard_constraints:
sample="[^/]+"
localrules: all
if bool(config['start_with_bams']):
if not os.path.exists(config['bams_dir']):
raise ValueError(f"Bam directory not exists: {config['fastq_dir']}")
else:
if not os.path.exists(config['fastq_dir']):
raise ValueError(f"Fastq directory not exists: {config['fastq_dir']}")
rule all:
input:
*([] if bool(config['start_with_bams']) else [
# Reads qc
rules.all_raw_qc_results.input,
# Optional reads trimming
*([] if not bool(config['trim_reads']) else rules.all_trim_fastq_results.input),
# Alignment
rules.all_alignment_results.input,
# Alignment qc
rules.all_alignment_qc.input,
# Optional advanced BAM quality metrics
*([] if not bool(config['bams_additional_qc']) else rules.all_bam_quality_metrics_results.input)
]),
# Visualization
rules.all_reads_bw_results.input,
# Visualization tags
rules.all_tags_bw_results.input,
# macs2
rules.all_macs2_results.input,
# sicer
rules.all_sicer_results.input,
# span
rules.all_span.input