-
Notifications
You must be signed in to change notification settings - Fork 0
/
Metatox.sh
942 lines (764 loc) · 32.2 KB
/
Metatox.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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
#! /usr/bin/bash
#####################
### Help Function ###
#####################
help_msg() {
printf """
===============
|| ||
|| MetaTox ||
|| ||
===============
==================================================
|| ||
|| https://github.com/alexisbourdais/MetaTox/ ||
|| ||
==================================================
####################
### Requirements ###
####################
- Singularity:
sudo apt-get install -y singularity-container
- Conda :
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh
- Some packages :
sudo apt install -y zenity bc gawk dos2unix
- If error when creating metatrans conda environment, run before using MetaTox : conda config --set channel_priority flexible
#####################
### Input file ###
#####################
-> 1st column : Molecule ID/Name
-> 2nd column : SMILES
-> Separator : comma ','
Example:
Nicotine,CN1CCC[C@H]1c2cccnc2
##################
### Usage ###
##################
* With zenity : ./MetaTox.sh
* To skip zenity : ./MetaTox.sh --input input_file
REQUIRED parameter
-i|--input
OPTIONAL parameter
-m|--meta To activate metaTrans and meta-Predictor [No]
-t|--type Type of biotransformation to use with BioTransformer3:
[allHuman] : Predicts all possible metabolites from any applicable reaction(Oxidation, reduction, (de-)conjugation) at each step
ecbased : Prediction of promiscuous metabolism (e.g. glycerolipid metabolism). EC-based metabolism is also called Enzyme Commission based metabolism
cyp450 : CYP450 metabolism prediction
phaseII : Prediction of major conjugative reactions, including glucuronidation, sulfation, glycine transfer, N-acetyl transfer, and glutathione transfer, among others
hgut : Human gut microbial
superbio : Runs a set number of transformation steps in a pre-defined order (e.g. deconjugation first, then Oxidation/reduction, etc.)
envimicro : Environmental microbial
-n|--nstep The number of steps for the prediction by BioTransformer [default=1]
-c|--cmode CYP450 prediction Mode uses by BioTransformer:
1 = CypReact+BioTransformer rules
2 = CyProduct only
[3] = CypReact+BioTransformer rules+CyProducts
-1|--phase1 Number of reaction cycles Phase 1 by SygMa [defaut=1]
-2|--phase2 Number of reaction cycles Phase 2 by SygMa [defaut=1]
-p|--tmp To keep intermediate files [No]
"""
}
while [ $# -gt 0 ] ; do
key="$1"
case $key in
-i|--input)
input="$2"
shift
shift
;;
-t|--type)
type="$2"
shift
shift
;;
-n|--nstep)
nstep="$2"
shift
shift
;;
-c|--cmode)
cmode="$2"
shift
shift
;;
-1|--phase1)
phase1="$2"
shift
shift
;;
-2|--phase2)
phase2="$2"
shift
shift
;;
-m|--meta)
meta_activate=true
shift
;;
-p|--tmp)
keep_tmp=true
shift
;;
*)
help_msg
exit 0
esac
done
#####################
### Progress Tool ###
#####################
bar_size=40
bar_char_done="#"
bar_char_todo="-"
bar_percentage_scale=2
function show_progress {
current="$1"
total="$2"
# calculate the progress in percentage
percent=$(bc <<< "scale=$bar_percentage_scale; 100 * $current / $total" )
# The number of done and todo characters
done=$(bc <<< "scale=0; $bar_size * $percent / 100" )
todo=$(bc <<< "scale=0; $bar_size - $done" )
# build the done and todo sub-bars
done_sub_bar=$(printf "%${done}s" | tr " " "${bar_char_done}")
todo_sub_bar=$(printf "%${todo}s" | tr " " "${bar_char_todo}")
# output the bar
echo -ne "\rProgress : [${done_sub_bar}${todo_sub_bar}] ${percent}%"
if [ $total -eq $current ]; then
echo -e "\nDONE"
fi
}
############################
### Index Function ###
############################
function get_index() {
for i in "${!smiles_tab[@]}"; do
if [[ "${smiles_tab[$i]}" = "${1}" ]]; then
echo "${i}";
fi
done
}
######################
### Work Directory ###
######################
work_dir="${PWD}"
DirOutput="${work_dir}/Results_Prediction/"
mkdir $DirOutput
tmp="${work_dir}/tmp/"
if test -d $tmp; then
rm -r $tmp
fi
mkdir $tmp
#For download version of biotransformer3
#DirBiotrans="${work_dir}/biotransformer3.0jar/"
DirMetatrans="${work_dir}/MetaTrans/"
DirMetapred="${work_dir}/Meta-Predictor/"
DirCondaEnv="${work_dir}/CondaEnv/"
DirScripts="${work_dir}/Scripts/"
Script_Smiles2Smart="${DirScripts}smilestosmart.py"
Script_Smart2Smiles="${DirScripts}smarttosmiles.py"
Script_SdftoSmi="${DirScripts}sdftosmi.py"
Script_SmitoStr="${DirScripts}smitostr.py"
Script_FormulaFromSmiles="${DirScripts}formulafromsmiles.py"
Script_massFromFormula="${DirScripts}massFromFormula.py"
##############
### Zenity ###
##############
if [ -z $input ]; then
zenity --info --text "
In silico prediction by :
- Bio-transformer3
- Sygma
- MetaTrans
- Meta-Predictor
https://github.com/alexisbourdais/MetaTox/
"
input=$(zenity --file-selection --title="Select input file with each line = molecule,smiles")
option_meta=$(zenity --forms --title="MetaTrans options" --text="Directly Validate to apply default values" --add-entry="Min length (SMILES) [defaut=5]" --add-entry="Max length (SMILES) [defaut=120]" --add-entry="Top results [defaut=5 : top 10]" --separator=",")
min=$(echo "$option_meta" | cut -d "," -f1)
max=$(echo "$option_meta" | cut -d "," -f2)
beam=$(echo "$option_meta" | cut -d "," -f3)
option_sygma=$(zenity --forms --title="Sygma options" --text="Directly Validate to apply default values" --add-entry="Number of reaction cycles Phase 1 [defaut=1]" --add-entry="Number of reaction cycles Phase 2 [defaut=1]" --separator=",")
phase1=$(echo "$option_sygma" | cut -d "," -f1)
phase2=$(echo "$option_sygma" | cut -d "," -f2)
type=$(zenity --list --title="Biotransformer 3 model" --text="Choose the type of biotransformation to use with Biotransformer3" --column="Type" --column="Description" \
allHuman "Predicts all possible metabolites from any applicable reaction(Oxidation, reduction, (de-)conjugation) at each step" ecbased "Prediction of promiscuous metabolism (e.g. glycerolipid metabolism). EC-based metabolism is also called Enzyme Commission based metabolism" cyp450 "CYP450 metabolism prediction" phaseII "Prediction of major conjugative reactions, including glucuronidation, sulfation, glycine transfer, N-acetyl transfer, and glutathione transfer, among others" hgut "Human gut microbial" superbio "Runs a set number of transformation steps in a pre-defined order (e.g. deconjugation first, then Oxidation/reduction, etc.)" envimicro "Environmental microbial" )
option_biotrans=$(zenity --forms --title="Biotransformer options" --text="Directly Validate to apply default values" --add-entry="The number of steps for the prediction [default=1]" --add-entry="CYP450 prediction Mode: 1=CypReact+BioTransformer rules; 2=CyProduct only; 3=CypReact+BioTransformer rules+CyProducts [Default=3]" --separator=",")
nstep=$(echo "$option_biotrans" | cut -d "," -f1)
cmode=$(echo "$option_biotrans" | cut -d "," -f2)
zenity --question --title="Meta-Predictor Activation" --text="Do you want to activate MetaTrans and Meta-Predictor ?"
metapred_activate_answer=$?
if [ $metapred_activate_answer -eq 0 ]; then
meta_activate=true
else [ $metapred_activate_answer -eq 1 ]
meta_activate=false
fi
fi
########################
### Defaults Options ###
########################
##### Bio-Transformer options
###Default Mode
if [ -z $type ]; then
type="allHuman"
fi
###Default nsteps
if [ -z $nstep ] || [[ ! $nstep = +([0-9]) ]]; then
nstep="1"
fi
###Default cmode
if [ -z $cmode ] || [[ ! $cmode = +([0-3]) ]]; then
cmode="3"
fi
##### Meta-Trans options
###Default Beam
if [ -z $BEAM ] || [[ ! $BEAM = +([0-9]) ]]; then
BEAM=5
fi
###Default min
if [ -z $MIN ] || [[ ! $MIN = +([0-9]) ]]; then
MIN=5
fi
###Default Max
if [ -z $MAX ] || [[ ! $MAX = +([0-9]) ]]; then
MAX=120
fi
##### Sygma options
###Default phase1
if [ -z $phase1 ] || [[ ! $phase1 = +([0-9]) ]]; then
phase1=1
fi
###Default phase2
if [ -z $phase2 ] || [[ ! $phase2 = +([0-9]) ]]; then
phase2=1
fi
##### Meta-Predictor option
###Activation
if [ -z $meta_activate ]; then
meta_activate=false
fi
###Keep intermediate files
if [ -z $keep_tmp ]; then
keep_tmp=false
fi
echo "
===============
|| ||
|| MetaTox ||
|| ||
===============
==================================================
|| ||
|| https://github.com/alexisbourdais/MetaTox/ ||
|| ||
==================================================
- BioTransformer bio-reaction : $type
- BioTransformer cycle number : $nstep
- Biotransformer CYP450 prediction Mode : $cmode
- SygMa Phase 1 cycle number : $phase1
- SygMa Phase 2 cycle number : $phase2
- MetaTrans & Meta-Predictor activation : $meta_activate
"
#########################
### Environment conda ###
#########################
eval "$(conda shell.bash hook)"
#conda init --all
if conda info --envs | grep -q rdkit; then
echo "Conda environment "rdkit" already exists"
else
conda env create --name rdkit --file ${DirCondaEnv}rdkit_environment.yml
fi
if $meta_activate; then
if conda info --envs | grep -q metapredictor; then
echo "Conda environment "metapredictor" already exists"
else
conda env create --name metapredictor --file ${DirCondaEnv}metapred_environment.yml
fi
if conda info --envs | grep -q metatrans; then
echo "Conda environment "metatrans" already exists"
else
conda env create --name metatrans --file ${DirCondaEnv}metatrans_environment.yml
fi
fi
###############
### Input ###
###############
file $input | grep CRLF && dos2unix $input
declare -a tab_molecule
declare -a tab_smiles
while read a
do
Molecule=$(echo $a | cut -d\, -f1)
Smiles=$(echo $a | cut -d\, -f2)
tab_smiles[${#tab_smiles[@]}]=${Smiles}
tab_molecule[${#tab_molecule[@]}]=${Molecule}
done < $input
path_input="$(realpath ${input})"
if ${meta_activate}; then
##################
### META-TRANS ###
##################
conda activate metatrans
cd $DirMetatrans
#Variables from MetaTrans
outfile=processed_data.txt
results=Prediction_MetaTrans.csv
images=./Figures/*
STORE=predictions/ #directory for output process
mkdir $STORE
### Step 1 : Prepare data
echo "
==================================================
|| ||
|| Process of MetaTrans step 1 : Prepara data ||
|| ||
==================================================
"
python prepare_input_file.py -input_file "${path_input}" -output_file ${outfile}
### Step 2 : Translate
echo "
==================================================
|| ||
|| Process of MetaTrans step 2 : Translate ||
|| ||
==================================================
"
for model_id in {1,2,3,4,5,6}
do
MODEL_FILE='models/model_'$model_id'.pt'
OUT_NAME='model'$model_id'_beam'$BEAM'.txt'
OUT_FILE=$STORE$OUT_NAME
python translate.py -model $MODEL_FILE -src $outfile -output $OUT_FILE -n_best $BEAM -beam_size $BEAM -verbose -min_length $MIN -max_length $MAX 2>&1 | tee -a "${tmp}MetaTrans_log.txt"
done
### Step 3 : Get predictions
echo "
========================================================
|| ||
|| Process of MetaTrans step 3 : Get prediction ||
|| ||
========================================================
"
python process_predictions.py \
-input_file "${path_input}" \
-output_file ${results} \
-beam_size ${BEAM} \
-visualise_molecules True
conda deactivate
#Moving results files and deleting intermediate files
rm -r ${outfile} ${STORE} ${images}
mv ${results} ${tmp}
cd ${tmp}
#Separation of results into separate files for each molecule
pat='^Molecule'
while read a
do
if [[ $a =~ $pat ]]; then
:
else
MoleculeID=$(echo $a | cut -d\, -f1)
#SmileParent=$(echo $a | cut -d\, -f2)
SmileMetabo=$(echo $a | cut -d\, -f3)
read -ra tab_metabo <<< "$SmileMetabo"
#n_metabo=0
for i in ${tab_metabo[@]}; do
#((n_metabo+=1))
echo "${i}" >> "${MoleculeID}_Metatrans.csv"
done
fi
done < "Prediction_MetaTrans.csv"
######################
### META-PREDICTOR ###
######################
echo "
=================================
|| ||
|| Process of MetaPredictor ||
|| ||
=================================
"
conda activate metapredictor
cd ${DirMetapred}
python prepare_input_file.py -input_file ${path_input} -output_file processed_data.txt
bash predict-top15.sh processed_data.txt ./prediction ${path_input} 2>&1 | tee -a "${tmp}Metapredictor_log"
conda deactivate
### Mv results and remove temp files
mv prediction/predict.csv ${tmp}Prediction_metapred.csv
rm -r prediction/* Figures/* processed_data.txt
#Separation of results into separate files for each molecule
cd ${tmp}
pat='^Name'
while read a
do
if [[ $a =~ $pat ]]; then
:
else
MoleculeID=$(echo $a | cut -d\, -f1)
#SmileParent=$(echo $a | cut -d\, -f2)
SmileMetabo=$(echo $a | cut -d\, -f3)
read -ra tab_metabo <<< "$SmileMetabo"
#n_metabo=0
for i in ${tab_metabo[@]}; do
#((n_metabo+=1))
echo "${i}" >> "${MoleculeID}_metapred.csv"
done
fi
done < "Prediction_metapred.csv"
fi
for indice in ${!tab_molecule[@]}
do
results_file="${DirOutput}${tab_molecule[${indice}]}_CompileResults.tsv"
# Reset table
smiles_tab=()
formuleBrute_tab=()
mass_tab=()
biotrans_tab=()
biotrans_score_tab=()
biotrans_pathway_tab=()
biotrans_enzyme_tab=()
biotrans_system_tab=()
biotrans_precursor_formule_tab=()
biotrans_precursor_smile_tab=()
sygma_pathway_tab=()
sygma_score_tab=()
sygma_tab=()
metapred_tab=()
metatrans_tab=()
#########################
### BIOTRANSFORMERS 3 ###
#########################
echo "
===============================================================================================================
||
|| Process of ${tab_molecule[${indice}]} : ${tab_smiles[${indice}]} by Biotransformer3
||
===============================================================================================================
"
#Download version
#java -jar BioTransformer3.0_20230525.jar -b ${type} -k pred -cm 3 -ismi "${smile}" -ocsv "${DirOutput}${molecule}_Biotransformer3.csv"
#Singularity version
singularity exec https://depot.galaxyproject.org/singularity/biotransformer%3A3.0.20230403--hdfd78af_0 biotransformer \
-b "${type}" \
-k "pred" \
-cm 3 \
-s "${nstep}" \
-ismi "${tab_smiles[${indice}]}" \
-ocsv "${tmp}${tab_molecule[${indice}]}_Biotransformer3.csv" 2>&1 | tee -a "${tmp}${tab_molecule[${indice}]}_Biotransformer3_log.txt"
#Changement csv format
csvformat -D ";" "${tmp}${tab_molecule[${indice}]}_Biotransformer3.csv" | gawk -v RS='"' 'NR % 2 == 0 { gsub(/\n/, "") } { printf("%s%s", $0, RT) }' > "${tmp}${tab_molecule[${indice}]}_Biotransformer3_brut.csv"
echo "
===================================================
|| ||
|| BioTransformer Results processing step 1/2 ||
|| ||
===================================================
"
#Keep informative column
pat_bioTrans="^InChI;InChIKey*"
tasks_in_total=$( nl "${tmp}${tab_molecule[${indice}]}_Biotransformer3_brut.csv" | wc -l )
current_task=0
while read line
do
((current_task+=1))
show_progress $current_task $tasks_in_total
if [[ $line =~ $pat_bioTrans ]]; then
:
else
info=$(echo $line | cut -d\; -f3,6,8,14,16,17,19)
echo "${info}" >> ${tmp}${tab_molecule[${indice}]}_Biotransformer3_brut2.csv
fi
done < "${tmp}${tab_molecule[${indice}]}_Biotransformer3_brut.csv"
echo "
===================================================
|| ||
|| BioTransformer Results processing step 2/2 ||
|| ||
===================================================
"
conda activate rdkit
tasks_in_total=$( nl "${tmp}${tab_molecule[${indice}]}_Biotransformer3_brut2.csv" | wc -l )
current_task=0
while read line
do
((current_task+=1))
show_progress $current_task $tasks_in_total
smiles=$(echo "$line" | cut -d';' -f1)
smart=$(python3 $Script_Smiles2Smart $smiles)
new_smiles=$(python3 $Script_Smart2Smiles $smart)
formulebrute=$(python3 $Script_FormulaFromSmiles $new_smiles)
#formulebrute=$(echo "$line" | cut -d',' -f2) Not use to keep same format between tools
score=$(echo "$line" | cut -d';' -f3)
pathway=$(echo "$line" | cut -d';' -f4)
enzyme=$(echo "$line" | cut -d';' -f5)
system=$(echo "$line" | cut -d';' -f6)
smiles_precursor=$(echo "$line" | cut -d';' -f7)
smart_precursor=$(python3 $Script_Smiles2Smart $smiles_precursor)
new_smiles_precursor=$(python3 $Script_Smart2Smiles $smart_precursor)
#if smiles already presents
if [[ $(echo ${smiles_tab[@]} | fgrep -w $new_smiles) ]]; then
index=$(get_index $new_smiles)
biotrans_tab["${index}"]="+"
biotrans_score_tab["${index}"]=${score}
biotrans_pathway_tab["${index}"]=${pathway}
biotrans_enzyme_tab["${index}"]=${enzyme}
biotrans_system_tab["${index}"]=${system}
biotrans_precursor_smile_tab["${index}"]=${new_smiles_precursor}
biotrans_precursor_formule_tab["${index}"]=$(python3 $Script_FormulaFromSmiles $new_smiles_precursor)
#if smiles not present
else
smiles_tab[${#smiles_tab[@]}]=${new_smiles}
formuleBrute_tab[${#formuleBrute_tab[@]}]=${formulebrute}
mass_tab[${#mass_tab[@]}]=$(python3 $Script_massFromFormula $formulebrute)
index=$(get_index $new_smiles)
biotrans_tab["${index}"]="+"
biotrans_score_tab["${index}"]=${score}
biotrans_pathway_tab["${index}"]=${pathway}
biotrans_enzyme_tab["${index}"]=${enzyme}
biotrans_system_tab["${index}"]=${system}
biotrans_precursor_smile_tab["${index}"]=${new_smiles_precursor}
biotrans_precursor_formule_tab["${index}"]=$(python3 $Script_FormulaFromSmiles $new_smiles_precursor)
fi
done < "${tmp}${tab_molecule[${indice}]}_Biotransformer3_brut2.csv"
##################
### SygMa ###
##################
echo "
=========================================================================================================
||
|| Process of ${tab_molecule[${indice}]} : ${tab_smiles[${indice}]} by Sygma
||
=========================================================================================================
"
pat_pathway="^> <Pathway>"
pat_score="^> <Score>"
singularity run docker://3dechem/sygma ${tab_smiles[${indice}]} -1 $phase1 -2 $phase2 >> "${tmp}${tab_molecule[${indice}]}_Sygma.sdf"
###Converting the sdf into smiles
python3 ${Script_SdftoSmi} ${tmp}${tab_molecule[${indice}]}_Sygma.sdf
mv ${PWD}/smiles.txt ${tmp}Prediction_sygma_${tab_molecule[${indice}]}_smiles.txt
echo "
==========================================
|| ||
|| SygMa Results processing step 1/2 ||
|| ||
==========================================
"
tasks_in_total=$( nl "${tmp}${tab_molecule[${indice}]}_Sygma.sdf" | wc -l )
current_task=0
#Adding scores & pathways from the sdf file to the txt file
while read line
do
((current_task+=1))
show_progress $current_task $tasks_in_total
if [[ $line_pre == "pathway" ]]; then
echo $line | sed 's/,/;/g' >> "${tmp}Prediction_sygma_${tab_molecule[${indice}]}_Path.txt"
line_pre=""
fi
if [[ $line_pre == "score" ]]; then
echo $line >> "${tmp}Prediction_sygma_${tab_molecule[${indice}]}_Score.txt"
line_pre=""
fi
if [[ $line =~ $pat_pathway ]]; then
line_pre=pathway
fi
if [[ $line =~ $pat_score ]]; then
line_pre=score
fi
done < "${tmp}${tab_molecule[${indice}]}_Sygma.sdf"
paste -d ',' ${tmp}Prediction_sygma_${tab_molecule[${indice}]}_smiles.txt ${tmp}Prediction_sygma_${tab_molecule[${indice}]}_Path.txt ${tmp}Prediction_sygma_${tab_molecule[${indice}]}_Score.txt > ${tmp}${tab_molecule[${indice}]}_Sygma_SmilesPathScore.txt
echo "
==========================================
|| ||
|| SygMa Results processing step 2/2 ||
|| ||
==========================================
"
tasks_in_total=$( nl "${tmp}${tab_molecule[${indice}]}_Sygma_SmilesPathScore.txt" | wc -l )
current_task=0
pat_parent="^Molecule1"
while read -r line
do
((current_task+=1))
show_progress $current_task $tasks_in_total
if [[ $line =~ $pat_parent ]]; then
:
else
smiles=$(echo "$line" | cut -d',' -f2)
pathway=$(echo "$line" | cut -d',' -f3)
score=$(echo "$line" | cut -d',' -f4)
smart=$(python3 $Script_Smiles2Smart $smiles)
new_smiles=$(python3 $Script_Smart2Smiles $smart)
#if smiles already presents
if [[ $(echo ${smiles_tab[@]} | fgrep -w $new_smiles) ]]; then
index=$(get_index $new_smiles)
sygma_pathway_tab["${index}"]=${pathway}
sygma_score_tab["${index}"]=${score}
sygma_tab["${index}"]="+"
#if smiles not present
else
smiles_tab[${#smiles_tab[@]}]=${new_smiles}
formulebrute=$(python3 $Script_FormulaFromSmiles $new_smiles)
if [ -z "${formulebrute}" ]; then
formulebrute="NA"
formuleBrute_tab["${#formuleBrute_tab[@]}"]="${formulebrute}"
mass_tab["${#mass_tab[@]}"]="NA"
else
formuleBrute_tab[${#formuleBrute_tab[@]}]="${formulebrute}"
mass_tab[${#mass_tab[@]}]="$(python3 $Script_massFromFormula $formulebrute)"
fi
index=$(get_index $new_smiles)
sygma_pathway_tab["${index}"]=${pathway}
sygma_score_tab["${index}"]=${score}
sygma_tab["${index}"]="+"
fi
fi
done < "${tmp}${tab_molecule[${indice}]}_Sygma_SmilesPathScore.txt"
if ${meta_activate}; then
#################
### MetaTrans ###
#################
echo "
==============================================
|| ||
|| MetaTrans Results processing step 1/1 ||
|| ||
==============================================
"
tasks_in_total=$( nl "${tmp}${tab_molecule[${indice}]}_Metatrans.csv" | wc -l )
current_task=0
while read -r line
do
((current_task+=1))
show_progress $current_task $tasks_in_total
smiles=$(echo "$line" | cut -d',' -f1)
smart=$(python3 $Script_Smiles2Smart $smiles)
new_smiles=$(python3 $Script_Smart2Smiles $smart)
#if smiles already presents
if [[ $(echo ${smiles_tab[@]} | fgrep -w $new_smiles) ]]; then
index=$(get_index $new_smiles)
metatrans_tab[${index}]="+"
#if smiles not present
else
smiles_tab[${#smiles_tab[@]}]=${new_smiles}
formulebrute=$(python3 $Script_FormulaFromSmiles $new_smiles)
if [ -z "${formulebrute}" ]; then
formulebrute="NA"
formuleBrute_tab["${#formuleBrute_tab[@]}"]="${formulebrute}"
mass_tab["${#mass_tab[@]}"]="NA"
else
formuleBrute_tab[${#formuleBrute_tab[@]}]="${formulebrute}"
mass_tab[${#mass_tab[@]}]="$(python3 $Script_massFromFormula $formulebrute)"
fi
index=$(get_index $new_smiles)
metatrans_tab[${index}]="+"
fi
done < "${tmp}${tab_molecule[${indice}]}_Metatrans.csv"
######################
### Meta-Predictor ###
######################
echo "
=====================================================
|| ||
|| Meta-Predictor Results processing step 1/1 ||
|| ||
=====================================================
"
tasks_in_total=$( nl "${tmp}${tab_molecule[${indice}]}_metapred.csv" | wc -l )
current_task=0
while read -r line
do
((current_task+=1))
show_progress $current_task $tasks_in_total
smiles=$(echo "$line" | cut -d',' -f2)
smart=$(python3 $Script_Smiles2Smart $smiles)
new_smiles=$(python3 $Script_Smart2Smiles $smart)
#if smiles already presents
if [[ $(echo ${smiles_tab[@]} | fgrep -w $new_smiles) ]]; then
index=$(get_index $new_smiles)
metapred_tab[${index}]="+"
#if smiles not present
else
smiles_tab[${#smiles_tab[@]}]=${new_smiles}
formulebrute=$(python3 $Script_FormulaFromSmiles $new_smiles)
if [ -z "${formulebrute}" ]; then
formulebrute="NA"
formuleBrute_tab["${#formuleBrute_tab[@]}"]="${formulebrute}"
mass_tab["${#mass_tab[@]}"]="NA"
else
formuleBrute_tab[${#formuleBrute_tab[@]}]="${formulebrute}"
mass_tab[${#mass_tab[@]}]="$(python3 $Script_massFromFormula $formulebrute)"
fi
index=$(get_index $new_smiles)
metapred_tab[${index}]="+"
fi
done < "${tmp}${tab_molecule[${indice}]}_metapred.csv"
fi
###################
### Compilation ###
###################
echo "
=================================
|| ||
|| Results Compilation ||
|| ||
=================================
"
# Entete
echo -e "FormuleBrute\tMasse(+H)\tSmiles\tSygma\tBioTransformer3\tMetaTrans\tMetaPredictor\tSygma_pathway\tBioTrans_pathway\tSygma_score\tBioTrans_score\tBioTrans_precursor\tBioTrans_precursor\tBioTrans_enzyme\tBioTrans_system\tFigure" > ${results_file}
#Progress tool
tasks_in_total=$( echo ${#smiles_tab[@]} )
current_task=0
nbmolecule=0
for indice2 in ${!smiles_tab[@]}
do
((current_task+=1))
show_progress $current_task $tasks_in_total
smiles="${smiles_tab[${indice2}]}"
formulebrute="${formuleBrute_tab[${indice2}]}"
masse="${mass_tab[${indice2}]}"
sygma="${sygma_tab[${indice2}]}"
score="${sygma_score_tab[${indice2}]}"
pathway="${sygma_pathway_tab[${indice2}]}"
metapred="${metapred_tab[${indice2}]}"
metatrans="${metatrans_tab[${indice2}]}"
biotrans="${biotrans_tab[${indice2}]}"
biotrans_pathway="${biotrans_pathway_tab[${indice2}]}"
biotrans_enzyme="${biotrans_enzyme_tab[${indice2}]}"
biotrans_system="${biotrans_system_tab[${indice2}]}"
biotrans_score="${biotrans_score_tab[${indice2}]}"
biotrans_precur_for="${biotrans_precursor_formule_tab[${indice2}]}"
biotrans_precur_smiles="${biotrans_precursor_smile_tab[${indice2}]}"
if [ "${formulebrute}" == "NA" ]; then
figure="NA"
echo -e "${formulebrute}\t${masse}\t${smiles}\t${sygma}\t${biotrans}\t${metatrans}\t${metapred}\t${pathway}\t${biotrans_pathway}\t${score}\t${biotrans_score}\t${biotrans_precur_for}\t${biotrans_precur_smiles}\t${biotrans_enzyme}\t${biotrans_system}\t${figure}" >> ${results_file}
else
((nbmolecule+=1))
figure="Figure_${nbmolecule}"
echo -e "${formulebrute}\t${masse}\t${smiles}\t${sygma}\t${biotrans}\t${metatrans}\t${metapred}\t${pathway}\t${biotrans_pathway}\t${score}\t${biotrans_score}\t${biotrans_precur_for}\t${biotrans_precur_smiles}\t${biotrans_enzyme}\t${biotrans_system}\t${figure}" >> ${results_file}
echo -e "Molecule${nbmolecule},${smiles}" >> "${tmp}${tab_molecule[${indice}]}_ListeSmile.txt"
fi
done
###Structure construction
echo "
=================================
|| ||
|| Structures creation ||
|| ||
=================================
"
python3 $Script_SmitoStr -i "${tmp}${tab_molecule[${indice}]}_ListeSmile.txt"
mkdir "${DirOutput}${tab_molecule[${indice}]}_figures"
mv Molecule*.jpeg "${DirOutput}${tab_molecule[${indice}]}_figures"
done
if ${keep_tmp}; then
:
else
rm -r $tmp
fi
echo "
Recording results in : ${DirOutput}
Execution completed !
"