Skip to content

Commit

Permalink
Propagating --do-not-raise-on-error as a CLI arg for IEDB constructor…
Browse files Browse the repository at this point in the history
…s. Also some logging updates
  • Loading branch information
julia326 committed Oct 13, 2020
1 parent 0a368d0 commit 92690a7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mhctools/__init__.py
Expand Up @@ -22,7 +22,7 @@
from .random_predictor import RandomBindingPredictor
from .unsupported_allele import UnsupportedAllele

__version__ = "1.8.1"
__version__ = "1.8.2"

__all__ = [
"BindingPrediction",
Expand Down
8 changes: 8 additions & 0 deletions mhctools/cli/args.py
Expand Up @@ -128,6 +128,11 @@ def add_mhc_args(arg_parser):
default="",
help="Comma or space separated list of allele (default HLA-A*02:01)")

mhc_options_arg_group.add_argument(
"--do-not-raise-on-error",
action="store_true", default=False,
help="If this arg is present, will not crash on error. Only applies to IEDB predictors")

return mhc_options_arg_group


Expand Down Expand Up @@ -180,4 +185,7 @@ def mhc_binding_predictor_from_args(args):
if args.mhc_predictor_path:
kwargs["program_name"] = args.mhc_predictor_path

if args.do_not_raise_on_error:
kwargs["raise_on_error"] = False

return mhc_class(**kwargs)
3 changes: 2 additions & 1 deletion mhctools/cli/script.py
Expand Up @@ -22,8 +22,9 @@
from pyensembl.fasta import parse_fasta_dictionary

from .args import make_mhc_arg_parser, mhc_binding_predictor_from_args
from mhctools.logging import get_logger


logging.config.fileConfig(pkg_resources.resource_filename(__name__, 'logging.conf'))
logger = logging.getLogger(__name__)


Expand Down
10 changes: 5 additions & 5 deletions mhctools/iedb.py
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

from __future__ import print_function, division, absolute_import
import logging
import io

# pylint: disable=import-error
Expand All @@ -31,6 +30,7 @@
from .common import seq_to_str, check_sequence_dictionary
from .binding_prediction import BindingPrediction
from .binding_prediction_collection import BindingPredictionCollection
from .logging import get_logger

"""
A note about prediction methods, copied from the IEDB website:
Expand All @@ -50,7 +50,7 @@
"""


logger = logging.getLogger(__name__)
logger = get_logger(__name__)


VALID_CLASS_I_METHODS = [
Expand Down Expand Up @@ -195,7 +195,7 @@ def predict_peptides(self, peptides):
binding_predictions,
peptides=peptides,
alleles=self.alleles)
except ValueError as e:
except Exception as e:
if self.raise_on_error:
raise e
else:
Expand Down Expand Up @@ -251,7 +251,7 @@ def predict_subsequences(self, sequence_dict, peptide_lengths=None):
affinity=row['ic50'],
percentile_rank=row['rank'],
prediction_method_name="iedb-" + self.prediction_method))
except ValueError as e:
except Exception as e:
if self.raise_on_error:
raise e
else:
Expand All @@ -262,7 +262,7 @@ def predict_subsequences(self, sequence_dict, peptide_lengths=None):
binding_predictions,
alleles=normalized_alleles,
peptides=expected_peptides)
except ValueError as e:
except Exception as e:
if self.raise_on_error:
raise e
else:
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions mhctools/logging.py
@@ -0,0 +1,10 @@
from __future__ import print_function, division, absolute_import

import logging
import logging.config
import pkg_resources


def get_logger(name):
logging.config.fileConfig(pkg_resources.resource_filename('mhctools', 'logging.conf'))
return logging.getLogger(name)
10 changes: 6 additions & 4 deletions setup.py
Expand Up @@ -42,12 +42,12 @@
name='mhctools',
version=version,
description="Python interface to running command-line and web-based MHC binding predictors",
author="Alex Rubinsteyn",
author_email="alex.rubinsteyn@mssm.edu",
author="Alex Rubinsteyn, Julia Kodysh, Tim O'Donnell",
author_email="alex@openvax.org, julia@openvax.org, tim@openvax.org",
url="https://github.com/openvax/mhctools",
license="http://www.apache.org/licenses/LICENSE-2.0.html",
classifiers=[
'Development Status :: 3 - Alpha',
'Development Status :: 4 - Beta',
'Environment :: Console',
'Operating System :: OS Independent',
'Intended Audience :: Science/Research',
Expand All @@ -68,7 +68,9 @@
long_description=readme_markdown,
long_description_content_type="text/markdown",
packages=['mhctools', 'mhctools.cli'],
package_data={'mhctools.cli': ['logging.conf']},
package_data={
'mhctools.cli': ['logging.conf'],
'mhctools': ['logging.conf']},
entry_points={
'console_scripts': [
'mhctools = mhctools.cli.script:main'
Expand Down

0 comments on commit 92690a7

Please sign in to comment.