Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions prody/dynamics/heatmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

__author__ = 'Ahmet Bakan, Anindita Dutta'

from numpy import arange, fromstring, array
from numpy import arange, fromstring, frombuffer, array

from prody.utilities import openFile, intorfloat, startswith, addext

Expand Down Expand Up @@ -131,7 +131,11 @@ def parseHeatmap(heatmap, **kwargs):
numbers.append(items[:nnums])
else:
items = [arr]
heatmap.append(fromstring(items[-1], float, sep=';'))

try:
heatmap.append(fromstring(items[-1], float, sep=';'))
except:
heatmap.append(frombuffer(items[-1], float, sep=';'))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fixes might be too ad-hoc. There should be a better way to determine which function to use. In addition, it is better the catch the specific error than a general "except"


heatmap = array(heatmap)
if nnums:
Expand Down
12 changes: 10 additions & 2 deletions prody/dynamics/nmdfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ def parseNMD(filename, type=NMA):

line, coords = atomic.pop('coordinates', None)
if coords is not None:
coords = np.fromstring(coords, dtype=float, sep=' ')
try:
coords = np.fromstring(coords, dtype=float, sep=' ')
except:
coords = np.frombuffer(coords, dtype=float, sep=' ')

dof = coords.shape[0]
if dof % 3 != 0:
LOGGER.warn('Coordinate data in {0} at line {1} is corrupt '
Expand Down Expand Up @@ -325,7 +329,11 @@ def parseNMD(filename, type=NMA):
eigvals = []
count = 0
for i, (line, mode) in enumerate(modes):
mode = np.fromstring(mode, dtype=float, sep=' ')
try:
mode = np.fromstring(mode, dtype=float, sep=' ')
except:
mode = np.frombuffer(mode, dtype=float, sep=' ')

diff = len(mode) - dof
if diff < 0 or diff > 2:
LOGGER.warn('Mode data in {0} at line {1} is corrupt.'
Expand Down
19 changes: 16 additions & 3 deletions prody/proteins/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,15 +1100,28 @@ def buildBiomolecules(header, atoms, biomol=None):
for times in range(int((len(mt)) / 4)):
rotation = np.zeros((3, 3))
translation = np.zeros(3)
line0 = np.fromstring(mt[times*4+1], sep=' ')

try:
line0 = np.fromstring(mt[times*4+1], sep=' ')
except:
line0 = np.frombuffer(mt[times*4+1], sep=' ')
rotation[0, :] = line0[:3]
translation[0] = line0[3]
line1 = np.fromstring(mt[times*4+2], sep=' ')

try:
line1 = np.fromstring(mt[times*4+2], sep=' ')
except:
line1 = np.frombuffer(mt[times*4+2], sep=' ')
rotation[1, :] = line1[:3]
translation[1] = line1[3]
line2 = np.fromstring(mt[times*4+3], sep=' ')

try:
line2 = np.fromstring(mt[times*4+3], sep=' ')
except:
line2 = np.frombuffer(mt[times*4+3], sep=' ')
rotation[2, :] = line2[:3]
translation[2] = line2[3]

t = Transformation(rotation, translation)

newag = atoms.select('chain ' + ' or chain '.join(mt[times*4+0]))
Expand Down
31 changes: 26 additions & 5 deletions prody/sequence/msa.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,16 @@ def __getitem__(self, index):
if isinstance(rows, list):
rows = self.getIndex(rows) or rows
elif isinstance(rows, int):
return Sequence(self._msa[rows, cols].tobytes(),
self._labels[rows])
if PY3K:
try:
return Sequence(self._msa[rows, cols].tostring().decode(),
self._labels[rows])
except:
return Sequence(self._msa[rows, cols].tobytes().decode(),
self._labels[rows])
else:
return Sequence(self._msa[rows, cols].tostring(),
self._labels[rows])
elif isinstance(rows, str):
try:
rows = self._mapping[rows]
Expand All @@ -164,8 +172,12 @@ def __getitem__(self, index):
.format(index))
else:
if isinstance(rows, int):
return Sequence(self._msa[rows, cols].tobytes(),
self._labels[rows])
try:
return Sequence(self._msa[rows, cols].tostring(),
self._labels[rows])
except:
return Sequence(self._msa[rows, cols].tobytes(),
self._labels[rows])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue with these lines. Maybe use PY3K macro to check this?

Copy link
Contributor Author

@jamesmkrieger jamesmkrieger Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the following block in the Sequence object, on which we could maybe base these:

        if PY3K:
            try:
                return self._array.tostring().decode()
            except:
                return self._array.tobytes().decode()
        else:
            return self._array.tostring()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now tried this


if cols is None:
msa = self._msa[rows]
Expand Down Expand Up @@ -546,7 +558,16 @@ def refineMSA(msa, index=None, label=None, rowocc=None, seqid=None, colocc=None,
from prody.utilities import GAP_PENALTY, GAP_EXT_PENALTY, ALIGNMENT_METHOD

chseq = chain.getSequence()
algn = alignBioPairwise(pystr(arr[index].tobytes().upper()), pystr(chseq),

if PY3K:
try:
arr2 = arr[index].tostring().decode()
except:
arr2 = arr[index].tobytes().decode()
else:
arr2 = arr[index].tostring()

algn = alignBioPairwise(pystr(arr2.upper()), pystr(chseq),
"local",
MATCH_SCORE, MISMATCH_SCORE,
GAP_PENALTY, GAP_EXT_PENALTY,
Expand Down
15 changes: 11 additions & 4 deletions prody/sequence/msafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from os.path import isfile, splitext, split, getsize

from numpy import array, fromstring, empty
from numpy import array, fromstring, empty, frombuffer

from .sequence import splitSeqLabel, Sequence

Expand Down Expand Up @@ -425,15 +425,22 @@ def setSlice(self, slice):
try:
seq[slice]
except Exception:
arr = fromstring(seq, '|S1')
try:
arr = fromstring(seq, '|S1')
except:
arr = frombuffer(seq, '|S1')
try:
arr[slice]
except Exception:
raise TypeError('invalid slice: ' + repr(slice))
else:
self._slice = slice
self._slicer = lambda seq, slc=slice: fromstring(seq,
'|S1')[slc].tobytes()
try:
self._slicer = lambda seq, slc=slice: fromstring(seq,
'|S1')[slc].tostring()
except:
self._slicer = lambda seq, slc=slice: fromstring(seq,
'|S1')[slc].tobytes()
else:
self._slice = slice
self._slicer = lambda seq, slc=slice: seq[slc]
Expand Down
5 changes: 4 additions & 1 deletion prody/sequence/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def _array(self):
def __str__(self):

if PY3K:
return self._array.tobytes().decode()
try:
return self._array.tostring().decode()
except:
return self._array.tobytes().decode()
else:
return self._array.tobytes()

Expand Down