Skip to content

Commit

Permalink
fixed izip import for Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Simkovic committed Jun 18, 2017
1 parent c9e9af2 commit ae77d0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 10 additions & 8 deletions conkit/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

import collections
import copy
import itertools
import numpy as np
import operator
import sys

if sys.version_info.major < 3:
from itertools import izip as zip

try:
import scipy.spatial
SCIPY = True
Expand Down Expand Up @@ -1052,7 +1054,7 @@ def precision(self):
# np.unique(..., return_counts=True) added in numpy > 1.9, backward compatibility
# requires we do it the old way :-/
s = np.asarray([c.status for c in self])
cdict = dict(itertools.izip(np.unique(s), np.asarray([s[s == i].shape[0] for i in np.unique(s)])))
cdict = dict(zip(np.unique(s), np.asarray([s[s == i].shape[0] for i in np.unique(s)])))
fp_count = cdict[Contact._MISMATCH] if Contact._MISMATCH in cdict else 0.0
uk_count = cdict[Contact._UNKNOWN] if Contact._UNKNOWN in cdict else 0.0
tp_count = cdict[Contact._MATCH] if Contact._MATCH in cdict else 0.0
Expand Down Expand Up @@ -1089,7 +1091,7 @@ def repr_sequence(self):
"""
if isinstance(self.sequence, Sequence):
res1_seqs, res2_seqs = list(itertools.izip(*[contact.id for contact in self]))
res1_seqs, res2_seqs = list(zip(*[contact.id for contact in self]))
res_seqs = set(sorted(res1_seqs + res2_seqs))
return self._construct_repr_sequence(list(res_seqs))
else:
Expand Down Expand Up @@ -1118,7 +1120,7 @@ def repr_sequence_altloc(self):
"""
if isinstance(self.sequence, Sequence):
res1_seqs, res2_seqs = list(itertools.izip(*[(contact.res1_altseq, contact.res2_altseq) for contact in self]))
res1_seqs, res2_seqs = list(zip(*[(contact.res1_altseq, contact.res2_altseq) for contact in self]))
res_seqs = set(sorted(res1_seqs + res2_seqs))
return self._construct_repr_sequence(list(res_seqs))
else:
Expand Down Expand Up @@ -1366,7 +1368,7 @@ def calculate_scalar_score(self):
"""
raw_scores = np.asarray([c.raw_score for c in self])
sca_scores = raw_scores / np.mean(raw_scores)
for contact, sca_score in itertools.izip(self, sca_scores):
for contact, sca_score in zip(self, sca_scores):
contact.scalar_score = sca_score

def find(self, indexes, altloc=False):
Expand Down Expand Up @@ -1592,7 +1594,7 @@ def rescale(self, inplace=False):
if np.isnan(norm_raw_scores).all():
norm_raw_scores = np.where(norm_raw_scores == np.isnan, 0, 1)

for contact, norm_raw_score in itertools.izip(contact_map, norm_raw_scores):
for contact, norm_raw_score in zip(contact_map, norm_raw_scores):
contact.raw_score = norm_raw_score

return contact_map
Expand Down Expand Up @@ -1661,7 +1663,7 @@ def _create_keymap(contact_map, altloc=False):
contact_map_keymap[res1_index] = pos1
contact_map_keymap[res2_index] = pos2
contact_map_keymap_sorted = sorted(list(contact_map_keymap.items()), key=lambda x: int(x[0]))
return list(itertools.izip(*contact_map_keymap_sorted))[1]
return list(zip(*contact_map_keymap_sorted))[1]

@staticmethod
def _find_single(contact_map, index):
Expand Down Expand Up @@ -1692,7 +1694,7 @@ def _reindex(keymap):
@staticmethod
def _renumber(contact_map, self_keymap, other_keymap):
"""Renumber the contact map based on the mapping of self and other keymaps"""
for self_residue, other_residue in itertools.izip(self_keymap, other_keymap):
for self_residue, other_residue in zip(self_keymap, other_keymap):
if isinstance(self_residue, _Gap):
continue
for contact in ContactMap._find_single(contact_map, self_residue.res_seq):
Expand Down
8 changes: 6 additions & 2 deletions conkit/io/PdbIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

import collections
import itertools
import sys
import warnings

if sys.version_info.major < 3:
from itertools import izip as zip

from Bio.PDB import MMCIFParser
from Bio.PDB import PDBParser

Expand Down Expand Up @@ -62,8 +66,8 @@ def _chain_contacts(self, chain1, chain2):
assert len(range1) == len(chain1)
assert len(range2) == len(chain2)

for (resseq1_alt, residue1), (resseq2_alt, residue2) in itertools.product(list(itertools.izip(range1, chain1)),
list(itertools.izip(range2, chain2))):
for (resseq1_alt, residue1), (resseq2_alt, residue2) in itertools.product(list(zip(range1, chain1)),
list(zip(range2, chain2))):
for atom1, atom2 in itertools.product(residue1, residue2):

# Ignore duplicates
Expand Down

0 comments on commit ae77d0d

Please sign in to comment.