Skip to content
Open
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
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
31 changes: 26 additions & 5 deletions prody/sequence/msa.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,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 @@ -163,8 +171,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
Copy Markdown
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?

@jamesmkrieger jamesmkrieger Oct 25, 2021

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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 @@ -545,7 +557,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
8 changes: 6 additions & 2 deletions prody/sequence/msafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,12 @@ def setSlice(self, slice):
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 @@ -48,7 +48,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
Loading