-
Notifications
You must be signed in to change notification settings - Fork 0
/
Separate_sets.sh
614 lines (567 loc) · 21.3 KB
/
Separate_sets.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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
#!/bin/bash
filename=$1
dataset=${filename%.*}
# Separate sequences w/o info on PI
head -n 1 $dataset > ${dataset}-NA
head -n 1 $dataset > ${dataset}-PI
sed '1d' $dataset | while read line
do
checkline=$(grep 'NA' <<< $line)
if [[ -n $checkline ]]
then
echo $line >> ${dataset}-NA
else
echo $line >> ${dataset}-PI
fi
done
nlinesNA=$(wc -l ${dataset}-NA | awk '{print $1}')
nlinesPI=$(wc -l ${dataset}-PI | awk '{print $1}')
if [[ $nlinesNA -eq 1 ]]; then rm ${dataset}-NA ;
elif [[ $nlinesPI -eq 1 ]]; then rm ${dataset}-PI ; echo "Review script parameters for susceptibility." ; exit 1 ; fi
if [[ -f ${dataset}-NA ]] ; then sed -i '/^$/d' ${dataset}-NA ; echo "The sequences which don't have information on PIs are saved in "${dataset}-NA ; fi
sed -i '/^$/d' ${dataset}-PI ; echo "The sequences with information on resistance to PIs are saved in "${dataset}-PI
#### Susceptible to all PI ####
head -n 1 $dataset > ${dataset}-susceptible
head -n 1 $dataset > ${dataset}-res20
sed '1d' ${dataset}-PI | while read sequence
do
DRV=$(awk '{print $9}' <<< $sequence) ; sDRV=${DRV%%.*} # don't use printf %1.0f because of approximations
FPV=$(awk '{print $2}' <<< $sequence) ; sFPV=${FPV%%.*}
ATV=$(awk '{print $3}' <<< $sequence) ; sATV=${ATV%%.*}
IDV=$(awk '{print $4}' <<< $sequence) ; sIDV=${IDV%%.*}
LPV=$(awk '{print $5}' <<< $sequence) ; sLPV=${LPV%%.*}
NFV=$(awk '{print $6}' <<< $sequence) ; sNFV=${NFV%%.*}
SQV=$(awk '{print $7}' <<< $sequence) ; sSQV=${SQV%%.*}
TPV=$(awk '{print $8}' <<< $sequence) ; sTPV=${TPV%%.*}
if [[ $sFPV -lt 3 && $sATV -lt 3 && $sIDV -lt 3 && $sLPV -lt 3 && $sNFV -lt 3 && $sSQV -lt 3 && $sTPV -lt 3 && $sDRV -lt 3 ]]
then
echo $sequence >> ${dataset}-susceptible
elif [[ $sFPV -gt 20 && $sATV -gt 20 && $sIDV -gt 20 && $sLPV -gt 20 && $sNFV -gt 20 && $sSQV -gt 20 && $sTPV -gt 20 && $sDRV -gt 20 ]]
then
echo $sequence >> ${dataset}-res20
echo $sequence >> ${dataset}-res15
echo $sequence >> ${dataset}-res10
elif [[ $sFPV -gt 15 && $sATV -gt 15 && $sIDV -gt 15 && $sLPV -gt 15 && $sNFV -gt 15 && $sSQV -gt 15 && $sTPV -gt 15 && $sDRV -gt 15 ]]
then
echo $sequence >> ${dataset}-res15
echo $sequence >> ${dataset}-res10
elif [[ $sFPV -gt 10 && $sATV -gt 10 && $sIDV -gt 10 && $sLPV -gt 10 && $sNFV -gt 10 && $sSQV -gt 10 && $sTPV -gt 10 && $sDRV -gt 10 ]]
then
echo $sequence >> ${dataset}-res10
fi
done
nlinesSUS=$(wc -l ${dataset}-susceptible | awk '{print $1}')
if [[ $nlinesSUS -eq 1 ]]; then rm ${dataset}-susceptible ; echo "No sequence is susceptible to all PI. Review script parameters for susceptibility." ; exit 0 ; fi
sed -i '/^$/d' ${dataset}-susceptible ; echo "All sequences susceptible to DRV, FPV, ATV, IDV, LPV, NFV, SQV, and TPV are saved in "${dataset}-susceptible
nlinesRES20=$(wc -l ${dataset}-res20 | awk '{print $1}')
if [[ $nlinesRES20 -eq 1 ]]; then rm ${dataset}-res20 ; echo "No sequence is >20.0-fold resistant to all PI. Review script parameters for susceptibility." ; exit 0 ; fi
sed -i '/^$/d' ${dataset}-res20 ; echo "All sequences highly resistant to DRV, FPV, ATV, IDV, LPV, NFV, SQV, and TPV are saved in "${dataset}-res20
nlinesRES15=$(wc -l ${dataset}-res15 | awk '{print $1}')
if [[ $nlinesRES15 -eq 1 ]]; then rm ${dataset}-res15 ; echo "No sequence is >15.0-fold resistant to all PI. Review script parameters for susceptibility." ; exit 0 ; fi
sed -i '/^$/d' ${dataset}-res15 ; echo "All sequences highly resistant to DRV, FPV, ATV, IDV, LPV, NFV, SQV, and TPV are saved in "${dataset}-res15
nlinesRES10=$(wc -l ${dataset}-res10 | awk '{print $1}')
if [[ $nlinesRES10 -eq 1 ]]; then rm ${dataset}-res10 ; echo "No sequence is >10.0-fold resistant to all PI. Review script parameters for susceptibility." ; exit 0 ; fi
sed -i '/^$/d' ${dataset}-res15 ; echo "All sequences highly resistant to DRV, FPV, ATV, IDV, LPV, NFV, SQV, and TPV are saved in "${dataset}-res15
#### Getting the sequences ####
sed '1d' ${dataset}-susceptible | while read sequence
do
seqID=$(awk '{print $1}' <<< $sequence)
echo ">"$seqID > ${seqID}.fasta
checkseqID=$(ls | grep $seqID | wc -l)
seqcons=PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF
# consensus B subtype (https://hivdb.stanford.edu/pages/documentPage/consensus_amino_acid_sequences.html)
for columnno in {10..108}
do
aminoacid=$(awk '{print $'$columnno'}' <<< $sequence)
position=$(expr $columnno - 10)
rescon=${seqcons:$position:1}
respos=$(expr $position + 1)
checkaa=$(wc -m <<< $aminoacid) # in dataset, if there's a mixture the $(wc -m) is ge 3, else is 2
if [[ -n $checkseqID && $checkaa -eq 2 ]]
then
for file in $(ls | grep $seqID)
do
if [[ $aminoacid == '-' ]] ; then printf "%s" $rescon >> $file
elif [[ $aminoacid == '.' || $aminoacid == '~' ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}d.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}d.fasta
else printf "%s" $aminoacid >> $file ; fi
done
elif [[ -n $checkseqID && $checkaa -ge 3 ]]
then
for file in $(ls | grep $seqID | grep -v STOP)
do
aa=$(expr $checkaa - 2) # discount for (newline + count from zero)
for resmix in $(seq 0 $aa)
do
resaa=${aminoacid:$resmix:1} # keep mixtures with consensus aminoacid, because of further mutations
if [[ -n $(grep '*' <<< $resaa) ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}_STOP.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}_STOP.fasta
elif [[ -n $(grep '#' <<< $resaa) ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
printf "%s" $aminoacid >> ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
else
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
printf "%s" $resaa >> ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
fi
done
rm $file
done
fi
done
done
echo "All susceptible sequences separated in FASTA files."
# Check for X residue
sed '1d' ${dataset}-susceptible | while read sequence
do
seqID=$(awk '{print $1}' <<< $sequence)
for file in $(ls | grep $seqID)
do
checkX=$(sed '1d' $file | grep X)
if [[ -n $checkX ]] ; then echo $seqID >> ${dataset}-susceptible_Xmut.tmp ; fi
done
done
if [[ -f ${dataset}-susceptible_Xmut.tmp ]]
then
cat PI_dataset-susceptible_Xmut.tmp | sort | uniq > PI_dataset-susceptible_Xmut.log
rm PI_dataset-susceptible_Xmut.tmp
echo "The following sequences have at least one mutation for any possible amino acid:"
echo
cat ${dataset}-susceptible_Xmut.log
echo
echo "The IDs are saved in the "${dataset}-susceptible_Xmut.log" file."
# Separate various X mutations
while read xmut
do
for file in $(ls | grep $xmut)
do
seqcons=PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF
seqX=$(sed '1d' $file | grep X)
seqNX=$(sed '1d' $file | grep -o X | wc -l)
if [[ $seqNX -eq 1 ]]
then
for position in {0..98}
do
resseq=${seqX:$position:1}
rescon=${seqcons:$position:1}
respos=$(expr $position + 1)
## Amino acids
# "A" = "ALA"
# "R" = "ARG"
# "D" = "ASP"
# "N" = "ASN"
# "C" = "CYS"
# "E" = "GLU"
# "Q" = "GLN"
# "G" = "GLY"
# "H" = "HIS"
# "I" = "ILE"
# "L" = "LEU"
# "K" = "LYS"
# "M" = "MET"
# "F" = "PHE"
# "P" = "PRO"
# "S" = "SER"
# "T" = "THR"
# "W" = "TRP"
# "Y" = "TYR"
# "V" = "VAL"
if [[ $resseq == "X" ]]
then
for aa in A R D N C E Q G H I L K M F P S T W Y V
do
echo ">"$xmut > ${file%%.fasta}_${rescon}${respos}${aa}.fasta
sed -r 's/(.{'$position'})(.)/\1'$aa'/' <<< $seqX >> ${file%%.fasta}_${rescon}${respos}${aa}.fasta
done
fi
done
rm $file
echo "All sequences from X mutations available."
fi
done
done < ${dataset}-susceptible_Xmut.log
fi
# Move FASTA to folder
rundate=$(date "+%Y%m%d")
mkdir -p ${rundate}_${dataset}_susceptible
mv *.fasta ${rundate}_${dataset}_susceptible
sed '1d' ${dataset}-res20 | while read sequence
do
seqID=$(awk '{print $1}' <<< $sequence)
echo ">"$seqID > ${seqID}.fasta
checkseqID=$(ls | grep $seqID | wc -l)
seqcons=PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF
# consensus B subtype (https://hivdb.stanford.edu/pages/documentPage/consensus_amino_acid_sequences.html)
for columnno in {10..108}
do
aminoacid=$(awk '{print $'$columnno'}' <<< $sequence)
position=$(expr $columnno - 10)
rescon=${seqcons:$position:1}
respos=$(expr $position + 1)
checkaa=$(wc -m <<< $aminoacid) # in dataset, if there's a mixture the $(wc -m) is ge 3, else is 2
if [[ -n $checkseqID && $checkaa -eq 2 ]]
then
for file in $(ls | grep $seqID)
do
if [[ $aminoacid == '-' ]] ; then printf "%s" $rescon >> $file
elif [[ $aminoacid == '.' || $aminoacid == '~' ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}d.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}d.fasta
else printf "%s" $aminoacid >> $file ; fi
done
elif [[ -n $checkseqID && $checkaa -ge 3 ]]
then
for file in $(ls | grep $seqID)
do
aa=$(expr $checkaa - 2) # discount for (newline + count from zero)
for resmix in $(seq 0 $aa)
do
resaa=${aminoacid:$resmix:1} # keep mixtures with consensus aminoacid, because of further mutations
if [[ -n $(grep '*' <<< $resaa) ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}_STOP.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}_STOP.fasta
elif [[ -n $(grep '#' <<< $resaa) ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
printf "%s" $aminoacid >> ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
else
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
printf "%s" $resaa >> ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
fi
done
rm $file
done
fi
done
done
echo "All highly resistant sequences separated in FASTA files."
# Check for X residue
sed '1d' ${dataset}-res20 | while read sequence
do
seqID=$(awk '{print $1}' <<< $sequence)
for file in $(ls | grep $seqID)
do
checkX=$(sed '1d' $file | grep X)
if [[ -n $checkX ]] ; then echo $seqID >> ${dataset}-res20_Xmut.tmp ; fi
done
done
if [[ -f ${dataset}-res20_Xmut.tmp ]]
then
cat PI_dataset-res20_Xmut.tmp | sort | uniq > PI_dataset-res20_Xmut.log
rm PI_dataset-res20_Xmut.tmp
echo "The following sequences have at least one mutation for any possible amino acid:"
echo
cat ${dataset}-res20_Xmut.log
echo
echo "The IDs are saved in the "${dataset}-res20_Xmut.log" file."
# Separate various X mutations
while read xmut
do
for file in $(ls | grep $xmut)
do
seqcons=PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF
seqX=$(sed '1d' $file | grep X)
seqNX=$(sed '1d' $file | grep -o X | wc -l)
if [[ $seqNX -eq 1 ]]
then
for position in {0..98}
do
resseq=${seqX:$position:1}
rescon=${seqcons:$position:1}
respos=$(expr $position + 1)
## Amino acids
# "A" = "ALA"
# "R" = "ARG"
# "D" = "ASP"
# "N" = "ASN"
# "C" = "CYS"
# "E" = "GLU"
# "Q" = "GLN"
# "G" = "GLY"
# "H" = "HIS"
# "I" = "ILE"
# "L" = "LEU"
# "K" = "LYS"
# "M" = "MET"
# "F" = "PHE"
# "P" = "PRO"
# "S" = "SER"
# "T" = "THR"
# "W" = "TRP"
# "Y" = "TYR"
# "V" = "VAL"
if [[ $resseq == "X" ]]
then
for aa in A R D N C E Q G H I L K M F P S T W Y V
do
echo ">"$xmut > ${file%%.fasta}_${rescon}${respos}${aa}.fasta
sed -r 's/(.{'$position'})(.)/\1'$aa'/' <<< $seqX >> ${file%%.fasta}_${rescon}${respos}${aa}.fasta
done
fi
done
rm $file
echo "All sequences from X mutations available."
fi
done
done < ${dataset}-res20_Xmut.log
fi
# Move FASTA to folder
rundate=$(date "+%Y%m%d")
mkdir -p ${rundate}_${dataset}_res20
mv *.fasta ${rundate}_${dataset}_res20
sed '1d' ${dataset}-res15 | while read sequence
do
seqID=$(awk '{print $1}' <<< $sequence)
echo ">"$seqID > ${seqID}.fasta
checkseqID=$(ls | grep $seqID | wc -l)
seqcons=PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF
# consensus B subtype (https://hivdb.stanford.edu/pages/documentPage/consensus_amino_acid_sequences.html)
for columnno in {10..108}
do
aminoacid=$(awk '{print $'$columnno'}' <<< $sequence)
position=$(expr $columnno - 10)
rescon=${seqcons:$position:1}
respos=$(expr $position + 1)
checkaa=$(wc -m <<< $aminoacid) # in dataset, if there's a mixture the $(wc -m) is ge 3, else is 2
if [[ -n $checkseqID && $checkaa -eq 2 ]]
then
for file in $(ls | grep $seqID)
do
if [[ $aminoacid == '-' ]] ; then printf "%s" $rescon >> $file
elif [[ $aminoacid == '.' || $aminoacid == '~' ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}d.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}d.fasta
else printf "%s" $aminoacid >> $file ; fi
done
elif [[ -n $checkseqID && $checkaa -ge 3 ]]
then
for file in $(ls | grep $seqID)
do
aa=$(expr $checkaa - 2) # discount for (newline + count from zero)
for resmix in $(seq 0 $aa)
do
resaa=${aminoacid:$resmix:1} # keep mixtures with consensus aminoacid, because of further mutations
if [[ -n $(grep '*' <<< $resaa) ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}_STOP.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}_STOP.fasta
elif [[ -n $(grep '#' <<< $resaa) ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
printf "%s" $aminoacid >> ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
else
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
printf "%s" $resaa >> ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
fi
done
rm $file
done
fi
done
done
echo "All highly resistant sequences greater than 15 are separated in FASTA files."
# Check for X residue
sed '1d' ${dataset}-res15 | while read sequence
do
seqID=$(awk '{print $1}' <<< $sequence)
for file in $(ls | grep $seqID)
do
checkX=$(sed '1d' $file | grep X)
if [[ -n $checkX ]] ; then echo $seqID >> ${dataset}-res15_Xmut.tmp ; fi
done
done
if [[ -f ${dataset}-res15_Xmut.tmp ]]
then
cat PI_dataset-res15_Xmut.tmp | sort | uniq > PI_dataset-res15_Xmut.log
rm PI_dataset-res15_Xmut.tmp
echo "The following sequences have at least one mutation for any possible amino acid:"
echo
cat ${dataset}-res15_Xmut.log
echo
echo "The IDs are saved in the "${dataset}-res15_Xmut.log" file."
# Separate various X mutations
while read xmut
do
for file in $(ls | grep $xmut)
do
seqcons=PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF
seqX=$(sed '1d' $file | grep X)
seqNX=$(sed '1d' $file | grep -o X | wc -l)
if [[ $seqNX -eq 1 ]]
then
for position in {0..98}
do
resseq=${seqX:$position:1}
rescon=${seqcons:$position:1}
respos=$(expr $position + 1)
## Amino acids
# "A" = "ALA"
# "R" = "ARG"
# "D" = "ASP"
# "N" = "ASN"
# "C" = "CYS"
# "E" = "GLU"
# "Q" = "GLN"
# "G" = "GLY"
# "H" = "HIS"
# "I" = "ILE"
# "L" = "LEU"
# "K" = "LYS"
# "M" = "MET"
# "F" = "PHE"
# "P" = "PRO"
# "S" = "SER"
# "T" = "THR"
# "W" = "TRP"
# "Y" = "TYR"
# "V" = "VAL"
if [[ $resseq == "X" ]]
then
for aa in A R D N C E Q G H I L K M F P S T W Y V
do
echo ">"$xmut > ${file%%.fasta}_${rescon}${respos}${aa}.fasta
sed -r 's/(.{'$position'})(.)/\1'$aa'/' <<< $seqX >> ${file%%.fasta}_${rescon}${respos}${aa}.fasta
done
fi
done
rm $file
echo "All sequences from X mutations available."
fi
done
done < ${dataset}-res15_Xmut.log
fi
# Move FASTA to folder
rundate=$(date "+%Y%m%d")
mkdir -p ${rundate}_${dataset}_res15
mv *.fasta ${rundate}_${dataset}_res15
sed '1d' ${dataset}-res10 | while read sequence
do
seqID=$(awk '{print $1}' <<< $sequence)
echo ">"$seqID > ${seqID}.fasta
checkseqID=$(ls | grep $seqID | wc -l)
seqcons=PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF
# consensus B subtype (https://hivdb.stanford.edu/pages/documentPage/consensus_amino_acid_sequences.html)
for columnno in {10..108}
do
aminoacid=$(awk '{print $'$columnno'}' <<< $sequence)
position=$(expr $columnno - 10)
rescon=${seqcons:$position:1}
respos=$(expr $position + 1)
checkaa=$(wc -m <<< $aminoacid) # in dataset, if there's a mixture the $(wc -m) is ge 3, else is 2
if [[ -n $checkseqID && $checkaa -eq 2 ]]
then
for file in $(ls | grep $seqID)
do
if [[ $aminoacid == '-' ]] ; then printf "%s" $rescon >> $file
elif [[ $aminoacid == '.' || $aminoacid == '~' ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}d.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}d.fasta
else printf "%s" $aminoacid >> $file ; fi
done
elif [[ -n $checkseqID && $checkaa -ge 3 ]]
then
for file in $(ls | grep $seqID)
do
aa=$(expr $checkaa - 2) # discount for (newline + count from zero)
for resmix in $(seq 0 $aa)
do
resaa=${aminoacid:$resmix:1} # keep mixtures with consensus aminoacid, because of further mutations
if [[ -n $(grep '*' <<< $resaa) ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}_STOP.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}_STOP.fasta
elif [[ -n $(grep '#' <<< $resaa) ]] ; then
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
printf "%s" $aminoacid >> ${file%%.fasta}_${rescon}${respos}${aminoacid}.fasta
else
echo ">"$seqID > ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
printf "%s" $(sed '1d' $file) >> ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
printf "%s" $resaa >> ${file%%.fasta}_${rescon}${respos}${resaa}.fasta
fi
done
rm $file
done
fi
done
done
echo "All highly resistant sequences greater than 10 are separated in FASTA files."
# Check for X residue
sed '1d' ${dataset}-res10 | while read sequence
do
seqID=$(awk '{print $1}' <<< $sequence)
for file in $(ls | grep $seqID)
do
checkX=$(sed '1d' $file | grep X)
if [[ -n $checkX ]] ; then echo $seqID >> ${dataset}-res10_Xmut.tmp ; fi
done
done
if [[ -f ${dataset}-res10_Xmut.tmp ]]
then
cat PI_dataset-res10_Xmut.tmp | sort | uniq > PI_dataset-res10_Xmut.log
rm PI_dataset-res10_Xmut.tmp
echo "The following sequences have at least one mutation for any possible amino acid:"
echo
cat ${dataset}-res10_Xmut.log
echo
echo "The IDs are saved in the "${dataset}-res10_Xmut.log" file."
# Separate various X mutations
while read xmut
do
for file in $(ls | grep $xmut)
do
seqcons=PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF
seqX=$(sed '1d' $file | grep X)
seqNX=$(sed '1d' $file | grep -o X | wc -l)
if [[ $seqNX -eq 1 ]]
then
for position in {0..98}
do
resseq=${seqX:$position:1}
rescon=${seqcons:$position:1}
respos=$(expr $position + 1)
## Amino acids
# "A" = "ALA"
# "R" = "ARG"
# "D" = "ASP"
# "N" = "ASN"
# "C" = "CYS"
# "E" = "GLU"
# "Q" = "GLN"
# "G" = "GLY"
# "H" = "HIS"
# "I" = "ILE"
# "L" = "LEU"
# "K" = "LYS"
# "M" = "MET"
# "F" = "PHE"
# "P" = "PRO"
# "S" = "SER"
# "T" = "THR"
# "W" = "TRP"
# "Y" = "TYR"
# "V" = "VAL"
if [[ $resseq == "X" ]]
then
for aa in A R D N C E Q G H I L K M F P S T W Y V
do
echo ">"$xmut > ${file%%.fasta}_${rescon}${respos}${aa}.fasta
sed -r 's/(.{'$position'})(.)/\1'$aa'/' <<< $seqX >> ${file%%.fasta}_${rescon}${respos}${aa}.fasta
done
fi
done
rm $file
echo "All sequences from X mutations available."
fi
done
done < ${dataset}-res10_Xmut.log
fi
# Move FASTA to folder
rundate=$(date "+%Y%m%d")
mkdir -p ${rundate}_${dataset}_res10
mv *.fasta ${rundate}_${dataset}_res10
echo -e "\aIt's finished!"
exit 0