diff --git a/mhcflurry/amino_acid.py b/mhcflurry/amino_acid.py index f40225612f6373c6609b3aed60fa23de14c2c90b..9c06fada8027970417a92279219eaf4b26676c8c 100644 --- a/mhcflurry/amino_acid.py +++ b/mhcflurry/amino_acid.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015. Mount Sinai School of Medicine +# Copyright (c) 2016. Mount Sinai School of Medicine # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,6 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import ( + print_function, + division, + absolute_import, +) import numpy as np diff --git a/mhcflurry/class1_allele_specific_hyperparameters.py b/mhcflurry/class1_allele_specific_hyperparameters.py index 33e15cdba88b2b7ea3dd5a52ef7a4925606682c0..cfdf846bd810b717c703f40820e5bc3433e229ae 100644 --- a/mhcflurry/class1_allele_specific_hyperparameters.py +++ b/mhcflurry/class1_allele_specific_hyperparameters.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015. Mount Sinai School of Medicine +# Copyright (c) 2016. Mount Sinai School of Medicine # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/mhcflurry/data.py b/mhcflurry/data.py index 1ea71212d1447e2f13dd4be3c9b5a88f83268445..59c2be51b01e75b1adee2d1871562e69790b0ad6 100644 --- a/mhcflurry/data.py +++ b/mhcflurry/data.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015. Mount Sinai School of Medicine +# Copyright (c) 2016. Mount Sinai School of Medicine # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/mhcflurry/feedforward.py b/mhcflurry/feedforward.py index e401b4b823eda2898fdcb7e51dbda5251501b4af..e526d6df23bd9c78e7698c632de098fec4453201 100644 --- a/mhcflurry/feedforward.py +++ b/mhcflurry/feedforward.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015. Mount Sinai School of Medicine +# Copyright (c) 2016. Mount Sinai School of Medicine # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/mhcflurry/imputation.py b/mhcflurry/imputation.py index 1bcb08dcb45117b8c74ef120adef1504e4e50c4e..cddeb5e34e50e85118f81076ac9dff71dfe22ee0 100644 --- a/mhcflurry/imputation.py +++ b/mhcflurry/imputation.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015. Mount Sinai School of Medicine +# Copyright (c) 2016. Mount Sinai School of Medicine # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ from __future__ import ( absolute_import, ) from collections import defaultdict +import logging + import numpy as np from fancyimpute.dictionary_helpers import ( dense_matrix_from_nested_dictionary @@ -34,6 +36,21 @@ from .data import ( create_allele_data_from_peptide_to_ic50_dict, ) +def _check_dense_pMHC_array(X, peptide_list, allele_list): + if len(peptide_list) != len(set(peptide_list)): + raise ValueError("Duplicate peptides detected in peptide list") + if len(allele_list) != len(set(allele_list)): + raise ValueError("Duplicate alleles detected in allele list") + n_rows, n_cols = X.shape + if n_rows != len(peptide_list): + raise ValueError( + "Expected dense array with shape %s to have %d rows" % ( + X.shape, len(peptide_list))) + if n_cols != len(allele_list): + raise ValueError( + "Expected dense array with shape %s to have %d columns" % ( + X.shape, len(allele_list))) + def prune_dense_matrix_and_labels( X, peptide_list, @@ -89,6 +106,7 @@ def prune_dense_matrix_and_labels( X = X[:, keep_allele_indices] observed_mask = observed_mask[:, keep_allele_indices] allele_list = [allele_list[i] for i in keep_allele_indices] + _check_dense_pMHC_array(X, peptide_list, allele_list) return X, peptide_list, allele_list @@ -135,6 +153,8 @@ def create_incomplete_dense_pMHC_matrix( X, peptide_list, allele_list = \ dense_matrix_from_nested_dictionary(peptide_to_allele_to_affinity_dict) + _check_dense_pMHC_array(X, peptide_list, allele_list) + return prune_dense_matrix_and_labels( X, peptide_list, @@ -187,6 +207,7 @@ def create_imputed_datasets( # if all entries in the matrix are already filled in then don't # try using an imputation algorithm since it might raise an # exception. + logging.warn("No missing values, using original data instead of imputation") X_complete = X_incomplete else: X_complete = imputer.complete(X_incomplete) diff --git a/mhcflurry/paths.py b/mhcflurry/paths.py index ec9e8377f431a33a4f6f7ec0f5d5538eb7486991..1ef41eb9869c32ab0dc7776b6e022136311c54e2 100644 --- a/mhcflurry/paths.py +++ b/mhcflurry/paths.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015. Mount Sinai School of Medicine +# Copyright (c) 2016. Mount Sinai School of Medicine # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,6 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import ( + print_function, + division, + absolute_import, +) from os.path import join from appdirs import user_data_dir diff --git a/mhcflurry/peptide_encoding.py b/mhcflurry/peptide_encoding.py index 450456803d8d32050179ced780776a532aea55c1..cad5f53cf1bdc8d8caefb76a11a64ca026c03b46 100644 --- a/mhcflurry/peptide_encoding.py +++ b/mhcflurry/peptide_encoding.py @@ -12,6 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import ( + print_function, + division, + absolute_import, +) import itertools import logging diff --git a/mhcflurry/predictor_base.py b/mhcflurry/predictor_base.py index dba570da307c3b594f566a6ce9cfaf9904157418..a335158cdafea545dde7a9f22ec68648903ba6c1 100644 --- a/mhcflurry/predictor_base.py +++ b/mhcflurry/predictor_base.py @@ -12,6 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import ( + print_function, + division, + absolute_import, +) from collections import defaultdict import numpy as np