-
Notifications
You must be signed in to change notification settings - Fork 7
/
iFeatureOmegaCLI.py
10900 lines (10095 loc) · 515 KB
/
iFeatureOmegaCLI.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
#!/usr/bin/env python
# _*_ coding: utf-8 _*_
import os, sys, re
from networkx.algorithms import cluster
from networkx.algorithms.tree.recognition import is_tree
pPath = os.path.split(os.path.realpath(__file__))[0]
sys.path.append(pPath)
sys.path.append(os.path.join(pPath, 'chem'))
import json
import random
import math
import cmath
import pickle
import itertools
import numpy as np
import networkx as nx
import pandas as pd
import warnings
from collections import Counter
from Bio.PDB.PDBParser import PDBParser
from Bio.PDB.MMCIFParser import MMCIFParser
from Bio.PDB.DSSP import DSSP
from Bio.PDB.ResidueDepth import ResidueDepth
from Bio.PDB.HSExposure import HSExposureCA, HSExposureCB
from Bio.PDB.PDBList import PDBList
from sklearn.cluster import (KMeans, AffinityPropagation, MeanShift, estimate_bandwidth, DBSCAN,
AgglomerativeClustering, SpectralClustering, MiniBatchKMeans)
from sklearn.mixture import GaussianMixture
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KernelDensity
import scipy.cluster.hierarchy as sch
from sklearn.decomposition import PCA, LatentDirichletAllocation
from sklearn.manifold import TSNE
from rdkit import Chem
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from chem import *
import copy
plt.style.use('ggplot')
warnings.filterwarnings("ignore", category=FutureWarning, module="sklearn")
warnings.filterwarnings("ignore", category=DeprecationWarning, module="sklearn")
warnings.filterwarnings("ignore", category=UserWarning, module="sklearn")
warnings.filterwarnings("ignore", category=RuntimeWarning)
warnings.filterwarnings("ignore", category=UserWarning)
class Sequence(object):
def __init__(self, file):
self.file = file # whole file path
self.fasta_list = [] # 2-D list [sampleName, fragment, label, training or testing]
self.sample_purpose = None # 1-D ndarray, sample used as training dataset (True) or testing dataset(False)
self.sequence_number = 0 # int: the number of samples
self.sequence_type = '' # DNA, RNA or Protein
self.is_equal = False # bool: sequence with equal length?
self.minimum_length = 1 # int
self.maximum_length = 0 # int
self.minimum_length_without_minus = 1 # int
self.maximum_length_without_minus = 0 # int
self.error_msg = '' # string
self.fasta_list, self.sample_purpose, self.error_msg = self.read_fasta(self.file)
self.sequence_number = len(self.fasta_list)
if self.sequence_number > 0:
self.is_equal, self.minimum_length, self.maximum_length, self.minimum_length_without_minus, self.maximum_length_without_minus = self.sequence_with_equal_length()
self.sequence_type = self.check_sequence_type()
else:
self.error_msg = 'File format error.'
def read_fasta(self, file):
"""
read fasta sequence
:param file:
:return:
"""
msg = ''
if not os.path.exists(self.file):
msg = 'Error: file %s does not exist.' % self.file
return [], None, msg
with open(file) as f:
records = f.read()
records = records.split('>')[1:]
fasta_sequences = []
for fasta in records:
array = fasta.split('\n')
header, sequence = array[0].split()[0], re.sub('[^ACDEFGHIKLMNPQRSTUVWY-]', '-', ''.join(array[1:]).upper())
header_array = header.split('|')
name = header_array[0]
label = header_array[1] if len(header_array) >= 2 else '0'
label_train = header_array[2] if len(header_array) >= 3 else 'training'
fasta_sequences.append([name, sequence, label, label_train])
sample_purpose = np.array([item[3] == 'training' for item in fasta_sequences])
return fasta_sequences, sample_purpose, msg
def sequence_with_equal_length(self):
"""
Check if fasta sequence is in equal length
:return:
"""
length_set = set()
length_set_1 = set()
for item in self.fasta_list:
length_set.add(len(item[1]))
length_set_1.add(len(re.sub('-', '', item[1])))
length_set = sorted(length_set)
length_set_1 = sorted(length_set_1)
if len(length_set) == 1:
return True, length_set[0], length_set[-1], length_set_1[0], length_set_1[-1]
else:
return False, length_set[0], length_set[-1], length_set_1[0], length_set_1[-1]
def check_sequence_type(self):
"""
Specify sequence type (Protein, DNA or RNA)
:return:
"""
tmp_fasta_list = []
if len(self.fasta_list) < 100:
tmp_fasta_list = self.fasta_list
else:
random_index = random.sample(range(0, len(self.fasta_list)), 100)
for i in random_index:
tmp_fasta_list.append(self.fasta_list[i])
sequence = ''
for item in tmp_fasta_list:
sequence += item[1]
char_set = set(sequence)
if 5 < len(char_set) <= 21:
for line in self.fasta_list:
line[1] = re.sub('[^ACDEFGHIKLMNPQRSTVWY]', '-', line[1])
return 'Protein'
elif 0 < len(char_set) <= 5 and 'T' in char_set:
return 'DNA'
elif 0 < len(char_set) <= 5 and 'U' in char_set:
for line in self.fasta_list:
line[1] = re.sub('U', 'T', line[1])
return 'RNA'
else:
return 'Unknown'
class iProtein(Sequence):
"""
# Running examples:
# import iFeatureOmegaCLI
>>> import iFeatureOmegaCLI
# create a instance
>>> protein = iFeatureOmegaCLI.iProtein("./data_examples/peptide_sequences.txt")
# display available feature descriptor methods
>>> protein.display_feature_types()
# import parameters for feature descriptors (optimal)
>>> protein.import_parameters('parameters/Protein_parameters_setting.json')
# calculate feature descriptors. Take "AAC" as an example.
>>> protein.get_descriptor("AAC")
# display the feature descriptors
>>> print(protein.encodings)
# save feature descriptors
>>> protein.to_csv("AAC.csv", "index=False", header=False)
"""
def __init__(self, file):
super(iProtein, self).__init__(file=file)
self.__default_para_dict = {
'EAAC': {'sliding_window': 5},
'CKSAAP type 1': {'kspace': 3},
'CKSAAP type 2': {'kspace': 3},
'EGAAC': {'sliding_window': 5},
'CKSAAGP type 1': {'kspace': 3},
'CKSAAGP type 2': {'kspace': 3},
'AAIndex': {'aaindex': 'ANDN920101;ARGP820101;ARGP820102;ARGP820103;BEGF750101;BEGF750102;BEGF750103;BHAR880101'},
'NMBroto': {'aaindex': 'ANDN920101;ARGP820101;ARGP820102;ARGP820103;BEGF750101;BEGF750102;BEGF750103;BHAR880101', 'nlag': 3,},
'Moran': {'aaindex': 'ANDN920101;ARGP820101;ARGP820102;ARGP820103;BEGF750101;BEGF750102;BEGF750103;BHAR880101', 'nlag': 3,},
'Geary': {'aaindex': 'ANDN920101;ARGP820101;ARGP820102;ARGP820103;BEGF750101;BEGF750102;BEGF750103;BHAR880101', 'nlag': 3,},
'KSCTriad': {'kspace': 3},
'SOCNumber': {'nlag': 3},
'QSOrder': {'nlag': 3, 'weight': 0.05},
'PAAC': {'weight': 0.05, 'lambdaValue': 3},
'APAAC': {'weight': 0.05, 'lambdaValue': 3},
'DistancePair': {'distance': 0, 'cp': 'cp(20)',},
'AC': {'aaindex': 'ANDN920101;ARGP820101;ARGP820102;ARGP820103;BEGF750101;BEGF750102;BEGF750103;BHAR880101', 'nlag': 3},
'CC': {'aaindex': 'ANDN920101;ARGP820101;ARGP820102;ARGP820103;BEGF750101;BEGF750102;BEGF750103;BHAR880101', 'nlag': 3},
'ACC': {'aaindex': 'ANDN920101;ARGP820101;ARGP820102;ARGP820103;BEGF750101;BEGF750102;BEGF750103;BHAR880101', 'nlag': 3},
'PseKRAAC type 1': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 2': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 3A': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 3B': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 4': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 5},
'PseKRAAC type 5': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 3},
'PseKRAAC type 6A': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 4},
'PseKRAAC type 6B': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 5},
'PseKRAAC type 6C': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 5},
'PseKRAAC type 7': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 8': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 9': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 10': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 11': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 12': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 13': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 4},
'PseKRAAC type 14': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 15': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
'PseKRAAC type 16': {'lambdaValue': 3, 'PseKRAAC_model': 'g-gap', 'g-gap': 2, 'k-tuple': 2, 'RAAC_clust': 2},
}
self.__default_para = {
'sliding_window': 5,
'kspace': 3,
'nlag': 3,
'weight': 0.05,
'lambdaValue': 3,
'PseKRAAC_model': 'g-gap',
'g-gap': 2,
'k-tuple': 2,
'RAAC_clust': 1,
'aaindex': 'ANDN920101;ARGP820101;ARGP820102;ARGP820103;BEGF750101;BEGF750102;BEGF750103;BHAR880101',
}
self.encodings = None # pandas dataframe
self.__cmd_dict ={
'AAC': 'self._AAC()',
'EAAC': 'self._EAAC()',
'CKSAAP type 1': 'self._CKSAAP(normalized=True)',
'CKSAAP type 2': 'self._CKSAAP(normalized=False)',
'DPC type 1': 'self._DPC(normalized=True)',
'DPC type 2': 'self._DPC(normalized=False)',
'DDE': 'self._DDE()',
'TPC type 1': 'self._TPC(normalized=True)',
'TPC type 2': 'self._TPC(normalized=False)',
'binary': 'self._binary()',
'binary_6bit': 'self._binary_6bit()',
'binary_5bit type 1': 'self._binary_5bit_type_1()',
'binary_5bit type 2': 'self._binary_5bit_type_2()',
'binary_3bit type 1': 'self._binary_3bit_type_1()',
'binary_3bit type 2': 'self._binary_3bit_type_2()',
'binary_3bit type 3': 'self._binary_3bit_type_3()',
'binary_3bit type 4': 'self._binary_3bit_type_4()',
'binary_3bit type 5': 'self._binary_3bit_type_5()',
'binary_3bit type 6': 'self._binary_3bit_type_6()',
'binary_3bit type 7': 'self._binary_3bit_type_7()',
'AESNN3': 'self._AESNN3()',
'GAAC': 'self._GAAC()',
'EGAAC': 'self._EGAAC()',
'CKSAAGP type 1': 'self._CKSAAGP(normalized=True)',
'CKSAAGP type 2': 'self._CKSAAGP(normalized=False)',
'GDPC type 1': 'self._GDPC(normalized=True)',
'GDPC type 2': 'self._GDPC(normalized=False)',
'GTPC type 1': 'self._GTPC(normalized=True)',
'GTPC type 2': 'self._GTPC(normalized=False)',
'AAIndex': 'self._AAIndex()',
'ZScale': 'self._ZScale()',
'BLOSUM62': 'self._BLOSUM62()',
'NMBroto': 'self._NMBroto()',
'Moran': 'self._Moran()',
'Geary': 'self._Geary()',
'CTDC': 'self._CTDC()',
'CTDT': 'self._CTDT()',
'CTDD': 'self._CTDD()',
'CTriad': 'self._CTriad()',
'KSCTriad': 'self._KSCTriad()',
'SOCNumber': 'self._SOCNumber()',
'QSOrder': 'self._QSOrder()',
'PAAC': 'self._PAAC()',
'APAAC': 'self._APAAC()',
'OPF_10bit': 'self._OPF_10bit()',
'OPF_10bit type 1': 'self._OPF_10bit_type_1()',
'OPF_7bit type 1': 'self._OPF_7bit_type_1()',
'OPF_7bit type 2': 'self._OPF_7bit_type_2()',
'OPF_7bit type 3': 'self._OPF_7bit_type_3()',
'ASDC': 'self._ASDC()',
'DistancePair': 'self._DistancePair()',
'AC': 'self._AC()',
'CC': 'self._CC()',
'ACC': 'self._ACC()',
'PseKRAAC type 1': 'self._PseKRAAC_type_1()',
'PseKRAAC type 2': 'self._PseKRAAC_type_2()',
'PseKRAAC type 3A': 'self._PseKRAAC_type_3A()',
'PseKRAAC type 3B': 'self._PseKRAAC_type_3B()',
'PseKRAAC type 4': 'self._PseKRAAC_type_4()',
'PseKRAAC type 5': 'self._PseKRAAC_type_5()',
'PseKRAAC type 6A': 'self._PseKRAAC_type_6A()',
'PseKRAAC type 6B': 'self._PseKRAAC_type_6B()',
'PseKRAAC type 6C': 'self._PseKRAAC_type_6C()',
'PseKRAAC type 7': 'self._PseKRAAC_type_7()',
'PseKRAAC type 8': 'self._PseKRAAC_type_8()',
'PseKRAAC type 9': 'self._PseKRAAC_type_9()',
'PseKRAAC type 10': 'self._PseKRAAC_type_10()',
'PseKRAAC type 11': 'self._PseKRAAC_type_11()',
'PseKRAAC type 12': 'self._PseKRAAC_type_12()',
'PseKRAAC type 13': 'self._PseKRAAC_type_13()',
'PseKRAAC type 14': 'self._PseKRAAC_type_14()',
'PseKRAAC type 15': 'self._PseKRAAC_type_15()',
'PseKRAAC type 16': 'self._PseKRAAC_type_16()',
'KNN': 'self._KNN()',
}
def import_parameters(self, file):
if os.path.exists(file):
with open(file) as f:
records = f.read().strip()
try:
self.__default_para_dict = json.loads(records)
print('File imported successfully.')
except Exception as e:
print('Parameter file parser error.')
def get_descriptor(self, descriptor='AAC'):
# copy parameters
if descriptor in self.__default_para_dict:
for key in self.__default_para_dict[descriptor]:
self.__default_para[key] = self.__default_para_dict[descriptor][key]
if descriptor in self.__cmd_dict:
cmd = self.__cmd_dict[descriptor]
status = eval(cmd)
else:
print('The descriptor type does not exist.')
def display_feature_types(self):
info = '''
----- Available feature types ------
AAC Amino acid composition
EAAC Enhanced amino acid composition
CKSAAP type 1 Composition of k-spaced amino acid pairs type 1 - normalized
CKSAAP type 2 Composition of k-spaced amino acid pairs type 2 - raw count
DPC type 1 Dipeptide composition type 1 - normalized
DPC type 2 Dipeptide composition type 2 - raw count
TPC type 1 Tripeptide composition type 1 - normalized
TPC type 2 Tripeptide composition type 1 - raw count
CTDC Composition
CTDT Transition
CTDD Distribution
CTriad Conjoint triad
KSCTriad Conjoint k-spaced triad
ASDC Adaptive skip dipeptide composition
DistancePair PseAAC of distance-pairs and reduced alphabe
GAAC Grouped amino acid composition
EGAAC Enhanced grouped amino acid composition
CKSAAGP type 1 Composition of k-spaced amino acid group pairs type 1- normalized
CKSAAGP type 2 Composition of k-spaced amino acid group pairs type 2- raw count
GDPC type 1 Grouped dipeptide composition type 1 - normalized
GDPC type 2 Grouped dipeptide composition type 2 - raw count
GTPC type 1 Grouped tripeptide composition type 1 - normalized
GTPC type 2 Grouped tripeptide composition type 1 - raw count
Moran Moran
Geary Geary
NMBroto Normalized Moreau-Broto
AC Auto covariance
CC Cross covariance
ACC Auto-cross covariance
SOCNumber Sequence-order-coupling number
QSOrder Quasi-sequence-order descriptors
PAAC Pseudo-amino acid composition
APAAC Amphiphilic PAAC
PseKRAAC type 1 Pseudo K-tuple reduced amino acids composition type 1
PseKRAAC type 2 Pseudo K-tuple reduced amino acids composition type 2
PseKRAAC type 3A Pseudo K-tuple reduced amino acids composition type 3A
PseKRAAC type 3B Pseudo K-tuple reduced amino acids composition type 3B
PseKRAAC type 4 Pseudo K-tuple reduced amino acids composition type 4
PseKRAAC type 5 Pseudo K-tuple reduced amino acids composition type 5
PseKRAAC type 6A Pseudo K-tuple reduced amino acids composition type 6A
PseKRAAC type 6B Pseudo K-tuple reduced amino acids composition type 6B
PseKRAAC type 6C Pseudo K-tuple reduced amino acids composition type 6C
PseKRAAC type 7 Pseudo K-tuple reduced amino acids composition type 7
PseKRAAC type 8 Pseudo K-tuple reduced amino acids composition type 8
PseKRAAC type 9 Pseudo K-tuple reduced amino acids composition type 9
PseKRAAC type 10 Pseudo K-tuple reduced amino acids composition type 10
PseKRAAC type 11 Pseudo K-tuple reduced amino acids composition type 11
PseKRAAC type 12 Pseudo K-tuple reduced amino acids composition type 12
PseKRAAC type 13 Pseudo K-tuple reduced amino acids composition type 13
PseKRAAC type 14 Pseudo K-tuple reduced amino acids composition type 14
PseKRAAC type 15 Pseudo K-tuple reduced amino acids composition type 15
PseKRAAC type 16 Pseudo K-tuple reduced amino acids composition type 16
binary Binary
binary_6bit Binary
binary_5bit type 1 Binary
binary_5bit type 2 Binary
binary_3bit type 1 Binary
binary_3bit type 2 Binary
binary_3bit type 3 Binary
binary_3bit type 4 Binary
binary_3bit type 5 Binary
binary_3bit type 6 Binary
binary_3bit type 7 Binary
AESNN3 Learn from alignments
OPF_10bit Overlapping property features - 10 bit
OPF_7bit type 1 Overlapping property features - 7 bit type 1
OPF_7bit type 2 Overlapping property features - 7 bit type 2
OPF_7bit type 3 Overlapping property features - 7 bit type 3
AAIndex AAIndex
BLOSUM62 BLOSUM62
ZScale Z-Scales index
KNN K-nearest neighbor
Note: the first column is the names of availables feature types while the second column is description.
'''
print(info)
def add_samples_label(self, file):
with open(file) as f:
labels = f.read().strip().split('\n')
for i in range(np.min([len(self.fasta_list), len(labels)])):
self.fasta_list[i][2] = '1' if labels[i] == '1' else '0'
def _AAC(self):
try:
AA = 'ACDEFGHIKLMNPQRSTVWY'
header = ['SampleName']
encodings = []
for i in AA:
header.append('AAC_{0}'.format(i))
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], re.sub('-', '', i[1]), i[2]
count = Counter(sequence)
for key in count:
count[key] = count[key] / len(sequence)
code = [name]
for aa in AA:
code.append(count[aa])
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _EAAC(self):
try:
if not self.is_equal:
self.error_msg = 'EAAC descriptor need fasta sequence with equal length.'
self.encodings = None
else:
AA = 'ARNDCQEGHILKMFPSTWYV'
encodings = []
header = ['SampleName']
for w in range(1, len(self.fasta_list[0][1]) - self.__default_para['sliding_window'] + 2):
for aa in AA:
header.append('EAAC_SW.' + str(w) + '.' + aa)
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for j in range(len(sequence)):
if j < len(sequence) and j + self.__default_para['sliding_window'] <= len(sequence):
count = Counter(sequence[j:j + self.__default_para['sliding_window']])
for key in count:
count[key] = count[key] / len(sequence[j:j + self.__default_para['sliding_window']])
for aa in AA:
code.append(count[aa])
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _CKSAAP(self, normalized=True):
try:
AA = 'ACDEFGHIKLMNPQRSTVWY'
encodings = []
aaPairs = []
for aa1 in AA:
for aa2 in AA:
aaPairs.append(aa1 + aa2)
header = ['SampleName']
gap = self.__default_para['kspace']
for g in range(gap + 1):
for aa in aaPairs:
header.append('CKSAAP_' + aa + '.gap' + str(g))
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], re.sub('-', '' , i[1]), i[2]
code = [name]
for g in range(gap + 1):
myDict = {}
for pair in aaPairs:
myDict[pair] = 0
sum = 0
for index1 in range(len(sequence)):
index2 = index1 + g + 1
if index1 < len(sequence) and index2 < len(sequence) and sequence[index1] in AA and sequence[
index2] in AA:
myDict[sequence[index1] + sequence[index2]] = myDict[sequence[index1] + sequence[index2]] + 1
sum = sum + 1
for pair in aaPairs:
if normalized:
code.append(myDict[pair] / sum)
else:
code.append(myDict[pair])
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _DPC(self, normalized=True):
try:
AA = 'ACDEFGHIKLMNPQRSTVWY'
encodings = []
diPeptides = ['DPC_' + aa1 + aa2 for aa1 in AA for aa2 in AA]
header = ['SampleName'] + diPeptides
encodings.append(header)
AADict = {}
for i in range(len(AA)):
AADict[AA[i]] = i
for i in self.fasta_list:
name, sequence, label = i[0], re.sub('-', '', i[1]), i[2]
code = [name]
tmpCode = [0] * 400
for j in range(len(sequence) - 2 + 1):
tmpCode[AADict[sequence[j]] * 20 + AADict[sequence[j + 1]]] = tmpCode[AADict[sequence[j]] * 20 + AADict[
sequence[j + 1]]] + 1
if sum(tmpCode) != 0:
if normalized:
tmpCode = [i / sum(tmpCode) for i in tmpCode]
code = code + tmpCode
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _DDE(self):
try:
AA = 'ACDEFGHIKLMNPQRSTVWY'
myCodons = {'A': 4, 'C': 2, 'D': 2, 'E': 2, 'F': 2, 'G': 4, 'H': 2, 'I': 3, 'K': 2, 'L': 6,
'M': 1, 'N': 2, 'P': 4, 'Q': 2, 'R': 6, 'S': 6, 'T': 4, 'V': 4, 'W': 1, 'Y': 2
}
encodings = []
diPeptides = [aa1 + aa2 for aa1 in AA for aa2 in AA]
header = ['SampleName'] + ['DDE_{0}'.format(i) for i in diPeptides]
encodings.append(header)
myTM = []
for pair in diPeptides:
myTM.append((myCodons[pair[0]] / 61) * (myCodons[pair[1]] / 61))
AADict = {}
for i in range(len(AA)):
AADict[AA[i]] = i
for i in self.fasta_list:
name, sequence, label = i[0], re.sub('-', '', i[1]), i[2]
code = [name]
tmpCode = [0] * 400
for j in range(len(sequence) - 2 + 1):
tmpCode[AADict[sequence[j]] * 20 + AADict[sequence[j + 1]]] = tmpCode[AADict[sequence[j]] * 20 + AADict[
sequence[j + 1]]] + 1
if sum(tmpCode) != 0:
tmpCode = [i / sum(tmpCode) for i in tmpCode]
myTV = []
for j in range(len(myTM)):
myTV.append(myTM[j] * (1 - myTM[j]) / (len(sequence) - 1))
for j in range(len(tmpCode)):
tmpCode[j] = (tmpCode[j] - myTM[j]) / math.sqrt(myTV[j])
code = code + tmpCode
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _TPC(self, normalized=True):
try:
AA = 'ACDEFGHIKLMNPQRSTVWY'
encodings = []
triPeptides = ['TPC_' + aa1 + aa2 + aa3 for aa1 in AA for aa2 in AA for aa3 in AA]
header = ['SampleName'] + triPeptides
encodings.append(header)
AADict = {}
for i in range(len(AA)):
AADict[AA[i]] = i
for i in self.fasta_list:
name, sequence, label = i[0], re.sub('-', '', i[1]), i[2]
code = [name]
tmpCode = [0] * 8000
for j in range(len(sequence) - 3 + 1):
tmpCode[AADict[sequence[j]] * 400 + AADict[sequence[j + 1]] * 20 + AADict[sequence[j + 2]]] = tmpCode[AADict[sequence[j]] * 400 + AADict[sequence[j + 1]] * 20 + AADict[sequence[j + 2]]] + 1
if sum(tmpCode) != 0:
if normalized:
tmpCode = [i / sum(tmpCode) for i in tmpCode]
code = code + tmpCode
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
AA = 'ARNDCQEGHILKMFPSTWYV'
encodings = []
header = ['SampleName']
for i in range(1, len(self.fasta_list[0][1]) * 20 + 1):
header.append('Binary_' + str(i))
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
if aa == '-':
code = code + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
continue
for aa1 in AA:
tag = 1 if aa == aa1 else 0
code.append(tag)
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary_6bit(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
self.AA_group_list = [
'HRK',
'DENQ',
'C',
'STPAG',
'MILV',
'FYW',
]
encodings = []
header = ['SampleName']
header += ['Binary6_p%s_g%s' % (i + 1, j + 1) for i in range(len(self.fasta_list[0][1])) for j in
range(len(self.AA_group_list))]
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
for j in self.AA_group_list:
if aa in j:
code.append(1)
else:
code.append(0)
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary_5bit_type_1(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
self.AA_group_list = [
'GAVLMI',
'FYW',
'KRH',
'DE',
'STCPNQ',
]
self.AA_group_index = ['alphatic', 'aromatic', 'postivecharge', 'negativecharge', 'uncharge']
encodings = []
header = ['SampleName']
header += ['Binary5_t1_p%s_%s' % (i + 1, j) for i in range(len(self.fasta_list[0][1])) for j in self.AA_group_index]
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
for j in self.AA_group_list:
if aa in j:
code.append(1)
else:
code.append(0)
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary_5bit_type_2(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
aa_dict = {
'A': [0, 0, 0, 1, 1],
'C': [0, 0, 1, 0, 1],
'D': [0, 0, 1, 1, 0],
'E': [0, 0, 1, 1, 1],
'F': [0, 1, 0, 0, 1],
'G': [0, 1, 0, 1, 0],
'H': [0, 1, 0, 1, 1],
'I': [0, 1, 1, 0, 0],
'K': [0, 1, 1, 0, 1],
'L': [0, 1, 1, 1, 0],
'M': [1, 0, 0, 0, 1],
'N': [1, 0, 0, 1, 0],
'P': [1, 0, 0, 1, 1],
'Q': [1, 0, 1, 0, 0],
'R': [1, 0, 1, 0, 1],
'S': [1, 0, 1, 1, 0],
'T': [1, 1, 0, 0, 0],
'V': [1, 1, 0, 0, 1],
'W': [1, 1, 0, 1, 0],
'Y': [1, 1, 1, 0, 0],
}
encodings = []
header = ['SampleName']
for i in range(1, len(self.fasta_list[0][1]) * 5 + 1):
header.append('Binary5_t2_' + str(i))
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
if aa in aa_dict:
code += aa_dict[aa]
else:
code += [0, 0, 0, 0, 0]
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary_3bit_type_1(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
self.AA_group_list = [
'RKEDQN',
'GASTPHY',
'CLVIMFW',
]
self.AA_group_index = ['Polar', 'Neutral', 'Hydrophobicity']
encodings = []
header = ['SampleName']
header += ['Binary3_t1_p%s_g%s' % (i + 1, j) for i in range(len(self.fasta_list[0][1])) for j in self.AA_group_index]
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
for j in self.AA_group_list:
if aa in j:
code.append(1)
else:
code.append(0)
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary_3bit_type_2(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
self.AA_group_list = [
'GASTPD',
'NVEQIL',
'MHKFRYW',
]
self.AA_group_index = ['Volume_range(0-2.78)', 'Volumn_range(2.95-4.0)', 'Volumn_range(4.03-8.08)']
encodings = []
header = ['SampleName']
header += ['Binary3_t2_p%s_g%s' % (i + 1, j) for i in range(len(self.fasta_list[0][1])) for j in self.AA_group_index]
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
for j in self.AA_group_list:
if aa in j:
code.append(1)
else:
code.append(0)
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary_3bit_type_3(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
self.AA_group_list = [
'RKEDQN',
'GASTPHY',
'CLVIMFW',
]
self.AA_group_index = ['PolarityValue(4.9-6.2)', 'PolarityValue(8.0-9.2)', 'PolarityValue(10.4-13.0)']
encodings = []
header = ['SampleName']
header += ['Binary3_t3_p%s_g%s' % (i + 1, j) for i in range(len(self.fasta_list[0][1])) for j in self.AA_group_index]
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
for j in self.AA_group_list:
if aa in j:
code.append(1)
else:
code.append(0)
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary_3bit_type_4(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
self.AA_group_list = [
'GASDT',
'CPNVEQIL',
'KMHFRYW',
]
self.AA_group_index = ['PolarizabilityValue(0-0.108)', 'PolarizabilityValue(0.128-0.186)',
'PolarizabilityValue(0.219-0.409)']
encodings = []
header = ['SampleName']
header += ['Binary3_t4_p%s_g%s' % (i + 1, j) for i in range(len(self.fasta_list[0][1])) for j in self.AA_group_index]
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
for j in self.AA_group_list:
if aa in j:
code.append(1)
else:
code.append(0)
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary_3bit_type_5(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
self.AA_group_list = [
'KR',
'ANCQGHILMFPStWYV',
'DE',
]
self.AA_group_index = ['Positive', 'Neutral', 'Negative']
encodings = []
header = ['SampleName']
header += ['Binary3_t5_p%s_g%s' % (i + 1, j) for i in range(len(self.fasta_list[0][1])) for j in self.AA_group_index]
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
for j in self.AA_group_list:
if aa in j:
code.append(1)
else:
code.append(0)
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary_3bit_type_6(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
self.AA_group_list = [
'EALMQKRH',
'VIYCWFT',
'GNPSD',
]
self.AA_group_index = ['Helix', 'Strand', 'Coil']
encodings = []
header = ['SampleName']
header += ['Binary3_t6_p%s_g%s' % (i + 1, j) for i in range(len(self.fasta_list[0][1])) for j in self.AA_group_index]
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
for j in self.AA_group_list:
if aa in j:
code.append(1)
else:
code.append(0)
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _binary_3bit_type_7(self):
try:
if not self.is_equal:
self.error_msg = 'binary descriptor need fasta sequence with equal length.'
return False
self.AA_group_list = [
'ALFCGIVW',
'PKQEND',
'MPSTHY',
]
self.AA_group_index = ['Buried', 'Exposed', 'Intermediate']
encodings = []
header = ['SampleName']
header += ['Binary3_t7_p%s_g%s' % (i + 1, j) for i in range(len(self.fasta_list[0][1])) for j in self.AA_group_index]
encodings.append(header)
for i in self.fasta_list:
name, sequence, label = i[0], i[1], i[2]
code = [name]
for aa in sequence:
for j in self.AA_group_list:
if aa in j:
code.append(1)
else:
code.append(0)
encodings.append(code)
encodings = np.array(encodings)
self.encodings = pd.DataFrame(encodings[1:, 1:].astype(float), columns=encodings[0, 1:], index=encodings[1:, 0])
return True
except Exception as e:
self.error_msg = str(e)
return False
def _AESNN3(self):
try:
if not self.is_equal:
self.error_msg = 'AESNN3 descriptor need fasta sequence with equal length.'
return False
AESNN3_dict = {
'A': [-0.99, -0.61, 0.00],
'R': [ 0.28, -0.99, -0.22],
'N': [ 0.77, -0.24, 0.59],
'D': [ 0.74, -0.72, -0.35],
'C': [ 0.34, 0.88, 0.35],
'Q': [ 0.12, -0.99, -0.99],
'E': [ 0.59, -0.55, -0.99],
'G': [-0.79, -0.99, 0.10],
'H': [ 0.08, -0.71, 0.68],
'I': [-0.77, 0.67, -0.37],
'L': [-0.92, 0.31, -0.99],
'K': [-0.63, 0.25, 0.50],
'M': [-0.80, 0.44, -0.71],
'F': [ 0.87, 0.65, -0.53],
'P': [-0.99, -0.99, -0.99],