Skip to content

Commit f3a1a20

Browse files
committed
fix errors in handling dimensions
1 parent a953f4a commit f3a1a20

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

protencoder/coMatrix.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,37 @@ def encode(self):
7474
encoded[i][k][j] = score
7575
else:
7676
break
77-
# encoded = np.mean(encoded, axis=0, dtype='float32')
78-
encoded = encoded.reshape((encoded.shape[1], encoded.shape[2], 3))
7977
encoded = self.co_resize(encoded)
8078
self.handler.seqDict[prot] = encoded.astype('uint8')
8179

8280
def co_resize(self, prot):
8381
if prot.shape[1] > self.dsize[0]:
84-
x = resize(prot, self.dsize, interpolation=INTER_AREA)
82+
x = np.moveaxis(prot, 0, -1)
83+
x = resize(x, self.dsize, interpolation=INTER_AREA)
84+
x = np.moveaxis(x, -1, 0)
8585
elif prot.shape[1] < self.dsize[0]:
8686
if self.action == "repeat":
8787
repeatSize = int(self.dsize[0]/prot.shape[1])
8888
x = np.repeat(prot, repeatSize, axis=1)
8989
x = np.repeat(x, repeatSize, axis=2)
9090
padSize = self.dsize[0] - x.shape[1]
91-
x = np.pad(prot, ((0, 0), (0, padSize), (0, padSize)),
91+
x = np.pad(x, ((0, 0), (0, padSize), (0, padSize)),
9292
mode="constant")
9393
elif self.action == "tile":
9494
tileSize = int(self.dsize[0]/prot.shape[1])+1
95-
x = np.tile(prot, (0, tileSize, tileSize))
95+
x = np.tile(prot, (1, tileSize, tileSize))
9696
x = x[:, :self.dsize[0], :self.dsize[0]]
9797
elif self.action == "resize":
98-
x = resize(prot, self.dsize, interpolation=INTER_LINEAR)
98+
x = np.moveaxis(prot, 0, -1)
99+
x = resize(x, self.dsize, interpolation=INTER_LINEAR)
100+
x = np.moveaxis(x, -1, 0)
99101
elif self.action == "pad":
100102
padSize = self.dsize[0] - prot.shape[1]
101103
x = np.pad(prot, ((0, 0), (0, padSize), (0, padSize)),
102104
mode="constant")
103105
else:
104106
x = prot
105-
return x
107+
return np.moveaxis(x, 0, -1)
106108

107109
def read(self, seqPath):
108110
self.handler.read_fasta(seqPath)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
test_suite='tests',
5050
tests_require=test_requirements,
5151
url='https://github.com/anegm98/protencoder',
52-
version='1.4.2',
52+
version='1.4.3',
5353
zip_safe=False,
5454
package_data={'protencoder': ['data/*']}
5555
)

0 commit comments

Comments
 (0)