-
Notifications
You must be signed in to change notification settings - Fork 0
/
pybiomed_helper.py
3391 lines (3228 loc) · 97.7 KB
/
pybiomed_helper.py
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
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# this helper script is from PyBioMed to get protein descriptors.
# there are incompatibility issues to use the entire library, so I copied and pasted here the src.
# https://pybiomed.readthedocs.io/en/latest/
import math
import string
import re
# import scipy
AALetter = [
"A",
"R",
"N",
"D",
"C",
"E",
"Q",
"G",
"H",
"I",
"L",
"K",
"M",
"F",
"P",
"S",
"T",
"W",
"Y",
"V",
]
_Hydrophobicity = {
"A": 0.62,
"R": -2.53,
"N": -0.78,
"D": -0.90,
"C": 0.29,
"Q": -0.85,
"E": -0.74,
"G": 0.48,
"H": -0.40,
"I": 1.38,
"L": 1.06,
"K": -1.50,
"M": 0.64,
"F": 1.19,
"P": 0.12,
"S": -0.18,
"T": -0.05,
"W": 0.81,
"Y": 0.26,
"V": 1.08,
}
_hydrophilicity = {
"A": -0.5,
"R": 3.0,
"N": 0.2,
"D": 3.0,
"C": -1.0,
"Q": 0.2,
"E": 3.0,
"G": 0.0,
"H": -0.5,
"I": -1.8,
"L": -1.8,
"K": 3.0,
"M": -1.3,
"F": -2.5,
"P": 0.0,
"S": 0.3,
"T": -0.4,
"W": -3.4,
"Y": -2.3,
"V": -1.5,
}
_residuemass = {
"A": 15.0,
"R": 101.0,
"N": 58.0,
"D": 59.0,
"C": 47.0,
"Q": 72.0,
"E": 73.0,
"G": 1.000,
"H": 82.0,
"I": 57.0,
"L": 57.0,
"K": 73.0,
"M": 75.0,
"F": 91.0,
"P": 42.0,
"S": 31.0,
"T": 45.0,
"W": 130.0,
"Y": 107.0,
"V": 43.0,
}
_pK1 = {
"A": 2.35,
"C": 1.71,
"D": 1.88,
"E": 2.19,
"F": 2.58,
"G": 2.34,
"H": 1.78,
"I": 2.32,
"K": 2.20,
"L": 2.36,
"M": 2.28,
"N": 2.18,
"P": 1.99,
"Q": 2.17,
"R": 2.18,
"S": 2.21,
"T": 2.15,
"V": 2.29,
"W": 2.38,
"Y": 2.20,
}
_pK2 = {
"A": 9.87,
"C": 10.78,
"D": 9.60,
"E": 9.67,
"F": 9.24,
"G": 9.60,
"H": 8.97,
"I": 9.76,
"K": 8.90,
"L": 9.60,
"M": 9.21,
"N": 9.09,
"P": 10.6,
"Q": 9.13,
"R": 9.09,
"S": 9.15,
"T": 9.12,
"V": 9.74,
"W": 9.39,
"Y": 9.11,
}
_pI = {
"A": 6.11,
"C": 5.02,
"D": 2.98,
"E": 3.08,
"F": 5.91,
"G": 6.06,
"H": 7.64,
"I": 6.04,
"K": 9.47,
"L": 6.04,
"M": 5.74,
"N": 10.76,
"P": 6.30,
"Q": 5.65,
"R": 10.76,
"S": 5.68,
"T": 5.60,
"V": 6.02,
"W": 5.88,
"Y": 5.63,
}
#############################################################################################
def _mean(listvalue):
"""
########################################################################################
The mean value of the list data.
Usage:
result=_mean(listvalue)
########################################################################################
"""
return sum(listvalue) / len(listvalue)
##############################################################################################
def _std(listvalue, ddof=1):
"""
########################################################################################
The standard deviation of the list data.
Usage:
result=_std(listvalue)
########################################################################################
"""
mean = _mean(listvalue)
temp = [math.pow(i - mean, 2) for i in listvalue]
res = math.sqrt(sum(temp) / (len(listvalue) - ddof))
return res
##############################################################################################
def NormalizeEachAAP(AAP):
"""
########################################################################################
All of the amino acid indices are centralized and
standardized before the calculation.
Usage:
result=NormalizeEachAAP(AAP)
Input: AAP is a dict form containing the properties of 20 amino acids.
Output: result is the a dict form containing the normalized properties
of 20 amino acids.
########################################################################################
"""
if len(AAP.values()) != 20:
print("You can not input the correct number of properities of Amino acids!")
else:
Result = {}
for i, j in AAP.items():
Result[i] = (j - _mean(AAP.values())) / _std(AAP.values(), ddof=0)
return Result
#############################################################################################
#############################################################################################
##################################Type I descriptors#########################################
####################### Pseudo-Amino Acid Composition descriptors############################
#############################################################################################
#############################################################################################
def _GetCorrelationFunction(
Ri="S", Rj="D", AAP=[_Hydrophobicity, _hydrophilicity, _residuemass]
):
"""
########################################################################################
Computing the correlation between two given amino acids using the above three
properties.
Usage:
result=_GetCorrelationFunction(Ri,Rj)
Input: Ri and Rj are the amino acids, respectively.
Output: result is the correlation value between two amino acids.
########################################################################################
"""
Hydrophobicity = NormalizeEachAAP(AAP[0])
hydrophilicity = NormalizeEachAAP(AAP[1])
residuemass = NormalizeEachAAP(AAP[2])
theta1 = math.pow(Hydrophobicity[Ri] - Hydrophobicity[Rj], 2)
theta2 = math.pow(hydrophilicity[Ri] - hydrophilicity[Rj], 2)
theta3 = math.pow(residuemass[Ri] - residuemass[Rj], 2)
theta = round((theta1 + theta2 + theta3) / 3.0, 3)
return theta
#############################################################################################
def _GetSequenceOrderCorrelationFactor(ProteinSequence, k=1):
"""
########################################################################################
Computing the Sequence order correlation factor with gap equal to k based on
[_Hydrophobicity,_hydrophilicity,_residuemass].
Usage:
result=_GetSequenceOrderCorrelationFactor(protein,k)
Input: protein is a pure protein sequence.
k is the gap.
Output: result is the correlation factor value with the gap equal to k.
########################################################################################
"""
LengthSequence = len(ProteinSequence)
res = []
for i in range(LengthSequence - k):
AA1 = ProteinSequence[i]
AA2 = ProteinSequence[i + k]
res.append(_GetCorrelationFunction(AA1, AA2))
result = round(sum(res) / (LengthSequence - k), 3)
return result
#############################################################################################
def GetAAComposition(ProteinSequence):
"""
########################################################################################
Calculate the composition of Amino acids
for a given protein sequence.
Usage:
result=CalculateAAComposition(protein)
Input: protein is a pure protein sequence.
Output: result is a dict form containing the composition of
20 amino acids.
########################################################################################
"""
LengthSequence = len(ProteinSequence)
Result = {}
for i in AALetter:
Result[i] = round(float(ProteinSequence.count(i)) / LengthSequence * 100, 3)
return Result
#############################################################################################
def _GetPseudoAAC1(ProteinSequence, lamda=10, weight=0.05):
"""
#######################################################################################
Computing the first 20 of type I pseudo-amino acid compostion descriptors based on
[_Hydrophobicity,_hydrophilicity,_residuemass].
########################################################################################
"""
rightpart = 0.0
for i in range(lamda):
rightpart = rightpart + _GetSequenceOrderCorrelationFactor(
ProteinSequence, k=i + 1
)
AAC = GetAAComposition(ProteinSequence)
result = {}
temp = 1 + weight * rightpart
for index, i in enumerate(AALetter):
result["PAAC" + str(index + 1)] = round(AAC[i] / temp, 3)
return result
#############################################################################################
def _GetPseudoAAC2(ProteinSequence, lamda=10, weight=0.05):
"""
########################################################################################
Computing the last lamda of type I pseudo-amino acid compostion descriptors based on
[_Hydrophobicity,_hydrophilicity,_residuemass].
########################################################################################
"""
rightpart = []
for i in range(lamda):
rightpart.append(_GetSequenceOrderCorrelationFactor(ProteinSequence, k=i + 1))
result = {}
temp = 1 + weight * sum(rightpart)
for index in range(20, 20 + lamda):
result["PAAC" + str(index + 1)] = round(
weight * rightpart[index - 20] / temp * 100, 3
)
return result
#############################################################################################
def _GetPseudoAAC(ProteinSequence, lamda=10, weight=0.05):
"""
#######################################################################################
Computing all of type I pseudo-amino acid compostion descriptors based on three given
properties. Note that the number of PAAC strongly depends on the lamda value. if lamda
= 20, we can obtain 20+20=40 PAAC descriptors. The size of these values depends on the
choice of lamda and weight simultaneously.
AAP=[_Hydrophobicity,_hydrophilicity,_residuemass]
Usage:
result=_GetAPseudoAAC(protein,lamda,weight)
Input: protein is a pure protein sequence.
lamda factor reflects the rank of correlation and is a non-Negative integer, such as 15.
Note that (1)lamda should NOT be larger than the length of input protein sequence;
(2) lamda must be non-Negative integer, such as 0, 1, 2, ...; (3) when lamda =0, the
output of PseAA server is the 20-D amino acid composition.
weight factor is designed for the users to put weight on the additional PseAA components
with respect to the conventional AA components. The user can select any value within the
region from 0.05 to 0.7 for the weight factor.
Output: result is a dict form containing calculated 20+lamda PAAC descriptors.
########################################################################################
"""
res = {}
res.update(_GetPseudoAAC1(ProteinSequence, lamda=lamda, weight=weight))
res.update(_GetPseudoAAC2(ProteinSequence, lamda=lamda, weight=weight))
return np.array(list(res.values()))
#############################################################################################
##################################Type II descriptors########################################
###############Amphiphilic Pseudo-Amino Acid Composition descriptors#########################
#############################################################################################
#############################################################################################
def _GetCorrelationFunctionForAPAAC(
Ri="S", Rj="D", AAP=[_Hydrophobicity, _hydrophilicity]
):
"""
########################################################################################
Computing the correlation between two given amino acids using the above two
properties for APAAC (type II PseAAC).
Usage:
result=_GetCorrelationFunctionForAPAAC(Ri,Rj)
Input: Ri and Rj are the amino acids, respectively.
Output: result is the correlation value between two amino acids.
########################################################################################
"""
Hydrophobicity = NormalizeEachAAP(AAP[0])
hydrophilicity = NormalizeEachAAP(AAP[1])
theta1 = round(Hydrophobicity[Ri] * Hydrophobicity[Rj], 3)
theta2 = round(hydrophilicity[Ri] * hydrophilicity[Rj], 3)
return theta1, theta2
#############################################################################################
def GetSequenceOrderCorrelationFactorForAPAAC(ProteinSequence, k=1):
"""
########################################################################################
Computing the Sequence order correlation factor with gap equal to k based on
[_Hydrophobicity,_hydrophilicity] for APAAC (type II PseAAC) .
Usage:
result=GetSequenceOrderCorrelationFactorForAPAAC(protein,k)
Input: protein is a pure protein sequence.
k is the gap.
Output: result is the correlation factor value with the gap equal to k.
########################################################################################
"""
LengthSequence = len(ProteinSequence)
resHydrophobicity = []
reshydrophilicity = []
for i in range(LengthSequence - k):
AA1 = ProteinSequence[i]
AA2 = ProteinSequence[i + k]
temp = _GetCorrelationFunctionForAPAAC(AA1, AA2)
resHydrophobicity.append(temp[0])
reshydrophilicity.append(temp[1])
result = []
result.append(round(sum(resHydrophobicity) / (LengthSequence - k), 3))
result.append(round(sum(reshydrophilicity) / (LengthSequence - k), 3))
return result
#############################################################################################
def GetAPseudoAAC1(ProteinSequence, lamda=30, weight=0.5):
"""
########################################################################################
Computing the first 20 of type II pseudo-amino acid compostion descriptors based on
[_Hydrophobicity,_hydrophilicity].
########################################################################################
"""
rightpart = 0.0
for i in range(lamda):
rightpart = rightpart + sum(
GetSequenceOrderCorrelationFactorForAPAAC(ProteinSequence, k=i + 1)
)
AAC = GetAAComposition(ProteinSequence)
result = {}
temp = 1 + weight * rightpart
for index, i in enumerate(AALetter):
result["APAAC" + str(index + 1)] = round(AAC[i] / temp, 3)
return result
#############################################################################################
def GetAPseudoAAC2(ProteinSequence, lamda=30, weight=0.5):
"""
#######################################################################################
Computing the last lamda of type II pseudo-amino acid compostion descriptors based on
[_Hydrophobicity,_hydrophilicity].
#######################################################################################
"""
rightpart = []
for i in range(lamda):
temp = GetSequenceOrderCorrelationFactorForAPAAC(ProteinSequence, k=i + 1)
rightpart.append(temp[0])
rightpart.append(temp[1])
result = {}
temp = 1 + weight * sum(rightpart)
for index in range(20, 20 + 2 * lamda):
result["PAAC" + str(index + 1)] = round(
weight * rightpart[index - 20] / temp * 100, 3
)
return result
#############################################################################################
def GetAPseudoAAC(ProteinSequence, lamda=30, weight=0.5):
"""
#######################################################################################
Computing all of type II pseudo-amino acid compostion descriptors based on the given
properties. Note that the number of PAAC strongly depends on the lamda value. if lamda
= 20, we can obtain 20+20=40 PAAC descriptors. The size of these values depends on the
choice of lamda and weight simultaneously.
Usage:
result=GetAPseudoAAC(protein,lamda,weight)
Input: protein is a pure protein sequence.
lamda factor reflects the rank of correlation and is a non-Negative integer, such as 15.
Note that (1)lamda should NOT be larger than the length of input protein sequence;
(2) lamda must be non-Negative integer, such as 0, 1, 2, ...; (3) when lamda =0, the
output of PseAA server is the 20-D amino acid composition.
weight factor is designed for the users to put weight on the additional PseAA components
with respect to the conventional AA components. The user can select any value within the
region from 0.05 to 0.7 for the weight factor.
Output: result is a dict form containing calculated 20+lamda PAAC descriptors.
#######################################################################################
"""
res = {}
res.update(GetAPseudoAAC1(ProteinSequence, lamda=lamda, weight=weight))
res.update(GetAPseudoAAC2(ProteinSequence, lamda=lamda, weight=weight))
return res
#############################################################################################
#############################################################################################
##################################Type I descriptors#########################################
####################### Pseudo-Amino Acid Composition descriptors############################
#############################based on different properties###################################
#############################################################################################
#############################################################################################
def GetCorrelationFunction(Ri="S", Rj="D", AAP=[]):
"""
########################################################################################
Computing the correlation between two given amino acids using the given
properties.
Usage:
result=GetCorrelationFunction(Ri,Rj,AAP)
Input: Ri and Rj are the amino acids, respectively.
AAP is a list form containing the properties, each of which is a dict form.
Output: result is the correlation value between two amino acids.
########################################################################################
"""
NumAAP = len(AAP)
theta = 0.0
for i in range(NumAAP):
temp = NormalizeEachAAP(AAP[i])
theta = theta + math.pow(temp[Ri] - temp[Rj], 2)
result = round(theta / NumAAP, 3)
return result
#############################################################################################
def GetSequenceOrderCorrelationFactor(ProteinSequence, k=1, AAP=[]):
"""
########################################################################################
Computing the Sequence order correlation factor with gap equal to k based on
the given properities.
Usage:
result=GetSequenceOrderCorrelationFactor(protein,k,AAP)
Input: protein is a pure protein sequence.
k is the gap.
AAP is a list form containing the properties, each of which is a dict form.
Output: result is the correlation factor value with the gap equal to k.
########################################################################################
"""
LengthSequence = len(ProteinSequence)
res = []
for i in range(LengthSequence - k):
AA1 = ProteinSequence[i]
AA2 = ProteinSequence[i + k]
res.append(GetCorrelationFunction(AA1, AA2, AAP))
result = round(sum(res) / (LengthSequence - k), 3)
return result
#############################################################################################
def GetPseudoAAC1(ProteinSequence, lamda=30, weight=0.05, AAP=[]):
"""
#######################################################################################
Computing the first 20 of type I pseudo-amino acid compostion descriptors based on the given
properties.
########################################################################################
"""
rightpart = 0.0
for i in range(lamda):
rightpart = rightpart + GetSequenceOrderCorrelationFactor(
ProteinSequence, i + 1, AAP
)
AAC = GetAAComposition(ProteinSequence)
result = {}
temp = 1 + weight * rightpart
for index, i in enumerate(AALetter):
result["PAAC" + str(index + 1)] = round(AAC[i] / temp, 3)
return result
#############################################################################################
def GetPseudoAAC2(ProteinSequence, lamda=30, weight=0.05, AAP=[]):
"""
#######################################################################################
Computing the last lamda of type I pseudo-amino acid compostion descriptors based on the given
properties.
########################################################################################
"""
rightpart = []
for i in range(lamda):
rightpart.append(GetSequenceOrderCorrelationFactor(ProteinSequence, i + 1, AAP))
result = {}
temp = 1 + weight * sum(rightpart)
for index in range(20, 20 + lamda):
result["PAAC" + str(index + 1)] = round(
weight * rightpart[index - 20] / temp * 100, 3
)
return result
#############################################################################################
def GetPseudoAAC(ProteinSequence, lamda=30, weight=0.05, AAP=[]):
"""
#######################################################################################
Computing all of type I pseudo-amino acid compostion descriptors based on the given
properties. Note that the number of PAAC strongly depends on the lamda value. if lamda
= 20, we can obtain 20+20=40 PAAC descriptors. The size of these values depends on the
choice of lamda and weight simultaneously. You must specify some properties into AAP.
Usage:
result=GetPseudoAAC(protein,lamda,weight)
Input: protein is a pure protein sequence.
lamda factor reflects the rank of correlation and is a non-Negative integer, such as 15.
Note that (1)lamda should NOT be larger than the length of input protein sequence;
(2) lamda must be non-Negative integer, such as 0, 1, 2, ...; (3) when lamda =0, the
output of PseAA server is the 20-D amino acid composition.
weight factor is designed for the users to put weight on the additional PseAA components
with respect to the conventional AA components. The user can select any value within the
region from 0.05 to 0.7 for the weight factor.
AAP is a list form containing the properties, each of which is a dict form.
Output: result is a dict form containing calculated 20+lamda PAAC descriptors.
########################################################################################
"""
res = {}
res.update(GetPseudoAAC1(ProteinSequence, lamda, weight, AAP))
res.update(GetPseudoAAC2(ProteinSequence, lamda, weight, AAP))
return res
def CalculateAAComposition(ProteinSequence):
"""
########################################################################
Calculate the composition of Amino acids
for a given protein sequence.
Usage:
result=CalculateAAComposition(protein)
Input: protein is a pure protein sequence.
Output: result is a dict form containing the composition of
20 amino acids.
########################################################################
"""
LengthSequence = len(ProteinSequence)
Result = {}
for i in AALetter:
Result[i] = round(float(ProteinSequence.count(i)) / LengthSequence * 100, 3)
return Result
def CalculateDipeptideComposition(ProteinSequence):
"""
Calculate the composition of dipeptidefor a given protein sequence.
Usage:
result=CalculateDipeptideComposition(protein)
Input: protein is a pure protein sequence.
Output: result is a dict form containing the composition of
400 dipeptides.
"""
LengthSequence = len(ProteinSequence)
Result = {}
for i in AALetter:
for j in AALetter:
Dipeptide = i + j
Result[Dipeptide] = round(
float(ProteinSequence.count(Dipeptide)) / (LengthSequence - 1) * 100, 2
)
return Result
#############################################################################################
def Getkmers():
"""
########################################################################
Get the amino acid list of 3-mers.
Usage:
result=Getkmers()
Output: result is a list form containing 8000 tri-peptides.
########################################################################
"""
kmers = list()
for i in AALetter:
for j in AALetter:
for k in AALetter:
kmers.append(i + j + k)
return kmers
def GetSpectrumDict(proteinsequence):
"""
########################################################################
Calcualte the spectrum descriptors of 3-mers for a given protein.
Usage:
result=GetSpectrumDict(protein)
Input: protein is a pure protein sequence.
Output: result is a dict form containing the composition values of 8000
3-mers.
"""
result = {}
kmers = Getkmers()
for i in kmers:
result[i] = len(re.findall(i, proteinsequence))
return result
import numpy as np
#############################################################################################
def CalculateAADipeptideComposition(ProteinSequence):
"""
########################################################################
Calculate the composition of AADs, dipeptide and 3-mers for a
given protein sequence.
Usage:
result=CalculateAADipeptideComposition(protein)
Input: protein is a pure protein sequence.
Output: result is a dict form containing all composition values of
AADs, dipeptide and 3-mers (8420).
########################################################################
"""
result = {}
result.update(CalculateAAComposition(ProteinSequence))
result.update(CalculateDipeptideComposition(ProteinSequence))
result.update(GetSpectrumDict(ProteinSequence))
return np.array(list(result.values()))
_repmat = {
1: ["A", "G", "V"],
2: ["I", "L", "F", "P"],
3: ["Y", "M", "T", "S"],
4: ["H", "N", "Q", "W"],
5: ["R", "K"],
6: ["D", "E"],
7: ["C"],
}
def _Str2Num(proteinsequence):
"""
translate the amino acid letter into the corresponding class based on the
given form.
"""
repmat = {}
for i in _repmat:
for j in _repmat[i]:
repmat[j] = i
res = proteinsequence
for i in repmat:
res = res.replace(i, str(repmat[i]))
return res
###############################################################################
def CalculateConjointTriad(proteinsequence):
"""
Calculate the conjoint triad features from protein sequence.
Useage:
res = CalculateConjointTriad(protein)
Input: protein is a pure protein sequence.
Output is a dict form containing all 343 conjoint triad features.
"""
res = {}
proteinnum = _Str2Num(proteinsequence)
for i in range(1, 8):
for j in range(1, 8):
for k in range(1, 8):
temp = str(i) + str(j) + str(k)
res[temp] = proteinnum.count(temp)
return np.array(list(res.values()))
## Distance is the Schneider-Wrede physicochemical distance matrix used by Chou et. al.
_Distance1 = {
"GW": 0.923,
"GV": 0.464,
"GT": 0.272,
"GS": 0.158,
"GR": 1.0,
"GQ": 0.467,
"GP": 0.323,
"GY": 0.728,
"GG": 0.0,
"GF": 0.727,
"GE": 0.807,
"GD": 0.776,
"GC": 0.312,
"GA": 0.206,
"GN": 0.381,
"GM": 0.557,
"GL": 0.591,
"GK": 0.894,
"GI": 0.592,
"GH": 0.769,
"ME": 0.879,
"MD": 0.932,
"MG": 0.569,
"MF": 0.182,
"MA": 0.383,
"MC": 0.276,
"MM": 0.0,
"ML": 0.062,
"MN": 0.447,
"MI": 0.058,
"MH": 0.648,
"MK": 0.884,
"MT": 0.358,
"MW": 0.391,
"MV": 0.12,
"MQ": 0.372,
"MP": 0.285,
"MS": 0.417,
"MR": 1.0,
"MY": 0.255,
"FP": 0.42,
"FQ": 0.459,
"FR": 1.0,
"FS": 0.548,
"FT": 0.499,
"FV": 0.252,
"FW": 0.207,
"FY": 0.179,
"FA": 0.508,
"FC": 0.405,
"FD": 0.977,
"FE": 0.918,
"FF": 0.0,
"FG": 0.69,
"FH": 0.663,
"FI": 0.128,
"FK": 0.903,
"FL": 0.131,
"FM": 0.169,
"FN": 0.541,
"SY": 0.615,
"SS": 0.0,
"SR": 1.0,
"SQ": 0.358,
"SP": 0.181,
"SW": 0.827,
"SV": 0.342,
"ST": 0.174,
"SK": 0.883,
"SI": 0.478,
"SH": 0.718,
"SN": 0.289,
"SM": 0.44,
"SL": 0.474,
"SC": 0.185,
"SA": 0.1,
"SG": 0.17,
"SF": 0.622,
"SE": 0.812,
"SD": 0.801,
"YI": 0.23,
"YH": 0.678,
"YK": 0.904,
"YM": 0.268,
"YL": 0.219,
"YN": 0.512,
"YA": 0.587,
"YC": 0.478,
"YE": 0.932,
"YD": 1.0,
"YG": 0.782,
"YF": 0.202,
"YY": 0.0,
"YQ": 0.404,
"YP": 0.444,
"YS": 0.612,
"YR": 0.995,
"YT": 0.557,
"YW": 0.244,
"YV": 0.328,
"LF": 0.139,
"LG": 0.596,
"LD": 0.944,
"LE": 0.892,
"LC": 0.296,
"LA": 0.405,
"LN": 0.452,
"LL": 0.0,
"LM": 0.062,
"LK": 0.893,
"LH": 0.653,
"LI": 0.013,
"LV": 0.133,
"LW": 0.341,
"LT": 0.397,
"LR": 1.0,
"LS": 0.443,
"LP": 0.309,
"LQ": 0.376,
"LY": 0.205,
"RT": 0.808,
"RV": 0.914,
"RW": 1.0,
"RP": 0.796,
"RQ": 0.668,
"RR": 0.0,
"RS": 0.86,
"RY": 0.859,
"RD": 0.305,
"RE": 0.225,
"RF": 0.977,
"RG": 0.928,
"RA": 0.919,
"RC": 0.905,
"RL": 0.92,
"RM": 0.908,
"RN": 0.69,
"RH": 0.498,
"RI": 0.929,
"RK": 0.141,
"VH": 0.649,
"VI": 0.135,
"EM": 0.83,
"EL": 0.854,
"EN": 0.599,
"EI": 0.86,
"EH": 0.406,
"EK": 0.143,
"EE": 0.0,
"ED": 0.133,
"EG": 0.779,
"EF": 0.932,
"EA": 0.79,
"EC": 0.788,
"VM": 0.12,
"EY": 0.837,
"VN": 0.38,
"ET": 0.682,
"EW": 1.0,
"EV": 0.824,
"EQ": 0.598,
"EP": 0.688,
"ES": 0.726,
"ER": 0.234,
"VP": 0.212,
"VQ": 0.339,
"VR": 1.0,
"VT": 0.305,
"VW": 0.472,
"KC": 0.871,
"KA": 0.889,
"KG": 0.9,
"KF": 0.957,
"KE": 0.149,
"KD": 0.279,
"KK": 0.0,
"KI": 0.899,
"KH": 0.438,
"KN": 0.667,
"KM": 0.871,
"KL": 0.892,
"KS": 0.825,
"KR": 0.154,
"KQ": 0.639,
"KP": 0.757,
"KW": 1.0,
"KV": 0.882,
"KT": 0.759,
"KY": 0.848,
"DN": 0.56,
"DL": 0.841,
"DM": 0.819,
"DK": 0.249,
"DH": 0.435,
"DI": 0.847,
"DF": 0.924,
"DG": 0.697,
"DD": 0.0,
"DE": 0.124,
"DC": 0.742,
"DA": 0.729,
"DY": 0.836,
"DV": 0.797,
"DW": 1.0,
"DT": 0.649,
"DR": 0.295,
"DS": 0.667,
"DP": 0.657,
"DQ": 0.584,
"QQ": 0.0,
"QP": 0.272,
"QS": 0.461,
"QR": 1.0,
"QT": 0.389,
"QW": 0.831,
"QV": 0.464,
"QY": 0.522,
"QA": 0.512,
"QC": 0.462,
"QE": 0.861,
"QD": 0.903,
"QG": 0.648,
"QF": 0.671,