forked from tobiaszehnder/IPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
executable file
·192 lines (171 loc) · 5.75 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
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
import os, sys
# parse config dict entries to variables, e.g. a = d['a']. (data_dir, species_list)
data_dir = os.path.abspath('../ipp-data')
for k,v in config.items():
exec(k + '=v')
# define directories
assembly_dir = data_dir + '/assembly'
alignment_dir = data_dir + '/alignment'
fasta_dir = data_dir + '/fasta'
lastdb_dir = alignment_dir + '/lastdb'
axtnet_dir = alignment_dir + '/axtNet'
axt_dir = alignment_dir + '/axt'
chain_dir = alignment_dir + '/chain'
maf_dir = alignment_dir + '/maf'
net_dir = alignment_dir + '/net'
psl_dir = alignment_dir + '/psl'
tbl_dir = alignment_dir + '/chainTbl'
bed_dir = alignment_dir + '/bed'
pkl_dir = alignment_dir + '/pkl'
# make directories
for dr in [assembly_dir, alignment_dir, fasta_dir, lastdb_dir, axtnet_dir, axt_dir, chain_dir, maf_dir, net_dir, psl_dir, tbl_dir, bed_dir, pkl_dir]:
if not os.path.exists(dr):
os.makedirs(dr)
# define targets (if not passed)
try:
targets = target_list.split(',')
species_list = []
except NameError:
species_list=species_list.split(',')
print(species_list)
targets = [tbl_dir + '/%s.%s.tbl' %(sp1,sp2) for sp1 in species_list for sp2 in species_list if not sp1 == sp2]
if not pickle == False:
targets += ['%s/%s.pwaln.pkl' %(pkl_dir, pickle.replace(',','.'))] # pickle contains the ref-target species pair, e.g. danrer11,mm39
### RULES ###
rule all:
input:
targets
rule pickle:
input:
[tbl_dir + '/%s.%s.tbl' %(sp1,sp2) for sp1 in species_list for sp2 in species_list if not sp1 == sp2]
output:
'{pkl_dir}/{species_pair}.pwaln.pkl'
params:
missing_pwalns='missing_pwalns_forbidden'
shell:
'pickle_pwalns.py {output} {params} {input}'
rule chain_to_tbl:
input:
chain='%s/{s1}.{s2}.all.pre.chain' %chain_dir,
output:
'{tbl_dir}/{s1}.{s2}.tbl'
shell:
'chainToTbl.py {input} {output}'
# rule axtnet_to_tbl:
# input:
# axtnet='%s/{s1}.{s2}.net.axt.gz' %axtnet_dir,
# s2_sizes=ancient('%s/{s2}.sizes' %assembly_dir)
# output:
# '{tbl_dir}/{s1}.{s2}.tbl'
# shell:
# 'axtnet_to_tbl.R {input} {output} > {output}.log'
rule gzip:
input:
ancient('{basename}.net.axt')
output:
'{basename}.net.axt.gz'
shell:
'gzip -1 -c {input} > {output}'
rule axt_net:
# netToAxt fails with too high chain ids (can only handle up to 268435456). In such cases, save an empty output file instead.
input:
noclassnet=ancient('%s/{s1}.{s2}.noClass.net' %net_dir),
allprechain=ancient('%s/{s1}.{s2}.all.pre.chain' %chain_dir),
twobit_s1=ancient('%s/{s1}.2bit' %assembly_dir),
twobit_s2=ancient('%s/{s2}.2bit' %assembly_dir)
output:
temp('{axtnet_dir}/{s1}.{s2}.net.axt')
shell:
'''
netToAxt {input} {output} &> {output}.log || echo -e "" > {output}
'''
rule no_class_net:
input:
allprechain=ancient('%s/{s1}.{s2}.all.pre.chain' %chain_dir),
sizes_s1=ancient('%s/{s1}.sizes' %assembly_dir),
sizes_s2=ancient('%s/{s2}.sizes' %assembly_dir)
output:
'{net_dir}/{s1}.{s2}.noClass.net'
shell:
'chainNet {input} stdout /dev/null | netSyntenic stdin {output}'
rule all_pre_chain:
input:
allchain=ancient('{chain_dir}/{s1}.{s2}.all.chain'),
sizes_s1=ancient('%s/{s1}.sizes' %assembly_dir),
sizes_s2='%s/{s2}.sizes' %assembly_dir
output:
'{chain_dir}/{s1}.{s2}.all.pre.chain'
shell:
'chainPreNet {input} {output}'
rule all_chain:
input:
axtchain=ancient('{basename}.axtChain')
output:
'{basename}.all.chain'
shell:
'chainMergeSort {input} > {output}'
rule axt_chain:
input:
psl=ancient('%s/{s1}.{s2}.psl' %psl_dir),
twobit_s1=ancient('%s/{s1}.2bit' %assembly_dir),
twobit_s2=ancient('%s/{s2}.2bit' %assembly_dir)
output:
'{chain_dir}/{s1}.{s2}.axtChain'
shell:
'axtChain -psl -linearGap=loose {input} {output} &> {output}.log'
rule maf_to_psl:
input:
ancient('%s/{species_pair}.maf' %maf_dir)
output:
'{psl_dir}/{species_pair}.psl'
shell:
'maf-convert psl {input} > {output}'
# lastal sometimes prepends the genome build as a prefix to the chromosome names (no idea why). replaces those occurrences.
rule lastal_maf:
input:
prj=ancient('%s/{s1}.prj' %lastdb_dir),
fa=ancient('%s/{s2}.fa' %fasta_dir),
assembly_dir=ancient(assembly_dir)
output:
'{maf_dir}/{s1}.{s2}.maf'
params:
lastdb_prefix='%s/{s1}' %lastdb_dir
threads:
min(workflow.cores, 2)
shell:
'''
/scratch/ngsvin/bin/Last/last-983/src/lastal -P {threads} {params.lastdb_prefix} {input.fa} > {output}
remove_species_prefix {input.assembly_dir} {output}
'''
rule lastdb_prj:
input:
ancient('%s/{species}.fa' %fasta_dir)
output:
'{lastdb_dir}/{species}.prj'
params:
prefix='{lastdb_dir}/{species}'
threads:
min(workflow.cores, 2)
shell:
'/scratch/ngsvin/bin/Last/last-983/src/lastdb -P {threads} -c {params.prefix} {input}'
rule twobit_to_sizes:
input:
ancient('{basename}.2bit')
output:
'{basename}.sizes'
shell:
'twoBitInfo {input} stdout | sort -k2rn > {output}'
rule fa_to_twobit:
input:
ancient('%s/{species}.fa' %fasta_dir)
output:
'{assembly_dir}/{species}.2bit'
shell:
'faToTwoBit {input} {output}'
rule get_fasta:
output:
'{fasta_dir}/{species}.fa'
params:
link='http://hgdownload.cse.ucsc.edu/goldenpath/{species}/bigZips/{species}.fa.gz'
shell:
'wget -nc {params.link} -O /dev/stdout | gzip -d > {output}'