-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
214 lines (196 loc) · 9.78 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# If rules are split across multiple snakefiles, list them here
# include: "rules-A"
# include: "rules-B"
PHYLOFLASH_DBHOME="/ebio/abt2_projects/ag-swart-loxodes/db/phyloFlash/132"
rule all:
input:
expand(
"qc/phyloFlash/{lib}_rnaseq_{readlim}.phyloFlash.tar.gz",
lib=[i for i in config['rnaseq'] if i not in ['kn01_yy','cmag_mm','pard_mm','bjap_mm','fsal_mm']], readlim=[1000000]), # skip libraries where SPAdes step fails
expand("qc/phyloFlash/{lib}_rnaseq_maponly_1000000.phyloFlash.tar.gz", lib=config['rnaseq']),
expand("qc/phyloFlash/{lib}_rnaseq_se_maponly_1000000.phyloFlash.tar.gz", lib=config['rnaseq_se']),
expand("qc/phyloFlash/{lib}_dnaseq.phyloFlash.tar.gz", lib=config['mda']),
expand("assembly/trinity.{lib}.Trinity.fasta", lib=config['rnaseq']),
expand("qc/barrnap/trinity.{lib}.barrnap.fasta", lib=config['rnaseq']),
expand("qc/trinity_assem/trinity.{lib}.v.{dbprefix}.blastx.out6.w_pct_hit_length", lib=config['rnaseq'], dbprefix=['uniprot_sprot','bsto_mac']),
"assembly/trinity_gg.bsto.Trinity-GG.fasta", # genome-guided assembly
"assembly/trinity_se.bsp_mk.Trinity.fasta", # single-end read library
"qc/trinity_assem/trinity_se.bsp_mk.v.bsto_mac.blastx.out6.w_pct_hit_length", # single-end read library
rule barrnap_trinity:
input: "assembly/trinity.{lib}.Trinity.fasta"
output:
gff="qc/barrnap/trinity.{lib}.barrnap.gff3",
fasta="qc/barrnap/trinity.{lib}.barrnap.fasta"
conda: "envs/barrnap.yml"
threads: 4
shell:
r"""
barrnap --threads {threads} --kingdom euk --outseq {output.fasta} < {input} > {output.gff}
"""
rule phyloflash_rnaseq:
input:
fwd=lambda wildcards: config['rnaseq'][wildcards.lib]['fwd'],
rev=lambda wildcards: config['rnaseq'][wildcards.lib]['rev']
output:
"qc/phyloFlash/{lib}_rnaseq_{readlim}.phyloFlash.tar.gz"
conda: "envs/phyloflash.yml"
threads: 16
log: "logs/phyloflash_rnaseq.{lib}.{readlim}.log"
wildcard_constraints: readlim="\d+"
params:
db=PHYLOFLASH_DBHOME
shell:
# Use -readlimit 1000000 for transcriptome libraries
"phyloFlash.pl -lib {wildcards.lib}_rnaseq_{wildcards.readlim} -readlength 150 -readlimit {wildcards.readlim} -read1 {input.fwd} -read2 {input.rev} -CPUs {threads} -almosteverything -dbhome {params.db} 2> {log};"
"mv {wildcards.lib}_rnaseq_{wildcards.readlim}.phyloFlash* qc/phyloFlash/;"
rule phyloflash_rnaseq_se:
input:
lambda wildcards: config['rnaseq_se'][wildcards.lib]
output:
"qc/phyloFlash/{lib}_rnaseq_se_{readlim}.phyloFlash.tar.gz"
conda: "envs/phyloflash.yml"
threads: 16
wildcard_constraints: readlim="\d+"
log: "logs/phyloflash_rnaseq_se.{lib}.{readlim}.log"
params:
db=PHYLOFLASH_DBHOME
shell:
# Do not run -poscov for SE libraries
# Use -readlimit 1000000 for transcriptome libraries
"phyloFlash.pl -lib {wildcards.lib}_rnaseq_se_{wildcards.readlim} -readlength 100 -readlimit {wildcards.readlim} -read1 {input} -CPUs {threads} -html -zip -treemap -log -dbhome {params.db} 2> {log};"
"mv {wildcards.lib}_rnaseq_se_{wildcards.readlim}.phyloFlash* qc/phyloFlash/;"
rule phyloflash_rnaseq_maponly:
input:
fwd=lambda wildcards: config['rnaseq'][wildcards.lib]['fwd'],
rev=lambda wildcards: config['rnaseq'][wildcards.lib]['rev']
output:
"qc/phyloFlash/{lib}_rnaseq_maponly_{readlim}.phyloFlash.tar.gz"
conda: "envs/phyloflash.yml"
threads: 16
wildcard_constraints: readlim="\d+"
log: "logs/phyloflash_rnaseq_maponly.{lib}.{readlim}.log"
params:
db=PHYLOFLASH_DBHOME
shell:
"phyloFlash.pl -lib {wildcards.lib}_rnaseq_maponly_{wildcards.readlim} -readlength 150 -readlimit {wildcards.readlim} -skip_spades -read1 {input.fwd} -read2 {input.rev} -CPUs {threads} -html -treemap -log -poscov -zip -dbhome {params.db} 2> {log};"
"mv {wildcards.lib}_rnaseq_maponly_{wildcards.readlim}.phyloFlash* qc/phyloFlash/;"
rule phyloflash_rnaseq_se_maponly:
input:
lambda wildcards: config['rnaseq_se'][wildcards.lib]
output:
"qc/phyloFlash/{lib}_rnaseq_se_maponly_{readlim}.phyloFlash.tar.gz"
conda: "envs/phyloflash.yml"
threads: 16
wildcard_constraints: readlim="\d+"
log: "logs/phyloflash_rnaseq_se_maponly.{lib}.{readlim}.log"
params:
db=PHYLOFLASH_DBHOME
shell:
# Do not run -poscov for SE libraries
# Use -readlimit 1000000 for transcriptome libraries
"phyloFlash.pl -lib {wildcards.lib}_rnaseq_se_maponly_{wildcards.readlim} -readlength 100 -readlimit {wildcards.readlim} -skip_spades -read1 {input} -CPUs {threads} -html -treemap -log -zip -dbhome {params.db} 2> {log};"
"mv {wildcards.lib}_rnaseq_se_maponly_{wildcards.readlim}.phyloFlash* qc/phyloFlash/;"
rule phyloflash_dnaseq:
input:
fwd=lambda wildcards: config['mda'][wildcards.lib]['fwd'],
rev=lambda wildcards: config['mda'][wildcards.lib]['rev']
output:
"qc/phyloFlash/{lib}_dnaseq.phyloFlash.tar.gz"
conda: "envs/phyloflash.yml"
threads: 16
log: "logs/phyloflash_dnaseq.{lib}.log"
params:
db=PHYLOFLASH_DBHOME
shell:
"phyloFlash.pl -lib {wildcards.lib}_dnaseq -readlength 150 -read1 {input.fwd} -read2 {input.rev} -CPUs {threads} -almosteverything -dbhome {params.db} 2> {log};"
"mv {wildcards.lib}_dnaseq.phyloFlash* qc/phyloFlash/;"
rule trim_reads_rnaseq:
input:
fwd=lambda wildcards: config['rnaseq'][wildcards.lib]['fwd'],
rev=lambda wildcards: config['rnaseq'][wildcards.lib]['rev']
output:
fwd="data/reads_trim/{lib}.trim.q24.R1.fastq.gz",
rev="data/reads_trim/{lib}.trim.q24.R2.fastq.gz"
threads: 8
log: "logs/trim_reads.{lib}.log"
conda: "envs/bbmap.yml"
shell:
"bbduk.sh -Xmx10g threads={threads} ref=resources/adapters.fa,resources/phix174_ill.ref.fa.gz in={input.fwd} in2={input.rev} ktrim=r qtrim=rl trimq=24 minlength=25 out={output.fwd} out2={output.rev} 2> {log}"
rule trim_reads_dnaseq:
input:
fwd=lambda wildcards: config['dnaseq'][wildcards.lib]['fwd'],
rev=lambda wildcards: config['dnaseq'][wildcards.lib]['rev']
output:
fwd="data/reads_trim/{lib}.trim.q24.R1.fastq.gz",
rev="data/reads_trim/{lib}.trim.q24.R2.fastq.gz"
threads: 8
log: "logs/trim_reads.{lib}.log"
conda: "envs/bbmap.yml"
shell:
"bbduk.sh -Xmx10g threads={threads} ref=resources/adapters.fa,resources/phix174_ill.ref.fa.gz in={input.fwd} in2={input.rev} ktrim=r qtrim=rl trimq=24 minlength=25 out={output.fwd} out2={output.rev} 2> {log}"
rule trinity:
input:
fwd="data/reads_trim/{lib}.trim.q24.R1.fastq.gz",
rev="data/reads_trim/{lib}.trim.q24.R2.fastq.gz"
output: "assembly/trinity.{lib}.Trinity.fasta"
conda: "envs/trinity.yml"
threads: 24
params:
prefix="assembly/trinity.{lib}"
log: "logs/trinity.{lib}.log"
shell:
"Trinity --seqType fq --max_memory 64G --bflyHeapSpaceMax 40G --CPU {threads} --full_cleanup --left {input.fwd} --right {input.rev} --output {params.prefix} &> {log};"
rule trinity_fulllength_qc:
# based on https://github.com/trinityrnaseq/trinityrnaseq/wiki/Counting-Full-Length-Trinity-Transcripts
# TODO use ciliate proteoms as reference db
input:
assem="assembly/{prefix}.Trinity.fasta",
db="db/{dbprefix}.fasta"
output:
blastx="qc/trinity_assem/{prefix}.v.{dbprefix}.blastx.out6",
pchitlen="qc/trinity_assem/{prefix}.v.{dbprefix}.blastx.out6.w_pct_hit_length"
threads: 8
conda: "envs/trinity.yml"
log: "logs/trinity_fulllength_qc.{dbprefix}.{prefix}.log"
params:
db_prefix="db/{dbprefix}"
shell:
"cat {input.assem} | parallel --gnu -j {threads} --recstart '>' -N 100 --pipe blastx -query - -db {params.db_prefix} -evalue 1e-20 -max_target_seqs 1 -outfmt 6 > {output.blastx};"
"analyze_blastPlus_topHit_coverage.pl {output.blastx} {input.assem} {input.db} &> {log};"
rule trim_reads_rnaseq_se: # Single-end sequencing
input:
lambda wildcards: config['rnaseq_se'][wildcards.lib]
output:
"data/reads_trim/{lib}.trim.q24.U.fastq.gz"
threads: 8
log: "logs/trim_reads_se.{lib}.log"
conda: "envs/bbmap.yml"
shell:
"bbduk.sh -Xmx10g threads={threads} ref=resources/adapters.fa,resources/phix174_ill.ref.fa.gz in={input} ktrim=r qtrim=rl trimq=24 minlength=25 out={output} 2> {log}"
rule trinity_se:
input:
"data/reads_trim/{lib}.trim.q24.U.fastq.gz"
output: "assembly/trinity_se.{lib}.Trinity.fasta"
conda: "envs/trinity.yml"
threads: 24
params:
prefix="assembly/trinity_se.{lib}"
log: "logs/trinity_se.{lib}.log"
shell:
"Trinity --seqType fq --max_memory 64G --bflyHeapSpaceMax 40G --CPU {threads} --full_cleanup --single {input} --output {params.prefix} &> {log};"
rule trinity_gg:
# Genome guided assembly from mapping file
input:
lambda wildcards: config['rnaseq_bam'][wildcards.lib]
output: "assembly/trinity_gg.{lib}.Trinity-GG.fasta"
conda: "envs/trinity.yml"
threads: 24
params:
prefix="assembly/trinity_gg.{lib}"
log: "logs/trinity_gg.{lib}.log"
shell:
# jaccard clip option for gene-dense genomes - without this option, we have about 1/3 of contigs with poly-A on both ends
"Trinity --genome_guided_bam {input} --genome_guided_max_intron 50 --max_memory 64G --CPU {threads} --bflyHeapSpaceMax 40G --output {params.prefix} --jaccard_clip --full_cleanup &> {log};"
"mv {params.prefix}/Trinity-GG.fasta {output};" # manual cleanup because --full_cleanup doesn't work with genome guided mode
"mv {params.prefix}/Trinity-GG.fasta.gene_trans_map {output}.gene_trans_map;"
# "rm -r {prefix}/;"