-
Notifications
You must be signed in to change notification settings - Fork 7
/
bowtie2-macs2-homer.smk
218 lines (185 loc) · 6.45 KB
/
bowtie2-macs2-homer.smk
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
from os.path import join
#Workding directory
workdir: config['workdir']
# Full path to a folder that holds all of your FASTQ files.
FASTQ_DIR = config['fastq_dir']
PAIRED = 'paired' if config['paired'] else 'single'
# Full path to a Genome.
GENOME = config['genome']
#CDNA = join(GENOME,"gencode.v25.transcripts.fa")
# genome sequence
FASTA_REF = config['dna']
# index_dir
BOWTIE_REFDIR= config['bowtie2_index']
# index basename
INDEX_PREFIX = config['index_prefix']
_SAMPLES = config['sample_meta']
############ Samples ##################
# A Snakemake regular expression matching the forward mate FASTQ files.
# the part in curly brackets {} will be saved, so the variable SAMPLES
# is a list of strings #['Sample1','Sample2'].
#notice that SAMPLES, has a trailing comma.
#you must include this trailing comma, or else the code won’t work correctly.
#SAMPLES, = glob_wildcards(join(FASTQ_DIR, '{sample, SRR[^/]+}_R1.fastq.gz'))
# Patterns for the 1st mate and the 2nd mate using the 'sample' wildcard.
#PATTERN_R1 = '{sample}_R1.fastq.gz'
#PATTERN_R2 = '{sample}_R2.fastq.gz'
PATTERN_U = config['read_pattern']['u']
PATTERN_R1 = config['read_pattern']['r1']
PATTERN_R2 = config['read_pattern']['r2']
with open(_SAMPLES, 'r') as s:
SAMPLES = [ l.strip() for l in s]
## find fastq files
FASTQ_GE = {s:[os.path.join(FASTQ_DIR, f) for f in os.listdir(FASTQ_DIR) if (f.startswith(s) and (f.endswith("fastq") or f.endswith(".gz"))) ] for s in SAMPLES}
#SAMPLES, GROUP, IDS,= glob_wildcards(join(FASTQ_DIR, '{sample}_{group}_{id}_R1.fastq.gz'))
#######output######
_BW = expand("igv/{sample}.q25.bw", sample=SAMPLES)
# _MACS = "macs_out"
# _HOMER
# _MOTIF ="motif"
# _GO = "peaks.GO.HOMMER"
# _GREAT = "peaks.GO.GREAT"
rule target:
input: _BW
# rule bowtie_index:
# input:
# fasta = FASTA_REF,
# gtf = GTF_FILE,
# output: expand(join(BOWTIE_REFDIR,INDEX_PREFIX)+".{ids}.bt2",ids=range(1,4))
# params:
# basename=join(BOWTIE_REFDIR, INDEX_PREFIX)
# log: "logs/bowtie2/bowtie2.index.build.log"
# threads: 12
# shell: "bowtie2-build -f {input.fasta} -p {threads} {params.basename} &> {log}"
rule botiwe_align:
input:
index=expand(join(BOWTIE_REFDIR, INDEX_PREFIX)+".{ids}.bt2", ids=range(1,4)),
# r1 = join(FASTQ_DIR, "{sample}.fastq")
fastqs = lambda wildcards: FASTQ_GE[wildcards.sample],
output:
temp('mapped/{sample}.bam')
log:
"logs/bowtie2/{sample}.align.log"
threads: 12
params:
ref = join(BOWTIE_REFDIR, INDEX_PREFIX),
fastqs = lambda wildcards: FASTQ_GE[wildcards.sample],
u = join(FASTQ_DIR, PATTERN_U),
r1 = join(FASTQ_DIR, PATTERN_R1),
r2 = join(FASTQ_DIR, PATTERN_R2),
run:
reads = f"-U {params.u}"
if isinstance(params.fastqs, list) and len(params.fastqs) == 2:
reads = f"-1 {params.r1} -2 {params.r2}"
cmd = "(bowtie2 -p {threads} -x {params.ref} %s "%reads +\
" | samtools view -Sbh -q 25 -@ {threads} -o {output} - ) 2> {log}"
shell(cmd)
rule bam_sort:
input: "mapped/{sample}.bam"
output: protected("mapped/{sample}.q25.sorted.bam")
threads: 12
shell:
"samtools sort -@ {threads} {input} > {output}"
rule bam_index:
input: "mapped/{sample}.q25.sorted.bam"
output: "mapped/{sample}.q25.sorted.bam.bai"
shell:
"samtools index {input}"
rule bam2bw:
"""deeptools"""
input:
bam = "mapped/{sample}.q25.sorted.bam",
bai = "mapped/{sample}.q25.sorted.bam.bai"
output:
"igv/{sample}.q25.bw"
log: "logs/deeptools/{sample}.bam2bw.log"
threads: 8
params:
fsize=200,
extra=" --normalizeUsing CPM --centerReads",
shell:
"bamCoverage -b {input.bam} -p {threads} --extendReads {params.fsize} -o {output} {params.extra} &> {log}"
# rule prepare_macs:
# input: config['groups']
# output: "temp/{sample}.{treat}.{ctrl}.txt"
# params:
# run:
# groups=[]
# with open(input[0],'r') as f:
# for line in f:
# groups.append(line.strip("\n").split("\t"))
# "touch temp/{sample}.{treat}.{ctrl}.txt"
# rule macs_narrow:
# """point source factors peaks calling.
# Transprition factors
# H3K4me3
# """
# input:
# treat="mapped/{treat}.q25.sorted.bam",
# ctrl="mapped/{ctrl}.q25.sorted.bam",
# temp="temp/{sample}.{treat}.{ctrl}.txt"
# output:
# "macs_out/{sample}_summits.bed",
# "macs_out/{sample}_peaks.narrowPeak",
# conda=MACS2_ENV,
# log: "logs/macs/{sample}.macs2.log"
# prams:
# extra=" -f BAM -g hs -B --SPMR -q 0.01 ",
# extra2=" --SPMR --nomodel --extsize 200",
# shell:
# "macs2 callpeak -t {input.treat} -c {input.ctrl}"
# " --outdir macs2_highQuality_results -n {wildcards.sample} "
# " {params.extra} 2> {log}"
# rule macs_broad:
# """use for broad domains calling, H3K27ac, H3K4me1.et. al"""
# input:
# treat="mapped/{treat}.q25.sorted.bam",
# ctrl="mapped/{ctrl}.q25.sorted.bam",
# temp="temp/{sample}.{treat}.{ctrl}.txt"
# output:
# "macs_out/{sample}_summits.bed",
# "macs_out/{sample}_peaks.broadPeak",
# log: "logs/macs/{sample}.macs2.log"
# params:
# extra=" -f BAM -g hs -B --SPMR --broad --call-summits",
# extra2=" --nomodel --extsize 147 -q 0.1 --fe-cutoff 1.5",
# shell:
# "macs2 callpeak -t {input.treat} -c {input.ctrl} "
# "--outdir macs2_highQuality_results -n {wildcards.sample} --broad"
# "{params.extra} {params.extra2} 2> {log}"
# rule annotatepeaks:
# input:
# bed="{sample}.bed"
# output:
# "{sample}.peaksAnnotate.txt"
# params:
# go_outdir=".",
# genome = "hg19"
# shell:
# "annotatePeaks.pl {input.bed} {params.genome} -go {params.go_outdir} > {output}"
# rule findmoitf:
# input:
# bed="{sample}.bed"
# output:
# params:
# go_outdir="",
# genome = "hg19"
# shell:
# """
# awk '{print $4"\t"$1"\t"$2"\t"$3"\t+"}' {input.bed} | \
# findMotifsGenome.pl - hg19 ./findMotif/NANOG_motif -len 8,10,12 -size given
# """
# rule beta:
# """differential motif finding"""
# rule region_profile:
# input:
# output:
# shell:
# rule region_heatmap:
# input:
# output:
# shell:
# rule screen_shoot:
# input:
# output:
# shell: