-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_motif_bigwigs.Snakefile
50 lines (44 loc) · 1.61 KB
/
make_motif_bigwigs.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
## needs: meme, ucsc-bedGraphToBigWig, bedtools
# conda create -n meme -c bioconda meme ucsc-bedgraphtobigwig bedtools snakemake
import re
import glob
genome_fasta=config['genome_fasta']#/hpc/hub_oudenaarden/vbhardwaj/annotations/mm10_gencode23/genome_and_annotation/GRCm38.p6.genome.fa'
chrsizes=config['chrsizes']#/hpc/hub_oudenaarden/vbhardwaj/annotations/mm10_gencode23/STARindex/no_junctions/chrNameLength.txt'
motif_meme=glob.glob('*.meme')
motif_names=[re.sub("\.meme", "", x) for x in motif_meme]
print(motif_names)
rule all:
input:
expand("{motif}/fimo.bw", motif = motif_names),
expand("{motif}/fimo.bed", motif = motif_names)
rule fimo:
input:
genome = genome_fasta,
meme = "{motif}.meme"
output: "{motif}/fimo.tsv"
params:
outdir = "{motif}"
conda: "meme.yaml"
shell:
"fimo --max-stored-scores 10000000 -oc {params.outdir} {input.meme} {input.genome}"
rule fimo_bed:
input: "{motif}/fimo.tsv"
output:
bed = "{motif}/fimo.bed",
bg = "{motif}/fimo.bg"
conda: "meme.yaml"
shell:
"""
awk 'OFS="\\t" {{ if(NR>1) {{print $2, $3, $4, $5, $6, $7}} }}' {input} | head -n -4 | \
bedtools sort -sizeA -i - > {output.bed}; \
awk 'OFS="\\t" {{ if(NR>1) {{print $2, $3, $4, $6}} }}' {input} | head -n -4 | \
bedtools sort -sizeA -i - | bedtools merge -i - -c 4 -o sum > {output.bg}
"""
rule fimo_bw:
input:
bg = "{motif}/fimo.bg",
sizes = chrsizes
output: "{motif}/fimo.bw"
conda: "meme.yaml"
shell:
" bedGraphToBigWig {input.bg} {input.sizes} {output}"