hammerlab / cohorts

Utilities for analyzing mutations and neoepitopes in patient cohorts
Apache License 2.0
20 stars 4 forks source link

ImportError: cannot import name 'AlleleParseError' #233

Closed jburos closed 7 years ago

jburos commented 7 years ago

A user reported this issue as part of issue #227, spinning it off into it's own thing.

When trying to create a cohort object with mhcnames v 1.2.0 in python 3.6, he encountered the following error:

ImportError: cannot import name 'AlleleParseError' 

He reported using mhcnames vs 1.2.0 & mhctools v 1.5.0.

I put together the following test case in an attempt to reproduce the error, which I then tested as I upgraded first mhcnames to v 1.2.0 & then mhctools to v 1.5.0.

The following worked fine with mhcnames v 1.20 & mhctools v 1.3.0, but 'broke' when I updated mhctools to 1.5.0.

from cohorts import Patient, Cohort
from cohorts.functions import neoantigen_count
patient_1 = Patient(
    id="patient_1",
    os=70,
    pfs=24,
    hla_alleles = "A2",
    variants = ['/mnt/disks/test-data/ba3e53e37140b56f139bae6ab44effc0818951d851dc73a3e23f8971b6604db8gatk_bqsr28776c18cc782b1677cc621621cd5023gatk_bqsr_mutect-default-merged_polyphen-snpeff.vcf'],
    deceased=True,
    progressed=True,
    benefit=False
)

patient_2 = Patient(
    id="patient_2",
    os=100,
    pfs=50,
    variants = ['/mnt/disks/test-data/passed_somatic_combined_polyphen-snpeff.vcf'],
    hla_alleles = "B2",
    deceased=False,
    progressed=True,
    benefit=False
)

cohort = Cohort(
    patients=[patient_1, patient_2],
    cache_dir="/mnt/disks/test-data/cache-dir"
)

cohort.plot_benefit(on=neoantigen_count)

The traceback when using mhctools 1.5.0 is included here:

(rcc) jacquelineburos@jacki2:~/projects/cohorts2/test$ python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cohorts import Patient, Cohort
Using TensorFlow backend.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jacquelineburos/projects/cohorts/cohorts/__init__.py", line 15, in <module>
    from .cohort import Cohort
  File "/home/jacquelineburos/projects/cohorts/cohorts/cohort.py", line 42, in <module>
    from mhctools import NetMHCcons, EpitopeCollection
  File "/home/jacquelineburos/miniconda3/envs/rcc/lib/python3.5/site-packages/mhctools/__init__.py", line 12, in <module>
    from .netmhc import NetMHC
  File "/home/jacquelineburos/miniconda3/envs/rcc/lib/python3.5/site-packages/mhctools/netmhc.py", line 20, in <module>
    from .netmhc3 import NetMHC3
  File "/home/jacquelineburos/miniconda3/envs/rcc/lib/python3.5/site-packages/mhctools/netmhc3.py", line 17, in <module>
    from .base_commandline_predictor import BaseCommandlinePredictor
  File "/home/jacquelineburos/miniconda3/envs/rcc/lib/python3.5/site-packages/mhctools/base_commandline_predictor.py", line 24, in <module>
    from mhcnames.parsing_helpers import AlleleParseError
ImportError: cannot import name 'AlleleParseError'
>>> from cohorts.functions import neoantigen_count
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jacquelineburos/projects/cohorts/cohorts/__init__.py", line 15, in <module>
    from .cohort import Cohort
  File "/home/jacquelineburos/projects/cohorts/cohorts/cohort.py", line 42, in <module>
    from mhctools import NetMHCcons, EpitopeCollection
  File "/home/jacquelineburos/miniconda3/envs/rcc/lib/python3.5/site-packages/mhctools/__init__.py", line 12, in <module>
    from .netmhc import NetMHC
  File "/home/jacquelineburos/miniconda3/envs/rcc/lib/python3.5/site-packages/mhctools/netmhc.py", line 20, in <module>
    from .netmhc3 import NetMHC3
  File "/home/jacquelineburos/miniconda3/envs/rcc/lib/python3.5/site-packages/mhctools/netmhc3.py", line 17, in <module>
    from .base_commandline_predictor import BaseCommandlinePredictor
  File "/home/jacquelineburos/miniconda3/envs/rcc/lib/python3.5/site-packages/mhctools/base_commandline_predictor.py", line 24, in <module>
    from mhcnames.parsing_helpers import AlleleParseError
ImportError: cannot import name 'AlleleParseError'

Which, in fact, doesn't require any test data since the error is on

from cohorts.functions import neoantigen_count
jburos commented 7 years ago

Linking to related PR: hammerlab/mhctools#109

jburos commented 7 years ago

Strange that this came up, since mhctools is limited in our requirements.txt

mhctools>=0.3.0, <0.4.0