-
Notifications
You must be signed in to change notification settings - Fork 1
/
influenza_analysis.sh
executable file
·397 lines (287 loc) · 11.8 KB
/
influenza_analysis.sh
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#!/bin/bash
## This script is for the assembly for influenza sequencing samples via de-novo and referenced based assembilies
## Author: Derek Rothenheber
## Date: 9-14-18
## Affliation: Cornell University - Animal Health and Diagnostic Center
# Exporting Program Paths to $PATH
# Need to add all different programs to the command-line $PATH
# so that they can be executed by calling the program name.
#Trinity Program (v2.6.6) - De-novo assembly program
export PATH=/programs/trinityrnaseq-Trinity-v2.6.6:$PATH
#Bowtie Program (v2.3.0) - Short read aligner
export PATH=/programs/bowtie2-2.3.0:$PATH
#Samtools Program (v1.8) - Suite of utilities for manipulating alingments in SAM format
export PATH=/programs/samtools-1.8/bin:$PATH
#Jellyfish Program (v2.2.3) - kmer counting program
export PATH=/programs/jellyfish-2.2.3/bin:$PATH
#Salmon Program (v0.10.0) - quanitifying gene expression (Used for quantifiying coverage of reads)
export PATH=/programs/salmon-0.10.0/bin:$PATH
# FastQC Program (v0.11.5) - Q/C program checking a variety of metrics from sequencing reads
export PATH=/programs/FastQC-0.11.5:$PATH
# BBMap Program (v37.50) - Q/C program to obtain read length distribution for histogram
export PATH=/programs/bbmap-37.50:$PATH
# Lighter Program - Fast and memory efficient error corrector
# Lighter needs to be used with full PATH
# Khmer (v0.4) - Library and suite of tools to work with sequences
export PATH=/programs/khmer/scripts:$PATH
# Kraken2 (v2) - Read binning using hash tables and khmer frequency
export PATH=/programs/kraken2:$PATH
# HMMER (3.1b1) - Search sequence database for homologs of protein sequences uses hidden Markov models
export PATH=/programs/hmmer-3.1b2-linux-intel-x86_64/binaries:$PATH
# Prodigal (v2.6.3) - Program needed from Prokka
export PATH=/programs/prodigal-2.6.3:$PATH
# GNU Parallel
export PATH=/programs/parallel/bin:$PATH
# Prokka The genome annotation tool
source /workdir/prokka-1.12/source.sh
# Pigz - gzip in parallel
export PATH=/programs/pigz-2.4:$PATH
echo
echo =========================================================================
echo Analysis script for Canine Influenza De-novo genome assembly and analysis
echo Author: Derek Rothenheber
echo Affliation: Cornell University - Animal Health and Diagnostic Center
echo email: dr575@cornell.edu
echo =========================================================================
echo
sleep 5s
## Step 1 Initial FastQC on foward and reverse reads
echo
echo --------------------------------------------------------------------------------------------------------
echo Step 1: Running FASTQC on concatanated fowards and reverse reads and obtaining read length distribution
echo --------------------------------------------------------------------------------------------------------
echo
rm -r -f fastqc/
mkdir fastqc
unpigz *R1* | unpigz *R2*
cat *R1* > fastqc/cat-r1.fastq | cat *R2* > fastqc/cat-r2.fastq
pigz *R1* | pigz *R2*
fastqc fastqc/cat-r1.fastq -o fastqc/ -t 40 --nogroup
fastqc fastqc/cat-r2.fastq -o fastqc/ -t 40 --nogroup
## awk command retriving read length distribution - in the future an R script will plot the results (two column data structure)
cd fastqc/
awk 'NR%4 == 2 {lengths[length($0)]++ ; counter++} END {for (l in lengths) {print l, lengths[l]}; print "total reads: " counter}' cat-r1.fastq > readlength-r1.csv
awk 'NR%4 == 2 {lengths[length($0)]++ ; counter++} END {for (l in lengths) {print l, lengths[l]}; print "total reads: " counter}' cat-r2.fastq > readlength-r2.csv
sort -t, -nk1 readlength-r1.csv > sorted.readlength-r1.csv
sort -t, -nk1 readlength-r2.csv > sorted.readlength-r2.csv
cd ..
## Step 2 Error Correction with Lighter
echo
echo ------------------------------------------------------------------------
echo Step 2: Error Correction wtih Lighter - program is for RNA based data
echo ------------------------------------------------------------------------
echo
rm -r -f lighter-output/
rm -f lighter.cmds
mkdir lighter-output
for R1 in *R1*
do
R2=${R1//R1_001.fastq/R2_001.fastq}
# echo $R1 $R2
echo "/programs/Lighter/lighter -r $R1 -r $R2 -t 40 -k 25 13000 .1 -od lighter-output/" >> lighter.cmds
done
cat lighter.cmds
chmod u+x lighter.cmds
./lighter.cmds
## Step 3 Trimming Error Corrected Sequences with Trimmomatic - using sliding window 4:5 check for Nextera Adapaters
echo
echo ----------------------------------------------------------
echo Step 3 Trimming Error Corrected Sequences with Trimmomatic
echo ----------------------------------------------------------
echo
rm -f -r trimmomatic-output/
mkdir trimmomatic-output
rm -f trimmomatic.cmds
cd lighter-output/
for R1 in *R1*
do
R2=${R1//R1_001.cor.fq/R2_001.cor.fq}
R1paired=${R1//.fq/.paired.fq}
R1unpaired=${R1//.fq/.unpaired.fq}
R2paired=${R2//.fq/.paired.fq}
R2unpaired=${R2//.fq/.unpaired.fq}
# echo $R1 $R2 $R1paired $R1unpaired $R2paired $R2unpaired
echo "java -jar /programs/trimmomatic/trimmomatic-0.36.jar PE lighter-output/$R1 lighter-output/$R2 trimmomatic-output/$R1paired trimmomatic-output/$R1unpaired trimmomatic-output/$R2paired trimmomatic-output/$R2unpaired ILLUMINACLIP:/programs/trimmomatic/adapters/NexteraPE-PE.fa:2:30:10 LEADING:2 TRAILING:2 MINLEN:25 SLIDINGWINDOW:4:5" >> trimmomatic.cmds
done
cat trimmomatic.cmds
chmod u+x trimmomatic.cmds
mv trimmomatic.cmds ../
cd ../
./trimmomatic.cmds
## Step 4: Rerunning FastQC post error correction and trimming
echo
echo ------------------------------------------------------------------------------------
echo Step 4 Rerun FastQC - post error correction and trimmming, compare pre and post runs
echo ------------------------------------------------------------------------------------
echo
cd fastqc/
mkdir post-qc
cd ../trimmomatic-output
unpigz *R1* | unpigz *R2*
cat *R1_001.cor.paired* > ../fastqc/post-qc/postqc-cat-r1.fastq | cat *R2_001.cor.paired* > ../fastqc/post-qc/postqc-cat-r2.fastq
pigz *R1* | pigz *R2*
cd ..
fastqc fastqc/post-qc/postqc-cat-r1.fastq -o fastqc/post-qc/ -t 40 --nogroup
fastqc fastqc/post-qc/postqc-cat-r2.fastq -o fastqc/post-qc/ -t 40 --nogroup
## Step 5: Classifying Reads using Kraken2 (remove all non-viral seqeuences)
echo
echo --------------------------------------------------------------------------------
echo Step 5 Classifying Reads with Kraken, removing non-viral reads and contamination
echo --------------------------------------------------------------------------------
echo
rm -r -f kraken-output
rm -f kraken.cmds
mkdir kraken-output
cd lighter-output/
for R1 in *R1_001.cor*
do
R2=${R1//R1_001.cor.fq/R2_001.cor.fq}
classified=${R1//.cor.fq.gz/.cor.classified#.fq}
output=${R1//_L001_R1_001.cor.fq.gz/_kraken-viral-only-classified}
report=${R1//_L001_R1_001.cor.fq.gz/_kraken-viral-only-report}
#echo $output $report
echo "kraken2 --db /workdir/dr575/kraken-viral-only/ --paired --classified-out $classified --fastq-input lighter-output/$R1 lighter-output/$R2 --use-names --output $output --report $report" >> kraken.cmds
done
cat kraken.cmds
chmod u+x kraken.cmds
mv kraken.cmds ../
cd ..
./kraken.cmds
mv *_kraken-* kraken-output/
mv *classified* kraken-output/
cd kraken-output/
for i in *L001_R1_001.cor.classified_2.fq
do
mv "$i" ${i/L001_R1_001.cor.classified_2.fq/L001_R2_001.cor.classified.fq}
done
for a in *L001_R1_001.cor.classified_1.fq
do
mv "$a" ${a/L001_R1_001.cor.classified_1.fq/L001_R1_001.cor.classified.fq}
done
cd ..
################################## Step 6: Trinity Assembly ######################################################
echo
echo ---------------------------------------------------------------------------------
echo Step 6: ~~~~~~~~~~~~~~~Trinity Assembly with digital normalization~~~~~~~~~~~~~~~
echo ---------------------------------------------------------------------------------
echo
rm -r -f trinity/
rm -f trinity.cmds
cd kraken-output/
for R1 in *R1_001.cor.classified.fq
do
R2=${R1//R1_001.cor.classified.fq/R2_001.cor.classified.fq}
wd=${R1//L001_R1_001.cor.classified.fq/trinity-output}
#echo $R1 $R2
echo "Trinity --seqType fq --max_memory 200G --CPU 40 --left kraken-output/$R1 --right kraken-output/$R2 --output $wd/ --normalize_max_read_cov 50" >> trinity.cmds
done
cat trinity.cmds
chmod u+x trinity.cmds
mv trinity.cmds ../
cd ..
./trinity.cmds
mkdir trinity
mv *trinity-output/ trinity/
## Step 7 Estimate of adundance using RSEM within Trinity (TPM && FPKM)
echo
echo --------------------------------------------------------------------------------------------------
echo Step 7: ~~~~~~~~~~~~~~~Estimate of adundance using RSEM within Trinity TPM and FPKM~~~~~~~~~~~~~~~
echo --------------------------------------------------------------------------------------------------
echo
################## Renaming all output files with sample specific prefixes and reformating fasta file to be blast-able
cd trinity/
rm -r -f trinity-output/
for file in */*
do
fname=${file##*/} #This gives your base filename.
fpath=${file%/*} # Your dir
dname=${fpath##*/}
mv $file ${fpath}/${dname}.${fname}
done
for fasta in */*Trinity.fasta
do
# echo $fasta
mv $fasta ./
done
for map in */*Trinity.fasta.gene_trans_map
do
# echo $map
mv $map ./
done
## Now starting RSEM analysis ##
mkdir trinity-output
mv *Trinity.fasta trinity-output/
mv *Trinity.fasta.gene_trans_map trinity-output/
rm -r -f resm-abundance/
rm -f resm.cmds
for file in trinity-output/*Trinity.fasta
do
file2=${file//.fasta/.fasta.gene_trans_map}
r1=${file//_trinity-output.Trinity.fasta/_L001_R1_001.cor.classified.fq}
r1p=${r1//trinity-output/}
r2=${file//_trinity-output.Trinity.fasta/_L001_R2_001.cor.classified.fq}
r2p=${r2//trinity-output/}
out=${file//_trinity-output.Trinity.fasta/_resm-abundance}
outdir=${out//trinity-output/}
echo $r1p $r2p
echo $outdir
echo "/programs/trinityrnaseq-Trinity-v2.6.6/util/align_and_estimate_abundance.pl --transcripts $file --seqType fq --left ../kraken-output$r1p --right ../kraken-output$r2p --est_method RSEM --aln_method bowtie2 --gene_trans_map $file2 --output_dir resm-adundance$outdir --thread_count 40 --prep_reference --include_rsem_bam" >> resm.cmds
done
cat resm.cmds
chmod u+x resm.cmds
./resm.cmds
###################### Reformating Trinity Output files for later BLASTING ###########################
cd trinity-output/
for fasta in *Trinity.fasta
do
echo $fasta
cat $fasta | sed "s/ path.*//gi" | sed "s/ /_/gi" | sed "s/=//gi" | sed "s/TRINITY/$fasta/gi" > $fasta.temp
awk '/^>/ {printf("\n%s\n",$0);next; } { printf("%s",$0);} END {printf("\n");}' < $fasta.temp > $fasta.temp2
tail -n +2 $fasta.temp2 > $fasta
rm -f $fasta.temp
rm -f $fasta.temp2
done
cd ../
echo
echo ----------------------------------------------------------------------------
echo Step 8 Finding the Longest ORFs searching for homologs with ProKKa with Pfam
echo ----------------------------------------------------------------------------
echo
rm -r -f prokka-output
mkdir prokka-output
for fasta in trinity-output/*Trinity.fasta
do
input=$fasta
temp=${fasta##*/}
fname=${temp//_trinity-output.Trinity.fasta/}
echo $input
echo $fname
echo "prokka --outdir prokka-output/$fname --force --compliant --kingdom Viruses --cpus 40 $input" >> prokka.cmds
done
cat prokka.cmds
chmod u+x prokka.cmds
./prokka.cmds
cd prokka-output/
for file in */*
do
fname=${file##*/} #This gives your base filename.
fpath=${file%/*} # Your dir
dname=${fpath##*/}
mv $file ${fpath}/${dname}.${fname}
done
#rm -r -f filtered.cmds
#for fasta in */*.ffn
#do
# input=$fasta
# temp=${fasta##*/}
# output=${temp//.ffn/_final.fasta}
# echo "python filter-genomic-segments.py /workdir/dr575/test-dir/trinity/prokka-output/$input $output" >> filtered.cmds
#done
#cat filtered.cmds
#chmod u+x filtered.cmds
#mv filtered.cmds /workdir/dr575/test-dir/
#cd /workdir/dr575/test-dir/
#rm -r -f annotated-fasta/
#mkdir annotated-fasta
#./filtered.cmds
#mv *final.fasta annotated-fasta/