Files changed (2) hide show
  1. PSTAAP.py +121 -0
  2. Physicochemical.py +68 -0
PSTAAP.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import numpy as np
3
+ import scipy.io
4
+ import os
5
+
6
+
7
+ def PSTAAP_feature(protein_sequences, test_PSTAAP=False):
8
+ for i in range(len(protein_sequences)):
9
+ protein_sequences[i] = protein_sequences[i][:24] + protein_sequences[i][25:]
10
+
11
+ if test_PSTAAP:
12
+ mat_contents = scipy.io.loadmat("Feature_extraction_algorithms/Fr_test.mat")
13
+ else:
14
+ mat_contents = scipy.io.loadmat("Feature_extraction_algorithms/Fr_train.mat")
15
+
16
+ Fr = mat_contents['Fr']
17
+ """
18
+ print(Fr[0*400+5*20+0,0])
19
+ print(Fr[5 * 400 + 0 * 20 + 16, 1])
20
+ print(Fr[0 * 400 + 16 * 20 + 14, 2])
21
+ """
22
+ AA = ['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y']
23
+ PSTAAP = np.zeros((len(protein_sequences), 46))
24
+ for i in range(len(protein_sequences)):
25
+ for j in range(len(protein_sequences[0])-2):
26
+ t1 = protein_sequences[i][j]
27
+ position1 = AA.index(t1)
28
+ t2 = protein_sequences[i][j+1]
29
+ position2 = AA.index(t2)
30
+ t3 = protein_sequences[i][j+2]
31
+ position3 = AA.index(t3)
32
+
33
+ PSTAAP[i][j] = Fr[400 * position1 + 20 * position2 + position3][j]
34
+
35
+ return PSTAAP
36
+
37
+
38
+ if __name__ == '__main__':
39
+ import numpy as np
40
+ import matplotlib.pyplot as plt
41
+ from scipy.interpolate import splrep, BSpline
42
+ from sklearn.preprocessing import MinMaxScaler
43
+ from numpy.polynomial import Polynomial
44
+
45
+
46
+ def plot_multiple_polynomial_fitted_functions(sample_datas, degree=3):
47
+ markers = ["o", "o", "^", "^", "v", "p"]
48
+ colors = ["b", "b", "c", "c", "m", "y"]
49
+ label = ["sample1(1,0,0,0)", "sample1(1,0,0,0)", "sample1(0,1,0,0)", "sample2(0,1,0,0)", "sample3(0,0,1,0)", "sample6(0,0,0,1)"]
50
+ plt.figure(figsize=(12, 6))
51
+
52
+ for i, sample_data in enumerate(sample_datas):
53
+ if i == 0 or i == 1 or i == 4 or i == 5:
54
+ continue
55
+ # 无量纲化处理
56
+ scaler = MinMaxScaler()
57
+ normalized_data = scaler.fit_transform(sample_data.reshape(-1, 1)).flatten()
58
+ # 拟合多项式函数
59
+ x = np.linspace(0, 1, len(normalized_data))
60
+ p = Polynomial.fit(x, normalized_data, degree)
61
+ y_poly = p(x)
62
+ # 计算极值点
63
+ dy_poly = p.deriv(1)(x)
64
+ extrema_indices = np.where(np.diff(np.sign(dy_poly)))[0]
65
+ extrema_x = x[extrema_indices]
66
+ extrema_y = y_poly[extrema_indices]
67
+
68
+ plt.plot(x, y_poly, label=f'{label[i]}', marker=markers[i], color=colors[i])
69
+ plt.plot(extrema_x, extrema_y, 'rx', markersize=10) # 标记极值点
70
+
71
+ plt.xlabel('X')
72
+ plt.ylabel('Y')
73
+ plt.title('Fitted Polynomial Functions with Extrema')
74
+ plt.legend()
75
+ plt.show()
76
+
77
+ def plot_multiple_fitted_functions(sample_datas, smooth_factor=1):
78
+ markers = ["o", "o", "^", "^", "v", "p"]
79
+ colors = ["b", "b", "c", "c", "m", "y"]
80
+ label = ["", "", "sample1(0,1,0,0)", "sample2(0,1,0,0)", "sample3(0,0,1,0)", ""]
81
+ plt.figure(figsize=(12, 6))
82
+
83
+ for i, sample_data in enumerate(sample_datas):
84
+ if i == 0 or i == 1 or i == 4 or i == 5:
85
+ continue
86
+
87
+ scaler = MinMaxScaler()
88
+ normalized_data = scaler.fit_transform(sample_data.reshape(-1, 1)).flatten()
89
+
90
+ x = np.linspace(0, 1, len(normalized_data))
91
+ tck = splrep(x, normalized_data, k=3, s=smooth_factor)
92
+ spline = BSpline(tck[0], tck[1], tck[2])
93
+
94
+ y_spline = spline(x)
95
+ dy_spline = spline.derivative()
96
+ extrema_indices = np.where(np.diff(np.sign(dy_spline(x))))[0]
97
+ extrema_x = x[extrema_indices]
98
+ extrema_y = y_spline[extrema_indices]
99
+
100
+ plt.plot(x, y_spline, label=f'{label[i]}', marker=markers[i], color=colors[i])
101
+ plt.plot(extrema_x, extrema_y, 'rx', markersize=10)
102
+
103
+ plt.xlabel('X')
104
+ plt.ylabel('Y')
105
+ plt.title('Fitted B-Spline Functions with Extrema')
106
+ plt.legend()
107
+ plt.show()
108
+
109
+ protein_sequences = [
110
+ "TSPASVASSSSTPSSKTKDLGHNDKSSTPGLKSNTPTPRNDAPTPGTST", # a
111
+ "LGGNIEQLVARSNILTLMYQCMQDKMPEVRQSSFALLGDLTKACFQHVK", # a
112
+ "VDFQHASEDARKTINQWVKGQTEGKIPELLASGMVDNMTKLVLVNAIYF", # c
113
+ "VEGTLKGPEVDLKGPRLDFEGPDAKLSGPSLKMPSLEISAPKVTAPDVD", # c
114
+ "IDILTSREQFFSDEERKYMAINQKKAYILVTPLKSRKVIEQRCMRYNLS", # m
115
+ "LAGTDGETTTQGLDGLSERCAQYKKDGADFAKWRCVLKISERTPSALAI", # s
116
+ ]
117
+ data = PSTAAP_feature(protein_sequences, False)
118
+
119
+ # 调用绘图函数
120
+ plot_multiple_polynomial_fitted_functions(data)
121
+ plot_multiple_fitted_functions(data)
Physicochemical.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+
4
+
5
+ data_dict = {
6
+ "A": [0.108555943, 0.405506884, 0.955223881, 0.896118721, 0, 1, 1, 1, 0, 0, 1, 0],
7
+ "R": [0.767557104, 1, 0.686567164, 0.801369863, 1.191, 1, 1, 1, 1, 1, 0, 0],
8
+ "N": [0.441656988, 0.330413016, 0.462686567, 0, 0, 1, 1, 1, 0, 1, 0, 0],
9
+ "D": [0.449322493, 0, 0.253731343, 0.865296804, 0.374, 1, 1, 1, -1, 1, 1, 0],
10
+ "C": [0.356871854, 0.285356696, 0, 1, 0.793, 1, 1, 0, 0, 1, 0, 1],
11
+ "Q": [0.55029036, 0.360450563, 0.686567164, 0.811643836, 0, 1, 1, 1, 0, 1, 0, 0],
12
+ "E": [0.557955865, 0.056320401, 0.71641791, 0.873287671, 0.403, 1, 1, 1, -1, 1, 1, 0],
13
+ "G": [0, 0.400500626, 0.955223881, 0.885844749, 0, 0, 1, 1, 0, 1, 1, 0],
14
+ "H": [0.62013163, 0.603254068, 0.164179104, 0.816210046, 0.569, 1, 1, 1, 1, 1, 1, 0.8],
15
+ "I": [0.43437863, 0.406758448, 0.910447761, 0.883561644, 0, 1, 0, 1, 0, 0, 0, 0],
16
+ "L": [0.43437863, 0.40175219, 0.970149254, 0.865296804, 0, 1, 0, 1, 0, 0, 0, 0],
17
+ "K": [0.550677507, 0.872340426, 0.701492537, 0.79109589, 1, 1, 1, 1, 1, 1, 0, 0],
18
+ "M": [0.574061169, 0.371714643, 0.850746269, 0.820776256, 0, 1, 0, 1, 0, 0, 0.1, 0],
19
+ "F": [0.697793264, 0.339173967, 0.179104478, 0.811643836, 0, 1, 0, 1, 0, 0, 0.1, 0.9],
20
+ "P": [0.310181959, 0.441802253, 0.417910448, 0.979452055, 0, 1, 1, 1, 0, 0.5, 1, 0],
21
+ "S": [0.232442896, 0.364205257, 0.746268657, 0.813926941, 0, 1, 1, 1, 0, 1, 1, 0],
22
+ "T": [0.341076268, 0.42428035, 0.567164179, 0.808219178, 0, 1, 1, 1, 0, 1, 0, 0],
23
+ "W": [1, 0.39048811, 1, 0.841324201, 0, 1, 0, 1, 0, 0, 0, 0.8],
24
+ "Y": [0.821680217, 0.361702128, 0.731343284, 0.809360731, 0.961, 1, 0, 1, 0, 0.5, 1, 0.8],
25
+ "V": [0.325822687, 0.399249061, 0.865671642, 0.878995434, 0, 1, 0, 1, 0, 0, 0, 0]
26
+ }
27
+
28
+
29
+ data_new_dict = {
30
+ "G": [0.0, 0.5363372093023252, -1],
31
+ "A": [0.07347447047353533, 0.5534883720930233, 1],
32
+ "T": [0.2366637964906612, 0.48837209302325573, -1],
33
+ "S": [0.15120012868167378, 0.372093023255814, -1],
34
+ "P": [0.21957275509630982, 0.7209302325581398, -1],
35
+ "V": [0.22993840656583635, 0.5363372093023252, 1],
36
+ "L": [0.31981981981981985, 0.5416666666666666, 1],
37
+ "I": [0.31981981981981985, 0.5552325581395349, 1],
38
+ "M": [0.4250240432219403, 0.4011627906976744, 1],
39
+ "F": [0.5205540765087008, 0.2558139534883721, 1],
40
+ "Y": [0.6151618372354518, 0.36046511627906974, 1],
41
+ "W": [0.740630755511022, 0.4976744186046512, 1],
42
+ "D": [0.33248277702242695, 0.0, -1],
43
+ "E": [0.409931793152727, 0.06976744186046511, -1],
44
+ "N": [0.32651104755672825, 0.2674418604651163, -1],
45
+ "Q": [0.40479484311833796, 0.34883720930232553, -1],
46
+ "K": [0.40452036659863644, 1.0, -1],
47
+ "R": [0.5447355923482843, 1.2325581395348837, -1],
48
+ "H": [0.47177217934844545, 0.8488372093023256, 1],
49
+ "C": [0.24070355568601118, 0.20348837209302326, 1]
50
+ }
51
+
52
+
53
+ def PC_feature(seq):
54
+ feature = []
55
+ for i in range(len(seq)):
56
+ f = [data_new_dict[aa] for aa in seq[i]]
57
+ feature.append(f)
58
+ return np.array(feature)
59
+
60
+
61
+ """
62
+ seq = ["AAC", 'CRN']
63
+ output = PC_feature(seq)
64
+ print(output)
65
+ print(output.shape)
66
+ """
67
+
68
+