-
Notifications
You must be signed in to change notification settings - Fork 2
/
pkmer.py
68 lines (61 loc) · 1.56 KB
/
pkmer.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
import numpy as np
import itertools
import utils
import save
def generate(X, seqType, args):
'''
:param X:
:param seqType:
:param args:
:return:
'''
if seqType == 'DNA' or seqType == 'RNA':
p = [0]*(4**args.kTuple)
else:
if seqType == 'PROT':
p = [0] * (20 ** args.kTuple)
else: None
# print(p)
# print(len(p))
elements = utils.sequenceElements(seqType)
m = list(itertools.product(elements, repeat=args.kTuple))
terminusLength = args.terminusLength
# print(terminusLength)
T = []
for x in X:
# print(len(x))
x = x[:terminusLength]
# print(len(x))
# print('-----------------')
require = (terminusLength - args.kTuple + 1) - (len(x) - args.kTuple + 1)
# print(require)
t = []
kmers = utils.kmers(x, args.kTuple)
for kmer in kmers:
d = {''.join(i): 0 for i in m}
d[kmer] = 1
t.append(list(d.values()))
#end-for
if require > 0:
for i in range(require):
t.append(p)
#end-for
else: None
t = np.array(t)
# print(t.shape)
T.append(t)
# print(t.shape)
#end-for
T = np.array(T)
# print(T.shape)
totalFeature = 0
if seqType == 'DNA' or seqType == 'RNA':
totalFeature = (4**args.kTuple)
else:
if seqType == 'PROT':
totalFeature = (20**args.kTuple)
else:
None
# end-if
save.datasetSave(T, totalFeature, 'pkmer')
#end-def