Skip to content

Commit

Permalink
fix subtle python 2 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timodonnell committed Sep 16, 2016
1 parent 9ff964f commit 45991e6
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 15 deletions.
5 changes: 2 additions & 3 deletions mhcflurry/__init__.py
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from . import class1_allele_specific
from .class1_allele_specific import Class1BindingPredictor
from .class1_allele_specific.class1_binding_predictor import (
Class1BindingPredictor)
from .predict import predict
from .package_metadata import __version__
from . import parallelism
Expand All @@ -22,7 +22,6 @@

__all__ = [
"Class1BindingPredictor",
"class1_allele_specific",
"predict",
"parallelism",
"__version__",
Expand Down
10 changes: 9 additions & 1 deletion mhcflurry/class1_allele_specific/class1_binding_predictor.py
Expand Up @@ -22,6 +22,7 @@
)

import tempfile
import os

import numpy as np

Expand Down Expand Up @@ -121,9 +122,16 @@ def __getstate__(self):
def __setstate__(self, state):
model_bytes = state.pop('model_bytes')
self.__dict__.update(state)
with tempfile.NamedTemporaryFile(suffix='.hdf5', delete=True) as fd:
fd = tempfile.NamedTemporaryFile(suffix='.hdf5', delete=False)
try:
fd.write(model_bytes)

# HDF5 has issues when the file is open multiple times, so we close
# it here before loading it into keras.
fd.close()
self.model = keras.models.load_model(fd.name)
finally:
os.unlink(fd.name)

def get_weights(self):
"""
Expand Down
7 changes: 5 additions & 2 deletions mhcflurry/class1_allele_specific/cross_validation.py
Expand Up @@ -12,8 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

from __future__ import (
print_function,
division,
absolute_import,
)
import collections
import logging

Expand Down
6 changes: 5 additions & 1 deletion mhcflurry/class1_allele_specific/cv_and_train_command.py
Expand Up @@ -36,7 +36,11 @@
the 'spawn' or 'forkserver' modes. See:
https://pythonhosted.org/joblib/parallel.html#bad-interaction-of-multiprocessing-and-third-party-libraries
'''

from __future__ import (
print_function,
division,
absolute_import,
)
import sys
import argparse
import json
Expand Down
6 changes: 5 additions & 1 deletion mhcflurry/class1_allele_specific/load.py
Expand Up @@ -14,7 +14,11 @@
'''
Load predictors
'''

from __future__ import (
print_function,
division,
absolute_import,
)
import pickle
from os.path import join

Expand Down
7 changes: 5 additions & 2 deletions mhcflurry/class1_allele_specific/scoring.py
@@ -1,5 +1,8 @@
from __future__ import absolute_import

from __future__ import (
print_function,
division,
absolute_import,
)
import sklearn
import numpy
import scipy
Expand Down
9 changes: 6 additions & 3 deletions mhcflurry/class1_allele_specific/train.py
Expand Up @@ -12,8 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

from __future__ import (
print_function,
division,
absolute_import,
)
import collections
import logging
import time
Expand Down Expand Up @@ -277,7 +280,7 @@ def train_across_models_and_folds(
pandas.DataFrame
'''
if cartesian_product_of_folds_and_models:
tasks_per_model = int(math.ceil(len(folds) / folds_per_task))
tasks_per_model = int(math.ceil(float(len(folds)) / folds_per_task))
fold_index_groups = [[] for _ in range(tasks_per_model)]
index_group = 0
for index in range(len(folds)):
Expand Down
6 changes: 5 additions & 1 deletion mhcflurry/downloads_command.py
Expand Up @@ -28,7 +28,11 @@
Summarize available and fetched downloads:
$ mhcflurry-downloads info
'''

from __future__ import (
print_function,
division,
absolute_import,
)
import sys
import argparse
import logging
Expand Down
6 changes: 5 additions & 1 deletion mhcflurry/hyperparameters.py
Expand Up @@ -11,7 +11,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import (
print_function,
division,
absolute_import,
)
import itertools


Expand Down

0 comments on commit 45991e6

Please sign in to comment.