-
Notifications
You must be signed in to change notification settings - Fork 1
/
Snakefile
executable file
·138 lines (118 loc) · 3.77 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
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
import os
import glob
from os.path import join as pjoin
import pandas as pd
MAFS = glob.glob('input/mafs/*.maf')
LABELS, = glob_wildcards('input/gff/{label}GenesRegions.gff')
BOX_CSV = config['gene_regions_csv']
box_df = pd.read_csv(BOX_CSV, index_col=False,
header=0)
box_genes = list(box_df['gene_id'].unique())
box_plot_dirs = expand(
"output/coevo-box/label-{label}_gene-{gene}/",
label=LABELS,
gene=box_genes,
)
rule flags:
input:
expand('flags/{label}.done', label=LABELS)
output:
'flags/all.done'
rule all:
input:
box_plot_dirs
# output a MAF file for each gene
checkpoint gff_to_mafs:
input:
gff='input/gff/{label}GenesRegions.gff',
mafs=MAFS
output:
tmp_bed=temp('mafs/{label}_tmp.bed'),
maf_dir=directory('mafs/{label}')
conda:
"envs/bedops_and_ucsc_mafs.yaml"
shell:
"gff2bed < {input.gff} | " # turn the gff into a NEWT
"sed 's/^/chr/' | " # add chr to each
"""awk -F '\\t' 'OFS="\\t" {{print $1, $2, $3, $10}}' | """ # use gene_id as 4th column
"sed 's/gene_id //g' | " # keep only the actual gene_id
"sed 's/\\\"//g' > {output.tmp_bed}; " # remove pesky quotes
"mafsInRegion {output.tmp_bed} -outDir {output.maf_dir} {input.mafs}"
def get_file_names(wc):
"Here be magic"
ck_output = checkpoints.gff_to_mafs.get(**wc).output['maf_dir']
GENES, = glob_wildcards(pjoin(ck_output, '{gene}.maf'))
return expand('output/coevo-box/label-{label}_gene-{gene}/corrected_mutinfo_clustermap.png', gene=GENES, label=wc.label)
rule almost_done:
input: get_file_names
output: "flags/{label}.done"
shell: "touch {output}"
rule maf_to_fa:
input:
'mafs/{label}/{gene}.maf'
output:
'fasta/{label}/{gene}.fasta'
conda:
'envs/bx-python.yaml'
shell:
"export SPECIES=$(maf_species_in_all_files.py {input}); "
"maf_to_concat_fasta.py $SPECIES < {input} > {output}"
# temporarily store the matrix since we read it multiple times
rule dna_coevo_matrix:
input:
'fasta/{label}/{gene}.fasta'
output:
raw_mat='matrix/{label}/{gene}_raw.mat',
refined_mat='matrix/{label}/{gene}_refined.mat'
conda:
'envs/coevo.yaml'
benchmark:
'benchmarks/dna_coevo_matrix/label-{label}_gene-{gene}.txt'
resources:
mem_mb=40000
shell:
"python scripts/DNAcoevolution.py "
"-i {input} "
"-s {output.raw_mat} "
"-v {output.refined_mat} "
rule dna_coevo_plain:
input:
raw_mat='matrix/{label}/{gene}_raw.mat',
refined_mat='matrix/{label}/{gene}_refined.mat'
output:
directory('output/coevo-plain/label-{label}_gene-{gene}')
conda:
'envs/coevo.yaml'
resources:
mem_mb=40000
benchmark:
'benchmarks/dna_coevo_plain/label-{label}_gene-{gene}.txt'
shell:
"python scripts/DNAcoevolution.py "
"-a {input.raw_mat} "
"-r {input.refined_mat} "
"-o {output} "
rule dna_coevo_box:
input:
fasta='fasta/{label}/{gene}.fasta',
csv='config/all_box_genes.csv',
output:
dirname=directory('output/coevo-box/label-{label}_gene-{gene}'),
clustermap='output/coevo-box/label-{label}_gene-{gene}/corrected_mutinfo_clustermap.png'
conda:
'envs/coevo.yaml'
resources:
mem_mb=1250000,
disk_mb=50000
benchmark:
'benchmarks/dna_coevo_box/label-{label}_gene-{gene}.txt'
shell:
"python scripts/DNAcoevolution.py "
"-i {input.fasta} "
"-c {input.csv} "
"-o {output.dirname} "
"-g {wildcards.gene} "
"--pvals "
# rule covariance_gene_level:
# input:
# shell: