forked from zqfang/snakeflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bowtie2-macs2-homer.smk
204 lines (172 loc) · 5.8 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
from os.path import join
configfile: 'config.chip-seq.yml'
#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['fasta']
# index_dir
BOWTIE_REFDIR= config['index_dir']
# index basename
INDEX_PREFIX = config['index_prefix']
############ 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_R1 = config['read_pattern']['r1']
PATTERN_R2 = config['read_pattern']['r2']
#PERRETY_SAMPLE = expand("mapped/{sample}.{replicate}.bam", sample=SAMPLES, replicate=[0, 1])
#SAMPLES,GROUP,IDS,= glob_wildcards(join(FASTQ_DIR, '{sample}_{group}_{id}_R1.fastq.gz'))
#######output######
_MACS = "macs_out"
_HOMER
_MOTIF ="motif"
_GO = "peaks.GO.HOMMER"
_GREAT = "peaks.GO.GREAT"
rule target:
input: _MACS,_MACS, _MOTIF, _GO, _GREAT, _BETA
rule bowtie_index:
input:
fasta = FASTA_REF,
gtf = GTF_FILE,
output: expand(join(BOWTIE_REFDIR,INDEX_PREFIX)+".{ids}.ht2",ids=range(1,9))
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}.ht2", ids=range(1,9)),
r1 = join(FASTQ_DIR, PATTERN_R1),
r2 = join(FASTQ_DIR, PATTERN_R2)
output:
temp('mapped/{sample}.highQuality.q25.bam')
log:
"logs/bowtie2/{sample}.align.log"
threads: 12
params:
ref = join(BOWTIE_REFDIR, INDEX_PREFIX),
shell:
"(bowtie2 {params.extra} -p {threads} -x {params.ref} -U {input.r1} "
" | samtools view -Sbh -q 25 -@ {threads} -o {output} - ) 2> {log}"
rule bam_sort:
input: "mapped/{sample}.bam"
output: protected("mapped/{sample}.highQuality.q25.sorted.bam")
threads: 12
shell:
"samtools sort -@ {threads} {input} > {output}"
rule bam_index:
input: "mapped/{sample}.highQuality.q25.sorted.bam"
output: "mapped/{sample}.highQuality.q25.sorted.bam.bai"
shell:
"samtools index {input}"
rule bam2bw:
"""deeptools"""
input: "mapped/{sample}.highQuality.q25.sorted.bam",
"mapped/{sample}.highQuality.q25.sorted.bam.bai"
output:
"mapped/{sample}.highQuality.q25.bw"
log: "logs/deeptools/{sample}.bam2bw.log"
threads: 4
params:
fsize=200,
extra=" --normalizeUsingRPKM --centerReads",
shell:
"bamCoverage -b {input} -p {threads} -e {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}.highQuality.q25.sorted.bam",
ctrl="mapped/{ctrl}.highQuality.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 braod domains calling, H3K27ac, H3K4me1.et. al"""
input:
treat="mapped/{treat}.highQuality.q25.sorted.bam",
ctrl="mapped/{ctrl}.highQuality.q25.sorted.bam",
temp="temp/{sample}.{treat}.{ctrl}.txt"
output:
"macs_out/{sample}_summits.bed",
"macs_out/{sample}_peaks.broadPeak",
conda=MACS2_ENV,
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: