forked from mpg-age-bioinformatics/htseq-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuxedo-slurm.sh
executable file
·383 lines (273 loc) · 10.5 KB
/
tuxedo-slurm.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
#!/bin/bash
"This script needs to run form inside the folder scripts in a working project with the following structure:
project/scripts
project/raw_data
Raw data needs to be labeled in the following fashion:
Sample_serial-Folder-Line-Time_point/day_of_life(day_post_Treament)-treament-REPlicate-READ
and with the exact number of characters as in the example bellow:
S_001-F_HaTS-L____N2-__0-____-REP_1-READ_1.fastq.gz
S_XXX-F_XXXX-L_XXXXX-XXX-XXXX-REP_X-READ_x.fastq.gz
Please notice that for paired samples, the S_XXX is the same.
Make sure you have edited the last section of this script - cuffdiff - before you execute this script."
#############################################################################
# Define series as SE or PE and stranded or unstranded
SE_unstr=("YiTS" "YiDR" "YiIS" "ShTe")
SE_str=("Yid1" "OeDA" "AgMi")
PE_str=("RoSt" "HaTS" "HaIS")
mix=("Yid3")
unstr=("YiTS" "YiDR" "YiIS" "ShTe")
str=("Yid1" "OeDA" "RoSt" "HaTS" "HaIS" "AgMi" )
#mix=("Yid3")
# Which series do you which to work on:
series="AgMi"
# Reference genome
ann=/data/genomes/mus_musculus/GRCm38_79
ori_GTF=$(readlink -f ${ann}/GRCm38.*.gtf)
GTF_file=$(readlink -f ${ann}/cuffcmp_GTF.*.gtf)
GTF_index=$(readlink -f ${ann}/cuffcmp_GTF_index/*.gff)
GTF_index=${GTF_index::(-4)}
genome=$(ls ${ann}/bowtie2/*dna.toplevel.fa)
genomeN=${genome::(-3)}
adapters_file=full_path_to_adapters_file_for_flexbar_to_use
#############################################################################
echo "Creating required folders"
mkdir ../slurm_logs
mkdir ../fastqc
mkdir ../tmp
mkdir ../tophat_output
mkdir ../cufflinks_output
mkdir ../raw_trimmed
mkdir ../cuffmerge_output
mkdir ../cuffquant_output
mkdir ../cuffdiff_output
top=$(readlink -f ../)/
tmp=$(readlink -f ../tmp)/
raw=$(readlink -f ../raw_data)/
rawt=$(readlink -f ../raw_trimmed)/
cli=$(readlink -f ../cufflinks_output)/
qua=$(readlink -f ../cuffquant_output)/
merg=$(readlink -f ../cuffmerge_output)/
# Required function
function contains() {
local n=$#
local value=${!n}
for ((i=1;i < $#;i++)) {
if [ "${!i}" == "${value}" ]; then
echo "y"
return 0
fi
}
echo "n"
return 1
}
#############################################################################
echo "Starting FASTQC"
cd ${raw}
if [[ -e ${tmp}fastqc.ids ]]; then
rm ${tmp}fastqc.ids
fi
for serie in $series; do
for file in $(ls *${serie}*.fastq.gz); do echo "#!/bin/bash
module load pigz
module load FastQC
cp ${raw}${file} ${tmp}
cd ${tmp}
unpigz -p 10 ${file}
fastqc -t 10 -o ../fastqc ${file::(-3)}
rm ${tmp}fastqc_${file::(-9)}.sh" > ${tmp}fastqc_${file::(-9)}.sh
cd ${tmp}
chmod 755 ${tmp}fastqc_${file::(-9)}.sh
rm ../slurm_logs/fastqc_${file::(-9)}.*.out
sbatch -p blade,himem,hugemem --cpus-per-task=10 -o ../slurm_logs/fastqc_${file::(-9)}.%j.out ${tmp}fastqc_${file::(-9)}.sh 2>&1 | tee ${tmp}fastqc_${file::(-2)}id
id=$(cat ${tmp}fastqc_${file::(-2)}id | grep 'Submitted batch job')
echo -n :${id:20} >> ${tmp}fastqc.ids
rm ${tmp}fastqc_${file::(-2)}id
done
done
fastqc_ids=$(cat ${tmp}fastqc.ids)
srun -p blade,himem,hugemem -d afterok${fastqc_ids} echo "FASTQC done"
#############################################################################
cd ${tmp}
if [[ -e ${tmp}flexbar.ids ]]; then
rm ${tmp}flexbar.ids
fi
for serie in $series; do
for file in $(ls *${serie}*1.fastq); do
if [[ -e ${file::(-7)}2.fastq ]]; then
echo "#!/bin/bash
module load pigz
module load Flexbar
flexbar -r ${tmp}${file::(-7)}1.fastq \
-p ${tmp}${file::(-7)}2.fastq -t ${top}raw_trimmed/${file::(-8)} \
-n 20 -a ${adapters_file} \
-ao 10 -u 5 -q 20 -m 20 -f i1.8 -ae ANY
cd ${top}raw_trimmed
pigz -p 10 ${file::(-7)}1.fastq
pigz -p 10 ${file::(-7)}2.fastq
rm ${tmp}flexbar_${file::(-5)}sh" > ${tmp}flexbar_${file::(-5)}sh
else
echo "#!/bin/bash
module load pigz
module load Flexbar
flexbar -r ${tmp}${file::(-7)}1.fastq \
-t ${top}raw_trimmed/${file::(-6)} \
-n 20 -a -a ${adapters_file} \
-ao 10 -u 5 -q 20 -m 20 -f i1.8 -ae ANY
cd ${top}raw_trimmed
pigz -p 10 ${file}
rm ${tmp}flexbar_${file::(-5)}sh" > ${tmp}flexbar_${file::(-5)}sh
fi
cd ${tmp}
chmod 755 ${tmp}flexbar_${file::(-5)}sh
rm ../slurm_logs/flexbar_${file::(-5)}*.out
sbatch -p blade,himem,hugemem --cpus-per-task=20 -o ../slurm_logs/flexbar_${file::(-5)}%j.out ${tmp}flexbar_${file::(-5)}sh 2>&1 | tee ${tmp}flexbar_${file::(-5)}id
id=$(cat ${tmp}flexbar_${file::(-5)}id | grep 'Submitted batch job')
echo -n :${id:20} >> ${tmp}flexbar.ids
rm ${tmp}flexbar_${file::(-5)}id
done
done
flexbar_ids=$(cat ${tmp}flexbar.ids)
srun -p blade,himem,hugemem -d afterok${flexbar_ids} echo "FLEXBAR done"
#############################################################################
if [[ -e ${tmp}assemblies.txt ]]; then
rm ${tmp}assemblies.txt
fi
if [[ -e ${tmp}th_cl.ids ]]; then
rm ${tmp}${tmp}th_cl.ids
fi
cd ${rawt}
for serie in $series; do
for file in $(ls *${serie}*1.fastq.gz); do
if [[ $(contains "${SE_unstr[@]}" "$serie") == "y" ]]; then
lib="fr-unstranded"
files=${file}
elif [[ $(contains "${SE_str[@]}" "$serie") == "y" ]]; then
lib="fr-firststrand"
files=${file}
elif [[ $(contains "${PE_str[@]}" "$serie") == "y" ]]; then
lib="fr-firststrand"
files="${file} ${file::(-10)}2.fastq.gz"
elif [[ $(contains "${mix[@]}" "$serie") == "y" ]]; then
files=${file}
REP=${file:30:5}
if [[ ${REP} == REP_3 ]]; then
lib="fr-firststrand"
else
lib="fr-unstranded"
fi
fi
echo "#!/bin/bash
cd ${rawt}
module load Bowtie2
module load TopHat
tophat -p 20 --library-type ${lib} \
--transcriptome-index ${GTF_index} \
-o ${top}tophat_output/${file::(-16)} \
${genomeN} \
${files}
module load Cufflinks
cufflinks -p 20 --library-type ${lib} \
-g ${GTF_file} --no-faux-reads \
-o ${top}cufflinks_output/${file::(-16)} \
${top}tophat_output/${file::(-16)}/accepted_hits.bam
cat ${top}cufflinks_output/${file::(-16)}/transcripts.gtf | grep yes > ${top}cufflinks_output/${file::(-16)}/transcripts_full_read.gtf
rm ${tmp}th_cl_${file::(-16)}.sh" > ${tmp}th_cl_${file::(-16)}.sh
cd ${tmp}
chmod 755 ${tmp}th_cl_${file::(-16)}.sh
rm ../slurm_logs/th_cl_${file::(-16)}.*.out
sbatch -p blade,himem,hugemem --cpus-per-task=20 -o ../slurm_logs/th_cl_${file::(-16)}.%j.out ${tmp}th_cl_${file::(-16)}.sh 2>&1 | tee ${tmp}th_cl_${file::(-16)}.id
id=$(cat ${tmp}th_cl_${file::(-16)}.id | grep 'Submitted batch job')
echo -n :${id:20} >> ${tmp}th_cl.ids
rm ${tmp}th_cl_${file::(-16)}.id
echo "cufflinks_output/${file::(-16)}/transcripts_full_read.gtf" >> ${tmp}assemblies.txt
done
done
th_cl_ids=$(cat ${tmp}th_cl.ids)
srun -p blade,himem,hugemem -d afterok${th_cl_ids} echo "TopHat and Cufflinks done"
#############################################################################
echo "Starting cuffmerge"
for serie in $series; do
cat ${tmp}assemblies.txt | grep ${serie} > ${tmp}assemblies_${serie}.txt
cd ${top}
mkdir cuffmerge_output/${serie}
cmout=$(readlink -f cuffmerge_output/${serie})/
echo ${serie}
cd ${top}
module load Cufflinks
srun -p blade,himem,hugemem --cpus-per-task=2 cuffmerge -p 2 -o ${cmout} \
-g ${GTF_file} -s ${genome} ${tmp}assemblies_${serie}.txt
cd ${cmout}
mkdir cuffcompare_output
cd cuffcompare_output
echo "STARTING CUFFCOMPARE"
module load Cufflinks
srun -p himem,hugemem,blade --cpus-per-task=2 cuffcompare -C -r ${ori_GTF} -s ${ann}/chromosomes ${cmout}merged.gtf
done
cd ${tmp}
cd ../scripts
#############################################################################
echo "Starting cuffquant"
if [[ -e ${tmp}quant.ids ]]; then
rm ${tmp}quant.ids
fi
for serie in $series; do
if [[ $(contains "${unstr[@]}" "$serie") == "y" ]]; then
lib="fr-unstranded"
elif [[ $(contains "${str[@]}" "$serie") == "y" ]]; then
lib="fr-firststrand"
elif [[ $(contains "${mix[@]}" "$serie") == "y" ]]; then
lib="fr-unstranded"
fi
cd ${top}tophat_output
for file in $(ls -d *${serie}*); do echo "#!/bin/bash
cd ${top}cuffquant_output
mkdir ${serie}
cd ${serie}
module load Cufflinks
cuffquant -p 20 --library-type ${lib} \
-o ${file} \
${top}cuffmerge_output/${serie}/cuffcompare_output/cuffcmp.combined.gtf \
${top}tophat_output/${file}/accepted_hits.bam
rm ${tmp}quant_${file}.sh" > ${tmp}quant_${file}.sh
cd ${tmp}
chmod 755 ${tmp}quant_${file}.sh
rm ../slurm_logs/quant_${file}.*.out
sbatch -p blade,himem,hugemem --cpus-per-task=20 -o ../slurm_logs/quant_${file}.%j.out ${tmp}quant_${file}.sh 2>&1 | tee ${tmp}quant_${file}.id
id=$(cat ${tmp}quant_${file}.id | grep 'Submitted batch job')
echo -n :${id:20} >> ${tmp}quant.ids
rm ${tmp}quant_${file}.id
done
done
quant_ids=$(cat ${tmp}quant.ids)
srun -p blade,himem,hugemem -d afterok${quant_ids} echo "Starting cuffdiff"
#############################################################################
echo "Starting cuffdiff"
#### cuff diff >>>> one section per serie ######
serie=AgMi
mkdir ${top}cuffdiff_output/${serie}
dout=$(readlink -f ${top}cuffdiff_output/${serie})
lib="fr-firststrand"
echo "#!/bin/bash
cd ${qua}${serie}
module load Cufflinks
cuffdiff -p 20 --library-type ${lib} \
-L liver_10M,heart_10M,cereb_10M,hippo_10M,liver_27M,heart_27M,cereb_27M,hippo_27M \
-o ${dout} --dispersion-method per-condition \
${top}cuffmerge_output/${serie}/cuffcompare_output/cuffcmp.combined.gtf \
S_001-F_AgMi-L_live-_10-____-REP_1/abundances.cxb,S_005-F_AgMi-L_live-_10-____-REP_2/abundances.cxb,S_009-F_AgMi-L_live-_10-____-REP_3/abundances.cxb \
S_002-F_AgMi-L_hear-_10-____-REP_1/abundances.cxb,S_006-F_AgMi-L_hear-_10-____-REP_2/abundances.cxb,S_010-F_AgMi-L_hear-_10-____-REP_3/abundances.cxb \
S_003-F_AgMi-L_cere-_10-____-REP_1/abundances.cxb,S_007-F_AgMi-L_cere-_10-____-REP_2/abundances.cxb,S_011-F_AgMi-L_cere-_10-____-REP_3/abundances.cxb \
S_004-F_AgMi-L_hipp-_10-____-REP_1/abundances.cxb,S_008-F_AgMi-L_hipp-_10-____-REP_2/abundances.cxb,S_012-F_AgMi-L_hipp-_10-____-REP_3/abundances.cxb \
S_013-F_AgMi-L_live-_27-____-REP_1/abundances.cxb,S_017-F_AgMi-L_live-_27-____-REP_2/abundances.cxb,S_021-F_AgMi-L_live-_27-____-REP_3/abundances.cxb \
S_014-F_AgMi-L_hear-_27-____-REP_1/abundances.cxb,S_018-F_AgMi-L_hear-_27-____-REP_2/abundances.cxb,S_022-F_AgMi-L_hear-_27-____-REP_3/abundances.cxb \
S_015-F_AgMi-L_cere-_27-____-REP_1/abundances.cxb,S_019-F_AgMi-L_cere-_27-____-REP_2/abundances.cxb,S_023-F_AgMi-L_cere-_27-____-REP_3/abundances.cxb \
S_016-F_AgMi-L_hipp-_27-____-REP_1/abundances.cxb,S_020-F_AgMi-L_hipp-_27-____-REP_2/abundances.cxb,S_024-F_AgMi-L_hipp-_27-____-REP_3/abundances.cxb
rm ${tmp}diff_${serie}.sh" > ${tmp}diff_${serie}.sh
#### END section
for serie in ${series}; do
cd ${tmp}
chmod 755 ${tmp}diff_${serie}.sh
rm ../slurm_logs/diff_${serie}.*.out
sbatch -p blade,himem,hugemem --mem=512gb --cpus-per-task=20 -o ../slurm_logs/diff_${serie}.%j.out ${tmp}diff_${serie}.sh
done
exit