althonos / pyhmmer

Cython bindings and Python interface to HMMER3.
https://pyhmmer.readthedocs.io
MIT License
120 stars 12 forks source link

Uninformative error when input hmm file contains profiles with different alphabets #70

Closed Sann5 closed 2 months ago

Sann5 commented 3 months ago

Assuming we have a hmm file containing profiles with different alphabets, and we run the following code:

  1. Download and unzip amino_dna.hmm.zip

  2. Open python, adjust the path to the file and run

    from pyhmmer.plan7 import HMMFile
    fp = "path_to_the_file/amino_dna.hmm"
    with HMMFile(fp) as hmm_file:
    hmm_profiles = list(hmm_file)

The following will raise a TypeError with an uninformative message.

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "pyhmmer/plan7.pyx", line 3563, in pyhmmer.plan7.HMMFile.__next__
  File "pyhmmer/plan7.pyx", line 3641, in pyhmmer.plan7.HMMFile.read
TypeError: an integer is required

It would be nice if instead, the message said something like: "Found profiles with different alphabets."

althonos commented 3 months ago

Actually, the error you get was raised in the code that was preparing a nicer exception message, but it had a bug and raised a TypeError instead. I fixed that and changed HMMFile.read and HMMPressedFile.read to raise AlphabetMismatch in that case, either because the file contains HMMs in multiple alphabets, or because the alphabet given to create the HMMFile is inconsistent with the alphabets of the HMMs in the file.

althonos commented 2 months ago

Fixed in v0.10.13.