-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmRNA_beta5.sh
executable file
·383 lines (271 loc) · 9.11 KB
/
smRNA_beta5.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
#SBATCH -J smRNA
#SBATCH -o %x.out
#SBATCH -n 6
#SBATCH --mem-per-cpu=18000
# source /programs/bin/util/setup_mirdeep2.sh
usage(){
echo "sm R N A - S E Q W O R K F L O W - @bixBeta"
echo
echo
echo "Usage: bash" $0 "[-h arg] [-p arg] [-t arg] [-g arg]"
echo
echo "-------------------------------------------------------------------------------------------------------------------------------------------------------"
echo "[-h] --> Display Help "
echo "[-p] --> Project Identifier Number "
echo "[-d] --> Comma Spearated Values for Delimiter and Field <delim,field or default> default: -,2 (complex field example: 2 | tail -c 4 or grep -o '...$')"
echo "[-t] --> NextSeq run < yes, no, na > "
echo "[-g] --> Mapper Genome < hsa, mmu, cel > "
echo "[-c] --> CleanUP < yes or no > "
echo "-------------------------------------------------------------------------------------------------------------------------------------------------------"
}
trimSmall(){
echo "trimSmall"
mkdir TrimQC_stats fastQC mirDeep2_results trimmed_fastqs
for i in fastqs/*.gz
do
/workdir/TREx_shared/projects/TREX_small_1.sif trim_galore --nextseq 20 --gzip -j 8 --length 10 $i
done
mv *_trimming_report.txt TrimQC_stats
mv *trimmed.fq.gz trimmed_fastqs
}
trimHiSeq(){
echo "trimHiSeq"
mkdir TrimQC_stats fastQC mirDeep2_results trimmed_fastqs
for i in fastqs/*.gz
do
/workdir/TREx_shared/projects/TREX_small_1.sif trim_galore --quality 20 --gzip -j 8 --length 10 $i
done
mv *_trimming_report.txt TrimQC_stats
mv *trimmed.fq.gz trimmed_fastqs
}
fastq2fasta(){
echo "fastq2fasta"
cd trimmed_fastqs
gunzip *.gz
USR=`pwd`
for i in *.fq
do
iSUB=`echo $i | cut -d "." -f1`
singularity run -B $USR --pwd $USR /workdir/TREx_shared/projects/TREX_small_1.sif fastq2fasta.pl $i > ${iSUB}.fasta
done
mkdir ../mirDeep2_results
mv *fasta ../mirDeep2_results
#gzip *
cd ..
}
config(){
echo "config"
cd mirDeep2_results
if [ -f config.txt ]; then
echo "config file exists"
CONFIG="config.txt"
cd ..
else
ls -1 *.fasta > f1
# readarray fastas < f1
#
#
# for i in "${fastas[@]}"
# do
#
# if echo $DELIM | grep -q "|"
#
# then
# echo $i | cut -d ${DELIMITER} -f${FIELD} | ${CCOUNT} >> f2
#
# else
# echo $i | cut -d ${DELIMITER} -f${FIELD} >> f2
#
# fi
#
# done
COUNTER=`wc -l f1 | cut -d " " -f1`
COUNTERC=`expr $COUNTER + 100 `
seq 101 1 $COUNTERC > f2
paste f1 f2 > config.txt
CONFIG="config.txt"
cd ..
fi
}
mapper(){
echo "mapper"
cd mirDeep2_results
if [ -f *collapsed.fa ]; then
echo "collapsed fasta exists"
PIN=`echo *.collapsed.fa | cut -d '_' -f1`
DATE=`echo *.collapsed.fa | cut -d '_' -f2- | cut -d '.' -f1`
else
DATE=`date +"%m_%d_%H-%M"`
USR=`pwd`
singularity run -B $USR --pwd $USR /workdir/TREx_shared/projects/TREX_small_1.sif mapper.pl $CONFIG -d -c -m -s ${PIN}_${DATE}.collapsed.fa
fi
cd ..
}
quant(){
echo "quant"
cd mirDeep2_results
if [ -d expression_analyses_${PIN}_${DATE} ]; then
echo
echo "previous expression analyses detected, re-setting the DATE variable"
echo
COLLAPSED="${PIN}_${DATE}.collapsed.fa"
DATE=`date +"%m_%d_%H-%M"`
echo
echo "New DATE = $DATE"
echo
#rsync -av /workdir/fa286/miRBase/v22_1/hairpin.fa .
#rsync -av /workdir/fa286/miRBase/v22_1/mature.fa .
singularity run -B $USR --pwd $USR /workdir/TREx_shared/projects/TREX_small_1.sif quantifier.pl -p /workdir/genomes/smRNA/hairpin.fa \
-m /workdir/genomes/smRNA/mature.fa \
-t $G -y ${PIN}_${DATE} -r ${COLLAPSED} -W -d
else
USR=`pwd`
PIN=`echo *.collapsed.fa | cut -d '_' -f1`
DATE=`echo *.collapsed.fa | cut -d '_' -f2- | cut -d '.' -f1`
#rsync -av /workdir/fa286/miRBase/v22_1/hairpin.fa .
#rsync -av /workdir/fa286/miRBase/v22_1/mature.fa .
singularity run -B $USR --pwd $USR /workdir/TREx_shared/projects/TREX_small_1.sif quantifier.pl -p /workdir/genomes/smRNA/hairpin.fa \
-m /workdir/genomes/smRNA/mature.fa \
-t $G -y ${PIN}_${DATE} -r ${PIN}_${DATE}.collapsed.fa -W -d
fi
# rm hairpin.fa
# rm mature.fa
cd ..
}
cleanUp(){
echo "cleanUp"
cd mirDeep2_results
rm -r dir_mapper* f1 f2 *_trimmed.fasta
cd expression_analyses/expression_analyses_${PIN}_${DATE}
mv *.mrd *.arf ../../
cd ../../
mv miRBase.mrd ${PIN}_${DATE}_miRBase.mrd
mv mature_mapped.arf ${PIN}_${DATE}_mature_mapped.arf
rm -r expression_analyses
mkdir expression_analyses_${PIN}_${DATE}
mv *.arf *.fa *.mrd *.html *.csv expression_analyses_${PIN}_${DATE}
cd expression_analyses_${PIN}_${DATE}
gzip *.arf *.fa *.mrd
/home/fa286/bin/scripts/firstBase_readLength.sh
cd ..
echo ""
echo "DONE =) "
}
# awk 'BEGIN {OFS="\t"; m=0} FNR==NR {d[$1]=1; next} { if(FNR%2==1) {s=substr($1,2,3); c=substr($1,match($1,"_x")+2,15); if(substr($1,2,25) in d) m=1} else { l=length($1); f=substr($1,1,1); a[s,l,f,m]++; b[s,l,f,m]=b[s,l,f,m]+c;s=0;c=0;l=0;f=0; m=0}} END {print "library\treadlength\tbase1\tmiRBaseMatch\t#distinctReads\t#reads"; for (var in a) {split(var,q,SUBSEP); print q[1], q[2], q[3], q[4], a[var], b[var]} }' <(zcat *miRBase.mrd.gz) <(zcat *collapsed.fa.gz) > mirmap_firstbase_readlengthcounts.txt
# PIN="1058"
# fastq2fasta
# config
# mapper
while getopts "hp:t:g:d:c:" opt; do
case ${opt} in
h)
echo
echo
echo
usage
echo
echo
exit 1
;;
p )
PIN=$OPTARG
echo "Project Identifier = " $PIN
;;
t )
T=$OPTARG
;;
g )
G=$OPTARG
;;
d )
DELIM=$OPTARG
;;
c )
CLEAN=$OPTARG
;;
\? )
echo
echo
echo
usage
;;
esac
done
#-------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------
## check if PIN is provided
if [[ -z "${PIN+x}" ]]; then
PIN="PIN_Null"
fi
#-------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------
## check if delimiter parameter exists
if [[ ! -z "${DELIM+x}" ]]; then
#statements
if [[ $DELIM == default ]]; then
DELIMITER="-"
FIELD="2"
echo "file naming will be done using the default delimiter settings"
else
DELIMITER=`echo $DELIM | cut -d , -f1`
FIELD=`echo $DELIM | cut -d , -f2- | cut -d "|" -f1`
CCOUNT=`echo $DELIM | cut -d , -f2- | cut -d "|" -f2-`
echo "file naming will be done using the delim = $DELIMITER and field = $FIELD initial params for $DELIM"
fi
fi
#-------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------
## check if trimming parameter exists and run on nextseq 500 series (or 2 color bias )
if [[ ! -z "${T+x}" ]]; then
#statements
if [[ $T == yes ]]; then
trimSmall
#fastq2fasta
else
trimHiSeq
#fastq2fasta
fi
fi
#-------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------
## check if genome parameter is provided
if [[ ! -z "${G+x}" ]]; then
#statements
echo "Genome selected --> $G "
fastq2fasta
config
mapper
quant
elif [[ -z "$G" ]]; then
echo "Genome info not provided "
fi
#-------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------
## check if clean up parameter exists
if [[ ! -z "${CLEAN+x}" ]]; then
#statements
if [[ $CLEAN == yes ]]; then
cleanUp
else
echo 'cleanUP not required at this time'
fi
fi
#-------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------
if [[ -z $1 ]] || [[ $1 = "--help" ]] ; then
#statements
echo
echo
usage
echo
echo
exit 1
else
echo
echo `date` >> beta5.small.run.log
echo "Project Identifier Specified = " $PIN >> beta5.small.run.log
echo "Trimming for NextSeq = " $T >> beta5.small.run.log
echo "Selected Genome = " $G >> beta5.small.run.log
echo -------------------------------------------------------------------------------------------------- >> beta5.small.run.log
fi