Skip to content
Snippets Groups Projects
Commit 45991e62 authored by Tim O'Donnell's avatar Tim O'Donnell
Browse files

fix subtle python 2 issues

parent 9ff964f5
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -22,7 +22,6 @@ parallelism.configure_joblib()
__all__ = [
"Class1BindingPredictor",
"class1_allele_specific",
"predict",
"parallelism",
"__version__",
......
......@@ -22,6 +22,7 @@ from __future__ import (
)
import tempfile
import os
import numpy as np
......@@ -121,9 +122,16 @@ class Class1BindingPredictor(Class1AlleleSpecificKmerIC50PredictorBase):
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):
"""
......
......@@ -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
......
......@@ -36,7 +36,11 @@ the 'fork' mode causes a library we use to hang. We have to instead use
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
......
......@@ -14,7 +14,11 @@
'''
Load predictors
'''
from __future__ import (
print_function,
division,
absolute_import,
)
import pickle
from os.path import join
......
from __future__ import absolute_import
from __future__ import (
print_function,
division,
absolute_import,
)
import sklearn
import numpy
import scipy
......
......@@ -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
......@@ -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)):
......
......@@ -28,7 +28,11 @@ Get the path to a download:
Summarize available and fetched downloads:
$ mhcflurry-downloads info
'''
from __future__ import (
print_function,
division,
absolute_import,
)
import sys
import argparse
import logging
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment